@coda-console/friends 0.1.0 → 0.3.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/README.md CHANGED
@@ -2,14 +2,56 @@
2
2
 
3
3
  管理本机的 Accord 身份、个人名片与熟人好友通道(`coda/accord@1`)。
4
4
 
5
- - **我的身份与名片**:显示本机公钥短码,可复制公钥;昵称、头像 Emoji、主题色以公开的 `profile` / `self` 记录发布(与 token-board 约定的同一格式,两个插件互不依赖)。
5
+ - **我的身份与名片**:显示本机公钥短码,可复制公钥;昵称、头像 Emoji、主题色以公开的 `profile` / `self` 记录发布;本机绑定了代签证书、`profile` 被拒(`forbidden`)时改发可代签的社交名片 `friends/card` / `self`。
6
6
  - **添加好友**:粘贴对方给的邀请(JSON、`coda-friend://` 链接或多行 `key=value`),接受后自动尝试互认。暂需由对方提供 friend 角色入网码。
7
7
  - **好友列表**:实时跟随好友表变化;可备注、重新互认、移除。
8
+ - **社交网关 `friends/social@1`**:业务无关,别的插件(在 `optionalUses` 里声明)经它读好友与好友分享的记录、向好友发布与撤回记录、发私信与动态、实时跟随私信与动态,不必各自处理没有身份、证书过期和重试。
9
+
10
+ ## 社交网关
11
+
12
+ 签名写入与记录查询全部透传 `coda/accord@1`,网关自己没有第二份目录库。本机网关记录(`friends/social@1`,key `local`)的 `status` 给出作者、证书状态(`no_identity` / `needs_cert` / `active`)、好友数、待发数与暂停的 kind。
13
+
14
+ | 操作 | 作用 |
15
+ | --- | --- |
16
+ | `friends`(读) | 互认的好友(`includePending` 带上待互认与冲突的),合并 `profile`、`friends/card`(逐字段 `profile` 优先)与本地备注;每行带 `avatar`(`content/<sha256>` 指针或 `null`) |
17
+ | `records`(读) | 按 `kind`、`author`、`id`、`cursor` 读好友分享的记录,不读 `binding` |
18
+ | `publish` | 发布 `{ kind, id, body, audience? }`;同作者同内容不重发,换作者重发 |
19
+ | `set-card` | 发布本机社交名片 `friends/card` / `self`:`{ name, emoji?, color?, avatar? }`,`avatar` 只收 `content/<sha256>` 指针(至多 5 MiB),`null` 清除;与 `publish` 同一条队 |
20
+ | `send-dm` | 发一条私信 `friends/dm`:`{ to, id?, text?, attachments?, replyTo? }`,受众只有 `to` 一人(不收 `public`、不收自己);结果带最终用的 `id` |
21
+ | `post-feed` | 发一条动态 `friends/feed`:`{ id?, text?, media?, audience? }`,`audience` 缺省 `['public']`,写了须是 1–500 项(去重);结果带最终用的 `id` |
22
+ | `retract` | 撤回一条,或省略 `id` 撤回本机在这个 `kind` 下的全部(含队列里还没发出去的) |
23
+ | `outbox`(读) | 待发与已同步条目的状态,从不给出 `body` |
24
+
25
+ - `publish`、`retract` 拒绝保留类型 `binding`、`profile`、`friends`、`coda/profile`、`coda/friends`;`kind` 须是 Accord 的格式,`id` 至多 200 个字符、256 字节,`body` 是对象且 JSON 至多 64 KiB,`audience` 每项是 `public` 或 `ed25519:` 加 64 位十六进制,至多 500 项。
26
+ - 没有身份、证书过期(或发布遇到 `invalid_state`)、`kind` 被暂停、发布失败时,待发的 `body` 暂存在本机 `outbox.json`;同步成功就释放 `body`,只留去重用的 `lastAuthor`、`lastSyncedHash`、`lastSyncedAt`;撤回完成就删掉条目。证书恢复后自动补发、补撤;待撤的条目记着排队时的作者(`targetAuthor`),换了作者不会替新作者撤,没有身份时的撤回只清本机未发出的待发,不排待撤。意图先落盘再签名,签名成功立即落盘确认;`outbox.json`、`policy.json` 读不出来(不是缺失或损坏)就报错,不当空表。
27
+ - 操作名照协议包的规定用小写加连字符(`set-card`、`send-dm`、`post-feed`)。
28
+ - 暂停与恢复某个 `kind` 的外发:`coda self policy.setKind '{"kind":"…","paused":true}'`,`coda self policy.get` 读现状(`policy.json`);暂停只拦发布,不拦撤回。
29
+
30
+ ## 私信与动态
31
+
32
+ 两类记录都由 Accord 签名与保存,网关只清洗与投影,没有第二套目录库;没有身份或证书过期时在 `outbox.json` 排队、恢复后补发,撤回统一走 `retract({ kind: 'friends/dm' | 'friends/feed', id })`。
33
+
34
+ - **正文**:`text` 按原样(含首尾空白)至多 8000 个字(码点,与 schema 的 `maxLength` 一致),发布时去首尾空白;图片指针(`attachments` / `media`)1–4 个,只收 `content/<sha256>`;两者不能都空。`id` 省略时网关生成 UUID,给了须是至多 200 个字符、且 UTF-8 至多 256 字节(与 Accord 一致;schema 表达不了字节数,超了由网关以 `invalid_input` 拒绝)、不含控制字符,去首尾空白后不能为空;`replyTo` 同。
35
+ - **只发给别人**:私信的 `to` 不能是本人。排队时还没有身份、后来绑定的身份正好是收件人的,补发时按实际签名的作者再判一次,标成被拒(`error`),不签。
36
+ - **幂等重试**:`body.createdAt` 先沿用同一 `id` 已有的:`outbox.json` 里待发条目的,或已同步条目留下的 `lastCreatedAt`;队列里没有才查本机在 Accord 里的那条,查明没有才取当前时间,查询失败报可重试的 `unavailable`,不拿新时间戳重签。所以同一 `id`、同样内容的重试按 `publish` 的去重返回 `skipped: true`,不会重签。
37
+ - **投影**:每个 `(author, id)` 只取 `version` 最大的一条,它若是撤回(空 `body`)或畸形,整条就没了,不回落旧版本。私信只收本机发出(本人签、发给别人)或发给本机(别人签、`to` 是本人)的,`peer` 是对面那个人;串线、伪造的丢掉。私信按 `(createdAt, version, author, id)` 升序,动态降序。
38
+
39
+ ### 实时流 `dm`、`feed`
40
+
41
+ 两条都是 `read` 形状的帧流(`application/x-ndjson`,30 秒没东西写一个空行心跳),参数走查询串:`dm` 收 `peer`(只看与这位好友的),`feed` 收 `author`(只看这一位的),都收 `after`(上次拿到的游标)。
42
+
43
+ - 快照分片发出:每帧 `{ type: 'snapshot', cursor, items, more }`,单帧 JSON 至多 256 KiB(远低于 `readFrames` 默认的一行 1 MiB);后面还有分片的 `more` 为 `true`,最后一片(空快照也有这一片,`items: []`)为 `false`。客户端把各片的 `items` 依次拼起来,收到 `more: false` 才落定整份快照与游标。
44
+ - 之后每次变化一帧 `{ type: 'upsert', cursor, item }` 或 `{ type: 'retract', cursor, author, id, peer? }`。同一条私信改投新收件人时,旧会话先收到 `retract`(`peer` 是旧收件人),新会话再收到 `upsert`。
45
+ - 游标是 `<epoch>:<seq>`:`epoch` 每次网关启动重新生成,`seq` 单调递增。网关在内存里留最近 500 次变化;`after` 有效时只补它之后的增量(含撤回,不重复)。`after` 缺失、不合法、来自上一次启动、比现在还新或已被挤出这 500 条的,回到全量快照。
46
+ - 只在有订阅者或新流连入时才翻页读 Accord,随本机 Accord 记录的变化和本机的发布、撤回刷新;刷新排成一条队,不会交错。每次都翻页读到底,读不全(翻页截断、查询失败)就不动内存里上一份完整的投影,不推虚假的快照或撤回;还从没读全过时新连入的流在第一个字节之前以 `unavailable` 失败。
47
+ - 调用方中止请求、取消应答体,或插件停用时,流当场收尾,订阅与监听随之释放(不等下一帧、也不管调用方读没读)。
8
48
 
