Display system messages in chats (#10312)

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
DS Boyce
2026-04-21 10:43:22 -07:00
committed by GitHub
parent 0df1d6f53e
commit 2ab1e2c9e9
16 changed files with 219 additions and 11 deletions
+46 -3
View File
@@ -52,6 +52,26 @@ export function isConvoItemMessage(
)
}
function toSystemMessageView(
ev: ChatBskyConvoGetLog.OutputSchema['logs'][number],
): ChatBskyConvoDefs.SystemMessageView | null {
const isSystem =
ChatBskyConvoDefs.isLogAddMember(ev) ||
ChatBskyConvoDefs.isLogRemoveMember(ev) ||
ChatBskyConvoDefs.isLogMemberJoin(ev) ||
ChatBskyConvoDefs.isLogMemberLeave(ev) ||
ChatBskyConvoDefs.isLogLockConvo(ev) ||
ChatBskyConvoDefs.isLogUnlockConvo(ev) ||
ChatBskyConvoDefs.isLogLockConvoPermanently(ev) ||
ChatBskyConvoDefs.isLogEditGroup(ev) ||
ChatBskyConvoDefs.isLogCreateJoinLink(ev) ||
ChatBskyConvoDefs.isLogEditJoinLink(ev) ||
ChatBskyConvoDefs.isLogEnableJoinLink(ev) ||
ChatBskyConvoDefs.isLogDisableJoinLink(ev)
if (!isSystem) return null
return ev.message
}
export class Convo {
private id: string
@@ -67,11 +87,15 @@ export class Convo {
private pastMessages: Map<
string,
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
| ChatBskyConvoDefs.MessageView
| ChatBskyConvoDefs.DeletedMessageView
| ChatBskyConvoDefs.SystemMessageView
> = new Map()
private newMessages: Map<
string,
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
| ChatBskyConvoDefs.MessageView
| ChatBskyConvoDefs.DeletedMessageView
| ChatBskyConvoDefs.SystemMessageView
> = new Map()
private pendingMessages: Map<
string,
@@ -680,7 +704,8 @@ export class Convo {
for (const message of messages) {
if (
ChatBskyConvoDefs.isMessageView(message) ||
ChatBskyConvoDefs.isDeletedMessageView(message)
ChatBskyConvoDefs.isDeletedMessageView(message) ||
ChatBskyConvoDefs.isSystemMessageView(message)
) {
/*
* If this message is already in new messages, it was added by the
@@ -832,6 +857,12 @@ export class Convo {
this.newMessages.set(ev.message.id, ev.message)
needsCommit = true
}
} else {
const systemView = toSystemMessageView(ev)
if (systemView) {
this.newMessages.set(systemView.id, systemView)
needsCommit = true
}
}
}
}
@@ -1119,6 +1150,12 @@ export class Convo {
nextMessage: null,
prevMessage: null,
})
} else if (ChatBskyConvoDefs.isSystemMessageView(m)) {
items.unshift({
type: 'system-message',
key: m.id,
message: m,
})
}
})
@@ -1150,6 +1187,12 @@ export class Convo {
nextMessage: null,
prevMessage: null,
})
} else if (ChatBskyConvoDefs.isSystemMessageView(m)) {
items.push({
type: 'system-message',
key: m.id,
message: m,
})
}
})
+5
View File
@@ -126,6 +126,11 @@ export type ConvoItem =
| ChatBskyConvoDefs.DeletedMessageView
| null
}
| {
type: 'system-message'
key: string
message: ChatBskyConvoDefs.SystemMessageView
}
| {
type: 'error'
key: string