chatluna-plugin-onebot-sandbox 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/client/app.tsx +306 -0
- package/client/chat/chat-pane.tsx +303 -0
- package/client/chat/composer.css +635 -0
- package/client/chat/composer.tsx +646 -0
- package/client/chat/details-panel.tsx +196 -0
- package/client/chat/emoji-picker.tsx +70 -0
- package/client/chat/extension-mark.tsx +16 -0
- package/client/chat/forward.tsx +257 -0
- package/client/chat/image-preview.tsx +93 -0
- package/client/chat/member-menu.tsx +64 -0
- package/client/chat/message-list.tsx +617 -0
- package/client/chat/messages.css +1018 -0
- package/client/chat/notifications.tsx +83 -0
- package/client/chat/reactions.tsx +52 -0
- package/client/chat/search-panel.tsx +231 -0
- package/client/chat/sidebar.tsx +424 -0
- package/client/chat/webqq-view.tsx +71 -0
- package/client/environment/avatar-picker.tsx +92 -0
- package/client/environment/create-popover.tsx +228 -0
- package/client/environment/directory-model.ts +63 -0
- package/client/environment/entity-dialog.css +383 -0
- package/client/environment/entity-dialog.tsx +442 -0
- package/client/environment/page.css +14 -0
- package/client/environment/page.tsx +280 -0
- package/client/i18n.ts +19 -0
- package/client/index.ts +17 -0
- package/client/locales/en.yml +617 -0
- package/client/locales/zh.yml +617 -0
- package/client/mcp/capability-catalog.tsx +277 -0
- package/client/mcp/credential-manager.tsx +257 -0
- package/client/onebot-debug/page.tsx +329 -0
- package/client/records/record-layout.tsx +429 -0
- package/client/records/records.css +259 -0
- package/client/settings/about.tsx +43 -0
- package/client/settings/draft.ts +47 -0
- package/client/settings/localize.ts +76 -0
- package/client/settings/page.tsx +210 -0
- package/client/settings/settings.css +47 -0
- package/client/shared/avatar.tsx +35 -0
- package/client/shared/confirm-dialog.tsx +44 -0
- package/client/shared/controls.css +17 -0
- package/client/shared/discard-confirm.tsx +45 -0
- package/client/shared/floating-panel.ts +40 -0
- package/client/shared/format-duration.ts +22 -0
- package/client/shared/format-time.ts +49 -0
- package/client/shared/glass.css +150 -0
- package/client/shared/implementation.ts +12 -0
- package/client/shared/overlay-scrollbar.css +45 -0
- package/client/shared/overlay-scrollbar.tsx +123 -0
- package/client/shared/use-element-width.ts +19 -0
- package/client/shared/use-retained.ts +12 -0
- package/client/test-call/page.tsx +260 -0
- package/client/test-space/agent-visuals.tsx +121 -0
- package/client/test-space/observe-overlay.tsx +42 -0
- package/client/test-space/overview.tsx +267 -0
- package/client/test-space/spaces.css +201 -0
- package/client/test-space/thumbnail-capture.ts +63 -0
- package/client/test-space/thumbnail-scale.ts +21 -0
- package/client/test-space/use-space-list.ts +35 -0
- package/client/test-space/zoom.ts +197 -0
- package/client/webqq/composer-draft-host.ts +578 -0
- package/client/webqq/composer-draft.ts +81 -0
- package/client/webqq/conversation-tree.ts +155 -0
- package/client/webqq/emoji-catalog.ts +78 -0
- package/client/webqq/fork-boundary.ts +28 -0
- package/client/webqq/forward-cluster.ts +20 -0
- package/client/webqq/forward-dialog-stack.ts +74 -0
- package/client/webqq/forward-preview.ts +40 -0
- package/client/webqq/friend-menu.ts +17 -0
- package/client/webqq/group-display.ts +18 -0
- package/client/webqq/group-menu.ts +25 -0
- package/client/webqq/mention.ts +4 -0
- package/client/webqq/message-capabilities.ts +37 -0
- package/client/webqq/message-cluster.ts +68 -0
- package/client/webqq/message-presentation.ts +197 -0
- package/client/webqq/message-reveal.ts +31 -0
- package/client/webqq/message-search-date.ts +40 -0
- package/client/webqq/message-selection.ts +85 -0
- package/client/webqq/notification-requests.ts +20 -0
- package/client/webqq/participant-presentation.ts +128 -0
- package/client/webqq/profile-card.ts +199 -0
- package/client/webqq/relationship-directory.ts +62 -0
- package/client/webqq/thinking-panel.ts +7 -0
- package/client/webqq/user-stack.ts +53 -0
- package/client/workspace/agent-overlay-effect.ts +238 -0
- package/client/workspace/context.tsx +117 -0
- package/client/workspace/overlay-host.tsx +299 -0
- package/client/workspace/profile-card.css +164 -0
- package/client/workspace/state.ts +28 -0
- package/client/workspace/store.ts +388 -0
- package/client/workspace/use-test-spaces.ts +21 -0
- package/dist/.vite/manifest.json +21 -0
- package/dist/app-63rfTh6w.js +85 -0
- package/dist/client.css +4 -0
- package/dist/client.js +1 -0
- package/lib/account-profile.d.ts +17 -0
- package/lib/account-profile.d.ts.map +1 -0
- package/lib/base-dir.d.ts +4 -0
- package/lib/base-dir.d.ts.map +1 -0
- package/lib/bot.d.ts +185 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/builtin-avatar-options.d.ts +11 -0
- package/lib/builtin-avatar-options.d.ts.map +1 -0
- package/lib/builtin-avatars.d.ts +6 -0
- package/lib/builtin-avatars.d.ts.map +1 -0
- package/lib/channel-assignee.d.ts +52 -0
- package/lib/channel-assignee.d.ts.map +1 -0
- package/lib/chatluna/conversation-lines.d.ts +46 -0
- package/lib/chatluna/conversation-lines.d.ts.map +1 -0
- package/lib/chatluna/runtime.d.ts +26 -0
- package/lib/chatluna/runtime.d.ts.map +1 -0
- package/lib/chatluna/state.d.ts +67 -0
- package/lib/chatluna/state.d.ts.map +1 -0
- package/lib/chatluna/thinking.d.ts +10 -0
- package/lib/chatluna/thinking.d.ts.map +1 -0
- package/lib/chatluna/tools.d.ts +36 -0
- package/lib/chatluna/tools.d.ts.map +1 -0
- package/lib/chatluna/wakeup.d.ts +143 -0
- package/lib/chatluna/wakeup.d.ts.map +1 -0
- package/lib/console-contract.d.ts +131 -0
- package/lib/console-contract.d.ts.map +1 -0
- package/lib/console.d.ts +31 -0
- package/lib/console.d.ts.map +1 -0
- package/lib/control-service.d.ts +425 -0
- package/lib/control-service.d.ts.map +1 -0
- package/lib/conversation-resolution.d.ts +157 -0
- package/lib/conversation-resolution.d.ts.map +1 -0
- package/lib/error-detail.d.ts +3 -0
- package/lib/error-detail.d.ts.map +1 -0
- package/lib/inbound-delivery.d.ts +156 -0
- package/lib/inbound-delivery.d.ts.map +1 -0
- package/lib/index.d.ts +76 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12834 -0
- package/lib/index.js.map +1 -0
- package/lib/lifecycle.d.ts +8 -0
- package/lib/lifecycle.d.ts.map +1 -0
- package/lib/mcp/arguments.d.ts +71 -0
- package/lib/mcp/arguments.d.ts.map +1 -0
- package/lib/mcp/call-records.d.ts +32 -0
- package/lib/mcp/call-records.d.ts.map +1 -0
- package/lib/mcp/http-api.d.ts +147 -0
- package/lib/mcp/http-api.d.ts.map +1 -0
- package/lib/mcp/page-cursor.d.ts +37 -0
- package/lib/mcp/page-cursor.d.ts.map +1 -0
- package/lib/mcp/server.d.ts +60 -0
- package/lib/mcp/server.d.ts.map +1 -0
- package/lib/mcp/service.d.ts +219 -0
- package/lib/mcp/service.d.ts.map +1 -0
- package/lib/mcp/tool-registry.d.ts +113 -0
- package/lib/mcp/tool-registry.d.ts.map +1 -0
- package/lib/mcp/types.d.ts +144 -0
- package/lib/mcp/types.d.ts.map +1 -0
- package/lib/media-storage.d.ts +33 -0
- package/lib/media-storage.d.ts.map +1 -0
- package/lib/message-capabilities.d.ts +78 -0
- package/lib/message-capabilities.d.ts.map +1 -0
- package/lib/onebot-debug.d.ts +115 -0
- package/lib/onebot-debug.d.ts.map +1 -0
- package/lib/onebot-message.d.ts +23 -0
- package/lib/onebot-message.d.ts.map +1 -0
- package/lib/onebot-profiles.d.ts +45 -0
- package/lib/onebot-profiles.d.ts.map +1 -0
- package/lib/persistence.d.ts +148 -0
- package/lib/persistence.d.ts.map +1 -0
- package/lib/random.d.ts +5 -0
- package/lib/random.d.ts.map +1 -0
- package/lib/record-store.d.ts +80 -0
- package/lib/record-store.d.ts.map +1 -0
- package/lib/relationship-actions.d.ts +157 -0
- package/lib/relationship-actions.d.ts.map +1 -0
- package/lib/scope-directory.d.ts +105 -0
- package/lib/scope-directory.d.ts.map +1 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/test-spaces.d.ts +69 -0
- package/lib/test-spaces.d.ts.map +1 -0
- package/lib/types.d.ts +739 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/webui.d.ts +26 -0
- package/lib/webui.d.ts.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { readConversationMessageIds, type ResolvedConversation } from '../../src/conversation-resolution'
|
|
2
|
+
import {
|
|
3
|
+
formatRecalledMessageEventText,
|
|
4
|
+
getSandboxBots,
|
|
5
|
+
getSandboxUsers,
|
|
6
|
+
isRecalledMessage,
|
|
7
|
+
type SandboxGroupMember,
|
|
8
|
+
type SandboxSnapshot,
|
|
9
|
+
} from '../../src/types'
|
|
10
|
+
import { formatMentionContent } from './mention'
|
|
11
|
+
import { getConversationPeerId } from './relationship-directory'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 侧栏会话树的投影口径:一个根会话在侧栏里长什么样,它的会话实例挂在哪。
|
|
15
|
+
*
|
|
16
|
+
* 形态是纯函数而不是持有场景的对象,与 `environment-directory-model.ts`、
|
|
17
|
+
* `relationship-directory.ts` 一致:把沙盒场景投影成某个视图要的形状,头像解析由调用方注入,
|
|
18
|
+
* 因此不必先起一个完整工作台就能问「这一行长什么样」。
|
|
19
|
+
*
|
|
20
|
+
* 转发目标的「最近」一列由 {@link toRecentForwardTargets} 从同一份结果派生:预览口径变了,
|
|
21
|
+
* 那一列跟着变,两处不会各自漂移。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** 侧栏会话树里的一行。根会话行与会话实例子项共用这些字段;子项列表不在其中。 */
|
|
25
|
+
export interface ConversationTreeRow {
|
|
26
|
+
id: string
|
|
27
|
+
groupId?: string
|
|
28
|
+
/** 根会话还是会话实例;会话实例作为所属根会话的子项展开。 */
|
|
29
|
+
kind: 'root' | 'instance'
|
|
30
|
+
title: string
|
|
31
|
+
avatar?: string
|
|
32
|
+
avatarKind: 'user' | 'bot' | 'group'
|
|
33
|
+
preview: string
|
|
34
|
+
time: string
|
|
35
|
+
actorRole?: SandboxGroupMember['role']
|
|
36
|
+
entityTarget: { type: 'user' | 'bot' | 'group', id: string }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 会话实例子项。它自己不带子项列表:层级严格两层,实例下不再有实例。 */
|
|
40
|
+
export interface ConversationTreeInstanceRow extends ConversationTreeRow {
|
|
41
|
+
kind: 'instance'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 会话树的顶层:根会话行,子项列表一定存在,没有会话实例时为空数组。
|
|
46
|
+
*
|
|
47
|
+
* 子项类型钉成会话实例行而不是任意一行,因此「层级严格两层,实例下不再有实例」
|
|
48
|
+
* 写在类型上,而不是只写在注释里。
|
|
49
|
+
*/
|
|
50
|
+
export interface ConversationTreeNode extends ConversationTreeRow {
|
|
51
|
+
kind: 'root'
|
|
52
|
+
children: ConversationTreeInstanceRow[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 转发目标的「最近」一列。字段逐项取自会话树的行,复用关系因此写在类型上:
|
|
57
|
+
* 改会话树的标题、预览或头像口径时,这一列会跟着变而不是悄悄留在旧口径上。
|
|
58
|
+
*/
|
|
59
|
+
export type ConversationTreeForwardTarget = Pick<ConversationTreeRow, 'title' | 'avatar' | 'avatarKind'> & {
|
|
60
|
+
conversationId: ConversationTreeRow['id']
|
|
61
|
+
subtitle: ConversationTreeRow['preview']
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ConversationTreeInput {
|
|
65
|
+
scene: SandboxSnapshot
|
|
66
|
+
/** 当前操作者可见的会话,根会话与会话实例都在里面。 */
|
|
67
|
+
conversations: readonly ResolvedConversation[]
|
|
68
|
+
operatorId?: string
|
|
69
|
+
resolveAvatar?: (avatar?: string) => string | undefined
|
|
70
|
+
/** 还没有消息的会话显示的预览,由调用方按界面语言传入。 */
|
|
71
|
+
emptyPreview?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function identity(avatar?: string) {
|
|
75
|
+
return avatar
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const timeFormat = new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit' })
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 侧栏会话树:顶层只有根会话,每个根会话下挂它自己的会话实例。
|
|
82
|
+
* 数据源是「根会话加其实例列表」,不是「一个扁平集合加父字段」。
|
|
83
|
+
*/
|
|
84
|
+
export function buildConversationTree(input: ConversationTreeInput): ConversationTreeNode[] {
|
|
85
|
+
const instancesByRoot = new Map<string, ConversationTreeInstanceRow[]>()
|
|
86
|
+
for (const conversation of input.conversations) {
|
|
87
|
+
if (conversation.kind !== 'instance') continue
|
|
88
|
+
const siblings = instancesByRoot.get(conversation.rootConversationId) ?? []
|
|
89
|
+
siblings.push({ ...toRow(input, conversation), kind: 'instance' })
|
|
90
|
+
instancesByRoot.set(conversation.rootConversationId, siblings)
|
|
91
|
+
}
|
|
92
|
+
return input.conversations
|
|
93
|
+
.filter(({ kind }) => kind === 'root')
|
|
94
|
+
.map((conversation) => ({
|
|
95
|
+
...toRow(input, conversation),
|
|
96
|
+
kind: 'root' as const,
|
|
97
|
+
children: instancesByRoot.get(conversation.id) ?? [],
|
|
98
|
+
}))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 「最近」一列只收根会话行:会话实例不是转发目标,转发落在联系人这一层。 */
|
|
102
|
+
export function toRecentForwardTargets(
|
|
103
|
+
tree: readonly ConversationTreeNode[],
|
|
104
|
+
): ConversationTreeForwardTarget[] {
|
|
105
|
+
return tree.map(({ id, title, preview, avatar, avatarKind }) => ({
|
|
106
|
+
conversationId: id,
|
|
107
|
+
title,
|
|
108
|
+
subtitle: preview,
|
|
109
|
+
avatar,
|
|
110
|
+
avatarKind,
|
|
111
|
+
}))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toRow(input: ConversationTreeInput, conversation: ResolvedConversation): ConversationTreeRow {
|
|
115
|
+
const { scene, operatorId } = input
|
|
116
|
+
const resolveAvatar = input.resolveAvatar ?? identity
|
|
117
|
+
const group = conversation.type === 'group'
|
|
118
|
+
? scene.groups.find(({ id }) => id === conversation.groupId)
|
|
119
|
+
: undefined
|
|
120
|
+
const peerId = getConversationPeerId(conversation, operatorId)
|
|
121
|
+
const bot = getSandboxBots(scene).find(({ id }) => id === peerId)
|
|
122
|
+
const peer = bot ?? getSandboxUsers(scene).find(({ id }) => id === peerId)
|
|
123
|
+
const latestMessage = readLatestMessage(scene, conversation.id)
|
|
124
|
+
return {
|
|
125
|
+
id: conversation.id,
|
|
126
|
+
groupId: group?.id,
|
|
127
|
+
kind: conversation.kind,
|
|
128
|
+
// 会话实例有自己的名字;根会话的名字由参与者关系决定。
|
|
129
|
+
title: conversation.title ?? group?.name ?? peer?.name ?? conversation.id,
|
|
130
|
+
avatar: resolveAvatar(group?.avatar ?? peer?.avatar),
|
|
131
|
+
avatarKind: group ? 'group' : bot ? 'bot' : 'user',
|
|
132
|
+
preview: latestMessage ? describeMessage(scene, latestMessage) : input.emptyPreview ?? '',
|
|
133
|
+
time: latestMessage?.createdAt ? timeFormat.format(new Date(latestMessage.createdAt)) : '',
|
|
134
|
+
actorRole: group?.members.find(({ participantId }) => participantId === operatorId)?.role,
|
|
135
|
+
entityTarget: group
|
|
136
|
+
? { type: 'group', id: group.id }
|
|
137
|
+
: { type: bot ? 'bot' : 'user', id: peerId ?? '' },
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 预览取拼接后的最后一条:会话实例的消息列表已经把继承前缀物化在自有消息之前,
|
|
143
|
+
* 因此刚分叉出来的会话实例显示分叉点那条,而不是「开始一段新对话」——它不是空会话。
|
|
144
|
+
*/
|
|
145
|
+
function readLatestMessage(scene: SandboxSnapshot, conversationId: string) {
|
|
146
|
+
const messageIds = new Set(readConversationMessageIds(scene, conversationId))
|
|
147
|
+
return scene.messages.filter(({ id }) => messageIds.has(id)).at(-1)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function describeMessage(scene: SandboxSnapshot, message: SandboxSnapshot['messages'][number]) {
|
|
151
|
+
const participantNames = Object.fromEntries(scene.participants.map(({ id, name }) => [id, name]))
|
|
152
|
+
if (!isRecalledMessage(message)) return formatMentionContent(message.content, participantNames)
|
|
153
|
+
const operatorId = message.lifecycle.operatorId
|
|
154
|
+
return formatRecalledMessageEventText(message, participantNames[operatorId] ?? operatorId)
|
|
155
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readStored, writeStored } from '@chatluna/ui-storage'
|
|
2
|
+
import * as qface from 'qface'
|
|
3
|
+
|
|
4
|
+
export interface SandboxEmojiFace {
|
|
5
|
+
id: string
|
|
6
|
+
label: string
|
|
7
|
+
url: string
|
|
8
|
+
inputs: string[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// TIM/QQ 常用回应优先展示这些 QSid;缺失时再回退到 qface 的 isCMEmoji。
|
|
12
|
+
const preferredCommonIds = ['76', '66', '63', '64', '39', '116', '59', '98', '2', '178', '179', '182']
|
|
13
|
+
|
|
14
|
+
function toFace(item: qface.Face): SandboxEmojiFace {
|
|
15
|
+
return {
|
|
16
|
+
id: item.QSid,
|
|
17
|
+
label: item.QDes.replace(/^\//, '') || item.QSid,
|
|
18
|
+
url: qface.getUrl(item.QSid),
|
|
19
|
+
inputs: item.Input ?? [],
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function listSandboxEmojiFaces(): SandboxEmojiFace[] {
|
|
24
|
+
return qface.data
|
|
25
|
+
.filter((item) => !item.QHide)
|
|
26
|
+
.map(toFace)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getSandboxEmojiFace(emojiId: string): SandboxEmojiFace | undefined {
|
|
30
|
+
const face = qface.get(emojiId)
|
|
31
|
+
if (face) return toFace(face)
|
|
32
|
+
// OneBot 有时上报 Unicode codepoint 数字(如 128077);找不到 qface 条目时用原值兜底展示。
|
|
33
|
+
const id = emojiId.trim()
|
|
34
|
+
if (!id) return undefined
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
label: /^\d+$/.test(id) ? '[表情]' : id,
|
|
38
|
+
url: '',
|
|
39
|
+
inputs: [],
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getCommonSandboxEmojiFaces(): SandboxEmojiFace[] {
|
|
44
|
+
const byId = new Map(listSandboxEmojiFaces().map((face) => [face.id, face]))
|
|
45
|
+
const preferred = preferredCommonIds.flatMap((id) => {
|
|
46
|
+
const face = byId.get(id)
|
|
47
|
+
return face ? [face] : []
|
|
48
|
+
})
|
|
49
|
+
if (preferred.length) return preferred
|
|
50
|
+
return listSandboxEmojiFaces().filter((face) => qface.get(face.id)?.isCMEmoji).slice(0, 24)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function searchSandboxEmojiFaces(query: string): SandboxEmojiFace[] {
|
|
54
|
+
const keyword = query.trim().toLowerCase()
|
|
55
|
+
const faces = listSandboxEmojiFaces()
|
|
56
|
+
if (!keyword) return faces
|
|
57
|
+
return faces.filter((face) => {
|
|
58
|
+
if (face.id.includes(keyword)) return true
|
|
59
|
+
if (face.label.toLowerCase().includes(keyword)) return true
|
|
60
|
+
return face.inputs.some((input) => input.toLowerCase().includes(keyword))
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const recentStorageKey = 'chatluna.onebot-sandbox.recent-emoji-ids'
|
|
65
|
+
|
|
66
|
+
export function loadRecentSandboxEmojiIds(): string[] {
|
|
67
|
+
const stored = readStored(recentStorageKey)
|
|
68
|
+
if (!Array.isArray(stored)) return []
|
|
69
|
+
return stored.filter((item): item is string => typeof item === 'string' && !!item.trim()).slice(0, 24)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function rememberSandboxEmojiId(emojiId: string): string[] {
|
|
73
|
+
const id = emojiId.trim()
|
|
74
|
+
if (!id) return loadRecentSandboxEmojiIds()
|
|
75
|
+
const next = [id, ...loadRecentSandboxEmojiIds().filter((item) => item !== id)].slice(0, 24)
|
|
76
|
+
writeStored(recentStorageKey, next)
|
|
77
|
+
return next
|
|
78
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isInheritedMessage } from '../../src/conversation-resolution'
|
|
2
|
+
import type { SandboxMessage } from '../../src/types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 分支视图里继承前缀与自有消息的边界。
|
|
6
|
+
*
|
|
7
|
+
* 判定依据只有「消息自己的归属会话」,由 {@link isInheritedMessage} 在共享模块里给出:投影出的
|
|
8
|
+
* 消息带着它真正所属的那个会话,与当前会话不同的就是继承前缀——它是与原会话共享的同一份记录,
|
|
9
|
+
* 不需要额外字段,也不需要客户端再沿来源链拼一次。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 这一条是不是继承前缀之后的第一条自有消息,也就是该显示分界标记的位置。
|
|
14
|
+
*
|
|
15
|
+
* 分界画在两段之间,因此它挂在自有消息那一侧:挂在前缀最后一条上会在「前缀被清空或被保留窗口
|
|
16
|
+
* 淘汰后整段变空」时连分界一起消失,而分支本身还在。根会话与没有继承前缀的实例因此都不画分界。
|
|
17
|
+
*/
|
|
18
|
+
export function isForkBoundaryMessage(
|
|
19
|
+
messages: readonly SandboxMessage[],
|
|
20
|
+
index: number,
|
|
21
|
+
currentConversationId: string | undefined,
|
|
22
|
+
) {
|
|
23
|
+
const message = messages[index]
|
|
24
|
+
const previous = messages[index - 1]
|
|
25
|
+
if (!message || !previous) return false
|
|
26
|
+
return !isInheritedMessage(message, currentConversationId)
|
|
27
|
+
&& isInheritedMessage(previous, currentConversationId)
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SandboxForwardNode } from '../../src/types'
|
|
2
|
+
|
|
3
|
+
function isSameForwardSender(left: SandboxForwardNode | undefined, right: SandboxForwardNode | undefined) {
|
|
4
|
+
return !!left && !!right && left.userId === right.userId
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// 合并转发详情弹窗复用 TIM 连续消息合并:同发送者相邻节点隐藏重复头像。
|
|
8
|
+
export function isMergedForwardNode(items: readonly SandboxForwardNode[], index: number) {
|
|
9
|
+
return isSameForwardSender(items[index - 1], items[index])
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getForwardNodeClusterClass(items: readonly SandboxForwardNode[], index: number) {
|
|
13
|
+
if (!items[index]) return ''
|
|
14
|
+
const hasPrevious = isSameForwardSender(items[index - 1], items[index])
|
|
15
|
+
const hasNext = isSameForwardSender(items[index], items[index + 1])
|
|
16
|
+
if (hasPrevious && hasNext) return 'is-cluster-middle'
|
|
17
|
+
if (hasNext) return 'is-cluster-first'
|
|
18
|
+
if (hasPrevious) return 'is-cluster-last'
|
|
19
|
+
return ''
|
|
20
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { SandboxForward, SandboxForwardNode } from '../../src/types'
|
|
2
|
+
import { buildForwardPreview } from './forward-preview'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 嵌套合并转发的逐层打开与逐层关闭。
|
|
6
|
+
*
|
|
7
|
+
* 它是一个纯栈加一次异步读取:每一帧对应一层叠起来的转发详情窗口,关掉上层只截断栈尾。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface ForwardDialogFrame {
|
|
11
|
+
readonly title: string
|
|
12
|
+
readonly items: SandboxForwardNode[]
|
|
13
|
+
readonly nestedForwards: Record<string, SandboxForward>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 压入新的一帧。
|
|
18
|
+
*
|
|
19
|
+
* 根消息用 `replace` 重置整条历史——从消息气泡打开的是一条新的转发链,把它压在旧链后面会让
|
|
20
|
+
* 关掉上层后露出一条无关的转发。嵌套详情用 `push`,关掉上层时下层原样保留而不重复 RPC。
|
|
21
|
+
*/
|
|
22
|
+
export function pushForwardFrame(
|
|
23
|
+
stack: readonly ForwardDialogFrame[],
|
|
24
|
+
frame: ForwardDialogFrame,
|
|
25
|
+
mode: 'replace' | 'push',
|
|
26
|
+
): ForwardDialogFrame[] {
|
|
27
|
+
return mode === 'push' ? [...stack, frame] : [frame]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 关闭:清空整条历史,下次打开重新读。 */
|
|
31
|
+
export function closeForwardStack(): ForwardDialogFrame[] {
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 按入参读一帧。
|
|
37
|
+
*
|
|
38
|
+
* 两种入参:从消息气泡打开时给的是转发资源标识与消息标识,从嵌套卡片打开时只有转发资源标识。
|
|
39
|
+
* 嵌套资源逐个尝试读取,失败的那个不算整帧失败——外层弹窗照旧打开,那张卡片回退为占位文案。
|
|
40
|
+
* 整帧读取失败则返回 undefined,弹窗不打开,错误由页面控制层展示。
|
|
41
|
+
*/
|
|
42
|
+
export async function loadForwardDialogFrame(input: {
|
|
43
|
+
readonly input: { forwardId?: string, messageId?: string }
|
|
44
|
+
readonly load: (input: { forwardId?: string, messageId?: string }) => Promise<SandboxForward>
|
|
45
|
+
}): Promise<ForwardDialogFrame | undefined> {
|
|
46
|
+
let forward: SandboxForward
|
|
47
|
+
try {
|
|
48
|
+
forward = await input.load(input.input)
|
|
49
|
+
} catch {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const nestedEntries = await Promise.all(
|
|
54
|
+
forward.nodes
|
|
55
|
+
.map((node) => node.forwardId)
|
|
56
|
+
.filter((forwardId): forwardId is string => !!forwardId)
|
|
57
|
+
.map(async (forwardId) => {
|
|
58
|
+
try {
|
|
59
|
+
return [forwardId, await input.load({ forwardId })] as const
|
|
60
|
+
} catch {
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
// 没有可推断的标题时留空,由界面按当前语言显示「合并转发」。
|
|
68
|
+
title: buildForwardPreview(forward).title,
|
|
69
|
+
items: forward.nodes.map((node) => ({ ...node })),
|
|
70
|
+
nestedForwards: Object.fromEntries(
|
|
71
|
+
nestedEntries.filter((entry): entry is readonly [string, SandboxForward] => !!entry),
|
|
72
|
+
),
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardNodeText,
|
|
3
|
+
type SandboxForward,
|
|
4
|
+
type SandboxForwardNode,
|
|
5
|
+
type SandboxForwardPreview,
|
|
6
|
+
type SandboxMessage,
|
|
7
|
+
} from '../../src/types'
|
|
8
|
+
import { getMediaLabel } from './message-presentation'
|
|
9
|
+
|
|
10
|
+
// 自定义节点可以同时带文字、媒体与嵌套转发,三者都要进摘要;与服务端 formatForwardPreview 同步。
|
|
11
|
+
function summarizeNode(node: SandboxForwardNode): string {
|
|
12
|
+
const text = forwardNodeText(node).replace(/\s+/g, ' ').trim()
|
|
13
|
+
const parts = [
|
|
14
|
+
text,
|
|
15
|
+
...(!text && node.media?.length ? node.media.map((item) => `[${getMediaLabel(item)}] ${item.name}`) : []),
|
|
16
|
+
...(node.forwardId ? ['[合并转发]'] : []),
|
|
17
|
+
].filter(Boolean)
|
|
18
|
+
return parts.join(' ') || '[消息]'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 列表卡片只需要标题、总数和最多 4 行摘要;完整 node 仍由 SandboxForward 承载。
|
|
22
|
+
export function buildForwardPreview(forward: SandboxForward): SandboxForwardPreview {
|
|
23
|
+
return {
|
|
24
|
+
title: forward.title ?? '群聊的聊天记录',
|
|
25
|
+
total: forward.nodes.length,
|
|
26
|
+
lines: forward.nodes.slice(0, 4).map((node) => `${node.nickname}:${summarizeNode(node)}`),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function buildForwardPreviewMap(
|
|
31
|
+
messages: readonly Pick<SandboxMessage, 'id' | 'forwardId'>[],
|
|
32
|
+
forwards: readonly SandboxForward[],
|
|
33
|
+
): Record<string, SandboxForwardPreview> {
|
|
34
|
+
const forwardsById = new Map(forwards.map((forward) => [forward.id, forward]))
|
|
35
|
+
return Object.fromEntries(messages.flatMap((message) => {
|
|
36
|
+
if (!message.forwardId) return []
|
|
37
|
+
const forward = forwardsById.get(message.forwardId)
|
|
38
|
+
return forward ? [[message.id, buildForwardPreview(forward)]] : []
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface FriendMenuState {
|
|
2
|
+
isFriend: boolean
|
|
3
|
+
pendingOutgoing: boolean
|
|
4
|
+
pendingIncoming: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type FriendMenuAction = 'request' | 'poke' | 'remark' | 'delete'
|
|
8
|
+
|
|
9
|
+
export function getFriendMenuActions(state: FriendMenuState, includeInteraction: boolean): FriendMenuAction[] {
|
|
10
|
+
if (!state.isFriend) {
|
|
11
|
+
return state.pendingOutgoing || state.pendingIncoming ? [] : ['request']
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return includeInteraction
|
|
15
|
+
? ['poke', 'remark', 'delete']
|
|
16
|
+
: ['remark', 'delete']
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SandboxGroupMember } from '../../src/types'
|
|
2
|
+
|
|
3
|
+
export function getGroupMemberDisplayName(member: Pick<SandboxGroupMember, 'card'> | undefined, participantName: string) {
|
|
4
|
+
return member?.card?.trim() || participantName
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type GroupAuthorityBadge =
|
|
8
|
+
| { readonly kind: 'owner' | 'admin', readonly title?: string }
|
|
9
|
+
| { readonly kind: 'title', readonly title: string }
|
|
10
|
+
|
|
11
|
+
// 与真实 QQ 一致:专属头衔占用群身份徽标的位置并覆盖身份文案,
|
|
12
|
+
// 但徽标配色仍跟随群身份,普通成员才使用独立的头衔配色。没有头衔时由界面按身份显示文案。
|
|
13
|
+
export function getGroupAuthorityBadge(member: Pick<SandboxGroupMember, 'role' | 'title'> | undefined): GroupAuthorityBadge | undefined {
|
|
14
|
+
if (!member) return
|
|
15
|
+
const title = member.title?.trim() || undefined
|
|
16
|
+
if (member.role === 'owner' || member.role === 'admin') return title ? { kind: member.role, title } : { kind: member.role }
|
|
17
|
+
return title ? { kind: 'title', title } : undefined
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SandboxGroupMember } from '../../src/types'
|
|
2
|
+
|
|
3
|
+
export type GroupMemberMenuAction = 'mention' | 'poke' | 'set-card' | 'set-title' | 'kick' | 'set-admin' | 'unset-admin' | 'transfer-owner'
|
|
4
|
+
|
|
5
|
+
export function getGroupMemberMenuActions(
|
|
6
|
+
actor: SandboxGroupMember | undefined,
|
|
7
|
+
target: SandboxGroupMember,
|
|
8
|
+
): GroupMemberMenuAction[] {
|
|
9
|
+
if (!actor) return []
|
|
10
|
+
const actions: GroupMemberMenuAction[] = []
|
|
11
|
+
if (actor.participantId !== target.participantId) actions.push('mention', 'poke')
|
|
12
|
+
if (actor.participantId === target.participantId
|
|
13
|
+
|| actor.role === 'owner'
|
|
14
|
+
|| (actor.role === 'admin' && target.role === 'member')) actions.push('set-card')
|
|
15
|
+
// 与真实 QQ 一致:专属头衔只有群主可以授予,且可以授予给自己。
|
|
16
|
+
if (actor.role === 'owner') actions.push('set-title')
|
|
17
|
+
if (actor.role === 'owner' && target.role !== 'owner') {
|
|
18
|
+
actions.push(target.role === 'admin' ? 'unset-admin' : 'set-admin')
|
|
19
|
+
}
|
|
20
|
+
if (actor.role === 'owner' && actor.participantId !== target.participantId) actions.push('transfer-owner')
|
|
21
|
+
if (actor.participantId !== target.participantId
|
|
22
|
+
&& target.role !== 'owner'
|
|
23
|
+
&& (actor.role === 'owner' || (actor.role === 'admin' && target.role === 'member'))) actions.push('kick')
|
|
24
|
+
return actions
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ResolvedConversation } from '../../src/conversation-resolution'
|
|
2
|
+
import { readMessageCapabilities, type MessageCapabilities } from '../../src/message-capabilities'
|
|
3
|
+
import type { SandboxGroup, SandboxMessage } from '../../src/types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 消息列表的能力位投影:一条消息一份,答案全部来自共享判据 `src/message-capabilities`。
|
|
7
|
+
*
|
|
8
|
+
* 客户端因此不再自己推导「这条消息能做什么」,右键菜单只渲染这份答案,判定从组件搬到工作台
|
|
9
|
+
* 外壳的投影里,从 `chatPaneModel` 的 interface 上就能观察到。能力位不进快照载荷:判据共享后
|
|
10
|
+
* 客户端自己就能算,没有理由让每条消息在 RPC 上多带几个布尔值。
|
|
11
|
+
*
|
|
12
|
+
* 客户端的答案只用来渲染菜单,不构成许可——服务端在写入路径上照旧自己问一遍再拒绝。
|
|
13
|
+
*/
|
|
14
|
+
export interface MessageCapabilityProjectionInput {
|
|
15
|
+
readonly messages: readonly SandboxMessage[]
|
|
16
|
+
/** 当前会话;缺省表示还没有选中会话,因此没有消息可判。 */
|
|
17
|
+
readonly conversation?: ResolvedConversation
|
|
18
|
+
readonly operatorId?: string
|
|
19
|
+
/** 群聊会话所属的群组;私聊为 undefined。 */
|
|
20
|
+
readonly group?: SandboxGroup
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function buildMessageCapabilityMap(
|
|
24
|
+
input: MessageCapabilityProjectionInput,
|
|
25
|
+
): Record<string, MessageCapabilities> {
|
|
26
|
+
const conversation = input.conversation
|
|
27
|
+
if (!conversation) return {}
|
|
28
|
+
return Object.fromEntries(input.messages.map((message) => [
|
|
29
|
+
message.id,
|
|
30
|
+
readMessageCapabilities({
|
|
31
|
+
message,
|
|
32
|
+
conversation,
|
|
33
|
+
operatorId: input.operatorId,
|
|
34
|
+
group: input.group,
|
|
35
|
+
}),
|
|
36
|
+
]))
|
|
37
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { SandboxMessage } from '../../src/types'
|
|
2
|
+
|
|
3
|
+
export function isImageOnlyMessage(message: SandboxMessage | undefined) {
|
|
4
|
+
const media = message?.media
|
|
5
|
+
return !!message
|
|
6
|
+
&& media?.length === 1
|
|
7
|
+
&& media[0].type === 'image'
|
|
8
|
+
&& message.content === `[图片] ${media[0].name}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getDirection(message: SandboxMessage | undefined, currentOperatorId: string | undefined) {
|
|
12
|
+
if (!message) return
|
|
13
|
+
return message.authorId === currentOperatorId ? 'outgoing' : 'incoming'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isSameClusterSender(
|
|
17
|
+
left: SandboxMessage | undefined,
|
|
18
|
+
right: SandboxMessage | undefined,
|
|
19
|
+
currentOperatorId: string | undefined,
|
|
20
|
+
) {
|
|
21
|
+
return !!left
|
|
22
|
+
&& !!right
|
|
23
|
+
&& !left.event
|
|
24
|
+
&& !right.event
|
|
25
|
+
// 撤回只改变呈现状态,不改变发送者连续性;继续合并可避免同一发送者重复头像。
|
|
26
|
+
&& left.authorId === right.authorId
|
|
27
|
+
// 跨会话的两条消息不是一簇:分支里继承前缀与自有消息之间有一条分界,合并会让分叉点之后的
|
|
28
|
+
// 第一条自有消息看起来是上面那条的续写,连发送者一行都被省掉。
|
|
29
|
+
&& left.conversationId === right.conversationId
|
|
30
|
+
&& getDirection(left, currentOperatorId) === getDirection(right, currentOperatorId)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getClusterBubbleMessage(
|
|
34
|
+
messages: SandboxMessage[],
|
|
35
|
+
index: number,
|
|
36
|
+
step: 1 | -1,
|
|
37
|
+
currentOperatorId: string | undefined,
|
|
38
|
+
) {
|
|
39
|
+
const message = messages[index]
|
|
40
|
+
if (!message) return
|
|
41
|
+
for (let cursor = index + step; cursor >= 0 && cursor < messages.length; cursor += step) {
|
|
42
|
+
const candidate = messages[cursor]
|
|
43
|
+
if (!isSameClusterSender(message, candidate, currentOperatorId)) return
|
|
44
|
+
if (!isImageOnlyMessage(candidate)) return candidate
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isMergedMessage(
|
|
49
|
+
messages: SandboxMessage[],
|
|
50
|
+
index: number,
|
|
51
|
+
currentOperatorId: string | undefined,
|
|
52
|
+
) {
|
|
53
|
+
return isSameClusterSender(messages[index - 1], messages[index], currentOperatorId)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getMessageClusterClass(
|
|
57
|
+
messages: SandboxMessage[],
|
|
58
|
+
index: number,
|
|
59
|
+
currentOperatorId: string | undefined,
|
|
60
|
+
) {
|
|
61
|
+
if (!messages[index]) return ''
|
|
62
|
+
const hasPrevious = !!getClusterBubbleMessage(messages, index, -1, currentOperatorId)
|
|
63
|
+
const hasNext = !!getClusterBubbleMessage(messages, index, 1, currentOperatorId)
|
|
64
|
+
if (hasPrevious && hasNext) return 'is-cluster-middle'
|
|
65
|
+
if (hasNext) return 'is-cluster-first'
|
|
66
|
+
if (hasPrevious) return 'is-cluster-last'
|
|
67
|
+
return ''
|
|
68
|
+
}
|