fix: add endpoint for muc creation
This commit is contained in:
@@ -26,6 +26,31 @@ try {
|
||||
console.log("error while connect to telnet:", error);
|
||||
}
|
||||
|
||||
async function doesMucExist(jid) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var queryparams = [];
|
||||
queryparams[0] = jid.split("@")[0];
|
||||
queryparams[1] = jid.split("@")[1];
|
||||
queryparams[2] = "jid";
|
||||
query = "select prosody.value from prosody where prosody.host=$2 and prosody.user=$1 and prosody.key=$3";
|
||||
dbpool.query(query, queryparams, async function (derr, dres) {
|
||||
if (derr == null) {
|
||||
// console.log("dres.rows: ", dres.rows);
|
||||
if (dres.rowCount > 0) {
|
||||
resolve(1);
|
||||
} else {
|
||||
resolve(0);
|
||||
}
|
||||
} else {
|
||||
console.log("db err: ", derr);
|
||||
resolve(-1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setMucData(actor, muc, data) {
|
||||
var query = "select value::jsonb as config from prosody where prosody.user=$1 and prosody.host=$2 and prosody.key=$3;"
|
||||
var queryparams = [];
|
||||
@@ -453,6 +478,74 @@ router.post('/affiliations/:target', async function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* create new groupchat
|
||||
* payload:
|
||||
* { jid: newgroupjid,
|
||||
* owner: owner of new group,
|
||||
* members: [],
|
||||
* subject: subject of the group
|
||||
* }
|
||||
*/
|
||||
|
||||
router.post('/creategroup', async function (req, res) {
|
||||
let mucJidValid = true;
|
||||
if (req.body.jid && req.body.jid != "") {
|
||||
if (!req.body.jid.toLowerCase().endsWith("@" + config.mucDomain.toLowerCase())) {
|
||||
mucJidValid = false;
|
||||
}
|
||||
}
|
||||
if (mucJidValid && req.body && req.body.jid && req.body.jid != "" && req.body.subject && req.body.subject != "" && req.body.owner && req.body.owner != "") {
|
||||
if ( connection && connection.socket) {
|
||||
if (!connection.socket.writable) {
|
||||
await connection.connect(params).catch(error => {
|
||||
console.log("connection error: ", error);
|
||||
});
|
||||
}
|
||||
let alreadyExists = doesMucExist(req.body.jid);
|
||||
if (alreadyExists == 1) {
|
||||
res.status(409).json({message: "muc already exists"});
|
||||
} else {
|
||||
if (connection.socket.writable) {
|
||||
console.log("creating room...");
|
||||
let cmd = 'muc:create("' + req.body.jid + '");\n';
|
||||
let response = await connection.send(cmd);
|
||||
console.log(response);
|
||||
cmd = 'muc:room("' + req.body.jid + '"):set_subject("' + req.body.jid + '/' + req.body.owner + '", "' + req.body.subject + '");\n';
|
||||
response = await connection.send(cmd);
|
||||
console.log(response);
|
||||
|
||||
cmd = 'muc:room("' + req.body.jid + '"):set_historylength(5);\n';
|
||||
response = await connection.send(cmd);
|
||||
console.log(response);
|
||||
|
||||
cmd = 'muc:room("' + req.body.jid + '"):set_persistent(true);\n';
|
||||
response = await connection.send(cmd);
|
||||
console.log(response);
|
||||
|
||||
cmd = 'muc:room("' + req.body.jid + '"):set_affiliation(true, "' + req.body.owner + '", "owner");\n';
|
||||
response = await connection.send(cmd);
|
||||
console.log(response);
|
||||
|
||||
//muc:room("testingtelnetcreate1_meeting@conference.microlab.zimbra-vnc.de"):set_affiliation(true, "richard.watson@microlab.zimbra-vnc.de", "member");
|
||||
|
||||
res.json({status: "ok"});
|
||||
} else {
|
||||
console.log("connection not writable");
|
||||
res.status(500).json({message: "connection not writable"});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("connection not writable2");
|
||||
res.status(500).json({message: "connection not writable"});
|
||||
}
|
||||
} else {
|
||||
res.status(500).json({message: "insufficient params"});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
router.get('/healthcheck', async function (req, res) {
|
||||
if ( connection && connection.socket) {
|
||||
if (!connection.socket.writable) {
|
||||
|
||||
Reference in New Issue
Block a user