Add option to filter messages sent by self.
This commit is contained in:
parent
c7d77ac920
commit
8b4ab119f8
2 changed files with 10 additions and 2 deletions
|
@ -81,7 +81,8 @@
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
room: {value:""},
|
room: {value:""},
|
||||||
server: {value:"", type:"matrix-server"}
|
server: {value:"", type:"matrix-server"},
|
||||||
|
filterself: {value:true}
|
||||||
},
|
},
|
||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
|
@ -105,6 +106,10 @@
|
||||||
<label for="node-input-room"><i class="icon-tag"></i> Room</label>
|
<label for="node-input-room"><i class="icon-tag"></i> Room</label>
|
||||||
<input type="text" id="node-input-room" placeholder="Room">
|
<input type="text" id="node-input-room" placeholder="Room">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-filterself"><i class="icon-tag"></i> Filter events sent by self</label>
|
||||||
|
<input type="checkbox" id="node-input-filterself" placeholder="Filterself">
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="matrix-input">
|
<script type="text/x-red" data-help-name="matrix-input">
|
||||||
|
|
|
@ -84,6 +84,7 @@ module.exports = function(RED) {
|
||||||
node.configNode = RED.nodes.getNode(config.server);
|
node.configNode = RED.nodes.getNode(config.server);
|
||||||
|
|
||||||
node.room = config.room;
|
node.room = config.room;
|
||||||
|
node.filterself = config.filterself;
|
||||||
|
|
||||||
if (!node.configNode) {
|
if (!node.configNode) {
|
||||||
node.warn("No configuration node");
|
node.warn("No configuration node");
|
||||||
|
@ -99,9 +100,10 @@ module.exports = function(RED) {
|
||||||
node.configNode.on("connected", function() {
|
node.configNode.on("connected", function() {
|
||||||
node.status({ fill: "green", shape: "ring", text: "connected" });
|
node.status({ fill: "green", shape: "ring", text: "connected" });
|
||||||
node.configNode.matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) {
|
node.configNode.matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) {
|
||||||
if (!event.getSender() || event.getSender() === node.configNode.userId) {
|
if (node.filterself && (!event.getSender() || event.getSender() === node.configNode.userid)) {
|
||||||
return; // ignore our own messages
|
return; // ignore our own messages
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.room && (node.room !== event.room)) {
|
if (node.room && (node.room !== event.room)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +111,7 @@ module.exports = function(RED) {
|
||||||
if (event.event.type !== "org.nodered.msg") {
|
if (event.event.type !== "org.nodered.msg") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = event.getContent();
|
var msg = event.getContent();
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue