From 1428ec4d49911a1dccc92d1079fb1a86d8499316 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 27 Jun 2022 16:08:15 +0200 Subject: [PATCH] Add support for draft/read-marker References: https://github.com/ircv3/ircv3-specifications/pull/489 --- components/app.js | 16 ++++++---------- lib/client.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/components/app.js b/components/app.js index e340ef9..d4a100d 100644 --- a/components/app.js +++ b/components/app.js @@ -414,17 +414,14 @@ export default class App extends Component { } sendReadReceipt(client, storedBuffer) { - if (!client.caps.enabled.has("soju.im/read")) { + if (!client.supportsReadMarker()) { return; } let readReceipt = storedBuffer.receipts[ReceiptType.READ]; if (storedBuffer.name === "*" || !readReceipt) { return; } - client.send({ - command: "READ", - params: [storedBuffer.name, "timestamp="+readReceipt.time], - }); + client.setReadMarker(storedBuffer.name, readReceipt.time); } switchBuffer(id) { @@ -870,6 +867,7 @@ export default class App extends Component { case "CHATHISTORY": case "ACK": case "BOUNCER": + case "MARKREAD": case "READ": // Ignore these return []; @@ -1020,6 +1018,7 @@ export default class App extends Component { this.autoOpenURL = null; } break; + case "MARKREAD": case "READ": target = msg.params[0]; let bound = msg.params[1]; @@ -1228,11 +1227,8 @@ export default class App extends Component { }); client.monitor(target); - if (client.caps.enabled.has("soju.im/read")) { - client.send({ - command: "READ", - params: [target], - }); + if (client.supportsReadMarker()) { + client.fetchReadMarker(target); } } diff --git a/lib/client.js b/lib/client.js index 70d59c0..c887d28 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1015,4 +1015,32 @@ export default class Client extends EventTarget { return { message: msg.params[2] }; }); } + + supportsReadMarker() { + return this.caps.enabled.has("draft/read-marker") || this.caps.enabled.has("soju.im/read"); + } + + _markReadCmd() { + if (this.caps.enabled.has("draft/read-marker")) { + return "MARKREAD"; + } else if (this.caps.enabled.has("soju.im/read")) { + return "READ"; + } else { + return null; + } + } + + fetchReadMarker(target) { + this.send({ + command: this._markReadCmd(), + params: [target], + }); + } + + setReadMarker(target, t) { + this.send({ + command: this._markReadCmd(), + params: [target, "timestamp="+t], + }); + } }