From daafe33e86d483359b0343d29bbd381f6ae3923f Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Wed, 1 Sep 2021 11:09:50 -0600 Subject: [PATCH 1/6] Fix clients using the same directory for local storage instead of being unique --- src/matrix-server-config.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/matrix-server-config.js b/src/matrix-server-config.js index df07f5e..7b28cda 100644 --- a/src/matrix-server-config.js +++ b/src/matrix-server-config.js @@ -1,12 +1,15 @@ global.Olm = require('olm'); +const fs = require("fs"); +const sdk = require("matrix-js-sdk"); +const { LocalStorage } = require('node-localstorage'); +const { LocalStorageCryptoStore } = require('matrix-js-sdk/lib/crypto/store/localStorage-crypto-store'); module.exports = function(RED) { - const sdk = require("matrix-js-sdk"); - const { LocalStorage } = require('node-localstorage'); - const localStorage = new LocalStorage('./matrix-local-storage'); - const { LocalStorageCryptoStore } = require('matrix-js-sdk/lib/crypto/store/localStorage-crypto-store'); function MatrixServerNode(n) { + let oldStorageDir = './matrix-local-storage'; + let storageDir = './matrix-client-storage'; + // we should add support for getting access token automatically from username/password // ref: https://matrix.org/docs/guides/usage-of-the-matrix-js-sdk#login-with-an-access-token @@ -30,6 +33,10 @@ module.exports = function(RED) { this.enableE2ee = n.enableE2ee || false; this.e2ee = (this.enableE2ee && this.deviceId); + function toFolderName(name) { + return name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + } + if(!this.credentials.accessToken) { node.log("Matrix connection failed: missing access token."); } else if(!this.url) { @@ -37,6 +44,21 @@ module.exports = function(RED) { } else if(!this.userId) { node.log("Matrix connection failed: missing user ID."); } else { + let localStorageDir = storageDir + '/' + toFolderName(this.userId); + + // create storage directory if it doesn't exist + if(!fs.existsSync(storageDir)) { + fs.mkdirSync(storageDir); + } + + // if the old storage location exists lets move it to it's new location + if(fs.existsSync(oldStorageDir) && !fs.existsSync(localStorageDir)){ + node.log("found old '" + oldStorageDir + "' path, moving to new location '" + localStorageDir + "' ------------------------------"); + fs.renameSync(oldStorageDir, localStorageDir); + } + + const localStorage = new LocalStorage(localStorageDir); + node.matrixClient = sdk.createClient({ baseUrl: this.url, accessToken: this.credentials.accessToken, From 14badaeeb50fc1c9da8dc06bffb4be40fd70e47c Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Wed, 1 Sep 2021 20:48:39 -0600 Subject: [PATCH 2/6] - fs-extra added as a dependency to handle config folder upgrading - config folder now upgrades automatically to the new structure - fixed error preventing matrix client from connecting to servers (just stays disconnected) --- package-lock.json | 39 ++++++-------------- package.json | 5 +-- src/matrix-server-config.js | 72 ++++++++++++++++++++----------------- 3 files changed, 53 insertions(+), 63 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6973054..c42198f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,20 @@ { "name": "node-red-contrib-matrix-chat", - "version": "0.0.5", + "version": "0.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.0.5", + "version": "0.1.8", "license": "SEE LICENSE FILE", "dependencies": { + "fs-extra": "^9.1.0", "got": "^11.8.2", "isomorphic-webcrypto": "^2.3.8", "matrix-js-sdk": "^12.2.0", + "node-localstorage": "^2.2.1", "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz", "utf8": "^3.0.0" - }, - "devDependencies": { - "node-localstorage": "^2.2.1" } }, "node_modules/@babel/code-frame": { @@ -2337,7 +2336,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "optional": true, "engines": { "node": ">= 4.0.0" } @@ -4126,7 +4124,6 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "optional": true, "dependencies": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", @@ -4298,8 +4295,7 @@ "node_modules/graceful-fs": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", - "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", - "devOptional": true + "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==" }, "node_modules/har-schema": { "version": "2.0.0", @@ -4537,7 +4533,6 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "dev": true, "engines": { "node": ">=0.8.19" } @@ -5129,7 +5124,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "optional": true, "dependencies": { "universalify": "^2.0.0" }, @@ -6082,7 +6076,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-2.2.1.tgz", "integrity": "sha512-vv8fJuOUCCvSPjDjBLlMqYMHob4aGjkmrkaE42/mZr0VT+ZAU10jRF8oTnX9+pgU9/vYJ8P7YT3Vd6ajkmzSCw==", - "dev": true, "dependencies": { "write-file-atomic": "^1.1.4" }, @@ -7979,7 +7972,6 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=", - "dev": true, "engines": { "node": "*" } @@ -8822,7 +8814,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "optional": true, "engines": { "node": ">= 10.0.0" } @@ -9090,7 +9081,6 @@ "version": "1.3.4", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", "integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=", - "dev": true, "dependencies": { "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", @@ -11090,8 +11080,7 @@ "at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "optional": true + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" }, "atob": { "version": "2.1.2", @@ -12552,7 +12541,6 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "optional": true, "requires": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", @@ -12678,8 +12666,7 @@ "graceful-fs": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", - "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", - "devOptional": true + "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==" }, "har-schema": { "version": "2.0.0", @@ -12863,8 +12850,7 @@ "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "dev": true + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=" }, "inflight": { "version": "1.0.6", @@ -13357,7 +13343,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "optional": true, "requires": { "graceful-fs": "^4.1.6", "universalify": "^2.0.0" @@ -14184,7 +14169,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/node-localstorage/-/node-localstorage-2.2.1.tgz", "integrity": "sha512-vv8fJuOUCCvSPjDjBLlMqYMHob4aGjkmrkaE42/mZr0VT+ZAU10jRF8oTnX9+pgU9/vYJ8P7YT3Vd6ajkmzSCw==", - "dev": true, "requires": { "write-file-atomic": "^1.1.4" } @@ -15684,8 +15668,7 @@ "slide": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", - "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=", - "dev": true + "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=" }, "snapdragon": { "version": "0.8.2", @@ -16387,8 +16370,7 @@ "universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "optional": true + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" }, "unpipe": { "version": "1.0.0", @@ -16615,7 +16597,6 @@ "version": "1.3.4", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", "integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=", - "dev": true, "requires": { "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", diff --git a/package.json b/package.json index 9fb74ad..4e96af1 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,13 @@ "version": "0.1.8", "description": "Matrix chat server client for Node-RED", "dependencies": { + "fs-extra": "^9.1.0", "got": "^11.8.2", "isomorphic-webcrypto": "^2.3.8", "matrix-js-sdk": "^12.2.0", + "node-localstorage": "^2.2.1", "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz", - "utf8": "^3.0.0", - "node-localstorage": "^2.2.1" + "utf8": "^3.0.0" }, "node-red": { "nodes": { diff --git a/src/matrix-server-config.js b/src/matrix-server-config.js index 7b28cda..68f8b17 100644 --- a/src/matrix-server-config.js +++ b/src/matrix-server-config.js @@ -1,13 +1,15 @@ global.Olm = require('olm'); -const fs = require("fs"); +const fs = require("fs-extra"); const sdk = require("matrix-js-sdk"); const { LocalStorage } = require('node-localstorage'); const { LocalStorageCryptoStore } = require('matrix-js-sdk/lib/crypto/store/localStorage-crypto-store'); module.exports = function(RED) { + function MatrixFolderNameFromUserId(name) { + return name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + } function MatrixServerNode(n) { - let oldStorageDir = './matrix-local-storage'; let storageDir = './matrix-client-storage'; // we should add support for getting access token automatically from username/password @@ -33,10 +35,6 @@ module.exports = function(RED) { this.enableE2ee = n.enableE2ee || false; this.e2ee = (this.enableE2ee && this.deviceId); - function toFolderName(name) { - return name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); - } - if(!this.credentials.accessToken) { node.log("Matrix connection failed: missing access token."); } else if(!this.url) { @@ -44,21 +42,11 @@ module.exports = function(RED) { } else if(!this.userId) { node.log("Matrix connection failed: missing user ID."); } else { - let localStorageDir = storageDir + '/' + toFolderName(this.userId); - - // create storage directory if it doesn't exist - if(!fs.existsSync(storageDir)) { - fs.mkdirSync(storageDir); - } - - // if the old storage location exists lets move it to it's new location - if(fs.existsSync(oldStorageDir) && !fs.existsSync(localStorageDir)){ - node.log("found old '" + oldStorageDir + "' path, moving to new location '" + localStorageDir + "' ------------------------------"); - fs.renameSync(oldStorageDir, localStorageDir); - } + let localStorageDir = storageDir + '/' + MatrixFolderNameFromUserId(this.userId); + fs.ensureDirSync(storageDir); // create storage directory if it doesn't exist + upgradeDirectoryIfNecessary(node, storageDir); const localStorage = new LocalStorage(localStorageDir); - node.matrixClient = sdk.createClient({ baseUrl: this.url, accessToken: this.credentials.accessToken, @@ -172,25 +160,19 @@ module.exports = function(RED) { }); async function run() { - if(node.e2ee){ - const initCrypto = ms => new Promise(res => node.matrixClient.initCrypto()); - try { - await initCrypto(); - } catch(error){ - node.error(error); - } - node.matrixClient.setGlobalErrorOnUnknownDevices(false); - } - - const startClient = ms => new Promise(res => node.matrixClient.startClient({ initialSyncLimit: 8 })); try { - await startClient(); + if(node.e2ee){ + node.log("Initializing crypto..."); + await node.matrixClient.initCrypto(); + node.matrixClient.setGlobalErrorOnUnknownDevices(false); + } + node.log("Connecting to Matrix server..."); + await node.matrixClient.startClient({ initialSyncLimit: 8 }); } catch(error){ node.error(error); } } - node.log("Connecting to Matrix server..."); run().catch((error) => node.error(error)); } } @@ -203,4 +185,30 @@ module.exports = function(RED) { url: { type: "text", required: true }, } }); + + function upgradeDirectoryIfNecessary(node, storageDir) { + let oldStorageDir = './matrix-local-storage'; + + // if the old storage location exists lets move it to it's new location + if(fs.pathExistsSync(oldStorageDir)){ + RED.nodes.eachNode(function(n){ + try { + if(n.type !== 'matrix-server-config') return; + let { userId } = RED.nodes.getCredentials(n.id); + let dir = storageDir + '/' + MatrixFolderNameFromUserId(userId); + if(!fs.pathExistsSync(dir)) { + fs.ensureDirSync(dir); + node.log("found old '" + oldStorageDir + "' path, copying to new location '" + dir); + fs.copySync(oldStorageDir, dir); + } + } catch (err) { + console.error(err) + } + }); + + // rename folder to keep as a backup (and so we don't run again) + node.log("archiving old config folder '" + oldStorageDir + "' to '" + oldStorageDir + "-backup"); + fs.renameSync(oldStorageDir, oldStorageDir + "-backup"); + } + } } \ No newline at end of file From b698389491846d756b96d0b5dcebfc26c555b2bf Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Wed, 1 Sep 2021 07:26:21 -0600 Subject: [PATCH 3/6] - matrix-create-room had wrong input information listed and wrong API reference URL (fixes #14) - fixed docs & node for matrix-receive --- src/matrix-create-room.html | 9 ++----- src/matrix-create-room.js | 1 - src/matrix-receive.html | 51 +++++++++++++++++++++++------------- src/matrix-receive.js | 2 ++ src/matrix-send-message.html | 38 ++++++++++++++------------- 5 files changed, 57 insertions(+), 44 deletions(-) diff --git a/src/matrix-create-room.html b/src/matrix-create-room.html index 6adb022..a745f09 100644 --- a/src/matrix-create-room.html +++ b/src/matrix-create-room.html @@ -38,19 +38,14 @@

Create a room with the defined options in msg.payload

- Synapse API Endpoint Information + Matrix API Endpoint Information

Inputs

msg.payload - string + object
a list of options to pass to the /createRoom API. Click here for information about what can be passed.
- -
msg.userId - string -
-
User's ID that will be set into the room.

Outputs

diff --git a/src/matrix-create-room.js b/src/matrix-create-room.js index eb5b73a..d60d2b3 100644 --- a/src/matrix-create-room.js +++ b/src/matrix-create-room.js @@ -53,7 +53,6 @@ module.exports = function(RED) { }; } - // we need the status code, so set onlydata to false for this request node.server.matrixClient .createRoom(msg.payload || {}) .then(function(e){ diff --git a/src/matrix-receive.html b/src/matrix-receive.html index 7c92d75..209c0db 100644 --- a/src/matrix-receive.html +++ b/src/matrix-receive.html @@ -107,7 +107,7 @@

Receive events from Matrix.

Outputs

-
    +
    • Always Returned
      msg.type string
      @@ -146,6 +146,11 @@
      the event object returned by the Matrix server
      +
      +
      msg.eventId object
      +
      The event ID, e.g. $143350589368169JsLZx:localhost
      +
      +
      msg.content object
      the message's content object
      @@ -159,11 +164,6 @@
    • msg.type == 'm.reaction' -
      -
      msg.info object
      -
      the content's info.
      -
      -
      msg.referenceEventId string
      the message that the reaction relates to
      @@ -187,39 +187,54 @@
      URL to the sticker image
      +
      +
      msg.mxc_url string
      +
      Matrix URL to the sticker image
      +
      +
      msg.thumbnail_url string
      URL to the thumbnail of the sticker
      + +
      +
      msg.thumbnail_mxc_url string
      +
      Matrix URL to the thumbnail of the sticker
      +
    • msg.type == 'm.file'
      -
      msg.file.info string
      -
      the content's info.
      +
      msg.url string
      +
      the file's URL
      -
      msg.file.url string
      -
      the file's URL
      +
      msg.mxc_url string
      +
      the file's Matrix URL
    • msg.type == 'm.image'
      -
      msg.image.info string
      -
      the image info.
      -
      - -
      -
      msg.file.url string
      +
      msg.url string
      the image's URL
      -
      msg.file.thumbnail_url string
      +
      msg.mxc_url string
      +
      the image's Matrix URL
      +
      + +
      +
      msg.thumbnail_url string
      the image's thumbnail URL
      + +
      +
      msg.thumbnail_mxc_url string
      +
      the image's thumbnail Matrix URL
      +
    • -
+ \ No newline at end of file diff --git a/src/matrix-receive.js b/src/matrix-receive.js index 980890c..b01a533 100644 --- a/src/matrix-receive.js +++ b/src/matrix-receive.js @@ -81,10 +81,12 @@ module.exports = function(RED) { if(msg.content.info) { if(msg.content.info.thumbnail_url) { msg.thumbnail_url = node.server.matrixClient.mxcUrlToHttp(msg.content.info.thumbnail_url); + msg.thumbnail_mxc_url = msg.content.info.thumbnail_url; } if(msg.content.url) { msg.url = node.server.matrixClient.mxcUrlToHttp(msg.content.url); + msg.mxc_url = msg.content.url; } } break; diff --git a/src/matrix-send-message.html b/src/matrix-send-message.html index 1023046..f501292 100644 --- a/src/matrix-send-message.html +++ b/src/matrix-send-message.html @@ -25,14 +25,20 @@ +
+
- +
+
+ The configuration Room ID will always override msg.topic +
+
+
+ It's recommended to use m.notice for bots because the message will render in a lighter text (at least in Element client) for users to distinguish bot and real user messages. +
+
-
- Must be a valid MIME Type -
@@ -66,18 +40,18 @@

Inputs

msg.payload - String + string
Usually an emoji but can also be text.
msg.topic - String | Null + string | null
Room ID to send image to. Optional if configured on the node. If configured on the node this will be ignored.
msg.referenceEventId
msg.eventId - String + string
One of these is required. This is the eventId of the message to react to. Uses msg.referenceEventId first and falls back to msg.eventId.
@@ -86,8 +60,6 @@
  1. Success
    -
    original msg object preserved.
    -
    msg.eventId string
    the eventId from the posted reaction.
    diff --git a/src/matrix-room-ban.html b/src/matrix-room-ban.html index 45f78ed..92b9252 100644 --- a/src/matrix-room-ban.html +++ b/src/matrix-room-ban.html @@ -31,9 +31,6 @@ -
    - Room ID must either be defined here or passed in via msg.topic. The config takes precedence over the input. -
    @@ -48,36 +48,42 @@

    Inputs

    msg.payload - File | String | Buffer | ReadStream | Blob + File | string | Buffer | ReadStream | Blob
    the contents of the file to upload.
    msg.topic - String | Null + string
    -
    Room ID to send file to. Optional if configured on the node. Overrides node configuration if set.
    +
    Room ID to send file to. Ignored if configured on the node, otherwise required.
    msg.filename - String | Null + string | null
    -
    name of the file to upload (optional). Overrides node configuration.
    - -
    msg.contentType - String | Null -
    -
    Content MIME Type. Optional if configured on the node. Overrides node configuration if set.
    +
    name of the file to upload (optional). Note: If this is not defined the file will receive a randomly generated name (without an extension).
    msg.body - String | Null + string | null
    -
    this will be the display name the client will see when rendered in their chat client. If this is left empty the it uses msg.filename. If msg.filename is also undefined it sets it to empty string
    +
    this will be the display name the client will see when rendered in their chat client. If this is left empty it will just display as "Attachment".
    + +
    msg.contentType + string | null +
    +
    Content MIME Type. Optional but highly recommended (so the client receiving knows what type of file it is).
    + +
    msg.content + object | null +
    +
    craft your own msg.content to send to the server. If defined then msg.filename, msg.contentType, msg.body, and msg.payload aren't required since the file already exists.

    Outputs

    1. Success
      -
      original msg object preserved.
      +
      msg.eventId string
      +
      the eventId from the posted message.
    2. Error diff --git a/src/matrix-send-file.js b/src/matrix-send-file.js index 247fb98..d6a6d59 100644 --- a/src/matrix-send-file.js +++ b/src/matrix-send-file.js @@ -61,17 +61,12 @@ module.exports = function(RED) { return; } - msg.contentType = msg.contentType || node.contentType; - if(!msg.contentType) { - node.error('msg.contentType is required'); - return; - } - + msg.contentType = node.contentType || msg.contentType || null; node.log("Uploading file " + msg.filename); node.server.matrixClient.uploadContent( msg.payload, { name: msg.filename || null, // Name to give the file on the server. - rawResponse: (msg.rawResponse || false), // Return the raw body, rather than parsing the JSON. + rawResponse: false, // Return the raw body, rather than parsing the JSON. type: msg.contentType, // Content-type for the upload. Defaults to file.type, or applicaton/octet-stream. onlyContentUri: false // Just return the content URI, rather than the whole body. Defaults to false. Ignored if opts.rawResponse is true. }) @@ -79,18 +74,18 @@ module.exports = function(RED) { const content = { msgtype: 'm.file', url: file.content_uri, - body: (msg.body || msg.filename) || "", + body: msg.body || "", }; node.server.matrixClient .sendMessage(msg.topic, content) - .then(function(imgResp) { - node.log("File message sent: " + imgResp); + .then(function(e) { + node.log("File message sent: " + e); msg.eventId = e.eventId; node.send([msg, null]); }) .catch(function(e){ node.warn("Error sending file message " + e); - msg.matrixError = e; + msg.error = e; node.send([null, msg]); }); }).catch(function(e){ diff --git a/src/matrix-send-image.html b/src/matrix-send-image.html index 2faa577..655c283 100644 --- a/src/matrix-send-image.html +++ b/src/matrix-send-image.html @@ -30,50 +30,50 @@
      - +
      - Must be a valid MIME Type + Must be a valid MIME Type (ex: image/png) or left empty
      @@ -79,7 +79,8 @@
      1. Success
        -
        original msg object preserved.
        +
        msg.error object
        +
        empty object response
      2. Error diff --git a/src/matrix-synapse-deactivate-user.js b/src/matrix-synapse-deactivate-user.js index 5597805..76f023f 100644 --- a/src/matrix-synapse-deactivate-user.js +++ b/src/matrix-synapse-deactivate-user.js @@ -55,7 +55,13 @@ module.exports = function(RED) { { $userId: msg.userId }, ); node.server.matrixClient.http - .authedRequest(undefined, 'POST', path, undefined, { "erase": (msg.erase || false) }, { prefix: '' }) + .authedRequest( + undefined, + 'POST', + path, + undefined, + {"erase": (msg.erase || false)}, + {"prefix": '' }) .then(function(e){ msg.payload = e; node.send([msg, null]); diff --git a/src/matrix-synapse-join-room.html b/src/matrix-synapse-join-room.html index fbabfe3..ad905b0 100644 --- a/src/matrix-synapse-join-room.html +++ b/src/matrix-synapse-join-room.html @@ -51,7 +51,7 @@
        msg.topic string
        -
        The room identifier or alias to join: for example, !h8zld9j31:example.com.. Not required if set in the config and will be ignored even if set.
        +
        The room identifier or alias to join: for example, !h8zld9j31:example.com.. Ignored if configured on the node, otherwise required.
        msg.userId string @@ -63,8 +63,8 @@
        1. Success
          -
          msg.payload string
          -
          This returns data directly from the API endpoint. Click here to see what this returns.
          +
          msg.topic string
          +
          the ID of the room we just added the user to.
        2. Error diff --git a/src/matrix-synapse-join-room.js b/src/matrix-synapse-join-room.js index 546a5a5..55a3682 100644 --- a/src/matrix-synapse-join-room.js +++ b/src/matrix-synapse-join-room.js @@ -46,8 +46,8 @@ module.exports = function(RED) { node.send([null, msg]); } - let roomId = node.roomId || msg.topic; - if(!roomId) { + msg.topic = node.roomId || msg.topic; + if(!msg.topic) { node.error("room must be defined in either msg.topic or in node config"); return; } @@ -70,7 +70,7 @@ module.exports = function(RED) { { "user_id": msg.userId }, { prefix: '' } ).then(function(e){ - msg.payload = e; + msg.topic = e.room_id; node.send([msg, null]); }).catch(function(e){ node.warn("Error joining user to room " + e); diff --git a/src/matrix-synapse-register.html b/src/matrix-synapse-register.html index cea1c35..1a38ae3 100644 --- a/src/matrix-synapse-register.html +++ b/src/matrix-synapse-register.html @@ -51,32 +51,32 @@

          Inputs

          msg.payload - Object + object
          Details of the new user to create.
          msg.payload.displayname - String | null + string | null
          Set the displayname for the user (default to username if not set).
          msg.payload.username - Object + object
          Username for the new user.
          msg.payload.password - String + string
          Password for the new user.
          msg.payload.admin - Bool + bool
          If true, the new user will be an admin. Default to false.
          msg.payload.user_type - String | null + string | null
          Set the user type. Leave this to null if you don't know what it is for. Check here and look for class UserTypes to figure out what is valid.
          @@ -84,9 +84,7 @@

          Outputs

          1. Success -
            -
            original msg object preserved.
            - +
            `
            msg.eventId string
            the eventId from the posted message.
            diff --git a/src/matrix-synapse-users.html b/src/matrix-synapse-users.html index 1e6e12f..b6ff5cc 100644 --- a/src/matrix-synapse-users.html +++ b/src/matrix-synapse-users.html @@ -39,22 +39,22 @@

            Inputs

            msg.from - Integer + integer
            -
            Is optional but used for pagination, denoting the offset in the returned results. This should be treated as an opaque value and not explicitly set to anything other than the return value of next_token from a previous call. Defaults to 0.
            +
            Is optional but used for pagination, denoting the offset in the returned results. This should be treated as an opaque value and not explicitly set to anything other than the return value of msg.next_token from a previous call. Defaults to 0.
            msg.limit - Integer + integer
            limit - representing a positive integer - Is optional but is used for pagination, denoting the maximum number of items to return in this call. Defaults to 100.
            msg.guests - Bool + bool
            Is optional and if false will exclude guest users. Defaults to true to include guest users.
            msg.order_by - String + string
            The method by which to sort the returned list of users. @@ -85,14 +85,41 @@
            msg.payload object
            the response object from the server.
            +
            msg.payload.next_token string
            +
            string representing a positive integer - Indication for pagination. If this is unset then there are no more users to paginate through.
            + +
            msg.payload.total integer
            +
            Total number of users.
            +
            msg.payload.users array
            -
            list of users from the Matrix server. Click here for details on what this contains (or do a test and dump the output). We would put the details here in the doc but Synapse is constantly changing so it's best to reference the official Synapse docs.
            +
            list of users from the Matrix server. Click here for details on what this contains (or do a debug on the output).
            -
            msg.next_token string
            -
            string representing a positive integer - Indication for pagination. See above (input msg.from)
            +
            msg.payload.users[].name string
            +
            Fully-qualified user ID (ex. @user:server.com).
            -
            msg.total integer
            -
            Total number of media.
            +
            msg.payload.users[].is_guest bool
            +
            Status if that user is a guest account.
            + +
            msg.payload.users[].admin string
            +
            Status if that user is a server administrator.
            + +
            msg.payload.users[].user_type string
            +
            Type of the user. Normal users are type None. This allows user type specific behaviour. There are also types support and bot.
            + +
            msg.payload.users[].deactivated bool
            +
            Status if that user has been marked as deactivated.
            + +
            msg.payload.users[].shadow_banned bool
            +
            Status if that user has been marked as shadow banned.
            + +
            msg.payload.users[].displayname string
            +
            The user's display name if they have set one.
            + +
            msg.payload.users[].avatar_url string
            +
            The user's avatar URL if they have set one.
            + +
            msg.payload.users[].creation_ts integer
            +
            The user's creation timestamp in ms.
          2. Error diff --git a/src/matrix-synapse-users.js b/src/matrix-synapse-users.js index 32d42e0..7be6eb3 100644 --- a/src/matrix-synapse-users.js +++ b/src/matrix-synapse-users.js @@ -58,7 +58,7 @@ module.exports = function(RED) { msg.payload = e; node.send([msg, null]); }).catch(function(e){ - node.warn("Error fetching user list " + e); + node.warn("Error fetching server user list " + e); msg.error = e; node.send([null, msg]); }); diff --git a/src/matrix-whois-user.html b/src/matrix-whois-user.html index edf68a4..81f1386 100644 --- a/src/matrix-whois-user.html +++ b/src/matrix-whois-user.html @@ -36,6 +36,7 @@