From 5c99493052b20232f0a3495abeb711404df7696b Mon Sep 17 00:00:00 2001 From: Inex Code Date: Fri, 13 Nov 2020 02:02:21 +0000 Subject: [PATCH] Redacts from matrix and documents from vk --- README.md | 7 ++++--- src/index.ts | 1 + src/vk.ts | 29 +++++++++++++++++++++++++++-- tslint.json | 1 + 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c33764a..c6fd1a5 100755 --- a/README.md +++ b/README.md @@ -23,20 +23,21 @@ Register that one with synapse and start the bridge with `npm run start`. - [ ] Presence - not possible yet - [ ] Read notifications - not possible yet - [x] Message edits - - [ ] Message redacts + - [x] Message redacts - only works in 24 hours after message is sent - VK -> Matrix - [x] Text content + - [ ] Forwards - [x] Image content - [x] Audio content - [ ] Video content - [x] Stickers - - [ ] Other files + - [x] Other files - [ ] Presence - not effective to track - [x] Typing notifs - [x] User profiles - [ ] Read notifications - not effective to track - [x] Message edits - - [ ] Message redacts + - [ ] Message redacts - doesn't work ## Usage 1. Get VK community token (Just open the "Manage community" tab, go to "API usage" tab and click "Create token") diff --git a/src/index.ts b/src/index.ts index 3d8efd9..32fd11c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -89,6 +89,7 @@ async function run() { puppet.on("puppetDelete", vk.deletePuppet.bind(vk)); puppet.on("message", vk.handleMatrixMessage.bind(vk)); puppet.on("edit", vk.handleMatrixEdit.bind(vk)); + puppet.on("redact", vk.handleMatrixRedact.bind(vk)); puppet.on("reply", vk.handleMatrixReply.bind(vk)); puppet.on("image", vk.handleMatrixImage.bind(vk)); puppet.on("file", vk.handleMatrixFile.bind(vk)); diff --git a/src/vk.ts b/src/vk.ts index 30e7cc4..1403b7e 100755 --- a/src/vk.ts +++ b/src/vk.ts @@ -214,6 +214,22 @@ export class VkPuppet { } } + public async handleMatrixRedact(room: IRemoteRoom, eventId: string) { + const p = this.puppets[room.puppetId]; + if (!p) { + return; + } + // usually you'd send it here to the remote protocol via the client object + try { + await p.client.api.messages.delete({ + spam: 0, + delete_for_all: 1, + message_ids: Number(eventId), + }); + } catch (err) { + log.error("Error sending edit to vk", err.error || err.body || err); + } + } public async handleMatrixReply( room: IRemoteRoom, @@ -361,7 +377,7 @@ export class VkPuppet { if (!p) { return; } - //log.info("Received new message!", context); + log.info("Received new message!", context); if (context.isOutbox) { return; // Deduping } @@ -399,7 +415,6 @@ export class VkPuppet { switch (f.type) { case AttachmentType.PHOTO: try { - // tslint:disable-next-line: no-string-literal await this.puppet.sendFileDetect(params, f["largeSizeUrl"]); } catch (err) { const opts: IMessageEvent = { @@ -428,6 +443,16 @@ export class VkPuppet { await this.puppet.sendMessage(params, opts); } break; + case AttachmentType.DOCUMENT: + try { + await this.puppet.sendFileDetect(params, f["url"], f["title"]); + } catch (err) { + const opts: IMessageEvent = { + body: `Document was sent: ${f["url"]}`, + }; + await this.puppet.sendMessage(params, opts); + } + break; default: break; } diff --git a/tslint.json b/tslint.json index 537caab..9ec0487 100755 --- a/tslint.json +++ b/tslint.json @@ -20,6 +20,7 @@ "curly": true, "no-empty": false, "no-invalid-this": true, + "no-string-literal": false, "no-string-throw": { "severity": "warning" },