Display system messages in chats (#10312)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -126,6 +126,11 @@ export type ConvoItem =
|
||||
| ChatBskyConvoDefs.DeletedMessageView
|
||||
| null
|
||||
}
|
||||
| {
|
||||
type: 'system-message'
|
||||
key: string
|
||||
message: ChatBskyConvoDefs.SystemMessageView
|
||||
}
|
||||
| {
|
||||
type: 'error'
|
||||
key: string
|
||||
|
||||
Reference in New Issue
Block a user