fix: ensure lastMessageId is updated on incoming messages

This commit is contained in:
izzy
2025-10-16 17:28:53 +01:00
parent 44949768ac
commit 719d9c5f0b
+88 -86
View File
@@ -42,21 +42,21 @@ export type ProtocolV1 = {
type ClientMessage =
| { type: "Authenticate"; token: string }
| {
type: "BeginTyping";
channel: string;
}
type: "BeginTyping";
channel: string;
}
| {
type: "EndTyping";
channel: string;
}
type: "EndTyping";
channel: string;
}
| {
type: "Ping";
data: number;
}
type: "Ping";
data: number;
}
| {
type: "Pong";
data: number;
};
type: "Pong";
data: number;
};
/**
* Messages sent from the server
@@ -70,46 +70,46 @@ type ServerMessage =
| { type: "Pong"; data: number }
| ({ type: "Message" } & Message)
| {
type: "MessageUpdate";
id: string;
channel: string;
data: Partial<Message>;
}
type: "MessageUpdate";
id: string;
channel: string;
data: Partial<Message>;
}
| {
type: "MessageAppend";
id: string;
channel: string;
append: Pick<Partial<Message>, "embeds">;
}
type: "MessageAppend";
id: string;
channel: string;
append: Pick<Partial<Message>, "embeds">;
}
| { type: "MessageDelete"; id: string; channel: string }
| {
type: "MessageReact";
id: string;
channel_id: string;
user_id: string;
emoji_id: string;
}
type: "MessageReact";
id: string;
channel_id: string;
user_id: string;
emoji_id: string;
}
| {
type: "MessageUnreact";
id: string;
channel_id: string;
user_id: string;
emoji_id: string;
}
type: "MessageUnreact";
id: string;
channel_id: string;
user_id: string;
emoji_id: string;
}
| {
type: "MessageRemoveReaction";
id: string;
channel_id: string;
emoji_id: string;
}
type: "MessageRemoveReaction";
id: string;
channel_id: string;
emoji_id: string;
}
| { type: "BulkMessageDelete"; channel: string; ids: string[] }
| ({ type: "ChannelCreate" } & Channel)
| {
type: "ChannelUpdate";
id: string;
data: Partial<Channel>;
clear?: FieldsChannel[];
}
type: "ChannelUpdate";
id: string;
data: Partial<Channel>;
clear?: FieldsChannel[];
}
| { type: "ChannelDelete"; id: string }
| { type: "ChannelGroupJoin"; id: string; user: string }
| { type: "ChannelGroupLeave"; id: string; user: string }
@@ -117,62 +117,62 @@ type ServerMessage =
| { type: "ChannelStopTyping"; id: string; user: string }
| { type: "ChannelAck"; id: string; user: string; message_id: string }
| {
type: "ServerCreate";
id: string;
server: Server;
channels: Channel[];
}
type: "ServerCreate";
id: string;
server: Server;
channels: Channel[];
}
| {
type: "ServerUpdate";
id: string;
data: Partial<Server>;
clear?: FieldsServer[];
}
type: "ServerUpdate";
id: string;
data: Partial<Server>;
clear?: FieldsServer[];
}
| { type: "ServerDelete"; id: string }
| {
type: "ServerMemberUpdate";
id: MemberCompositeKey;
data: Partial<Member>;
clear?: FieldsMember[];
}
type: "ServerMemberUpdate";
id: MemberCompositeKey;
data: Partial<Member>;
clear?: FieldsMember[];
}
| { type: "ServerMemberJoin"; id: string; user: string }
| { type: "ServerMemberLeave"; id: string; user: string }
| {
type: "ServerRoleUpdate";
id: string;
role_id: string;
data: Partial<Role>;
}
type: "ServerRoleUpdate";
id: string;
role_id: string;
data: Partial<Role>;
}
| { type: "ServerRoleDelete"; id: string; role_id: string }
| {
type: "UserUpdate";
id: string;
data: Partial<User>;
clear?: FieldsUser[];
}
type: "UserUpdate";
id: string;
data: Partial<User>;
clear?: FieldsUser[];
}
| { type: "UserRelationship"; user: User; status: RelationshipStatus }
| { type: "UserPresence"; id: string; online: boolean }
| {
type: "UserSettingsUpdate";
id: string;
update: { [key: string]: [number, string] };
}
type: "UserSettingsUpdate";
id: string;
update: { [key: string]: [number, string] };
}
| { type: "UserPlatformWipe"; user_id: string; flags: number }
| ({ type: "EmojiCreate" } & Emoji)
| { type: "EmojiDelete"; id: string }
| ({
type: "Auth";
} & (
type: "Auth";
} & (
| {
event_type: "DeleteSession";
user_id: string;
session_id: string;
}
event_type: "DeleteSession";
user_id: string;
session_id: string;
}
| {
event_type: "DeleteAllSessions";
user_id: string;
exclude_session_id: string;
}
event_type: "DeleteAllSessions";
user_id: string;
exclude_session_id: string;
}
));
/**
@@ -277,13 +277,15 @@ export async function handleEvent(
client.messages.getOrCreate(event._id, event, true);
const channel = client.channels.get(event.channel);
if (!channel) return;
client.channels.updateUnderlyingObject(channel.id, "lastMessageId", event._id);
if (
event.mentions?.includes(client.user!.id) &&
client.options.syncUnreads
) {
const channel = client.channels.get(event.channel);
if (!channel) return;
const unread = client.channelUnreads.for(channel);
unread.messageMentionIds.add(event._id);
client.channels.updateUnderlyingObject(