9
49
  ## 权限与数据边界
10
50
 
51
+ - `friends/social@1` 的权限组:`read` 管 `friends`、`records` 和 `dm`、`feed` 两条流;`publish` 管 `publish`、`set-card`、`send-dm`、`post-feed`、`retract`、`outbox`。
11
52
  - `uses`:`coda/accord@1` 的 `read`(读好友表与名片)、`publish`(发布名片)、`manage`(接受邀请、互认、移除)。
12
53
  - 入网码(`authKey`)是凭据:只在提交时用一次,提交后立即清空输入框,不写入任何文件、日志或页面状态。
13
54
  - 本地备注只存在插件自己的持久目录 `notes.json`(卸载后保留),不发给好友,也不进 Accord 目录。
14
55
  - 好友发来的昵称、Emoji、颜色按同一套规则清洗,只当文本渲染(`textContent`),不当指令或 HTML。
15
- - `activate` 不调用 Accord,所有 Accord 读写都在页面交互时发起。
56
+ - 好友页的 Accord 读写在页面交互时发起;模块只在 `activate` 时监听本机 Accord 记录(证书、好友表),用来刷新网关记录、证书恢复后冲洗待发队列。
57
+ - `uses` 的 `publish` 也供网关代别的插件向好友发布;待发的 `body` 只在本机 `outbox.json`,不经别处。
package/lib/friends.mjs CHANGED
@@ -4,13 +4,15 @@
4
4
  export const COLORS = ['blue', 'orange', 'green', 'purple', 'pink', 'teal', 'gray'];
