fix: adjustments for prosody 13
Part-of: <http://gitlab.vnc.biz/uxf/prosody-muc-rest/-/merge_requests/3>
This commit is contained in:
+27
-31
@@ -28,7 +28,8 @@ async function doesMucExist(jid) {
|
||||
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";
|
||||
queryparams[3] = "_jid";
|
||||
query = "select prosody.value from prosody where prosody.host=$2 and prosody.user=$1 and (prosody.key=$3 or prosody.key=$4)";
|
||||
dbpool.query(query, queryparams, async function (derr, dres) {
|
||||
if (derr == null) {
|
||||
console.log("doesMucExist dres.rows: ", dres.rows);
|
||||
@@ -236,23 +237,24 @@ router.get('/groupchats/:target', async function (req, res) {
|
||||
var queryparams = [];
|
||||
queryparams[0] = target.split("@")[0];
|
||||
queryparams[1] = target.split("@")[1];
|
||||
var sqlquery="select value, created, updated from prosody INNER JOIN group_owners ON split_part(group_owners.room, '@', 1) = ";
|
||||
sqlquery += "prosody.user AND split_part(group_owners.room, '@', 2) = prosody.host where prosody.store='config' and ";
|
||||
sqlquery += "prosody.key='_data' and prosody.user=$1 and prosody.host=$2";
|
||||
var sqlquery="select key, value from prosody where prosody.store='config' and prosody.user=$1 and prosody.host=$2";
|
||||
dbpool.query(sqlquery, queryparams, function (derr, dres) {
|
||||
if (derr == null) {
|
||||
if (dres.rowCount > 0) {
|
||||
let groupInfo = JSON.parse(dres.rows[0].value);
|
||||
if (!groupInfo.subject) {
|
||||
groupInfo.subject = queryparams[0].split(".").map(v => v.replace(/^\w/, c => c.toUpperCase())).join(" ");
|
||||
let result = dres.rows.filter(row => row.key === "_data").map(row => JSON.parse(row.value))[0];
|
||||
let owners = dres.rows.filter(row => row.value === "owner").map(row => { return { jid: row.key } });
|
||||
let members = dres.rows.filter(row => row.value === "member").map(row => { return { jid: row.key } });
|
||||
result.affiliations_owner = owners;
|
||||
result.affiliations_member = members;
|
||||
if (!result.subject) {
|
||||
result.subject = queryparams[0].split(".").map(v => v.replace(/^\w/, c => c.toUpperCase())).join(" ");
|
||||
}
|
||||
groupInfo.created = dres.rows[0].created;
|
||||
groupInfo.updated = dres.rows[0].updated;
|
||||
res.send(JSON.stringify(groupInfo));
|
||||
res.send(result);
|
||||
} else {
|
||||
res.status(410).json({status:"groupchat not found - probably deleted"});
|
||||
}
|
||||
} else {
|
||||
console.log("db err: ", derr);
|
||||
res.status(500).json(derr);
|
||||
}
|
||||
});
|
||||
@@ -312,29 +314,15 @@ router.put('/groupchats/:target', async function (req, res) {
|
||||
var queryparams = [];
|
||||
queryparams[0] = target.split("@")[0];
|
||||
queryparams[1] = target.split("@")[1];
|
||||
queryparams[2] = '_affiliations';
|
||||
queryparams[2] = 'owner';
|
||||
var actor = "";
|
||||
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";
|
||||
var query = "select prosody.key as actor from prosody where prosody.user=$1 and prosody.host=$2 and prosody.value=$3 limit 1";
|
||||
|
||||
console.log("creating xmpp data from: ", req.body.data);
|
||||
dbpool.query(query, queryparams, async function (derr, dres) {
|
||||
if (derr == null) {
|
||||
if (dres.rowCount > 0) {
|
||||
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));
|
||||
@@ -375,11 +363,19 @@ router.get('/affiliations/:target', async function (req, res) {
|
||||
var queryparams = [];
|
||||
queryparams[0] = target.split("@")[0];
|
||||
queryparams[1] = target.split("@")[1];
|
||||
var sqlquery="select value from prosody where prosody.store='config' and prosody.key='_affiliations' and prosody.user=$1 and prosody.host=$2";
|
||||
queryparams[2] = 'member';
|
||||
queryparams[3] = 'owner';
|
||||
var sqlquery="select key, value from prosody where prosody.store='config' and prosody.user=$1 and prosody.host=$2 and prosody.value=any(array[$3, $4])";
|
||||
dbpool.query(sqlquery, queryparams, function (derr, dres) {
|
||||
if (derr == null) {
|
||||
if (dres.rowCount > 0) {
|
||||
res.send(dres.rows[0].value);
|
||||
let result = {};
|
||||
for (var i = 0; i < dres.rowCount; i++) {
|
||||
let affiliation = dres.rows[i].value;
|
||||
let key = dres.rows[i].key;
|
||||
result[key] = affiliation;
|
||||
}
|
||||
res.send(result);
|
||||
} else {
|
||||
res.status(410).json({status:"groupchat not found - probably deleted"});
|
||||
}
|
||||
@@ -432,7 +428,7 @@ router.post('/affiliations/:target', async function (req, res) {
|
||||
var queryparams = [];
|
||||
queryparams[0] = target.split("@")[0];
|
||||
queryparams[1] = target.split("@")[1];
|
||||
var sqlquery="select value from prosody where prosody.store='config' and prosody.key='_affiliations' and prosody.user=$1 and prosody.host=$2";
|
||||
var sqlquery="select value from prosody where prosody.store='config' and prosody.key='_jid' and prosody.user=$1 and prosody.host=$2";
|
||||
dbpool.query(sqlquery, queryparams, async function (derr, dres) {
|
||||
if (derr == null) {
|
||||
if (dres.rowCount > 0) {
|
||||
|
||||
Reference in New Issue
Block a user