From 5bc2c6485916b1eb32e42bddcf2bf674e5d65101 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 24 Mar 2020 21:26:52 +0100 Subject: [PATCH] send read reciepts --- src/client.ts | 4 +++- src/skype.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index d4f0629..d9bdd2b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -77,7 +77,9 @@ export class Client extends EventEmitter { } break; case "ThreadActivity": -// log.silly(resource); + if (subtype === "MemberConsumptionHorizonUpdate") { + this.emit("presence", resource); + } break; } }); diff --git a/src/skype.ts b/src/skype.ts index d3b68ac..fd2a7d5 100644 --- a/src/skype.ts +++ b/src/skype.ts @@ -106,6 +106,7 @@ export class Skype { if (!p) { return; } + p.client = new Client(p.data.username, p.data.password); const client = p.client; client.on("text", async (resource: skypeHttp.resources.TextResource) => { try { @@ -137,11 +138,18 @@ export class Skype { }); client.on("typing", async (resource: skypeHttp.resources.Resource, typing: boolean) => { try { - + await this.handleSkypeTyping(puppetId, resource, typing); } catch (err) { log.error("Error while handling typing event", err); } }); + client.on("presence", async (resource: skypeHttp.resources.Resource) => { + try { + await this.handleSkypePresence(puppetId, resource); + } catch (err) { + log.error("Error while handling presence event", err); + } + }); await client.connect(); await this.puppet.setUserId(puppetId, client.username); } @@ -412,4 +420,47 @@ export class Skype { const buffer = await p.client.downloadFile(resource.uri); await this.puppet.sendFileDetect(params, buffer, filename); } + + private async handleSkypeTyping(puppetId: number, resource: skypeHttp.resources.Resource, typing: boolean) { + const p = this.puppets[puppetId]; + if (!p) { + return; + } + log.info("Got new skype typing event"); + log.silly(resource); + const params = await this.getSendParams(puppetId, resource); + if (!params) { + log.warn("Couldn't generate params"); + return; + } + await this.puppet.setUserTyping(params, typing); + } + + private async handleSkypePresence(puppetId: number, resource: skypeHttp.resources.Resource) { + const p = this.puppets[puppetId]; + if (!p || !resource.native) { + return; + } + log.info("Got new skype presence event"); + log.silly(resource); + const content = JSON.parse(resource.native.content); + const contact = await p.client.getContact(content.user); + const conversation = await p.client.getConversation({ + puppetId, + roomId: resource.conversation, + }); + if (!contact || !conversation) { + log.warn("Couldn't generate params"); + return; + } + const params: IReceiveParams = { + user: this.getUserParams(puppetId, contact), + room: this.getRoomParams(puppetId, conversation), + }; + const [id, _, clientId] = content.consumptionhorizon.split(";"); + params.eventId = id; + await this.puppet.sendReadReceipt(params); + params.eventId = clientId; + await this.puppet.sendReadReceipt(params); + } }