5
5
  export const PROFILE_KIND = 'profile';
6
6
  export const PROFILE_ID = 'self';
7
+ // 可代签的社交名片:和 profile 同形,id 也是 self;profile 须客户端根签,绑定代签证书后用它。
8
+ export const CARD_KIND = 'friends/card';
7
9
  const MAX_NAME = 40, MAX_EMOJI = 8;
8
10
  // 邀请各字段的上限,与 coda/accord@1 的 accept 输入一致。
9
- const LIMITS = { control: 500, authKey: 500, linkId: 64, scope: 200, hostname: 100, peerNode: 100 };
10
- const LABELS = { control: '入网地址 control', authKey: '入网码 authKey', linkId: 'linkId', scope: 'scope', hostname: 'hostname', peerNode: 'peerNode' };
11
+ const LIMITS = { control: 500, authKey: 500, linkId: 64, scope: 520, hostname: 100, peerNode: 100 };
12
+ const LABELS = { control: '入网地址 control', authKey: '入网码 authKey', linkId: 'linkId', scope: 'scope', hostname: 'hostname', peerNode: 'peerNode', peerPort: 'peerPort' };
11
13
  const LINK_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
12
14
  const ALIASES = { controlurl: 'control', control_url: 'control', authkey: 'authKey', auth_key: 'authKey', linkid: 'linkId', link_id: 'linkId',
13
- link: 'linkId', peernode: 'peerNode', peer_node: 'peerNode' };
15
+ link: 'linkId', peernode: 'peerNode', peer_node: 'peerNode', peerport: 'peerPort', peer_port: 'peerPort' };
14
16
  const CONTROL_CHARS = /[\p{Cc}\u2028\u2029]/gu;
15
17
  const length = text => [...text].length;
16
18
 
@@ -19,7 +21,7 @@ const clean = text => typeof text === 'string' ? text.replace(CONTROL_CHARS, '')
19
21
  // ---- 邀请 ----
20
22
 
21
23
  const fail = message => { throw new Error(message); };
22
- const field = key => ALIASES[key] ?? ALIASES[key.toLowerCase()] ?? (Object.hasOwn(LIMITS, key) ? key : null);
24
+ const field = key => ALIASES[key] ?? ALIASES[key.toLowerCase()] ?? (Object.hasOwn(LABELS, key) ? key : null);
23
25
 
