mirror of
https://github.com/Skylar-Tech/node-red-contrib-matrix-chat.git
synced 2025-04-20 21:13:08 -06:00
parent
b36286d994
commit
6dca3aa70e
@ -46,7 +46,8 @@
|
|||||||
"matrix-synapse-join-room": "src/matrix-synapse-join-room.js",
|
"matrix-synapse-join-room": "src/matrix-synapse-join-room.js",
|
||||||
"matrix-whois-user": "src/matrix-whois-user.js",
|
"matrix-whois-user": "src/matrix-whois-user.js",
|
||||||
"matrix-typing": "src/matrix-typing.js",
|
"matrix-typing": "src/matrix-typing.js",
|
||||||
"matrix-user-settings": "src/matrix-user-settings.js"
|
"matrix-user-settings": "src/matrix-user-settings.js",
|
||||||
|
"matrix-get-user": "src/matrix-get-user.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
352
src/matrix-get-user.html
Normal file
352
src/matrix-get-user.html
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
<script type="text/html" data-template-name="matrix-get-user">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-server"><i class="fa fa-user"></i> Matrix Server Config</label>
|
||||||
|
<input type="text" id="node-input-server">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-user"><i class="fa fa-user"></i> User ID</label>
|
||||||
|
<input type="text" id="node-input-user">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-property"><i class="fa fa-user"></i> Property</label>
|
||||||
|
<input type="text" id="node-input-property">
|
||||||
|
</div>
|
||||||
|
<div class="form-row form-tips">
|
||||||
|
This is the property the user data object will be set to
|
||||||
|
</div>
|
||||||
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
|
<label><i class="fa fa-list"></i> <span data-i18n="change.label.rules"></span></label>
|
||||||
|
</div>
|
||||||
|
<div class="form-row node-input-rule-container-row">
|
||||||
|
<ol id="node-input-rule-container"></ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/html" data-help-name="matrix-get-user">
|
||||||
|
<h3>Details</h3>
|
||||||
|
<p>
|
||||||
|
Get data for a user. Data includes display name, avatar URL, presence, last active, currently active, and latest user events.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt class="optional">msg.userId | dynamic
|
||||||
|
<span class="property-type">string</span>
|
||||||
|
</dt>
|
||||||
|
<dd> The user to get details for.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<h3>Outputs</h3>
|
||||||
|
<ol class="node-ports">
|
||||||
|
<li>Success
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt>msg <span class="property-type">object</span></dt>
|
||||||
|
<dd>Original message object with modifications based on config.</dd>
|
||||||
|
</dl>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt>msg.error <span class="property-type">undefined|object</span></dt>
|
||||||
|
<dd>Returned if there was an error getting the user</dd>
|
||||||
|
</dl>
|
||||||
|
<dt class="optional">dynamic
|
||||||
|
<span class="property-type">string|object</span>
|
||||||
|
</dt>
|
||||||
|
<dd> You configure what to return on the node.</dd>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function(){
|
||||||
|
var roomEventTypeOptions = [
|
||||||
|
{ value: "m.room.name", label: "m.room.name" },
|
||||||
|
{ value: "m.room.topic", label: "m.room.topic" },
|
||||||
|
{ value: "m.room.avatar", label: "m.room.avatar" },
|
||||||
|
{ value: "m.room.power_levels", label: "m.room.power_levels" },
|
||||||
|
{ value: "m.room.guest_access", label: "m.room.guest_access" },
|
||||||
|
{ value: "m.room.join_rules", label: "m.room.join_rules" },
|
||||||
|
{ value: "m.room.canonical_alias", label: "m.room.canonical_alias" },
|
||||||
|
{ value: "m.room.history_visibility", label: "m.room.history_visibility" },
|
||||||
|
{ value: "m.room.server_acl", label: "m.room.server_acl" },
|
||||||
|
{ value: "m.room.pinned_events", label: "m.room.pinned_events"},
|
||||||
|
{ value: "m.space.child", label: "m.space.child" },
|
||||||
|
{ value: "m.space.parent", label: "m.space.parent" },
|
||||||
|
];
|
||||||
|
var defaultRules = [{
|
||||||
|
t: "set",
|
||||||
|
p: roomEventTypeOptions[0].value,
|
||||||
|
to: "payload",
|
||||||
|
tot: "msg"
|
||||||
|
}];
|
||||||
|
|
||||||
|
function isInvalidProperty(v,vt) {
|
||||||
|
if (/msg|flow|global/.test(vt)) {
|
||||||
|
if (!RED.utils.validatePropertyExpression(v)) {
|
||||||
|
return "Invalid property: " + v;
|
||||||
|
}
|
||||||
|
} else if (vt === "jsonata") {
|
||||||
|
try{ jsonata(v); } catch(e) {
|
||||||
|
return "Invalid expression: " + e.message;
|
||||||
|
}
|
||||||
|
} else if (vt === "json") {
|
||||||
|
try{ JSON.parse(v); } catch(e) {
|
||||||
|
return "Invalid JSON data: " + e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RED.nodes.registerType('matrix-get-user',{
|
||||||
|
category: 'matrix',
|
||||||
|
color: '#00b7ca',
|
||||||
|
icon: "matrix.png",
|
||||||
|
outputLabels: ["success", "error"],
|
||||||
|
inputs:1,
|
||||||
|
outputs:2,
|
||||||
|
defaults: {
|
||||||
|
name: { value: null },
|
||||||
|
server: { type: "matrix-server-config" },
|
||||||
|
userType: { value: "msg" },
|
||||||
|
userValue: { value: "userId" },
|
||||||
|
propertyType: { value: "msg" },
|
||||||
|
propertyValue: { value: "user" },
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
$("#node-input-user").typedInput({
|
||||||
|
type: this.roomType,
|
||||||
|
types:['msg','flow','global','str'],
|
||||||
|
})
|
||||||
|
.typedInput('value', this.userValue)
|
||||||
|
.typedInput('type', this.userType);
|
||||||
|
|
||||||
|
$("#node-input-property").typedInput({
|
||||||
|
type: this.roomType,
|
||||||
|
types:['msg','flow','global','str'],
|
||||||
|
})
|
||||||
|
.typedInput('value', this.propertyValue)
|
||||||
|
.typedInput('type', this.propertyType);
|
||||||
|
|
||||||
|
var set = "Set";
|
||||||
|
var to = "to the value";
|
||||||
|
var toValueLabel = "to the property";
|
||||||
|
var search = this._("change.action.search");
|
||||||
|
var replace = this._("change.action.replace");
|
||||||
|
var regex = this._("change.label.regex");
|
||||||
|
|
||||||
|
function createPropertyValue(row2_1, row2_2, type, defaultType) {
|
||||||
|
var propValInput = $('<input/>',{class:"node-input-rule-property-value",type:"text"})
|
||||||
|
.appendTo(row2_1)
|
||||||
|
.typedInput({
|
||||||
|
default: defaultType || (type === 'set' ? 'str' : 'msg'),
|
||||||
|
types: (type === 'set' ? ['msg','flow','global','str','json','jsonata'] : ['msg', 'flow', 'global'])
|
||||||
|
});
|
||||||
|
|
||||||
|
var lsLabel = $('<label style="padding-left: 130px;"></label>').appendTo(row2_2);
|
||||||
|
var localStorageEl = $('<input type="checkbox" class="node-input-rule-property-localStorage" style="width: auto; margin: 0 6px 0 0">').appendTo(lsLabel);
|
||||||
|
$('<span>').text("Fetch from local storage").appendTo(lsLabel);
|
||||||
|
|
||||||
|
propValInput.on("change", function(evt,type,val) {
|
||||||
|
row2_2.toggle(type === "msg" || type === "flow" || type === "global" || type === "env");
|
||||||
|
})
|
||||||
|
return [propValInput, localStorageEl];
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#node-input-rule-container').css('min-height','150px').css('min-width','450px').editableList({
|
||||||
|
addItem: function(container,i,opt) {
|
||||||
|
var rule = opt;
|
||||||
|
if (!rule.hasOwnProperty('t')) {
|
||||||
|
rule = {t:"set",p:roomEventTypeOptions[0].value,to:"payload",tot:"msg"};
|
||||||
|
}
|
||||||
|
if (rule.t === "set" && !rule.tot) {
|
||||||
|
if (rule.to.indexOf("msg.") === 0 && !rule.tot) {
|
||||||
|
rule.to = rule.to.substring(4);
|
||||||
|
rule.tot = "msg";
|
||||||
|
} else {
|
||||||
|
rule.tot = "str";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
container.css({
|
||||||
|
overflow: 'hidden',
|
||||||
|
whiteSpace: 'nowrap'
|
||||||
|
});
|
||||||
|
let fragment = document.createDocumentFragment();
|
||||||
|
var row1 = $('<div/>',{style:"display:flex; align-items: center"}).appendTo(fragment);
|
||||||
|
var row2 = $('<div/>',{style:"margin-top:8px;"}).appendTo(fragment);
|
||||||
|
var row3 = $('<div/>',{style:"margin-top:8px;"}).appendTo(fragment);
|
||||||
|
var row4 = $('<div/>',{style:"display:flex;margin-top:8px;align-items: baseline"}).appendTo(fragment);
|
||||||
|
|
||||||
|
var selectField = $('<select/>',{class:"node-input-rule-type",style:"width:110px; margin-right:10px;"}).appendTo(row1);
|
||||||
|
var selectOptions = [
|
||||||
|
{v:"set",l:"Set"},
|
||||||
|
{v:"get",l:"Get"}
|
||||||
|
];
|
||||||
|
for (var x=0; x<selectOptions.length; x++) {
|
||||||
|
selectField.append($("<option></option>").val(selectOptions[x].v).text(selectOptions[x].l));
|
||||||
|
}
|
||||||
|
|
||||||
|
var propertyName = $('<input/>',{class:"node-input-rule-property-name",type:"text"})
|
||||||
|
.appendTo(row1)
|
||||||
|
.autoComplete({
|
||||||
|
minLength:0,
|
||||||
|
search: function(val) {
|
||||||
|
if(!val) {
|
||||||
|
return roomEventTypeOptions.sort(function(A,B){return A.i-B.i});
|
||||||
|
}
|
||||||
|
var matches = [];
|
||||||
|
roomEventTypeOptions.map((x) => x.value).forEach(v => {
|
||||||
|
var i = v.toLowerCase().indexOf(val.toLowerCase());
|
||||||
|
if (i > -1) {
|
||||||
|
matches.push({
|
||||||
|
value: v,
|
||||||
|
label: v,
|
||||||
|
i: i
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
matches.sort(function(A,B){return A.i-B.i})
|
||||||
|
return matches
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('focus', function(evt){
|
||||||
|
// following is a fix so autocomplete will show list on focus
|
||||||
|
if(!evt.isTrigger) {
|
||||||
|
evt.stopPropagation();
|
||||||
|
$(this).trigger("keyup.red-ui-autoComplete");
|
||||||
|
}
|
||||||
|
}).on("keyup", function(evt) {
|
||||||
|
// following allows autocomplete to display even when backspace/delete is used
|
||||||
|
if (evt.keyCode === 8 || evt.keyCode === 46) {
|
||||||
|
evt.stopPropagation();
|
||||||
|
$(this).trigger("keyup.red-ui-autoComplete");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var row2_1 = $('<div/>', {style:"display:flex;align-items: baseline"}).appendTo(row2);
|
||||||
|
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||||
|
.text(toValueLabel)
|
||||||
|
.appendTo(row2_1);
|
||||||
|
|
||||||
|
var row2_2 = $('<div/>', {style:"margin-top: 4px;"}).appendTo(row2);
|
||||||
|
|
||||||
|
var row3_1 = $('<div/>', {style:"display:flex;align-items: baseline"}).appendTo(row3);
|
||||||
|
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||||
|
.text(search)
|
||||||
|
.appendTo(row3_1);
|
||||||
|
|
||||||
|
var row3_2 = $('<div/>',{style:"display:flex;margin-top:8px;align-items: baseline"}).appendTo(row3);
|
||||||
|
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||||
|
.text(replace)
|
||||||
|
.appendTo(row3_2);
|
||||||
|
|
||||||
|
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||||
|
.text(to)
|
||||||
|
.appendTo(row4);
|
||||||
|
|
||||||
|
let propertyValue = null;
|
||||||
|
let localStorageEl = null;
|
||||||
|
let fromValue = null;
|
||||||
|
let toValue = null;
|
||||||
|
|
||||||
|
selectField.on("change", function() {
|
||||||
|
var type = $(this).val();
|
||||||
|
if (propertyValue) {
|
||||||
|
propertyValue.typedInput('hide');
|
||||||
|
}
|
||||||
|
if (fromValue) {
|
||||||
|
fromValue.typedInput('hide');
|
||||||
|
}
|
||||||
|
if (toValue) {
|
||||||
|
toValue.typedInput('hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!propertyValue) {
|
||||||
|
var parts = createPropertyValue(row2_1, row2_2, type);
|
||||||
|
propertyValue = parts[0];
|
||||||
|
localStorageEl = parts[1];
|
||||||
|
} else {
|
||||||
|
propertyValue.typedInput('types', (type === 'set' ? ['msg','flow','global','str','json','jsonata'] : ['msg', 'flow', 'global']));
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyValue.typedInput('show');
|
||||||
|
row2.show();
|
||||||
|
if(type === 'get') {
|
||||||
|
localStorageEl.parent().show();
|
||||||
|
} else {
|
||||||
|
localStorageEl.parent().hide();
|
||||||
|
}
|
||||||
|
row3.hide();
|
||||||
|
row4.hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
selectField.val(rule.t);
|
||||||
|
propertyName.val(rule.p);
|
||||||
|
if (rule.t === "set" || rule.t === "get") {
|
||||||
|
var parts = createPropertyValue(row2_1, row2_2, rule.t, rule.tot);
|
||||||
|
propertyValue = parts[0];
|
||||||
|
localStorageEl = parts[1];
|
||||||
|
propertyValue.typedInput('value',rule.to);
|
||||||
|
localStorageEl.prop("checked", !!rule.ls);
|
||||||
|
if(rule.t === 'get') {
|
||||||
|
localStorageEl.parent().show();
|
||||||
|
} else {
|
||||||
|
localStorageEl.parent().hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectField.change();
|
||||||
|
container[0].appendChild(fragment);
|
||||||
|
},
|
||||||
|
removable: true,
|
||||||
|
sortable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i=0; i<this.rules.length; i++) {
|
||||||
|
var rule = this.rules[i];
|
||||||
|
$("#node-input-rule-container").editableList('addItem',rule);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
oneditsave: function() {
|
||||||
|
this.userType = $("#node-input-user").typedInput('type');
|
||||||
|
this.userValue = $("#node-input-user").typedInput('value');
|
||||||
|
this.propertyType = $("#node-input-property").typedInput('type');
|
||||||
|
this.propertyValue = $("#node-input-property").typedInput('value');
|
||||||
|
var rules = $("#node-input-rule-container").editableList('items');
|
||||||
|
var node = this;
|
||||||
|
node.rules= [];
|
||||||
|
rules.each(function(i) {
|
||||||
|
var rule = $(this);
|
||||||
|
var type = rule.find(".node-input-rule-type").val();
|
||||||
|
var r = {
|
||||||
|
t:type,
|
||||||
|
p:rule.find(".node-input-rule-property-name").val(),
|
||||||
|
to:rule.find(".node-input-rule-property-value").typedInput('value'),
|
||||||
|
tot:rule.find(".node-input-rule-property-value").typedInput('type')
|
||||||
|
};
|
||||||
|
|
||||||
|
if (r.t === "get" && rule.find(".node-input-rule-property-localStorage").prop("checked")) {
|
||||||
|
r.ls = true;
|
||||||
|
}
|
||||||
|
node.rules.push(r);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
oneditresize: function(size) {
|
||||||
|
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
|
||||||
|
var height = size.height;
|
||||||
|
for (var i=0; i<rows.length; i++) {
|
||||||
|
height -= $(rows[i]).outerHeight(true);
|
||||||
|
}
|
||||||
|
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
|
||||||
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
||||||
|
height += 16;
|
||||||
|
$("#node-input-rule-container").editableList('height',height);
|
||||||
|
},
|
||||||
|
label: function() {
|
||||||
|
return this.name || "Get User";
|
||||||
|
},
|
||||||
|
paletteLabel: 'Get User'
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
145
src/matrix-get-user.js
Normal file
145
src/matrix-get-user.js
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
module.exports = function(RED) {
|
||||||
|
function MatrixGetUser(n) {
|
||||||
|
RED.nodes.createNode(this, n);
|
||||||
|
|
||||||
|
var node = this;
|
||||||
|
|
||||||
|
this.name = n.name;
|
||||||
|
this.server = RED.nodes.getNode(n.server);
|
||||||
|
this.userType = n.userType || "msg";
|
||||||
|
this.userValue = n.userValue || "userId";
|
||||||
|
this.propertyType = n.propertyType || "msg";
|
||||||
|
this.propertyValue = n.propertyValue || "user";
|
||||||
|
|
||||||
|
if (!node.server) {
|
||||||
|
node.warn("No configuration node");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node.server.register(node);
|
||||||
|
|
||||||
|
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
||||||
|
|
||||||
|
node.server.on("disconnected", function(){
|
||||||
|
node.status({ fill: "red", shape: "ring", text: "disconnected" });
|
||||||
|
});
|
||||||
|
|
||||||
|
node.server.on("connected", function() {
|
||||||
|
node.status({ fill: "green", shape: "ring", text: "connected" });
|
||||||
|
});
|
||||||
|
|
||||||
|
node.on("input", async function (msg) {
|
||||||
|
|
||||||
|
function getToValue(msg, type, property) {
|
||||||
|
let value = property;
|
||||||
|
if (type === "msg") {
|
||||||
|
value = RED.util.getMessageProperty(msg, property);
|
||||||
|
} else if ((type === 'flow') || (type === 'global')) {
|
||||||
|
try {
|
||||||
|
value = RED.util.evaluateNodeProperty(property, type, node, msg);
|
||||||
|
} catch(e2) {
|
||||||
|
throw new Error("Invalid value evaluation");
|
||||||
|
}
|
||||||
|
} else if(type === "bool") {
|
||||||
|
value = (property === 'true');
|
||||||
|
} else if(type === "num") {
|
||||||
|
value = Number(property);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setToValue(value, type, property) {
|
||||||
|
if(type === 'global' || type === 'flow') {
|
||||||
|
var contextKey = RED.util.parseContextStore(property);
|
||||||
|
if (/\[msg/.test(contextKey.key)) {
|
||||||
|
// The key has a nest msg. reference to evaluate first
|
||||||
|
contextKey.key = RED.util.normalisePropertyExpression(contextKey.key, msg, true)
|
||||||
|
}
|
||||||
|
var target = node.context()[type];
|
||||||
|
var callback = err => {
|
||||||
|
if (err) {
|
||||||
|
node.error(err, msg);
|
||||||
|
getterErrors[rule.p] = err.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
target.set(contextKey.key, value, contextKey.store, callback);
|
||||||
|
} else if(type === 'msg') {
|
||||||
|
if (!RED.util.setMessageProperty(msg, property, value)) {
|
||||||
|
node.warn(RED._("change.errors.no-override",{property:property}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! node.server || ! node.server.matrixClient) {
|
||||||
|
msg.error = "No matrix server selected";
|
||||||
|
node.error(msg.error, msg);
|
||||||
|
node.send([null, msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!node.server.isConnected()) {
|
||||||
|
msg.error = "Matrix server connection is currently closed";
|
||||||
|
node.error(msg.error, msg);
|
||||||
|
node.send([null, msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let userId = getToValue(msg, node.userType, node.userValue);
|
||||||
|
if(!userId) {
|
||||||
|
msg.error = "Missing userId";
|
||||||
|
node.error(msg.error, msg);
|
||||||
|
node.send([null, msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = null;
|
||||||
|
try {
|
||||||
|
user = node.server.matrixClient.getUser(userId);
|
||||||
|
} catch(e) {
|
||||||
|
msg.error = "Failed getting user: " + e.message;
|
||||||
|
node.error(msg.error, msg);
|
||||||
|
node.send([null, msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!user) {
|
||||||
|
// failed to fetch from local storage, try to fetch data from server
|
||||||
|
let user2 = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
let profileInfo = node.server.matrixClient.getProfileInfo(userId);
|
||||||
|
if(Object.keys(profileInfo).length > 0) {
|
||||||
|
user2.displayName = profileInfo.displayname;
|
||||||
|
user2.avatarUrl = profileInfo.avatar_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
let presence = node.server.matrixClient.getPresence(userId);
|
||||||
|
if(Object.keys(presence).length > 0) {
|
||||||
|
user2.currentlyActive = presence.currently_active;
|
||||||
|
user2.lastActiveAgo = presence.last_active_ago;
|
||||||
|
user2.presenceStatusMsg = presence.presence_status_msg;
|
||||||
|
user2.presence = presence.presence;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Object.keys(user2).length > 0) {
|
||||||
|
setToValue(user2, node.propertyType, node.propertyValue);
|
||||||
|
node.send([msg, null]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
msg.error = "Failed getting user: " + e.message;
|
||||||
|
node.error(msg.error, msg);
|
||||||
|
node.send([null, msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setToValue(user, node.propertyType, node.propertyValue);
|
||||||
|
node.send([msg, null]);
|
||||||
|
});
|
||||||
|
|
||||||
|
node.on("close", function() {
|
||||||
|
node.server.deregister(node);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RED.nodes.registerType("matrix-get-user", MatrixGetUser);
|
||||||
|
}
|
@ -130,7 +130,6 @@
|
|||||||
name: { value: null },
|
name: { value: null },
|
||||||
server: { type: "matrix-server-config" },
|
server: { type: "matrix-server-config" },
|
||||||
roomId: { value: null },
|
roomId: { value: null },
|
||||||
reason: { value: null },
|
|
||||||
rules: {
|
rules: {
|
||||||
value: defaultRules,
|
value: defaultRules,
|
||||||
validate: function(rules, opt) {
|
validate: function(rules, opt) {
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
$("#node-input-room").typedInput({
|
$("#node-input-room").typedInput({
|
||||||
type: this.roomType,
|
type: this.roomType,
|
||||||
types:['msg','flow','global','str'],
|
types:['msg','flow','global','str'],
|
||||||
}).typedInput('value', this.roomValue);
|
})
|
||||||
|
.typedInput('value', this.roomValue)
|
||||||
|
.typedInput('type', this.roomType);
|
||||||
|
|
||||||
$("#node-input-typing").typedInput({
|
$("#node-input-typing").typedInput({
|
||||||
types:['msg','flow','global','bool'],
|
types:['msg','flow','global','bool'],
|
||||||
@ -66,12 +68,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-room"><i class="fa fa-commenting-o"></i> Is Typing</label>
|
<label for="node-input-typing"><i class="fa fa-commenting-o"></i> Is Typing</label>
|
||||||
<input type="text" id="node-input-typing">
|
<input type="text" id="node-input-typing">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-room"><i class="fa fa-clock-o"></i> Timeout Milliseconds</label>
|
<label for="node-input-timeoutMs"><i class="fa fa-clock-o"></i> Timeout Milliseconds</label>
|
||||||
<input type="text" id="node-input-timeoutMs">
|
<input type="text" id="node-input-timeoutMs">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -105,7 +105,6 @@
|
|||||||
name: { value: null },
|
name: { value: null },
|
||||||
server: { type: "matrix-server-config" },
|
server: { type: "matrix-server-config" },
|
||||||
roomId: { value: null },
|
roomId: { value: null },
|
||||||
reason: { value: null },
|
|
||||||
rules: {
|
rules: {
|
||||||
value: defaultRules,
|
value: defaultRules,
|
||||||
validate: function(rules, opt) {
|
validate: function(rules, opt) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user