From 3d81466788ed9884fc6233ea7d8a0db7c2932de0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Feb 2022 16:30:46 +0100 Subject: [PATCH] components/app: introduce receiptFromMessage --- components/app.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/app.js b/components/app.js index 4f3dd8c..e3d35ff 100644 --- a/components/app.js +++ b/components/app.js @@ -144,6 +144,16 @@ function showNotification(title, options) { } } +function receiptFromMessage(msg) { + // At this point all messages are supposed to have a time tag. + // App.addMessage ensures this is the case even if the server doesn't + // support server-time. + if (!msg.tags.time) { + throw new Error("Missing time message tag"); + } + return { time: msg.tags.time }; +} + let lastErrorID = 0; export default class App extends Component { @@ -464,7 +474,7 @@ export default class App extends Component { // TODO: this doesn't trigger a redraw this.receipts.set(target, { ...this.receipts.get(target), - [type]: { time: msg.tags.time }, + [type]: receiptFromMessage(msg), }); this.saveReceipts(); } @@ -587,7 +597,7 @@ export default class App extends Component { // Don't show unread marker for my own messages if (client.isMyNick(msg.prefix.name) && (!prevReadReceipt || prevReadReceipt.time < msg.tags.time)) { - prevReadReceipt = { time: msg.tags.time }; + prevReadReceipt = receiptFromMessage(msg); } this.bufferStore.put({