send read reciepts

This commit is contained in:
Sorunome 2020-03-24 21:26:52 +01:00
parent 79dc0295cf
commit 5bc2c64859
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 55 additions and 2 deletions

View File

@ -77,7 +77,9 @@ export class Client extends EventEmitter {
}
break;
case "ThreadActivity":
// log.silly(resource);
if (subtype === "MemberConsumptionHorizonUpdate") {
this.emit("presence", resource);
}
break;
}
});

View File

@ -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);
}
}