@iwpz/fishpi-dsh 0.1.0 → 0.1.2

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/client.js CHANGED
@@ -70,10 +70,10 @@ window.__ModuleLoader__.load({
70
70
  'login.account': '账号或邮箱',
71
71
  'login.password': '密码',
72
72
  'login.mfa': '两步验证码(选填)',
73
- 'login.remember': '记住密码(仅保存 MD5 摘要)',
73
+ 'login.remember': '在此设备保持登录',
74
74
  'login.submit': '登录',
75
75
  'login.busy': '登录中…',
76
- 'login.hint': '账号凭据保存在本机 DSH 凭据库,不会写进配置文件。',
76
+ 'login.hint': '登录后保存鱼排刷新凭据,重启 DSH 后无需重新登录。',
77
77
  'login.register': '去注册',
78
78
  'login.needMfa': '该账号启用了两步验证,请输入验证码后重试。',
79
79
  logout: '退出登录',
@@ -89,8 +89,25 @@ window.__ModuleLoader__.load({
89
89
  'settings.notifications.denied': '浏览器拒绝了通知权限。',
90
90
  'settings.notifications.unsupported': '当前环境不支持系统通知。',
91
91
  'error.crash': '聊天室渲染失败',
92
- 'settings.credentialNote': '登录凭据保存在本机 DSH 凭据库。勾选“记住密码”时保存密码的 MD5 摘要,用于访问令牌过期后自动重新登录;开启两步验证的账号仍需手动输入验证码。',
93
- 'settings.version': '插件版本 0.1.0',
92
+ 'host.restart': '插件 Host 还是旧版本,撤回和管理员撤回暂不可用。请完全退出 DSH 再重新打开。',
93
+ 'settings.update': '插件更新',
94
+ 'settings.update.versions': '当前 {current} · {latest}',
95
+ 'settings.update.check': '检查更新',
96
+ 'settings.update.checking': '检查中…',
97
+ 'settings.update.install': '立即安装',
98
+ 'settings.update.installing': '安装中…',
99
+ 'message.actions': '消息操作',
100
+ 'message.quoteShort': '引',
101
+ 'message.recallShort': '撤',
102
+ 'message.recallConfirmShort': '确',
103
+ 'message.mentionShort': '@',
104
+ 'message.repeatShort': '+1',
105
+ 'message.quote': '引用这条消息',
106
+ 'message.recall': '撤回这条消息(再次点击确认,撤回可能消耗积分)',
107
+ 'message.recallModerate': '撤回这条消息(管理员/OP/纪律委员操作;再次点击确认)',
108
+ 'message.recallConfirm': '再次点击确认撤回',
109
+ 'message.mention': '在输入框艾特这条消息的作者',
110
+ 'message.repeat': '复读 +1',
94
111
  'composer.placeholder': '说点什么…',
95
112
  'composer.addImage': '添加图片',
96
113
  'composer.uploading': '正在上传图片…',
@@ -159,6 +176,10 @@ window.__ModuleLoader__.load({
159
176
  'error.rate': '操作过于频繁,请稍后再试。',
160
177
  'error.server': '摸鱼派服务暂时不可用。',
161
178
  'error.upload': '图片上传失败,请稍后重试。',
179
+ 'error.notRemovable': '这条消息不能撤回(红包等特殊消息不支持撤回)。',
180
+ 'error.notFound': '消息不存在或已被撤回。',
181
+ 'error.recallFailed': '撤回失败,请稍后重试。',
182
+ 'error.hostRestart': '插件 Host 还是旧版本,请完全退出 DSH 再重新打开。',
162
183
  'error.generic': '操作失败,请稍后重试。',
163
184
  'error.dismiss': '关闭',
164
185
  'card.redPacket': '红包',
@@ -192,10 +213,10 @@ window.__ModuleLoader__.load({
192
213
  'login.account': 'Username or email',
193
214
  'login.password': 'Password',
194
215
  'login.mfa': 'Two-step code (optional)',
195
- 'login.remember': 'Remember password (MD5 digest only)',
216
+ 'login.remember': 'Stay signed in on this device',
196
217
  'login.submit': 'Sign in',
197
218
  'login.busy': 'Signing in…',
198
- 'login.hint': 'Credentials stay in the local DSH credential store and never enter configuration.',
219
+ 'login.hint': 'The FishPi refresh credential is saved locally, so restarting DSH does not require another sign-in.',
199
220
  'login.register': 'Create account',
200
221
  'login.needMfa': 'This account uses two-step verification. Enter the code and try again.',
201
222
  logout: 'Sign out',
@@ -211,8 +232,25 @@ window.__ModuleLoader__.load({
211
232
  'settings.notifications.denied': 'The browser denied notification permission.',
212
233
  'settings.notifications.unsupported': 'System notifications are unavailable here.',
213
234
  'error.crash': 'The chat panel failed to render',
214
- 'settings.credentialNote': 'Credentials stay in the local DSH credential store. With “Remember password”, the MD5 digest is saved so an expired access token can sign in again automatically. Accounts with two-step verification still need the code.',
215
- 'settings.version': 'Plugin version 0.1.0',
235
+ 'host.restart': 'The plugin Host is still on an older build; recall and moderator recall are unavailable. Quit and reopen DSH completely.',
236
+ 'settings.update': 'Plugin updates',
237
+ 'settings.update.versions': 'Current {current} · {latest}',
238
+ 'settings.update.check': 'Check for updates',
239
+ 'settings.update.checking': 'Checking…',
240
+ 'settings.update.install': 'Install now',
241
+ 'settings.update.installing': 'Installing…',
242
+ 'message.actions': 'Message actions',
243
+ 'message.quoteShort': 'Q',
244
+ 'message.recallShort': 'R',
245
+ 'message.recallConfirmShort': 'C',
246
+ 'message.mentionShort': '@',
247
+ 'message.repeatShort': '+1',
248
+ 'message.quote': 'Quote this message',
249
+ 'message.recall': 'Recall this message (click again to confirm; may cost points)',
250
+ 'message.recallModerate': 'Recall this message (moderator action; click again to confirm)',
251
+ 'message.recallConfirm': 'Click again to confirm recall',
252
+ 'message.mention': 'Mention this message’s author in the composer',
253
+ 'message.repeat': 'Repeat +1',
216
254
  'composer.placeholder': 'Say something…',
217
255
  'composer.addImage': 'Add images',
218
256
  'composer.uploading': 'Uploading images…',
@@ -281,6 +319,10 @@ window.__ModuleLoader__.load({
281
319
  'error.rate': 'Too many requests. Wait a moment and try again.',
282
320
  'error.server': 'The FishPi service is temporarily unavailable.',
283
321
  'error.upload': 'Image upload failed. Try again.',
322
+ 'error.notRemovable': 'This message cannot be recalled (red packets and other special messages are excluded).',
323
+ 'error.notFound': 'The message no longer exists or was already recalled.',
324
+ 'error.recallFailed': 'Recall failed. Try again.',
325
+ 'error.hostRestart': 'The plugin Host is still on an older build. Quit and reopen DSH completely.',
284
326
  'error.generic': 'The operation failed. Try again.',
285
327
  'error.dismiss': 'Dismiss',
286
328
  'card.redPacket': 'Red packet',
@@ -648,6 +690,11 @@ window.__ModuleLoader__.load({
648
690
  case 'insufficient_points': return t('error.points')
649
691
  case 'rate_limited': return t('error.rate')
650
692
  case 'upload_failed': return t('error.upload')
693
+ case 'message_not_removable': return t('error.notRemovable')
694
+ case 'http_404':
695
+ case 'not_found': return t('error.notFound')
696
+ case 'recall_failed': return t('error.recallFailed')
697
+ case 'host_restart': return t('error.hostRestart')
651
698
  case 'realtime_unavailable':
652
699
  case 'internal':
653
700
  case 'http_500':
@@ -666,6 +713,7 @@ window.__ModuleLoader__.load({
666
713
  let state = {
667
714
  loaded: false,
668
715
  ready: false,
716
+ hostVersion: '',
669
717
  loggedIn: false,
670
718
  user: null,
671
719
  connection: 'disconnected',
@@ -674,6 +722,7 @@ window.__ModuleLoader__.load({
674
722
  loadingMessages: false,
675
723
  loadingOlder: false,
676
724
  sending: false,
725
+ recalling: false,
677
726
  uploadingImages: false,
678
727
  loggingIn: false,
679
728
  loginError: null,
@@ -685,6 +734,9 @@ window.__ModuleLoader__.load({
685
734
  unread: 0,
686
735
  chatVisible: false,
687
736
  error: null,
737
+ update: null,
738
+ checkingUpdate: false,
739
+ installingUpdate: false,
688
740
  siteUrl: 'https://fishpi.cn',
689
741
  prefs: readPrefs(),
690
742
  redPacketId: null,
@@ -707,6 +759,7 @@ window.__ModuleLoader__.load({
707
759
  let started = false
708
760
  let claimedUserId = ''
709
761
  let redPacketSeq = 0
762
+ let recallKey = { id: '', requestId: '' }
710
763
  const medalPending = new Set()
711
764
  const listeners = new Set()
712
765
  const store = {
@@ -806,6 +859,7 @@ window.__ModuleLoader__.load({
806
859
  set({
807
860
  loaded: true,
808
861
  ready: data.ready === true,
862
+ hostVersion: typeof data.hostVersion === 'string' ? data.hostVersion : '',
809
863
  loggedIn: data.loggedIn === true,
810
864
  user: data.user ?? null,
811
865
  connection: typeof data.connection === 'string' ? data.connection : state.connection,
@@ -813,11 +867,13 @@ window.__ModuleLoader__.load({
813
867
  mfaRequired: data.mfaRequired === true,
814
868
  siteUrl: typeof data.siteUrl === 'string' && data.siteUrl !== '' ? data.siteUrl : state.siteUrl,
815
869
  error: data.error === undefined ? state.error : data.error,
870
+ update: data.update === undefined ? state.update : data.update,
816
871
  claimedPacketIds,
817
872
  })
818
873
  if (was && !data.loggedIn) {
819
874
  set({
820
875
  messages: [],
876
+ recalling: false,
821
877
  unread: 0,
822
878
  topic: '',
823
879
  online: 0,
@@ -1038,6 +1094,7 @@ window.__ModuleLoader__.load({
1038
1094
  loggedIn: false,
1039
1095
  user: null,
1040
1096
  messages: [],
1097
+ recalling: false,
1041
1098
  unread: 0,
1042
1099
  topic: '',
1043
1100
  online: 0,
@@ -1198,6 +1255,49 @@ window.__ModuleLoader__.load({
1198
1255
  }
1199
1256
  }
1200
1257
 
1258
+ /**
1259
+ * Recall one of the current account's messages.
1260
+ * @param {string} id - message id.
1261
+ * @returns {Promise<{ok: boolean}>} whether the Host withdrew the message.
1262
+ */
1263
+ async function recall(id) {
1264
+ if (state.recalling) return { ok: false }
1265
+ const clean = String(id)
1266
+ if (!/^\d+$/u.test(clean)) return { ok: false }
1267
+ if (recallKey.id !== clean) recallKey = { id: clean, requestId: uuid() }
1268
+ set({ recalling: true, error: null })
1269
+ try {
1270
+ await call('recall', { method: 'POST', body: { id: clean, requestId: recallKey.requestId } })
1271
+ recallKey = { id: '', requestId: '' }
1272
+ set({
1273
+ recalling: false,
1274
+ messages: state.messages.filter(message => message.id !== clean),
1275
+ })
1276
+ return { ok: true }
1277
+ } catch (error) {
1278
+ const code = error.code ?? 'generic'
1279
+ if ((code === 'http_404' || code === 'not_found') && state.hostVersion !== '') {
1280
+ // The message was already withdrawn (for example by another
1281
+ // client) but is still in this local window. Drop it instead of
1282
+ // surfacing a misleading failure.
1283
+ recallKey = { id: '', requestId: '' }
1284
+ set({
1285
+ recalling: false,
1286
+ messages: state.messages.filter(message => message.id !== clean),
1287
+ error: null,
1288
+ })
1289
+ return { ok: true, removed: true }
1290
+ }
1291
+ set({
1292
+ recalling: false,
1293
+ error: state.hostVersion === ''
1294
+ ? { code: 'host_restart', message: error.message }
1295
+ : { code, message: error.message },
1296
+ })
1297
+ return { ok: false }
1298
+ }
1299
+ }
1300
+
1201
1301
  /**
1202
1302
  * @param {string} content - composer text.
1203
1303
  * @returns {Promise<{ok: boolean}>}
@@ -1255,6 +1355,62 @@ window.__ModuleLoader__.load({
1255
1355
  set({ error: null })
1256
1356
  }
1257
1357
 
1358
+ /**
1359
+ * Ask the Host to re-check npm and publish the result.
1360
+ * @returns {Promise<{ok: boolean}>} whether the check completed.
1361
+ */
1362
+ async function checkUpdate() {
1363
+ if (state.checkingUpdate) return { ok: false }
1364
+ set({ checkingUpdate: true })
1365
+ try {
1366
+ const data = await call('update/check', { method: 'POST', body: {} })
1367
+ set({
1368
+ checkingUpdate: false,
1369
+ update: data.update === undefined ? state.update : data.update,
1370
+ })
1371
+ return { ok: true }
1372
+ } catch (error) {
1373
+ set({
1374
+ checkingUpdate: false,
1375
+ update: {
1376
+ ...(state.update ?? {
1377
+ current: '',
1378
+ latest: '',
1379
+ available: false,
1380
+ localAhead: false,
1381
+ url: '',
1382
+ source: '',
1383
+ checkedAt: 0,
1384
+ }),
1385
+ checkedAt: Date.now(),
1386
+ error: { code: error.code ?? 'generic', message: error.message },
1387
+ },
1388
+ })
1389
+ return { ok: false }
1390
+ }
1391
+ }
1392
+
1393
+ /** Install the available npm update through the Host plugin manager. */
1394
+ async function installUpdate() {
1395
+ if (state.installingUpdate) return { ok: false }
1396
+ set({ installingUpdate: true, error: null })
1397
+ try {
1398
+ await call('update/install', { method: 'POST', body: {} })
1399
+ set({
1400
+ installingUpdate: false,
1401
+ update: state.update === null ? state.update : { ...state.update, available: false },
1402
+ })
1403
+ window.setTimeout(() => { window.location.reload() }, 300)
1404
+ return { ok: true }
1405
+ } catch (error) {
1406
+ set({
1407
+ installingUpdate: false,
1408
+ error: { code: error.code ?? 'generic', message: error.message },
1409
+ })
1410
+ return { ok: false }
1411
+ }
1412
+ }
1413
+
1258
1414
  /**
1259
1415
  * Open one red packet's detail and claim records.
1260
1416
  * @param {string} id - message id.
@@ -1417,6 +1573,7 @@ window.__ModuleLoader__.load({
1417
1573
  login,
1418
1574
  logout,
1419
1575
  send,
1576
+ recall,
1420
1577
  suggestUsers,
1421
1578
  openUserInfo,
1422
1579
  closeUserInfo,
@@ -1431,6 +1588,8 @@ window.__ModuleLoader__.load({
1431
1588
  setChatVisible,
1432
1589
  clearUnreadIfVisible,
1433
1590
  clearError,
1591
+ checkUpdate,
1592
+ installUpdate,
1434
1593
  openRedPacket,
1435
1594
  closeRedPacket,
1436
1595
  claimRedPacket,
@@ -1774,10 +1933,48 @@ window.__ModuleLoader__.load({
1774
1933
  return h('div', { className: 'fc-plain' }, message.content)
1775
1934
  }
1776
1935
 
1936
+ /**
1937
+ * A run of identical messages, rendered as whole cards where each card
1938
+ * overlaps the previous one. The front (latest) card keeps the body and
1939
+ * actions; the earlier cards keep their avatar/name header visible.
1940
+ * @param {{messages: object[], mode: string, t: Function, siteUrl: string, actions: object|null}} props - the folded run.
1941
+ */
1942
+ function MessageStack({ messages, mode, t, siteUrl, actions, medalIcons }) {
1943
+ const offset = 33
1944
+ return h('div', { className: 'fc-msg-stack-row' },
1945
+ h('div', {
1946
+ className: 'fc-msg-stack',
1947
+ style: { paddingTop: `${(messages.length - 1) * offset}px` },
1948
+ },
1949
+ messages.map((message, index) => {
1950
+ const front = index === messages.length - 1
1951
+ return h('div', {
1952
+ key: message.id,
1953
+ className: `fc-stack-card${front ? ' fc-stack-card-front' : ''}`,
1954
+ style: front
1955
+ ? { zIndex: index + 1 }
1956
+ : { top: `${index * offset}px`, zIndex: index + 1 },
1957
+ },
1958
+ h(MessageRow, {
1959
+ message,
1960
+ own: false,
1961
+ grouped: false,
1962
+ mode,
1963
+ t,
1964
+ siteUrl,
1965
+ medalIcons: medalIcons[message.author?.userName ?? ''] ?? [],
1966
+ actions: front ? actions : null,
1967
+ }),
1968
+ )
1969
+ }),
1970
+ ),
1971
+ )
1972
+ }
1973
+
1777
1974
  /**
1778
1975
  * @param {{message: object, own: boolean, grouped: boolean, mode: string, t: Function}} props - one row.
1779
1976
  */
1780
- function MessageRow({ message, own, grouped, mode, t, siteUrl, medalIcons = [] }) {
1977
+ function MessageRow({ message, own, grouped, mode, t, siteUrl, medalIcons = [], actions = null }) {
1781
1978
  if (message.type === 'system') {
1782
1979
  return h('div', { className: 'fc-system' }, message.text)
1783
1980
  }
@@ -1794,45 +1991,50 @@ window.__ModuleLoader__.load({
1794
1991
  })
1795
1992
  .filter(Boolean)
1796
1993
  const avatar = h(Avatar, { url: author.userAvatarURL ?? '', name: avatarName })
1797
- return h('div', { className: `fc-msg${own ? ' fc-own' : ''}${grouped ? ' fc-grouped' : ''}` },
1798
- grouped
1799
- ? h('span', { className: 'fc-avatar-spacer' })
1800
- : author.userName !== ''
1801
- ? h('button', {
1802
- type: 'button',
1803
- className: 'fc-avatar-button',
1804
- 'aria-label': name,
1805
- onClick: () => { void sharedStore.openUserInfo(author.userName) },
1806
- }, avatar)
1807
- : avatar,
1808
- h('div', { className: 'fc-msg-body' },
1994
+ return h('div', { className: `fc-msg-line${grouped ? ' fc-grouped' : ''}` },
1995
+ h('div', { className: `fc-msg${own ? ' fc-own' : ''}${grouped ? ' fc-grouped' : ''}` },
1809
1996
  grouped
1810
- ? null
1811
- : h('div', { className: 'fc-msg-head' },
1812
- author.userName !== ''
1813
- ? h('button', {
1814
- type: 'button',
1815
- className: 'fc-msg-name fc-user-link',
1816
- onClick: () => { void sharedStore.openUserInfo(author.userName) },
1817
- }, name)
1818
- : h('span', { className: 'fc-msg-name' }, name),
1819
- resolvedMedals.length > 0
1820
- ? h('span', { className: 'fc-msg-medals' },
1821
- resolvedMedals.map((medal, index) => h('img', {
1822
- key: medal.id || medal.name || index,
1823
- className: 'fc-msg-medal',
1824
- src: medal.url,
1825
- alt: medal.name,
1826
- title: [medal.name, medal.description].filter(Boolean).join(' · '),
1827
- loading: 'lazy',
1828
- referrerPolicy: 'no-referrer',
1829
- onError: event => { event.currentTarget.style.display = 'none' },
1830
- })),
1831
- )
1832
- : null,
1833
- h('time', { className: 'fc-msg-time', dateTime: new Date(message.createdAt).toISOString() }, clock(message.createdAt)),
1834
- ),
1835
- h('div', { className: 'fc-msg-content' }, h(MessageContent, { message, mode, t, siteUrl })),
1997
+ ? h('span', { className: 'fc-avatar-spacer' })
1998
+ : author.userName !== ''
1999
+ ? h('button', {
2000
+ type: 'button',
2001
+ className: 'fc-avatar-button',
2002
+ 'aria-label': name,
2003
+ onClick: () => { void sharedStore.openUserInfo(author.userName) },
2004
+ }, avatar)
2005
+ : avatar,
2006
+ h('div', { className: 'fc-msg-body' },
2007
+ grouped
2008
+ ? null
2009
+ : h('div', { className: 'fc-msg-head' },
2010
+ author.userName !== ''
2011
+ ? h('button', {
2012
+ type: 'button',
2013
+ className: 'fc-msg-name fc-user-link',
2014
+ onClick: () => { void sharedStore.openUserInfo(author.userName) },
2015
+ }, name)
2016
+ : h('span', { className: 'fc-msg-name' }, name),
2017
+ resolvedMedals.length > 0
2018
+ ? h('span', { className: 'fc-msg-medals' },
2019
+ resolvedMedals.map((medal, index) => h('img', {
2020
+ key: medal.id || medal.name || index,
2021
+ className: 'fc-msg-medal',
2022
+ src: medal.url,
2023
+ alt: medal.name,
2024
+ title: [medal.name, medal.description].filter(Boolean).join(' · '),
2025
+ loading: 'lazy',
2026
+ referrerPolicy: 'no-referrer',
2027
+ onError: event => { event.currentTarget.style.display = 'none' },
2028
+ })),
2029
+ )
2030
+ : null,
2031
+ h('time', { className: 'fc-msg-time', dateTime: new Date(message.createdAt).toISOString() }, clock(message.createdAt)),
2032
+ ),
2033
+ h('div', { className: 'fc-msg-content-row' },
2034
+ h('div', { className: 'fc-msg-content' }, h(MessageContent, { message, mode, t, siteUrl })),
2035
+ actions,
2036
+ ),
2037
+ ),
1836
2038
  ),
1837
2039
  )
1838
2040
  }
@@ -1964,6 +2166,17 @@ window.__ModuleLoader__.load({
1964
2166
  )
1965
2167
  }
1966
2168
 
2169
+ /**
2170
+ * @param {Function} t - bound translate.
2171
+ * @param {object|null|undefined} update - Host update state.
2172
+ * @returns {string} current and npm versions, nothing else.
2173
+ */
2174
+ function updateVersions(t, update) {
2175
+ const current = typeof update?.current === 'string' && update.current !== '' ? update.current : '—'
2176
+ const latest = typeof update?.latest === 'string' && update.latest !== '' ? update.latest : '—'
2177
+ return t('settings.update.versions', { current, latest })
2178
+ }
2179
+
1967
2180
  /**
1968
2181
  * @param {{t: Function}} props - the Settings section page.
1969
2182
  */
@@ -2012,6 +2225,9 @@ window.__ModuleLoader__.load({
2012
2225
  onClick: () => store.clearError(),
2013
2226
  }, '×'),
2014
2227
  ),
2228
+ state.ready && state.hostVersion === ''
2229
+ ? h('div', { className: 'fc-banner', role: 'alert' }, h('span', null, t('host.restart')))
2230
+ : null,
2015
2231
  h('section', { className: 'fc-section' },
2016
2232
  h('h2', { className: 'fc-section-title' }, t('settings.account')),
2017
2233
  h(AccountCard, { t }),
@@ -2053,8 +2269,29 @@ window.__ModuleLoader__.load({
2053
2269
  ? h('p', { className: 'fc-error', role: 'alert' }, supported ? t('settings.notifications.denied') : t('settings.notifications.unsupported'))
2054
2270
  : null,
2055
2271
  ),
2056
- h('p', { className: 'fc-note' }, t('settings.credentialNote')),
2057
- h('p', { className: 'fc-note' }, t('settings.version')),
2272
+ h('section', { className: 'fc-section' },
2273
+ h('div', { className: 'fc-row' },
2274
+ h('div', { className: 'fc-row-body' },
2275
+ h('div', { className: 'fc-row-title' }, t('settings.update')),
2276
+ h('div', { className: 'fc-hint' }, updateVersions(t, state.update)),
2277
+ ),
2278
+ h('button', {
2279
+ type: 'button',
2280
+ className: 'fc-button',
2281
+ disabled: state.checkingUpdate || state.installingUpdate,
2282
+ onClick: () => {
2283
+ if (state.update?.available === true) void store.installUpdate()
2284
+ else void store.checkUpdate()
2285
+ },
2286
+ }, state.installingUpdate
2287
+ ? t('settings.update.installing')
2288
+ : state.checkingUpdate
2289
+ ? t('settings.update.checking')
2290
+ : state.update?.available === true
2291
+ ? t('settings.update.install')
2292
+ : t('settings.update.check')),
2293
+ ),
2294
+ ),
2058
2295
  )
2059
2296
  }
2060
2297
 
@@ -2521,12 +2758,16 @@ window.__ModuleLoader__.load({
2521
2758
  const fileInputRef = useRef(null)
2522
2759
  const stickRef = useRef(true)
2523
2760
  const restoreRef = useRef(null)
2761
+ const recallTimerRef = useRef()
2762
+ const [recallingId, setRecallingId] = useState('')
2524
2763
 
2525
2764
  useEffect(() => {
2526
2765
  store.setChatVisible(visible)
2527
2766
  return () => { store.setChatVisible(false) }
2528
2767
  }, [visible])
2529
2768
 
2769
+ useEffect(() => () => { clearTimeout(recallTimerRef.current) }, [])
2770
+
2530
2771
  useLayoutEffect(() => {
2531
2772
  const element = scrollRef.current
2532
2773
  if (element === null) return
@@ -2716,6 +2957,146 @@ window.__ModuleLoader__.load({
2716
2957
  })
2717
2958
  }
2718
2959
 
2960
+ const insertDraft = text => {
2961
+ const element = textareaRef.current
2962
+ const start = element?.selectionStart ?? draft.length
2963
+ const end = element?.selectionEnd ?? draft.length
2964
+ const next = draft.slice(0, start) + text + draft.slice(end)
2965
+ setDraft(next)
2966
+ requestAnimationFrame(() => {
2967
+ const target = textareaRef.current
2968
+ if (target === null) return
2969
+ target.focus()
2970
+ const position = start + text.length
2971
+ target.setSelectionRange(position, position)
2972
+ updateMention(next, position)
2973
+ })
2974
+ }
2975
+
2976
+ /** @param {object} message - one normalized message. @returns {string} source text for a quote. */
2977
+ const quoteSource = message => {
2978
+ let source = ''
2979
+ if (message.type === 'text') {
2980
+ source = typeof message.content === 'string' ? message.content : ''
2981
+ if (source.trim() === '' && typeof message.contentHtml === 'string') source = plainFromHtml(message.contentHtml)
2982
+ }
2983
+ if (source.trim() === '') source = messageSummary(message, t)
2984
+ source = source.replace(/\r\n/gu, '\n').trimEnd()
2985
+ return source.length > 1000 ? `${source.slice(0, 1000)}…` : source
2986
+ }
2987
+
2988
+ /** @param {object} message - one normalized message. */
2989
+ const quoteMessage = message => {
2990
+ const source = quoteSource(message)
2991
+ if (source === '') return
2992
+ const author = message.author?.userName ?? ''
2993
+ const site = state.siteUrl.replace(/\/+$/u, '')
2994
+ const link = `${site}/cr#chatroom${message.id}`
2995
+ const attribution = author !== ''
2996
+ ? `##### 引用 @${author} [↩](${link} "跳转至原消息")`
2997
+ : `##### 引用 [↩](${link} "跳转至原消息")`
2998
+ const quoted = source.split('\n').map(line => `> ${line}`).join('\n')
2999
+ const base = draft.trim() === '' ? '' : `${draft.replace(/\s+$/u, '')}\n\n`
3000
+ setDraft(`${base}${attribution} \n${quoted}\n`)
3001
+ closeMention()
3002
+ requestAnimationFrame(() => {
3003
+ const element = textareaRef.current
3004
+ if (element === null) return
3005
+ element.focus()
3006
+ const position = element.value.length
3007
+ element.setSelectionRange(position, position)
3008
+ })
3009
+ }
3010
+
3011
+ /** @param {object} message - one normalized message. */
3012
+ const mentionAuthor = message => {
3013
+ const userName = message.author?.userName ?? ''
3014
+ if (userName !== '') insertDraft(`@${userName} `)
3015
+ }
3016
+
3017
+ /** @param {object} message - one normalized text message. */
3018
+ const repeatMessage = message => {
3019
+ if (state.sending) return
3020
+ const content = typeof message.content === 'string' ? message.content : ''
3021
+ if (message.type !== 'text' || content.trim() === '') return
3022
+ void store.send(content)
3023
+ }
3024
+
3025
+ /** @param {object} message - one normalized message. */
3026
+ const requestRecall = message => {
3027
+ if (state.recalling) return
3028
+ if (recallingId !== message.id) {
3029
+ clearTimeout(recallTimerRef.current)
3030
+ setRecallingId(message.id)
3031
+ recallTimerRef.current = window.setTimeout(() => setRecallingId(''), 4000)
3032
+ return
3033
+ }
3034
+ clearTimeout(recallTimerRef.current)
3035
+ recallTimerRef.current = undefined
3036
+ setRecallingId('')
3037
+ void store.recall(message.id)
3038
+ }
3039
+
3040
+ /** @param {object} message - one normalized message. @returns {object|null} its hover actions. */
3041
+ const messageActions = message => {
3042
+ if (message.type === 'system') return null
3043
+ const author = message.author ?? {}
3044
+ const own = author.id !== undefined && author.id !== '' && author.id === state.user?.id
3045
+ const canQuote = quoteSource(message) !== ''
3046
+ const canModerate = state.user?.capabilities?.chatRevokeOthers === true
3047
+ const canRecall = state.hostVersion !== ''
3048
+ && (own || canModerate)
3049
+ && message.type !== 'redPacket'
3050
+ && /^\d+$/u.test(message.id)
3051
+ const canMention = typeof author.userName === 'string' && author.userName !== '' && !own
3052
+ const canRepeat = message.type === 'text' && typeof message.content === 'string' && message.content.trim() !== ''
3053
+ if (!canQuote && !canRecall && !canMention && !canRepeat) return null
3054
+ const pending = recallingId === message.id
3055
+ return h('div', { className: 'fc-msg-actions', role: 'toolbar', 'aria-label': t('message.actions') },
3056
+ canQuote
3057
+ ? h('button', {
3058
+ type: 'button',
3059
+ className: 'fc-msg-action',
3060
+ title: t('message.quote'),
3061
+ 'aria-label': t('message.quote'),
3062
+ onClick: () => quoteMessage(message),
3063
+ }, t('message.quoteShort'))
3064
+ : null,
3065
+ canRecall
3066
+ ? h('button', {
3067
+ type: 'button',
3068
+ className: `fc-msg-action fc-msg-action-danger${pending ? ' fc-msg-action-pending' : ''}`,
3069
+ disabled: state.recalling,
3070
+ title: pending
3071
+ ? t('message.recallConfirm')
3072
+ : (own ? t('message.recall') : t('message.recallModerate')),
3073
+ 'aria-label': pending
3074
+ ? t('message.recallConfirm')
3075
+ : (own ? t('message.recall') : t('message.recallModerate')),
3076
+ onClick: () => requestRecall(message),
3077
+ }, pending ? t('message.recallConfirmShort') : t('message.recallShort'))
3078
+ : null,
3079
+ canMention
3080
+ ? h('button', {
3081
+ type: 'button',
3082
+ className: 'fc-msg-action',
3083
+ title: t('message.mention'),
3084
+ 'aria-label': t('message.mention'),
3085
+ onClick: () => mentionAuthor(message),
3086
+ }, t('message.mentionShort'))
3087
+ : null,
3088
+ canRepeat
3089
+ ? h('button', {
3090
+ type: 'button',
3091
+ className: 'fc-msg-action',
3092
+ title: t('message.repeat'),
3093
+ 'aria-label': t('message.repeat'),
3094
+ onClick: () => repeatMessage(message),
3095
+ }, t('message.repeatShort'))
3096
+ : null,
3097
+ )
3098
+ }
3099
+
2719
3100
  const retry = async () => {
2720
3101
  store.clearError()
2721
3102
  await store.syncAll()
@@ -2768,6 +3149,10 @@ window.__ModuleLoader__.load({
2768
3149
  }, '×'),
2769
3150
  )
2770
3151
 
3152
+ const hostBanner = state.ready && state.hostVersion === ''
3153
+ ? h('div', { className: 'fc-banner', role: 'alert' }, h('span', null, t('host.restart')))
3154
+ : null
3155
+
2771
3156
  if (!state.loaded) {
2772
3157
  return h('div', { className: 'fc-root' },
2773
3158
  h(Style), header, h('div', { className: 'fc-empty' }, t('loading')),
@@ -2779,6 +3164,7 @@ window.__ModuleLoader__.load({
2779
3164
  h(Style),
2780
3165
  header,
2781
3166
  errorBanner,
3167
+ hostBanner,
2782
3168
  h('div', { className: 'fc-login-wrap' },
2783
3169
  h('div', { className: 'fc-login-title' }, t('login.title')),
2784
3170
  h(LoginForm, { t, compact: true }),
@@ -2788,31 +3174,73 @@ window.__ModuleLoader__.load({
2788
3174
  )
2789
3175
  }
2790
3176
 
3177
+ // Fold a run of identical text messages into a stack of whole message
3178
+ // cards: each card keeps its own avatar/name header and body, and every
3179
+ // later card overlaps the previous one. The stack lives only in this
3180
+ // render; nothing is persisted or sent.
3181
+ const runs = []
3182
+ let last = null
3183
+ for (const message of state.messages) {
3184
+ const repeat = message.type === 'text'
3185
+ && typeof message.content === 'string'
3186
+ && message.content.trim() !== ''
3187
+ && last !== null
3188
+ && last.type === 'text'
3189
+ && typeof last.content === 'string'
3190
+ && last.content === message.content
3191
+ && dayKey(last.createdAt) === dayKey(message.createdAt)
3192
+ if (repeat && runs.length > 0) runs[runs.length - 1].push(message)
3193
+ else runs.push([message])
3194
+ last = message
3195
+ }
3196
+ const display = runs.map(run => ({
3197
+ message: run[0],
3198
+ stack: { count: run.length, messages: run },
3199
+ }))
3200
+
2791
3201
  let previous = null
2792
3202
  const rows = []
2793
- for (const message of state.messages) {
3203
+ for (const entry of display) {
3204
+ const message = entry.message
2794
3205
  const authorId = message.author?.id ?? ''
2795
3206
  const authorName = message.author?.userName ?? ''
2796
- const dateChanged = previous === null || dayKey(message.createdAt) !== dayKey(previous.createdAt)
3207
+ const dateChanged = previous === null || dayKey(message.createdAt) !== dayKey(previous.message.createdAt)
2797
3208
  if (dateChanged) rows.push(h('div', { className: 'fc-day', key: `day-${message.id}` }, dayLabel(message.createdAt, t)))
2798
- const grouped = !dateChanged
3209
+ const stacked = entry.stack.messages.length > 1
3210
+ const front = entry.stack.messages[entry.stack.messages.length - 1] ?? message
3211
+ const grouped = !stacked
3212
+ && !dateChanged
2799
3213
  && previous !== null
3214
+ && previous.stack.count === 1
2800
3215
  && message.type === 'text'
2801
- && previous.type === 'text'
3216
+ && previous.message.type === 'text'
2802
3217
  && authorId !== ''
2803
- && authorId === (previous.author?.id ?? '')
2804
- && message.createdAt - previous.createdAt < 5 * 60 * 1000
2805
- rows.push(h(MessageRow, {
2806
- key: message.id,
2807
- message,
2808
- own: authorId !== '' && authorId === state.user?.id,
2809
- grouped,
2810
- mode,
2811
- t,
2812
- siteUrl: state.siteUrl,
2813
- medalIcons: authorName !== '' ? state.medalIcons[authorName] ?? [] : [],
2814
- }))
2815
- previous = message
3218
+ && authorId === (previous.message.author?.id ?? '')
3219
+ && message.createdAt - previous.message.createdAt < 5 * 60 * 1000
3220
+ if (stacked) {
3221
+ rows.push(h(MessageStack, {
3222
+ key: message.id,
3223
+ messages: entry.stack.messages,
3224
+ mode,
3225
+ t,
3226
+ siteUrl: state.siteUrl,
3227
+ medalIcons: state.medalIcons,
3228
+ actions: messageActions(front),
3229
+ }))
3230
+ } else {
3231
+ rows.push(h(MessageRow, {
3232
+ key: message.id,
3233
+ message,
3234
+ own: authorId !== '' && authorId === state.user?.id,
3235
+ grouped,
3236
+ mode,
3237
+ t,
3238
+ siteUrl: state.siteUrl,
3239
+ medalIcons: authorName !== '' ? state.medalIcons[authorName] ?? [] : [],
3240
+ actions: messageActions(message),
3241
+ }))
3242
+ }
3243
+ previous = entry
2816
3244
  }
2817
3245
 
2818
3246
  const body = state.loadingMessages && state.messages.length === 0
@@ -2835,6 +3263,7 @@ window.__ModuleLoader__.load({
2835
3263
  h(Style),
2836
3264
  header,
2837
3265
  errorBanner,
3266
+ hostBanner,
2838
3267
  body,
2839
3268
  state.messages.length > 0 && !atBottom
2840
3269
  ? h('button', {
@@ -3059,13 +3488,96 @@ window.__ModuleLoader__.load({
3059
3488
  overscroll-behavior: contain;
3060
3489
  }
3061
3490
  .fc-day { margin: 10px 0 6px; color: var(--dsw-alias-label-tertiary); font-size: 11px; text-align: center; }
3062
- .fc-msg { display: flex; gap: 8px; margin-top: 10px; }
3063
- .fc-msg.fc-grouped { margin-top: 3px; }
3491
+ .fc-msg-line { position: relative; margin-top: 10px; }
3492
+ .fc-msg-line.fc-grouped { margin-top: 3px; }
3493
+ .fc-msg { display: flex; gap: 8px; }
3494
+ .fc-msg-actions {
3495
+ flex: none;
3496
+ display: flex;
3497
+ gap: 2px;
3498
+ align-self: flex-start;
3499
+ padding: 2px;
3500
+ border: 1px solid var(--dsw-alias-border-l2);
3501
+ border-radius: var(--dsw-radius-md);
3502
+ background: var(--dsw-alias-bg-layer-2);
3503
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
3504
+ opacity: 0;
3505
+ pointer-events: none;
3506
+ transition: opacity 120ms ease;
3507
+ }
3508
+ .fc-msg-body:hover .fc-msg-actions,
3509
+ .fc-msg-body:focus-within .fc-msg-actions {
3510
+ opacity: 1;
3511
+ pointer-events: auto;
3512
+ }
3513
+ .fc-msg-action {
3514
+ width: auto;
3515
+ min-width: 20px;
3516
+ height: 20px;
3517
+ padding: 0 3px;
3518
+ border: 0;
3519
+ border-radius: 4px;
3520
+ background: transparent;
3521
+ color: var(--dsw-alias-label-tertiary);
3522
+ font: inherit;
3523
+ font-size: 11px;
3524
+ line-height: 20px;
3525
+ text-align: center;
3526
+ cursor: pointer;
3527
+ }
3528
+ .fc-msg-action:hover:not(:disabled) {
3529
+ background: var(--dsw-alias-interactive-bg-hover);
3530
+ color: var(--dsw-alias-label-primary);
3531
+ }
3532
+ .fc-msg-action:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 1px; }
3533
+ .fc-msg-action:disabled { opacity: 0.45; cursor: default; }
3534
+ .fc-msg-action-danger { color: var(--dsw-alias-state-error-primary); }
3535
+ .fc-msg-action-pending {
3536
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 18%, transparent);
3537
+ color: var(--dsw-alias-state-error-primary);
3538
+ }
3539
+ .fc-msg-content-row {
3540
+ position: relative;
3541
+ display: inline-flex;
3542
+ align-items: flex-start;
3543
+ gap: 4px;
3544
+ max-width: 100%;
3545
+ vertical-align: top;
3546
+ }
3547
+ .fc-msg-content-row .fc-msg-content { flex: 1 1 auto; }
3548
+ .fc-msg-stack-row { margin-top: 10px; }
3549
+ .fc-msg-stack {
3550
+ position: relative;
3551
+ display: inline-block;
3552
+ max-width: 100%;
3553
+ vertical-align: top;
3554
+ }
3555
+ .fc-stack-card {
3556
+ position: absolute;
3557
+ left: 0;
3558
+ right: 0;
3559
+ box-sizing: border-box;
3560
+ padding: 4px 8px;
3561
+ border: 1px solid var(--dsw-alias-border-l2);
3562
+ border-radius: var(--dsw-radius-md);
3563
+ background: var(--dsw-alias-bg-layer-2);
3564
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
3565
+ overflow: hidden;
3566
+ }
3567
+ .fc-stack-card-front { position: relative; }
3568
+ .fc-stack-card .fc-msg-line { margin-top: 0; }
3569
+ .fc-stack-card .fc-msg-body { padding-top: 5px; }
3570
+ .fc-stack-card-front:hover .fc-msg-actions,
3571
+ .fc-stack-card-front:focus-within .fc-msg-actions {
3572
+ opacity: 1;
3573
+ pointer-events: auto;
3574
+ }
3064
3575
  .fc-msg.fc-own { flex-direction: row-reverse; }
3065
3576
  .fc-msg.fc-own .fc-msg-body { display: flex; flex-direction: column; align-items: flex-end; }
3066
3577
  .fc-msg.fc-own .fc-msg-head { flex-direction: row-reverse; }
3067
3578
  .fc-msg.fc-own .fc-msg-content { max-width: 100%; text-align: left; }
3068
3579
  .fc-msg.fc-own .fc-msg-name { color: var(--dsw-alias-brand-text); }
3580
+ .fc-msg.fc-own .fc-msg-content-row { flex-direction: row-reverse; }
3069
3581
  .fc-avatar { flex: none; border-radius: 50%; object-fit: cover; background: var(--dsw-alias-bg-layer-2); }
3070
3582
  .fc-avatar-button {
3071
3583
  display: inline-flex;
@@ -3086,7 +3598,7 @@ window.__ModuleLoader__.load({
3086
3598
  color: var(--dsw-alias-label-secondary);
3087
3599
  font-weight: 500;
3088
3600
  }
3089
- .fc-msg-body { min-width: 0; flex: 1; }
3601
+ .fc-msg-body { position: relative; min-width: 0; flex: 0 1 auto; max-width: 100%; }
3090
3602
  .fc-msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
3091
3603
  .fc-msg-name { overflow: hidden; font-size: 12px; font-weight: 500; color: var(--dsw-alias-label-secondary); text-overflow: ellipsis; white-space: nowrap; }
3092
3604
  .fc-user-link {