Redacts from matrix and documents from vk

This commit is contained in:
Inex Code 2020-11-13 02:02:21 +00:00
parent f384ba6584
commit 5c99493052
4 changed files with 33 additions and 5 deletions

View File

@ -23,20 +23,21 @@ Register that one with synapse and start the bridge with `npm run start`.
- [ ] Presence - not possible yet - [ ] Presence - not possible yet
- [ ] Read notifications - not possible yet - [ ] Read notifications - not possible yet
- [x] Message edits - [x] Message edits
- [ ] Message redacts - [x] Message redacts - only works in 24 hours after message is sent
- VK -> Matrix - VK -> Matrix
- [x] Text content - [x] Text content
- [ ] Forwards
- [x] Image content - [x] Image content
- [x] Audio content - [x] Audio content
- [ ] Video content - [ ] Video content
- [x] Stickers - [x] Stickers
- [ ] Other files - [x] Other files
- [ ] Presence - not effective to track - [ ] Presence - not effective to track
- [x] Typing notifs - [x] Typing notifs
- [x] User profiles - [x] User profiles
- [ ] Read notifications - not effective to track - [ ] Read notifications - not effective to track
- [x] Message edits - [x] Message edits
- [ ] Message redacts - [ ] Message redacts - doesn't work
## Usage ## Usage
1. Get VK community token (Just open the "Manage community" tab, go to "API usage" tab and click "Create token") 1. Get VK community token (Just open the "Manage community" tab, go to "API usage" tab and click "Create token")

View File

@ -89,6 +89,7 @@ async function run() {
puppet.on("puppetDelete", vk.deletePuppet.bind(vk)); puppet.on("puppetDelete", vk.deletePuppet.bind(vk));
puppet.on("message", vk.handleMatrixMessage.bind(vk)); puppet.on("message", vk.handleMatrixMessage.bind(vk));
puppet.on("edit", vk.handleMatrixEdit.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("reply", vk.handleMatrixReply.bind(vk));
puppet.on("image", vk.handleMatrixImage.bind(vk)); puppet.on("image", vk.handleMatrixImage.bind(vk));
puppet.on("file", vk.handleMatrixFile.bind(vk)); puppet.on("file", vk.handleMatrixFile.bind(vk));

View File

@ -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( public async handleMatrixReply(
room: IRemoteRoom, room: IRemoteRoom,
@ -361,7 +377,7 @@ export class VkPuppet {
if (!p) { if (!p) {
return; return;
} }
//log.info("Received new message!", context); log.info("Received new message!", context);
if (context.isOutbox) { if (context.isOutbox) {
return; // Deduping return; // Deduping
} }
@ -399,7 +415,6 @@ export class VkPuppet {
switch (f.type) { switch (f.type) {
case AttachmentType.PHOTO: case AttachmentType.PHOTO:
try { try {
// tslint:disable-next-line: no-string-literal
await this.puppet.sendFileDetect(params, f["largeSizeUrl"]); await this.puppet.sendFileDetect(params, f["largeSizeUrl"]);
} catch (err) { } catch (err) {
const opts: IMessageEvent = { const opts: IMessageEvent = {
@ -428,6 +443,16 @@ export class VkPuppet {
await this.puppet.sendMessage(params, opts); await this.puppet.sendMessage(params, opts);
} }
break; 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: default:
break; break;
} }

View File

@ -20,6 +20,7 @@
"curly": true, "curly": true,
"no-empty": false, "no-empty": false,
"no-invalid-this": true, "no-invalid-this": true,
"no-string-literal": false,
"no-string-throw": { "no-string-throw": {
"severity": "warning" "severity": "warning"
}, },