From 12c422c3244cf50ea6e52cdda5350ea256dcd567 Mon Sep 17 00:00:00 2001 From: vulet Date: Mon, 4 Sep 2023 17:43:52 +0800 Subject: [PATCH] fix(timeline): some missing files --- commands/expand.js | 9 +++++++++ commands/fediverse/react.js | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 commands/expand.js create mode 100644 commands/fediverse/react.js diff --git a/commands/expand.js b/commands/expand.js new file mode 100644 index 0000000..f327bcb --- /dev/null +++ b/commands/expand.js @@ -0,0 +1,9 @@ +exports.runQuery = async (roomId, event, userInput) => { + return matrix.utils.fetchEncryptedOrNot(roomId, { event_id: userInput }) + .then(event => matrix.utils.expandReact(event)) + .catch(e => { + matrixClient.sendHtmlNotice(roomId, 'Sad!', 'Sad!') + }) + .catch(() => {}); + }; + diff --git a/commands/fediverse/react.js b/commands/fediverse/react.js new file mode 100644 index 0000000..a75fa14 --- /dev/null +++ b/commands/fediverse/react.js @@ -0,0 +1,26 @@ +const run = async (roomId, event, id, emoji, remove) => { + axios({ + method: remove ? 'DELETE' : 'PUT', + url: `${config.fediverse.domain}/api/v1/pleroma/statuses/${id}/reactions/${emoji}`, + headers: { Authorization: `Bearer ${fediverse.auth.access_token}` }, + }) + .then(() => { + matrix.utils.addReact(event, '✅'); + }) + .catch((e) => { + matrix.utils.addReact(event, '❌'); + matrix.utils.sendError(event, roomId, e); + }); +}; + +exports.runQuery = async (roomId, event, userInput, remove) => { + try { + const chunks = userInput.trim().split(' '); + if (chunks.length !== 2) throw ''; + const id = encodeURIComponent(chunks[0]); + const emoji = encodeURIComponent(chunks[1]); + return run(roomId, event, id, emoji, remove); + } catch (e) { + return matrixClient.sendHtmlNotice(roomId, 'Sad!', 'Sad!').catch(() => {}); + } +};