From 5ee5be9ef387f4dfc81e436aaefcb379365ef53b Mon Sep 17 00:00:00 2001 From: onewhobridges Date: Wed, 14 Oct 2026 16:56:24 -0700 Subject: [PATCH] fix: skip channelUnreads update for own messages Signed-off-by: onewhobridges --- src/events/v1.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/events/v1.ts b/src/events/v1.ts index 868a472f..37ec4dde 100644 --- a/src/events/v1.ts +++ b/src/events/v1.ts @@ -375,23 +375,36 @@ export async function handleEvent( const channel = client.channels.get(event.channel); if (!channel) return; + const isOwn = event.author === client.user!.id; + + // Capture the ack position and last message before they are updated + const previousLastId = channel.lastMessageId; + const previousAckId = + client.channelUnreads.for(channel).lastMessageId; + client.channels.updateUnderlyingObject( channel.id, "lastMessageId", event._id, ); - if ( + if (isOwn) { + // Only advance the ack locally if nothing else was unread (the ack + // was at the channel's last message), otherwise we would mark + // others' messages as read. + if ( + client.options.syncUnreads && + previousAckId && + previousAckId === previousLastId + ) { + void channel.ack(event._id, false, true); + } + } else if ( event.mentions?.includes(client.user!.id) && client.options.syncUnreads ) { const unread = client.channelUnreads.for(channel); unread.messageMentionIds.add(event._id); - client.channels.updateUnderlyingObject( - event.channel, - "lastMessageId", - event._id, - ); } }); }