支持私聊消息加密转发到群聊
This commit is contained in:
1 parent
20e179a877
commit
9028ba0eed
8 files changed
+99
-62
No files matched your search
@@ -284,14 +284,17 @@ export function discardPendingGroupMessage(identity: ChatIdentity, group: GroupD
|
||||
}
|
||||
|
||||
export async function forwardGroupMessage(identity: ChatIdentity, source: GroupDetail, message: LineRef, destination: ForwardDestination, call: Call) {
|
||||
const content = await update(identity, async (state) => {
|
||||
return forwardContent(identity, destination, call, () => update(identity, async (state) => {
|
||||
const item = state.groupChats?.[source.id]?.lines.find((entry) => entry.id === message.id &&
|
||||
entry.epoch === message.epoch && entry.sender === message.sender)
|
||||
if (!item || item.recalled) throw new Error('此群消息无法转发')
|
||||
return item.attachment ? readForwardedFile(item.attachment, call, groupAttachmentPath(source, item.attachment.id)) : item.text
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
export async function forwardContent(identity: ChatIdentity, destination: ForwardDestination, call: Call, readContent: () => Promise<string | File>) {
|
||||
if ('user' in destination) {
|
||||
await send(identity, destination.user, destination.device, content, call)
|
||||
await send(identity, destination.user, destination.device, await readContent(), call)
|
||||
return '已提交转发'
|
||||
}
|
||||
|
||||
@@ -300,7 +303,7 @@ export async function forwardGroupMessage(identity: ChatIdentity, source: GroupD
|
||||
const view = await synchronizeGroup(identity, target, call)
|
||||
if (!view.ready || !view.current) throw new Error('请先在目标群加入加密会话')
|
||||
if (view.hasPending) throw new Error('目标群还有待处理的消息,请先打开目标群')
|
||||
await sendGroupMessage(identity, target, content, call, view.current.id)
|
||||
await sendGroupMessage(identity, target, await readContent(), call, view.current.id)
|
||||
// At this point the outbox is durable. The target can retry after a network failure.
|
||||
try {
|
||||
const result = await synchronizeGroup(identity, target, call)
|
||||
|
||||
Reference in new issue
Block a user