Add support for draft/read-marker

References: https://github.com/ircv3/ircv3-specifications/pull/489
This commit is contained in:
Simon Ser 2022-06-27 16:08:15 +02:00
parent 839e46360e
commit 1428ec4d49
2 changed files with 34 additions and 10 deletions

View file

@ -414,17 +414,14 @@ export default class App extends Component {
} }
sendReadReceipt(client, storedBuffer) { sendReadReceipt(client, storedBuffer) {
if (!client.caps.enabled.has("soju.im/read")) { if (!client.supportsReadMarker()) {
return; return;
} }
let readReceipt = storedBuffer.receipts[ReceiptType.READ]; let readReceipt = storedBuffer.receipts[ReceiptType.READ];
if (storedBuffer.name === "*" || !readReceipt) { if (storedBuffer.name === "*" || !readReceipt) {
return; return;
} }
client.send({ client.setReadMarker(storedBuffer.name, readReceipt.time);
command: "READ",
params: [storedBuffer.name, "timestamp="+readReceipt.time],
});
} }
switchBuffer(id) { switchBuffer(id) {
@ -870,6 +867,7 @@ export default class App extends Component {
case "CHATHISTORY": case "CHATHISTORY":
case "ACK": case "ACK":
case "BOUNCER": case "BOUNCER":
case "MARKREAD":
case "READ": case "READ":
// Ignore these // Ignore these
return []; return [];
@ -1020,6 +1018,7 @@ export default class App extends Component {
this.autoOpenURL = null; this.autoOpenURL = null;
} }
break; break;
case "MARKREAD":
case "READ": case "READ":
target = msg.params[0]; target = msg.params[0];
let bound = msg.params[1]; let bound = msg.params[1];
@ -1228,11 +1227,8 @@ export default class App extends Component {
}); });
client.monitor(target); client.monitor(target);
if (client.caps.enabled.has("soju.im/read")) { if (client.supportsReadMarker()) {
client.send({ client.fetchReadMarker(target);
command: "READ",
params: [target],
});
} }
} }

View file

@ -1015,4 +1015,32 @@ export default class Client extends EventTarget {
return { message: msg.params[2] }; 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],
});
}
} }