24
26
  function fromObject(object) {
25
27
  const found = {};
@@ -54,7 +56,7 @@ function fromLines(text) {
54
56
  }
55
57
 
56
58
  /**
57
- * 把粘贴的邀请解析成 accept 的入参:`{ linkId, control, authKey, scope?, hostname?, peerNode? }`。
59
+ * 把粘贴的邀请解析成 accept 的入参:`{ linkId, control, authKey, scope?, hostname?, peerNode?, peerPort? }`。
58
60
  * 接受 JSON 对象、coda-friend:// 或带查询串的链接、多行 key=value;错误抛出清晰的中文提示。
59
61
  */
60
62
  export function parseInvite(raw) {
@@ -91,30 +93,90 @@ export function checked(input) {
91
93
  if (!invite.control) fail('邀请缺少 control(入网地址)');
92
94
  if (!invite.authKey) fail('邀请缺少 authKey(入网码)');
93
95
  for (const [name, max] of Object.entries(LIMITS)) if (invite[name] && length(invite[name]) > max) fail(`${LABELS[name]} 太长(最多 ${max} 字)`);
96
+ const raw = input?.peerPort;
97
+ if (raw !== undefined && raw !== null && typeof raw !== 'number' && typeof raw !== 'string') fail('peerPort 须是 1–65535 的整数');
98
+ const port = typeof raw === 'string' ? raw.trim() : raw;
99
+ if (port !== undefined && port !== null && port !== '') {
100
+ const number = typeof port === 'number' ? port : /^\d+$/.test(port) ? Number(port) : NaN;
101
+ if (!Number.isInteger(number) || number < 1 || number > 65535) fail('peerPort 须是 1–65535 的整数');
102
+ invite.peerPort = number;
103
+ }
94
104
  if (invite.linkId && !LINK_ID.test(invite.linkId)) fail('linkId 须以小写字母或数字开头,只能含小写字母、数字、下划线和连字符,最长 64 位');
95
105
  invite.linkId ??= `f-${[...globalThis.crypto.getRandomValues(new Uint8Array(4))].map(n => n.toString(16).padStart(2, '0')).join('')}`;
96
106
  return invite;
97
107
  }
98
108
 
109
+ // ---- 头像指针 ----
110
+
111
+ const MAX_BLOB = 5 * 1024 * 1024, MAX_MIME = 128, MAX_FILE_NAME = 200;
112
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
113
+ const CONTENT_PATH = /^content\/([0-9a-f]{64})$/;
114
+ const MIME = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;
115
+ const POINTER_KEYS = new Set(['owner', 'path', 'sha256', 'mime', 'size', 'name']);
116
+
117
+ /**
118
+ * 内容寻址的图片指针(BlobPointer,`path` 只收 `content/<sha256>`)的校验:`{ owner, path, sha256, mime?, size?, name? }`,
119
+ * 不许别的键,`sha256` 须与 `path` 里的一致,`size` 至多 5 MiB。合法返回只含这些字段的新对象,不合法抛出中文错误。
120
+ */
121
+ export function normalizeContentPointer(pointer) {
122
+ if (!pointer || typeof pointer !== 'object' || Array.isArray(pointer)) fail('头像须是图片指针对象');
123
+ for (const key of Object.keys(pointer)) if (!POINTER_KEYS.has(key)) fail(`头像指针不认识的字段:${key}`);
124
+ const { owner, path, sha256, mime, size, name } = pointer;
125
+ if (typeof owner !== 'string' || !UUID.test(owner)) fail('头像指针的 owner 须是小写 UUID');
126
+ const match = typeof path === 'string' ? CONTENT_PATH.exec(path) : null;
127
+ if (!match) fail('头像指针的 path 须是 content/<64 位小写十六进制 SHA-256>');
128
+ if (sha256 !== match[1]) fail('头像指针的 sha256 须与 path 里的一致');
129
+ const out = { owner, path, sha256 };
130
+ if (mime !== undefined) {
131
+ if (typeof mime !== 'string' || !mime || mime.length > MAX_MIME || !MIME.test(mime)) fail(`头像指针的 mime 须是合法的 MIME 类型(最多 ${MAX_MIME} 字)`);
132
+ out.mime = mime;
133
+ }
134
+ if (size !== undefined) {
135
+ if (!Number.isSafeInteger(size) || size < 0 || size > MAX_BLOB) fail('头像指针的 size 须是 0 到 5 MiB 之间的整数');
136
+ out.size = size;
137
+ }
138
+ if (name !== undefined) {
139
+ const text = clean(name);
140
+ if (!text || length(text) > MAX_FILE_NAME) fail(`头像指针的 name 须是非空文本(最多 ${MAX_FILE_NAME} 字)`);
141
+ out.name = text;
142
+ }
143
+ return out;
144
+ }
145
+
146
+ /** 读外来记录里的图片指针:合法给规范化的指针,不合法给 null,从不抛错。 */
147
+ export function readContentPointer(pointer) {
148
+ try { return normalizeContentPointer(pointer); } catch { return null; }
149
+ }
150
+
99
151
  // ---- 名片 ----
100
152
 
101
- /** 名片输入的清洗:昵称 1–40 字,emoji 最多 8 字,颜色须在白名单里。不合法的昵称、emoji 抛错;不认识的颜色丢掉。 */
102
- export function normalizeProfileInput({ name, emoji, color } = {}) {
153
+ /**
154
+ * 名片输入的清洗(profile 与 friends/card 同形):昵称 1–40 字,emoji 最多 8 字,颜色须在白名单里;
155
+ * avatar 省略不写,null 表示清除,否则须是合法的 content 指针。不合法的昵称、emoji、头像抛错;不认识的颜色丢掉。
156
+ */
157
+ export function normalizeCardInput({ name, emoji, color, avatar } = {}) {
103
158
  const body = { name: clean(name) };
104
159
  if (!body.name) fail('昵称不能为空');
105
160
  if (length(body.name) > MAX_NAME) fail(`昵称最多 ${MAX_NAME} 个字`);
106
161
  const mark = clean(emoji);
107
162
  if (mark) { if (length(mark) > MAX_EMOJI) fail(`头像最多 ${MAX_EMOJI} 个字符`); body.emoji = mark; }
108
163
  if (typeof color === 'string' && COLORS.includes(color)) body.color = color;
164
+ if (avatar !== undefined) body.avatar = avatar === null ? null : normalizeContentPointer(avatar);
109
165
  return body;
110
166
  }
167
+ export const normalizeProfileInput = normalizeCardInput;
111
168
 
112
169
  /**
113
170
  * 读 Accord 记录里的名片,来自好友的外来数据:按同样的规则清洗,不合法的字段忽略,昵称不合法整张忽略(null)。
171
+ * 头像分三种:没写或畸形是 `avatarPresent: false`;显式清除(`avatar: null`)与合法指针是 `avatarPresent: true`,`avatar` 为 null 或指针。
114
172
  * 结果只当文本用,不当指令或 HTML。
115
173
  */
116
- export function readProfileRecord(record) {
117
- if (!record || record.kind !== PROFILE_KIND || record.id !== PROFILE_ID) return null;
174
+ export const readProfileRecord = record => readNameRecord(record, PROFILE_KIND);
175
+ /** 同 readProfileRecord,读 friends/card 记录。 */
176
+ export const readCardRecord = record => readNameRecord(record, CARD_KIND);
177
+
178
+ function readNameRecord(record, kind) {
179
+ if (!record || record.kind !== kind || record.id !== PROFILE_ID) return null;
118
180
  const body = record.body;
119
181
  if (!body || typeof body !== 'object' || Array.isArray(body)) return null;
120
182
  const name = clean(body.name);
@@ -123,9 +185,32 @@ export function readProfileRecord(record) {
123
185
  const emoji = clean(body.emoji);
124
186
  if (emoji && length(emoji) <= MAX_EMOJI) profile.emoji = emoji;
125
187
  if (typeof body.color === 'string' && COLORS.includes(body.color)) profile.color = body.color;
188
+ const avatar = body.avatar === null ? null : readContentPointer(body.avatar);
189
+ profile.avatar = avatar;
190
+ profile.avatarPresent = body.avatar === null || avatar !== null;
126
191
  return profile;
127
192
  }
128
193
 
194
+ /**
195
+ * 同一作者的 profile(根私钥签名)与 friends/card(可代签)合成一张名片:profile 写了的字段优先,免得代签的机器盖过根签的资料;
196
+ * profile 没写的由 friends/card 补。头像看 `avatarPresent`:profile 写了(含显式清除的 null)就用 profile 的。两张都没有给 null。
197
+ */
198
+ export function mergeProfileAndCard(profile, card) {
199
+ if (!profile && !card) return null;
200
+ const pick = key => profile?.[key] ?? card?.[key];
201
+ const from = profile?.avatarPresent ? profile : card?.avatarPresent ? card : null;
202
+ return { name: pick('name'), emoji: pick('emoji'), color: pick('color'), avatar: from ? from.avatar : null, avatarPresent: Boolean(from) };
203
+ }
204
+
205
+ /**
206
+ * 代签回退发布了 friends/card 之后的提示:`true` 已确认有根签的 profile,如实说明好友看到的仍以它为准;`false` 已确认没有;
207
+ * `null` / `undefined` 没读出来,不承诺好友看到的是哪张。
208
+ */
209
+ export const cardFallbackNotice = hasRootProfile => hasRootProfile === true
210
+ ? '社交名片已保存,但你已有根私钥签名的名片,昵称等已有项仍以根签名为准(未设项由社交名片补充)'
211
+ : hasRootProfile === false ? '本机用的是代签证书,名片已改作社交名片(friends/card)发布,好友会看到它'
212
+ : '社交名片已保存;若你曾用根私钥发布过名片,昵称等已有项仍以根签名为准';
213
+
129
214
  /** 密钥的短码:`ed25519:` 之后的前 8 位(没有就空串)。 */
130
215
  export function shortAuthor(author) {
131
216
  const match = /^ed25519:([0-9a-f]{64})$/.exec(author ?? '');
@@ -138,22 +223,27 @@ const RANK = { conflict: 0, pending: 1, bound: 2 };
138
223
  export const statusOf = friend => friend.conflict ? 'conflict' : friend.bound ? 'bound' : 'pending';
139
224
 
140
225
  /**
141
- * 好友表(`status.friends`)、好友的名片记录(取每把钥匙 version 最大的)和本地备注(按 node,没有再按 author)合成的行,
142
- * 按状态(冲突、待互认、已互认)再按更新时间新的在前排序,同样的输入排出同样的顺序。
226
+ * 好友表(`status.friends`)、好友的名片记录(profile 与 friends/card 各取每把钥匙 version 最大的,按 mergeProfileAndCard
227
+ * 合成)和本地备注(按 node,没有再按 author)合成的行,按状态(冲突、待互认、已互认)再按更新时间新的在前排序,
228
+ * 同样的输入排出同样的顺序。
143
229
  */
144
- export function mergeFriendRows({ friends = [], profiles = [], notes = {} } = {}) {
145
- const latest = new Map();
146
- for (const record of profiles) {
147
- const profile = readProfileRecord(record);
148
- if (profile?.author && (!latest.has(profile.author) || profile.version > latest.get(profile.author).version)) latest.set(profile.author, profile);
149
- }
230
+ export function mergeFriendRows({ friends = [], profiles = [], cards = [], notes = {} } = {}) {
231
+ const latestOf = (records, read) => {
232
+ const latest = new Map();
233
+ for (const record of records) {
234
+ const one = read(record);
235
+ if (one?.author && (!latest.has(one.author) || one.version > latest.get(one.author).version)) latest.set(one.author, one);
236
+ }
237
+ return latest;
238
+ };
239
+ const byProfile = latestOf(profiles, readProfileRecord), byCard = latestOf(cards, readCardRecord);
150
240
  const note = friend => (Object.hasOwn(notes, friend.node) ? notes[friend.node] : friend.author && Object.hasOwn(notes, friend.author) ? notes[friend.author] : '');
151
241
  const rows = friends.map(friend => {
152
- const profile = friend.author ? latest.get(friend.author) ?? null : null, status = statusOf(friend), remark = clean(note(friend));
153
- const short = shortAuthor(friend.author);
242
+ const card = friend.author ? mergeProfileAndCard(byProfile.get(friend.author), byCard.get(friend.author)) : null;
243
+ const status = statusOf(friend), remark = clean(note(friend)), short = shortAuthor(friend.author), name = card?.name;
154
244
  return { node: friend.node, author: friend.author ?? null, short, status, peerNode: friend.peerNode ?? null, scope: friend.scope, updatedAt: friend.updatedAt ?? 0,
155
- note: remark, profileName: profile?.name ?? '', emoji: profile?.emoji ?? '', color: profile?.color ?? 'gray',
156
- title: remark || profile?.name || (short ? `好友 ${short}` : friend.node) };
245
+ note: remark, profileName: name ?? '', emoji: card?.emoji ?? '', color: card?.color ?? 'gray', avatar: card?.avatar ?? null,
246
+ title: remark || name || (short ? `好友 ${short}` : friend.node) };
157
247
  });
158
248
  return rows.sort((a, b) => RANK[a.status] - RANK[b.status] || b.updatedAt - a.updatedAt || (a.node < b.node ? -1 : a.node > b.node ? 1 : 0));
159
249
  }