1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Let xmpp in handle a list of rooms

This commit is contained in:
Dave Conway-Jones 2021-02-23 12:45:55 +00:00
parent 7485760db9
commit 40362ee985
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 9 additions and 5 deletions

View File

@ -19,6 +19,7 @@
</div> </div>
<div class="form-tips"><b>Note:</b> By leaving Buddy empty and ticking "Is a chat room", <div class="form-tips"><b>Note:</b> By leaving Buddy empty and ticking "Is a chat room",
the node will try to listen to all the rooms the user has access to. the node will try to listen to all the rooms the user has access to.
You can specify multiple rooms by separating them by a :
</div> </div>
</script> </script>

View File

@ -322,7 +322,8 @@ module.exports = function(RED) {
this.join = n.join || false; this.join = n.join || false;
this.sendAll = n.sendObject; this.sendAll = n.sendObject;
// Yes, it's called "from", don't ask me why; I don't know why // Yes, it's called "from", don't ask me why; I don't know why
this.from = (n.to || "").trim(); // (because it's where you are asking to get messages from...)
this.from = ((n.to || "").split(':')).map(s => s.trim());
this.quiet = false; this.quiet = false;
// MUC == Multi-User-Chat == chatroom // MUC == Multi-User-Chat == chatroom
//this.muc = this.join && (this.from !== "") //this.muc = this.join && (this.from !== "")
@ -357,13 +358,15 @@ module.exports = function(RED) {
node.quiet = false; node.quiet = false;
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
if (node.join) { if (node.join) {
if (node.from === "") { if (node.from[0] === "") {
// try to get list of all rooms and join them all. // try to get list of all rooms and join them all.
getItems(this.serverConfig.server,this.serverConfig.id,xmpp); getItems(this.serverConfig.server,this.serverConfig.id,xmpp);
} }
else { else {
// if we want to use a chatroom, we need to tell the server we want to join it // if we want to use a chatroom, we need to tell the server we want to join it
joinMUC(node, xmpp, node.from+'/'+node.nick); for (var i=0; i<node.from.length; i++) {
joinMUC(node, xmpp, node.from[i]+'/'+node.nick);
}
} }
} }
}); });
@ -413,7 +416,7 @@ module.exports = function(RED) {
} }
else { msg.topic = ids[0]; } else { msg.topic = ids[0]; }
// if (RED.settings.verbose || LOGITALL) {node.log("Received a message from "+stanza.attrs.from); } // if (RED.settings.verbose || LOGITALL) {node.log("Received a message from "+stanza.attrs.from); }
if (!node.join && ((node.from === "") || (node.from === stanza.attrs.to))) { if (!node.join && ((node.from[0] === "") || (node.from.includes(stanza.attrs.to)))) {
node.send([msg,null]); node.send([msg,null]);
} }
} }
@ -429,7 +432,7 @@ module.exports = function(RED) {
} }
var msg = { topic:from, payload:payload, room:conference }; var msg = { topic:from, payload:payload, room:conference };
//if (from && stanza.attrs.from != node.nick && from != node.nick) { //if (from && stanza.attrs.from != node.nick && from != node.nick) {
if (from && node.join && (node.from === "" || node.from === conference)) { if (from && node.join && (node.from[0] === "" || node.from.includes(conference))) {
node.send([msg,null]); node.send([msg,null]);
} }
//} //}