增加群消息本机搜索和加密收藏
This commit is contained in:
1 parent
5b7c03e4ec
commit
2e51827a07
5 files changed
+109
-13
No files matched your search
@@ -14,7 +14,7 @@ type Outgoing = { id: string; epoch: string; wire: string }
|
||||
type Packet = Outgoing & { sequence: string; senderDevice: string; createdAt: string; attachmentId?: string }
|
||||
export type GroupLine = {
|
||||
id: string; user: string; sender: string; name: string; text: string; time: string; epoch?: string
|
||||
attachment?: Attachment; quote?: string; edited?: boolean; recalled?: boolean
|
||||
attachment?: Attachment; quote?: string; edited?: boolean; recalled?: boolean; favorite?: boolean
|
||||
}
|
||||
type LineRef = Pick<GroupLine, 'id' | 'sender' | 'epoch'>
|
||||
type GroupContent = string | File | { text: string; reply: LineRef } | (Mutation & { epoch: string })
|
||||
@@ -47,7 +47,27 @@ function finishPending(chat: GroupChatState, pending: NonNullable<GroupChatState
|
||||
|
||||
function applyGroupMutation(chat: GroupChatState, epoch: string, sender: string, mutation: Mutation) {
|
||||
const target = chat.lines.find((line) => line.id === mutation.id && line.epoch === epoch && line.sender === sender)
|
||||
if (target) applyMutation(target, mutation)
|
||||
if (!target) return
|
||||
applyMutation(target, mutation)
|
||||
if (target.recalled) delete target.favorite
|
||||
}
|
||||
|
||||
function trimHistory(chat: GroupChatState) {
|
||||
const cutoff = Math.max(0, chat.lines.length - 1000)
|
||||
chat.lines = [...chat.lines.slice(0, cutoff).filter((line) => line.favorite), ...chat.lines.slice(cutoff)]
|
||||
}
|
||||
|
||||
export function setGroupFavorite(identity: ChatIdentity, group: GroupDetail, message: LineRef, favorite: boolean) {
|
||||
return update(identity, async (state, save) => {
|
||||
const chat = state.groupChats?.[group.id]
|
||||
const line = chat?.lines.find((item) => item.id === message.id && item.epoch === message.epoch && item.sender === message.sender)
|
||||
if (!chat || !line || line.recalled) throw new Error('此群消息无法收藏')
|
||||
if (favorite) line.favorite = true
|
||||
else delete line.favorite
|
||||
trimHistory(chat)
|
||||
await save(state)
|
||||
return chat.lines
|
||||
})
|
||||
}
|
||||
|
||||
export function groupQuote(line: GroupLine) {
|
||||
@@ -241,7 +261,7 @@ export function synchronizeGroup(identity: ChatIdentity, group: GroupDetail, cal
|
||||
chat.cursor = item.sequence
|
||||
}
|
||||
if (chat.cursor !== previousCursor) {
|
||||
chat.lines = chat.lines.slice(-1000)
|
||||
trimHistory(chat)
|
||||
await save(state)
|
||||
}
|
||||
if (Date.now() - (state.packageChecked ?? 0) >= 60_000) {
|
||||
|
||||
Reference in new issue
Block a user