mirror of
https://codeberg.org/emersion/gamja
synced 2025-03-12 23:43:42 +01:00
Introduce isMessageBeforeReceipt
This commit is contained in:
parent
3d81466788
commit
d2bcea8c86
@ -16,7 +16,7 @@ import ScrollManager from "./scroll-manager.js";
|
|||||||
import Dialog from "./dialog.js";
|
import Dialog from "./dialog.js";
|
||||||
import { html, Component, createRef } from "../lib/index.js";
|
import { html, Component, createRef } from "../lib/index.js";
|
||||||
import { strip as stripANSI } from "../lib/ansi.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 commands from "../commands.js";
|
||||||
import { setup as setupKeybindings } from "../keybindings.js";
|
import { setup as setupKeybindings } from "../keybindings.js";
|
||||||
import * as store from "../store.js";
|
import * as store from "../store.js";
|
||||||
@ -463,7 +463,7 @@ export default class App extends Component {
|
|||||||
|
|
||||||
hasReceipt(target, type, msg) {
|
hasReceipt(target, type, msg) {
|
||||||
let receipt = this.getReceipt(target, type);
|
let receipt = this.getReceipt(target, type);
|
||||||
return receipt && msg.tags.time <= receipt.time;
|
return isMessageBeforeReceipt(msg, receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
setReceipt(target, type, msg) {
|
setReceipt(target, type, msg) {
|
||||||
@ -596,7 +596,7 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't show unread marker for my own messages
|
// 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);
|
prevReadReceipt = receiptFromMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { html, Component } from "../lib/index.js";
|
|||||||
import linkify from "../lib/linkify.js";
|
import linkify from "../lib/linkify.js";
|
||||||
import * as irc from "../lib/irc.js";
|
import * as irc from "../lib/irc.js";
|
||||||
import { strip as stripANSI } from "../lib/ansi.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 * as store from "../store.js";
|
||||||
import Membership from "./membership.js";
|
import Membership from "./membership.js";
|
||||||
|
|
||||||
@ -633,7 +633,7 @@ export default class Buffer extends Component {
|
|||||||
buf.messages.forEach((msg) => {
|
buf.messages.forEach((msg) => {
|
||||||
let sep = [];
|
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"/>`);
|
sep.push(html`<${UnreadSeparator} key="unread"/>`);
|
||||||
hasUnreadSeparator = true;
|
hasUnreadSeparator = true;
|
||||||
}
|
}
|
||||||
|
13
state.js
13
state.js
@ -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) {
|
function updateState(state, updater) {
|
||||||
let updated;
|
let updated;
|
||||||
if (typeof updater === "function") {
|
if (typeof updater === "function") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user