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: {
|
||||
name: {value:""},
|
||||
room: {value:""},
|
||||
server: {value:"", type:"matrix-server"}
|
||||
server: {value:"", type:"matrix-server"},
|
||||
filterself: {value:true}
|
||||
},
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
|
@ -105,6 +106,10 @@
|
|||
<label for="node-input-room"><i class="icon-tag"></i> Room</label>
|
||||
<input type="text" id="node-input-room" placeholder="Room">
|
||||
</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 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.room = config.room;
|
||||
node.filterself = config.filterself;
|
||||
|
||||
if (!node.configNode) {
|
||||
node.warn("No configuration node");
|
||||
|
@ -99,9 +100,10 @@ module.exports = function(RED) {
|
|||
node.configNode.on("connected", function() {
|
||||
node.status({ fill: "green", shape: "ring", text: "connected" });
|
||||
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
|
||||
}
|
||||
|
||||
if (node.room && (node.room !== event.room)) {
|
||||
return;
|
||||
}
|
||||
|
@ -109,6 +111,7 @@ module.exports = function(RED) {
|
|||
if (event.event.type !== "org.nodered.msg") {
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = event.getContent();
|
||||
node.send(msg);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue