From 5f8cd976e6dd8826c0c35e5e7b6f54ff7507e965 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 12 Feb 2022 10:05:58 +0100 Subject: [PATCH] keybindings: fix error on alt+h Fixes the following JS error: TypeError: e.setReceipt is not a function --- components/app.js | 12 +----------- keybindings.js | 14 ++++++++------ state.js | 10 ++++++++++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/components/app.js b/components/app.js index a0cb31e..320fff1 100644 --- a/components/app.js +++ b/components/app.js @@ -16,7 +16,7 @@ import ScrollManager from "./scroll-manager.js"; import Dialog from "./dialog.js"; import { html, Component, createRef } from "../lib/index.js"; import { strip as stripANSI } from "../lib/ansi.js"; -import { SERVER_BUFFER, BufferType, ReceiptType, ServerStatus, Unread, State, getServerName, isMessageBeforeReceipt } from "../state.js"; +import { SERVER_BUFFER, BufferType, ReceiptType, ServerStatus, Unread, State, getServerName, receiptFromMessage, isMessageBeforeReceipt } from "../state.js"; import commands from "../commands.js"; import { setup as setupKeybindings } from "../keybindings.js"; import * as store from "../store.js"; @@ -133,16 +133,6 @@ 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 }; -} - function getReceipt(stored, type) { if (!stored || !stored.receipts) { return null; diff --git a/keybindings.js b/keybindings.js index 655bf42..dc76c5a 100644 --- a/keybindings.js +++ b/keybindings.js @@ -1,4 +1,4 @@ -import { ReceiptType, Unread, BufferType, SERVER_BUFFER } from "./state.js"; +import { ReceiptType, Unread, BufferType, SERVER_BUFFER, receiptFromMessage } from "./state.js"; function getSiblingBuffer(buffers, bufID, delta) { let bufList = Array.from(buffers.values()); @@ -19,22 +19,24 @@ export const keybindings = [ app.setState((state) => { let buffers = new Map(); state.buffers.forEach((buf) => { - if (buf.messages.length > 0) { - let lastMsg = buf.messages[buf.messages.length - 1]; - app.setReceipt(buf.name, ReceiptType.READ, lastMsg); - } - buffers.set(buf.id, { ...buf, unread: Unread.NONE, prevReadReceipt: null, }); + let receipts = {}; + if (buf.messages.length > 0) { + let lastMsg = buf.messages[buf.messages.length - 1]; + receipts[ReceiptType.READ] = receiptFromMessage(lastMsg); + } + let client = app.clients.get(buf.server); app.bufferStore.put({ name: buf.name, server: client.params, unread: Unread.NONE, + receipts, }); }); return { buffers }; diff --git a/state.js b/state.js index a2c04d5..b2e4aeb 100644 --- a/state.js +++ b/state.js @@ -85,6 +85,16 @@ export function getServerName(server, bouncerNetwork) { } } +export 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 }; +} + export function isMessageBeforeReceipt(msg, receipt) { if (!receipt) { return false;