From f79b6bfaa11192ee11fa4be86bc72ca41515dd19 Mon Sep 17 00:00:00 2001 From: sitting33 Date: Thu, 25 Apr 2024 15:59:47 +0200 Subject: [PATCH] components/app: split switchBuffer() and markBufferAsRead() We'll want to mark as read independently in response to focus events. --- components/app.js | 67 +++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/components/app.js b/components/app.js index dcd1dfd..e6f5c77 100644 --- a/components/app.js +++ b/components/app.js @@ -537,17 +537,7 @@ export default class App extends Component { if (!buf) { return; } - - let client = this.clients.get(buf.server); - let stored = this.bufferStore.get({ name: buf.name, server: client.params }); - let prevReadReceipt = getReceipt(stored, ReceiptType.READ); - // TODO: only mark as read if user scrolled at the bottom - let update = State.updateBuffer(state, buf.id, { - unread: Unread.NONE, - prevReadReceipt, - }); - - return { ...update, activeBuffer: buf.id }; + return { activeBuffer: buf.id }; }, () => { if (!buf) { return; @@ -557,6 +547,46 @@ export default class App extends Component { this.buffer.current.focus(); } + let server = this.state.servers.get(buf.server); + if (buf.type === BufferType.NICK && !server.users.has(buf.name)) { + this.whoUserBuffer(buf.name, buf.server); + } + + if (buf.type === BufferType.CHANNEL && !buf.hasInitialWho) { + this.whoChannelBuffer(buf.name, buf.server); + } + + if (buf.type !== BufferType.SERVER) { + document.title = buf.name + ' · ' + this.baseTitle; + } else { + document.title = this.baseTitle; + } + }); + + // TODO: only mark as read if user scrolled at the bottom + this.markBufferAsRead(id); + } + + markBufferAsRead(id) { + let buf; + this.setState((state) => { + buf = State.getBuffer(state, id); + if (!buf) { + return; + } + + let client = this.clients.get(buf.server); + let stored = this.bufferStore.get({ name: buf.name, server: client.params }); + let prevReadReceipt = getReceipt(stored, ReceiptType.READ); + return State.updateBuffer(state, buf.id, { + unread: Unread.NONE, + prevReadReceipt, + }); + }, () => { + if (!buf) { + return; + } + let client = this.clients.get(buf.server); for (let notif of this.messageNotifications) { @@ -577,21 +607,6 @@ export default class App extends Component { this.sendReadReceipt(client, stored); } } - - let server = this.state.servers.get(buf.server); - if (buf.type === BufferType.NICK && !server.users.has(buf.name)) { - this.whoUserBuffer(buf.name, buf.server); - } - - if (buf.type === BufferType.CHANNEL && !buf.hasInitialWho) { - this.whoChannelBuffer(buf.name, buf.server); - } - - if (buf.type !== BufferType.SERVER) { - document.title = buf.name + ' · ' + this.baseTitle; - } else { - document.title = this.baseTitle; - } }); }