fix: determine actor for muc data messages

This commit is contained in:
2022-02-21 05:47:27 +01:00
parent 04902bee2e
commit e635a55f3f
+26 -6
View File
@@ -265,16 +265,36 @@ router.put('/groupchats/:target', async function (req, res) {
queryparams[0] = target.split("@")[0];
queryparams[1] = target.split("@")[1];
queryparams[2] = '_affiliations';
queryparams[3] = '":"admin';
queryparams[4] = '"';
queryparams[5] = '":"owner';
// queryparams[3] = '":"owner';
// queryparams[4] = '"';
// queryparams[5] = '":"admin';
var actor = "";
var query = "select split_part(split_part(prosody.value, $4, 1), $5, 2) as actor from prosody where prosody.user=$1 and prosody.host=$2 and prosody.key=$3";
query += "union select split_part(split_part(prosody.value, $6, 1), $5, 2) as actor from prosody where prosody.user=$1 and prosody.host=$2 and prosody.key=$3";
var query = "select prosody.value as actor from prosody where prosody.user=$1 and prosody.host=$2 and prosody.key=$3";
// query += "union select split_part(split_part(prosody.value, $6, 1), $5, 2) as actor from prosody where prosody.user=$1 and prosody.host=$2 and prosody.key=$3";
console.log("creating xmpp data from: ", req.body.data);
dbpool.query(query, queryparams, function (derr, dres) {
if (derr == null) {
if (dres.rowCount > 0) {
actor = dres.rows[0].actor;
let nAct = {};
let nKeys = [];
try {
nAct = JSON.parse(dres.rows[0].actor);
nKeys = Object.keys(nAct);
} catch (e) {
console.log("error parsing actor... ", e);
}
if (nKeys.length > 0) {
for (var i = 0; i < nKeys.length; i++) {
if (nAct[nKeys[i]] === "owner") {
actor = nKeys[i];
}
}
}
// actor = dres.rows[0].actor;
console.log("actor1: ", actor);
console.log("actor1: ", Object.keys(nAct));
setMucData(actor, req.params.target, req.body.data);
res.status(200).json(null);
} else {