Introduce isMessageBeforeReceipt

This commit is contained in:
Simon Ser 2022-02-11 16:37:58 +01:00
parent 3d81466788
commit d2bcea8c86
3 changed files with 18 additions and 5 deletions

View file

@ -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 } from "../state.js";
import { SERVER_BUFFER, BufferType, ReceiptType, ServerStatus, Unread, State, getServerName, isMessageBeforeReceipt } from "../state.js";
import commands from "../commands.js";
import { setup as setupKeybindings } from "../keybindings.js";
import * as store from "../store.js";
@ -463,7 +463,7 @@ export default class App extends Component {
hasReceipt(target, type, msg) {
let receipt = this.getReceipt(target, type);
return receipt && msg.tags.time <= receipt.time;
return isMessageBeforeReceipt(msg, receipt);
}
setReceipt(target, type, msg) {
@ -596,7 +596,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)) {
if (client.isMyNick(msg.prefix.name) && !isMessageBeforeReceipt(msg, prevReadReceipt)) {
prevReadReceipt = receiptFromMessage(msg);
}

View file

@ -2,7 +2,7 @@ import { html, Component } from "../lib/index.js";
import linkify from "../lib/linkify.js";
import * as irc from "../lib/irc.js";
import { strip as stripANSI } from "../lib/ansi.js";
import { BufferType, ServerStatus, getNickURL, getChannelURL, getMessageURL } from "../state.js";
import { BufferType, ServerStatus, getNickURL, getChannelURL, getMessageURL, isMessageBeforeReceipt } from "../state.js";
import * as store from "../store.js";
import Membership from "./membership.js";
@ -633,7 +633,7 @@ export default class Buffer extends Component {
buf.messages.forEach((msg) => {
let sep = [];
if (!hasUnreadSeparator && buf.type != BufferType.SERVER && buf.prevReadReceipt && msg.tags.time > buf.prevReadReceipt.time) {
if (!hasUnreadSeparator && buf.type != BufferType.SERVER && !isMessageBeforeReceipt(msg, buf.prevReadReceipt)) {
sep.push(html`<${UnreadSeparator} key="unread"/>`);
hasUnreadSeparator = true;
}

View file

@ -85,6 +85,19 @@ export function getServerName(server, bouncerNetwork) {
}
}
export function isMessageBeforeReceipt(msg, receipt) {
if (!receipt) {
return false;
}
if (!msg.tags.time) {
throw new Error("Missing time message tag");
}
if (!receipt.time) {
throw new Error("Missing receipt time");
}
return msg.tags.time <= receipt.time;
}
function updateState(state, updater) {
let updated;
if (typeof updater === "function") {