diff --git a/commands/media.js b/commands/media.js
index 593678f..cda0c47 100644
--- a/commands/media.js
+++ b/commands/media.js
@@ -28,7 +28,7 @@ const mediaUpload = async ({ domain, token }, { data, mimetype }) => {
return upload.data.id;
};
-const run = async (matrixClient, { roomId }, mediaURL, content, registrar) => {
+const run = async (matrixClient, { roomId }, mediaURL, content, replyId, registrar) => {
const fediverse = registrar.config.fediverse;
const media = await mediaDownload(mediaURL, registrar.config.matrix.mimetypes);
const mediaId = await mediaUpload(fediverse, media);
@@ -40,21 +40,27 @@ const run = async (matrixClient, { roomId }, mediaURL, content, registrar) => {
status: content,
content_type: `text/markdown`,
media_ids: [ mediaId ],
+ in_reply_to_id: replyId || undefined
}, { arrayFormat: 'brackets' })
});
return matrixClient.sendHtmlNotice(roomId, '', `${response.data.id}`);
}
-exports.runQuery = async (client, room, userInput, registrar) => {
+exports.runQuery = async (client, room, userInput, isReply, registrar) => {
try {
- let chunks = userInput.trim().split(' ');
+ const chunks = userInput.trim().split(' ');
if(chunks.length < 2) throw '';
+ let replyId = null;
+ if(isReply) {
+ replyId = chunks[0];
+ chunks.shift();
+ }
const url = new URL(chunks[0]);
chunks.shift();
if(url.protocol !== 'https:') throw '';
if(!registrar.config.matrix.domains.includes(url.hostname)) throw '';
if(!/^\/_matrix\/media\/r0\/download\/[^/]+\/[^/]+\/?$/.test(url.pathname)) throw '';
- return await run(client, room, url.toString(), chunks.join(' '), registrar);
+ return await run(client, room, url.toString(), chunks.join(' '), replyId, registrar);
} catch(e) {
return client.sendHtmlNotice(room.roomId, 'Sad!', `Sad!`).catch(()=>{});
}
diff --git a/main.js b/main.js
index 45ec64d..cf9cdcf 100644
--- a/main.js
+++ b/main.js
@@ -129,7 +129,11 @@ let CreateClient = (token, user_id) => {
}
if (command === 'media') {
- registrar.media.runQuery(matrixClient, room, userInput, registrar);
+ registrar.media.runQuery(matrixClient, room, userInput, false, registrar);
+ }
+
+ if (command === 'mediareply') {
+ registrar.media.runQuery(matrixClient, room, userInput, true, registrar);
}
if (command === 'status') {