mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-28 18:45:51 -05:00
keybindings: fix error on alt+h
Fixes the following JS error: TypeError: e.setReceipt is not a function
This commit is contained in:
parent
fbc42b6dab
commit
5f8cd976e6
3 changed files with 19 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
|
|
10
state.js
10
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;
|
||||
|
|
Loading…
Reference in a new issue