@iwpz/fishpi-dsh 0.0.0-stage → 0.1.1
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 +165 -2
- package/client.js +3614 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +36 -0
- package/docs/screenshot.jpg +0 -0
- package/fishpi.js +706 -0
- package/icon.svg +4 -0
- package/icon.webp +0 -0
- package/index.js +990 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +47 -4
package/client.js
ADDED
|
@@ -0,0 +1,3614 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of the FishPi chat plugin.
|
|
3
|
+
*
|
|
4
|
+
* Registers:
|
|
5
|
+
* - a right-Sidebar tab type (`fishpi.chat`) with a guide entry and a live tab title;
|
|
6
|
+
* - a chat button in the Session header's utilities;
|
|
7
|
+
* - a Settings section (`settings.section`) with account login and display preferences.
|
|
8
|
+
*
|
|
9
|
+
* All FishPi traffic goes through the Host routes under `api/fishpi/*`, so the
|
|
10
|
+
* page never contacts fishpi.cn and never holds the password or token.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
window.__ModuleLoader__.load({
|
|
14
|
+
id: '@iwpz/fishpi-dsh',
|
|
15
|
+
factory(require) {
|
|
16
|
+
const React = require('react')
|
|
17
|
+
const h = React.createElement
|
|
18
|
+
const {
|
|
19
|
+
useCallback,
|
|
20
|
+
useEffect,
|
|
21
|
+
useLayoutEffect,
|
|
22
|
+
useRef,
|
|
23
|
+
useState,
|
|
24
|
+
useSyncExternalStore,
|
|
25
|
+
} = React
|
|
26
|
+
|
|
27
|
+
/** Right-Sidebar tab kind; opened by the guide entry and the header button. */
|
|
28
|
+
const TAB_KIND = 'fishpi.chat'
|
|
29
|
+
/** Tab implementation identity: the key its body, title, and definition share. */
|
|
30
|
+
const TAB_ID = '@iwpz/fishpi-dsh'
|
|
31
|
+
/** Client locale namespace. */
|
|
32
|
+
const NS = 'fishpiChat'
|
|
33
|
+
/** Host route prefix, document-relative so deployments under a path prefix work. */
|
|
34
|
+
const API = 'api/fishpi'
|
|
35
|
+
/** Local preference document. */
|
|
36
|
+
const PREFS_KEY = 'fishpi-chat.prefs.v1'
|
|
37
|
+
/** FishPi registration page, returning to the chatroom after sign-up. */
|
|
38
|
+
const REGISTER_URL = 'https://fishpi.cn/register?goto=https%3A%2F%2Ffishpi.cn%2Fcr'
|
|
39
|
+
/** Message window size used by the initial load and by sync/reconnect. */
|
|
40
|
+
const WINDOW_SIZE = 30
|
|
41
|
+
/** A longer server-published topic or message is clipped for display. */
|
|
42
|
+
const MAX_TOPIC = 160
|
|
43
|
+
/** Retained messages before the oldest is dropped from the live window. */
|
|
44
|
+
const MAX_RETAINED = 400
|
|
45
|
+
/**
|
|
46
|
+
* The FishPi home logo animation (`#logo-animate`, a three-image Lottie
|
|
47
|
+
* composition). Its asset bytes and keyframes are embedded so the icons
|
|
48
|
+
* animate offline with no player dependency.
|
|
49
|
+
*/
|
|
50
|
+
const LOGO_ANIMATION = {"v":"5.12.2","fr":25,"ip":0,"op":75,"w":800,"h":800,"nm":"fishpi","ddd":0,"assets":[{"id":"image_0","w":200,"h":200,"u":"","p":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAJHpUWHRDcmVhdG9yAAAImXNMyU9KVXBMK0ktUnBNS0tNLikGAEF6Bs5qehXFAAAACXBIWXMAAAABAAAAAQBPJcTWAAAAM1BMVEVHcEwFAAAEAAAEAAAAAAAEAAACAAAAAAAEAAADAAAEAAAEAAAEAAADAAADAAADAAAEAAAqwPqLAAAAEHRSTlMAJTdqDM4XA/TjprqBlFdHOxCbzwAABtBJREFUeNrtXdmO4zgMjKzbtqz8/9cu6e7J+ijFXmABUwPWcxoIWzyqSEp5vRQKhUKhUCgUCoVCoVAoFAqFQqFQKBT/L+KKv8AQ50IILvZ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lGazE2gx6OPEM3Qp/ePzgM5yJEXnIKDZarWWvw+UOA/soodh7GQJW9JfodfDXwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUk/8DeM14cNwg/IoAAAAASUVORK5CYII=","e":1}],"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"cat_l.png","cl":"png","refId":"image_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":33,"s":[-8]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":37,"s":[8.167]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":44,"s":[-25.342]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":57,"s":[-44]},{"t":68,"s":[-21]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":33,"s":[578,228,0],"to":[10.333,6,0],"ti":[27.667,3.333,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":37,"s":[640,264,0],"to":[-11.813,-1.423,0],"ti":[42.984,10.685,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":44,"s":[634.737,265.568,0],"to":[-57.683,-14.339,0],"ti":[12.033,3.438,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":57,"s":[412,208,0],"to":[-21,-6,0],"ti":[-18.333,-1.5,0]},{"t":68,"s":[522,217,0]}],"ix":2,"l":2},"a":{"a":0,"k":[100,100,0],"ix":1,"l":2},"s":{"a":1,"k":[{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"t":33,"s":[33,33,100]},{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"t":37,"s":[56,56,100]},{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"t":44,"s":[44,44,100]},{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"t":57,"s":[32.042,32.042,100]},{"t":68,"s":[57,57,100]}],"ix":6,"l":2}},"ao":0,"ip":33,"op":108,"st":33,"bm":0},{"ddd":0,"ind":2,"ty":2,"nm":"cat.png","cl":"png","refId":"image_1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":20,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":26,"s":[9]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":44,"s":[9.201]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":57,"s":[-13.043]},{"t":69,"s":[4]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":20,"s":[390,227,0],"to":[0,0,0],"ti":[2,-5,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":26,"s":[390,266,0],"to":[-0.444,1.11,0],"ti":[0.904,-2.26,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":44,"s":[477.912,319.219,0],"to":[-1.63,4.075,0],"ti":[25.061,7.513,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":57,"s":[267.235,304.488,0],"to":[-23.651,-7.09,0],"ti":[0.755,-1.889,0]},{"t":69,"s":[378,296,0]}],"ix":2,"l":2},"a":{"a":0,"k":[400,400,0],"ix":1,"l":2},"s":{"a":1,"k":[{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"t":20,"s":[6.5,6.5,100]},{"t":26,"s":[65.5,65.5,100]}],"ix":6,"l":2}},"ao":0,"ip":20,"op":95,"st":20,"bm":0},{"ddd":0,"ind":3,"ty":2,"nm":"fish.png","cl":"png","refId":"image_2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":12,"s":[-23]},{"t":28,"s":[0]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":0,"s":[402,1198,0],"to":[-1,-163.667,0],"ti":[0.333,133,0]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":12,"s":[396,216,0],"to":[-0.333,-133,0],"ti":[-0.667,-30.667,0]},{"t":26,"s":[400,400,0]}],"ix":2,"l":2},"a":{"a":0,"k":[400,400,0],"ix":1,"l":2},"s":{"a":0,"k":[80,80,100],"ix":6,"l":2}},"ao":0,"ip":0,"op":75,"st":0,"bm":0}],"markers":[],"props":{}}
|
|
51
|
+
|
|
52
|
+
const zh = {
|
|
53
|
+
nav: '摸鱼派',
|
|
54
|
+
tabTitle: '摸鱼派',
|
|
55
|
+
open: '打开摸鱼派聊天室',
|
|
56
|
+
'guide.title': '摸鱼派聊天室',
|
|
57
|
+
'guide.description': '在右侧边栏收发摸鱼派聊天室消息',
|
|
58
|
+
'day.today': '今天',
|
|
59
|
+
'day.yesterday': '昨天',
|
|
60
|
+
'status.connected': '已连接',
|
|
61
|
+
'status.connecting': '连接中',
|
|
62
|
+
'status.disconnected': '未连接',
|
|
63
|
+
online: '在线 {count}',
|
|
64
|
+
topic: '话题',
|
|
65
|
+
refresh: '刷新',
|
|
66
|
+
'loadOlder': '加载更早的消息',
|
|
67
|
+
loading: '加载中…',
|
|
68
|
+
empty: '还没有消息,来打个招呼吧',
|
|
69
|
+
'login.title': '登录摸鱼派',
|
|
70
|
+
'login.account': '账号或邮箱',
|
|
71
|
+
'login.password': '密码',
|
|
72
|
+
'login.mfa': '两步验证码(选填)',
|
|
73
|
+
'login.remember': '记住密码(仅保存 MD5 摘要)',
|
|
74
|
+
'login.submit': '登录',
|
|
75
|
+
'login.busy': '登录中…',
|
|
76
|
+
'login.hint': '账号凭据保存在本机 DSH 凭据库,不会写进配置文件。',
|
|
77
|
+
'login.register': '去注册',
|
|
78
|
+
'login.needMfa': '该账号启用了两步验证,请输入验证码后重试。',
|
|
79
|
+
logout: '退出登录',
|
|
80
|
+
'settings.title': '摸鱼派聊天室',
|
|
81
|
+
'settings.account': '账号',
|
|
82
|
+
'settings.loggedInAs': '已登录',
|
|
83
|
+
'settings.display': '消息显示',
|
|
84
|
+
'settings.display.hint': '富文本会渲染 Markdown、图片和链接;纯文本只显示文字内容。',
|
|
85
|
+
'settings.display.rich': '富文本',
|
|
86
|
+
'settings.display.plain': '纯文本',
|
|
87
|
+
'settings.notifications': '桌面通知',
|
|
88
|
+
'settings.notifications.hint': '当聊天室不在前台时,用系统通知提醒新消息。',
|
|
89
|
+
'settings.notifications.denied': '浏览器拒绝了通知权限。',
|
|
90
|
+
'settings.notifications.unsupported': '当前环境不支持系统通知。',
|
|
91
|
+
'error.crash': '聊天室渲染失败',
|
|
92
|
+
'settings.credentialNote': '登录凭据保存在本机 DSH 凭据库。勾选“记住密码”时保存密码的 MD5 摘要,用于访问令牌过期后自动重新登录;开启两步验证的账号仍需手动输入验证码。',
|
|
93
|
+
'settings.version': '插件版本 0.1.0',
|
|
94
|
+
'composer.placeholder': '说点什么…',
|
|
95
|
+
'composer.addImage': '添加图片',
|
|
96
|
+
'composer.uploading': '正在上传图片…',
|
|
97
|
+
'mention.title': '提及用户',
|
|
98
|
+
'mention.hint': '继续输入用户名进行搜索',
|
|
99
|
+
'mention.empty': '没有匹配的用户',
|
|
100
|
+
'composer.label': '消息输入框',
|
|
101
|
+
messages: '聊天室消息',
|
|
102
|
+
jump: '跳到最新消息',
|
|
103
|
+
'plain.image': '图片',
|
|
104
|
+
'redPacket.title': '红包',
|
|
105
|
+
'redPacket.type.random': '拼手气红包',
|
|
106
|
+
'redPacket.type.average': '普通红包',
|
|
107
|
+
'redPacket.type.specify': '专属红包',
|
|
108
|
+
'redPacket.type.heartbeat': '心跳红包',
|
|
109
|
+
'redPacket.type.rockPaperScissors': '猜拳红包',
|
|
110
|
+
'redPacket.from': '来自 {name}',
|
|
111
|
+
'redPacket.progress': '{got}/{count} 已领取',
|
|
112
|
+
'redPacket.pool': '奖池 {points} 积分',
|
|
113
|
+
'redPacket.claims': '领取明细',
|
|
114
|
+
'redPacket.noClaims': '还没有人领取',
|
|
115
|
+
'redPacket.claim': '抢红包',
|
|
116
|
+
'redPacket.claiming': '领取中…',
|
|
117
|
+
'redPacket.finished': '红包已领完',
|
|
118
|
+
'redPacket.legacy': '旧红包仅可查看领取记录,暂不支持在这里领取。',
|
|
119
|
+
'redPacket.riskHeartbeat': '心跳红包可能领到负积分,领取前请确认积分余额充足。',
|
|
120
|
+
'redPacket.riskRps': '猜拳红包可能扣除积分。请选择出拳并确认风险。',
|
|
121
|
+
'redPacket.riskAccept': '我已知晓可能扣除积分',
|
|
122
|
+
'redPacket.gesture': '出拳',
|
|
123
|
+
'redPacket.rock': '石头',
|
|
124
|
+
'redPacket.scissors': '剪刀',
|
|
125
|
+
'redPacket.paper': '布',
|
|
126
|
+
'redPacket.shortRock': '石',
|
|
127
|
+
'redPacket.shortScissors': '剪',
|
|
128
|
+
'redPacket.shortPaper': '布',
|
|
129
|
+
'redPacket.close': '关闭',
|
|
130
|
+
'redPacket.retry': '重试',
|
|
131
|
+
'redPacket.own': '这是你发出的红包。',
|
|
132
|
+
'redPacket.confirm': '确认领取',
|
|
133
|
+
'redPacket.confirmRisk': '确认领取(可能扣除积分)',
|
|
134
|
+
'redPacket.cardClaimed': '已领取',
|
|
135
|
+
'redPacket.cardFinished': '已抢完',
|
|
136
|
+
'user.title': '用户资料',
|
|
137
|
+
'user.medals': '勋章',
|
|
138
|
+
'user.points': '积分 {points}',
|
|
139
|
+
'user.online': '累计在线 {minutes} 分钟',
|
|
140
|
+
'user.number': '编号 {number}',
|
|
141
|
+
'user.location': '位置 {city}',
|
|
142
|
+
'user.home': '主页',
|
|
143
|
+
'user.profileLink': '个人链接',
|
|
144
|
+
'user.loadFailed': '用户资料加载失败',
|
|
145
|
+
'user.close': '关闭',
|
|
146
|
+
'redPacket.outcome.win': '赢',
|
|
147
|
+
'redPacket.outcome.lose': '输',
|
|
148
|
+
'redPacket.outcome.tie': '平局',
|
|
149
|
+
|
|
150
|
+
'composer.send': '发送',
|
|
151
|
+
'composer.sending': '发送中…',
|
|
152
|
+
'error.network': '网络连接失败,请稍后重试。',
|
|
153
|
+
'error.unauthorized': '登录已失效,请重新登录。',
|
|
154
|
+
'error.credentials': '账号或密码错误。',
|
|
155
|
+
'error.mfa': '需要两步验证码。',
|
|
156
|
+
'error.captcha': '需要人机验证,请先在摸鱼派网页完成验证。',
|
|
157
|
+
'error.forbidden': '当前账号没有权限(可能需要绑定手机)。',
|
|
158
|
+
'error.points': '积分不足。',
|
|
159
|
+
'error.rate': '操作过于频繁,请稍后再试。',
|
|
160
|
+
'error.server': '摸鱼派服务暂时不可用。',
|
|
161
|
+
'error.upload': '图片上传失败,请稍后重试。',
|
|
162
|
+
'error.generic': '操作失败,请稍后重试。',
|
|
163
|
+
'error.dismiss': '关闭',
|
|
164
|
+
'card.redPacket': '红包',
|
|
165
|
+
'card.redPacketMeta': '金额 {money} · {got}/{count} 已领取',
|
|
166
|
+
'card.music': '音乐',
|
|
167
|
+
'card.weather': '天气',
|
|
168
|
+
'card.unavailable': '这条消息暂不可读',
|
|
169
|
+
'system.join': '{name} 加入了聊天室',
|
|
170
|
+
'system.leave': '{name} 离开了聊天室',
|
|
171
|
+
'notify.title': '{name} · 摸鱼派',
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const en = {
|
|
175
|
+
nav: 'FishPi',
|
|
176
|
+
tabTitle: 'FishPi',
|
|
177
|
+
open: 'Open the FishPi chatroom',
|
|
178
|
+
'guide.title': 'FishPi chatroom',
|
|
179
|
+
'guide.description': 'Read and send FishPi chatroom messages in the right Sidebar',
|
|
180
|
+
'day.today': 'Today',
|
|
181
|
+
'day.yesterday': 'Yesterday',
|
|
182
|
+
'status.connected': 'Connected',
|
|
183
|
+
'status.connecting': 'Connecting',
|
|
184
|
+
'status.disconnected': 'Offline',
|
|
185
|
+
online: '{count} online',
|
|
186
|
+
topic: 'Topic',
|
|
187
|
+
refresh: 'Refresh',
|
|
188
|
+
'loadOlder': 'Load earlier messages',
|
|
189
|
+
loading: 'Loading…',
|
|
190
|
+
empty: 'No messages yet. Say hello!',
|
|
191
|
+
'login.title': 'Sign in to FishPi',
|
|
192
|
+
'login.account': 'Username or email',
|
|
193
|
+
'login.password': 'Password',
|
|
194
|
+
'login.mfa': 'Two-step code (optional)',
|
|
195
|
+
'login.remember': 'Remember password (MD5 digest only)',
|
|
196
|
+
'login.submit': 'Sign in',
|
|
197
|
+
'login.busy': 'Signing in…',
|
|
198
|
+
'login.hint': 'Credentials stay in the local DSH credential store and never enter configuration.',
|
|
199
|
+
'login.register': 'Create account',
|
|
200
|
+
'login.needMfa': 'This account uses two-step verification. Enter the code and try again.',
|
|
201
|
+
logout: 'Sign out',
|
|
202
|
+
'settings.title': 'FishPi chatroom',
|
|
203
|
+
'settings.account': 'Account',
|
|
204
|
+
'settings.loggedInAs': 'Signed in',
|
|
205
|
+
'settings.display': 'Message display',
|
|
206
|
+
'settings.display.hint': 'Rich text renders Markdown, images, and links; plain text shows the text only.',
|
|
207
|
+
'settings.display.rich': 'Rich text',
|
|
208
|
+
'settings.display.plain': 'Plain text',
|
|
209
|
+
'settings.notifications': 'Desktop notifications',
|
|
210
|
+
'settings.notifications.hint': 'Notify through the system when the chatroom is not in front.',
|
|
211
|
+
'settings.notifications.denied': 'The browser denied notification permission.',
|
|
212
|
+
'settings.notifications.unsupported': 'System notifications are unavailable here.',
|
|
213
|
+
'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',
|
|
216
|
+
'composer.placeholder': 'Say something…',
|
|
217
|
+
'composer.addImage': 'Add images',
|
|
218
|
+
'composer.uploading': 'Uploading images…',
|
|
219
|
+
'mention.title': 'Mention a user',
|
|
220
|
+
'mention.hint': 'Keep typing a username to search',
|
|
221
|
+
'mention.empty': 'No matching users',
|
|
222
|
+
'composer.label': 'Message input',
|
|
223
|
+
messages: 'Chat messages',
|
|
224
|
+
jump: 'Jump to latest',
|
|
225
|
+
'plain.image': 'Image',
|
|
226
|
+
'redPacket.title': 'Red packet',
|
|
227
|
+
'redPacket.type.random': 'Random red packet',
|
|
228
|
+
'redPacket.type.average': 'Standard red packet',
|
|
229
|
+
'redPacket.type.specify': 'Dedicated red packet',
|
|
230
|
+
'redPacket.type.heartbeat': 'Heartbeat red packet',
|
|
231
|
+
'redPacket.type.rockPaperScissors': 'Rock-paper-scissors red packet',
|
|
232
|
+
'redPacket.from': 'From {name}',
|
|
233
|
+
'redPacket.progress': '{got}/{count} claimed',
|
|
234
|
+
'redPacket.pool': 'Pool {points} points',
|
|
235
|
+
'redPacket.claims': 'Claims',
|
|
236
|
+
'redPacket.noClaims': 'No claims yet',
|
|
237
|
+
'redPacket.claim': 'Claim',
|
|
238
|
+
'redPacket.claiming': 'Claiming…',
|
|
239
|
+
'redPacket.finished': 'All claims are gone',
|
|
240
|
+
'redPacket.legacy': 'This legacy red packet is view-only here.',
|
|
241
|
+
'redPacket.riskHeartbeat': 'A heartbeat red packet can award negative points. Check your balance before claiming.',
|
|
242
|
+
'redPacket.riskRps': 'A rock-paper-scissors red packet can cost points. Pick a gesture and accept the risk.',
|
|
243
|
+
'redPacket.riskAccept': 'I understand this may cost points',
|
|
244
|
+
'redPacket.gesture': 'Gesture',
|
|
245
|
+
'redPacket.rock': 'Rock',
|
|
246
|
+
'redPacket.scissors': 'Scissors',
|
|
247
|
+
'redPacket.paper': 'Paper',
|
|
248
|
+
'redPacket.shortRock': 'R',
|
|
249
|
+
'redPacket.shortScissors': 'S',
|
|
250
|
+
'redPacket.shortPaper': 'P',
|
|
251
|
+
'redPacket.close': 'Close',
|
|
252
|
+
'redPacket.retry': 'Retry',
|
|
253
|
+
'redPacket.own': 'You sent this red packet.',
|
|
254
|
+
'redPacket.confirm': 'Confirm claim',
|
|
255
|
+
'redPacket.confirmRisk': 'Confirm claim (may cost points)',
|
|
256
|
+
'redPacket.cardClaimed': 'Claimed',
|
|
257
|
+
'redPacket.cardFinished': 'All claimed',
|
|
258
|
+
'user.title': 'User profile',
|
|
259
|
+
'user.medals': 'Medals',
|
|
260
|
+
'user.points': '{points} points',
|
|
261
|
+
'user.online': '{minutes} minutes online',
|
|
262
|
+
'user.number': 'No. {number}',
|
|
263
|
+
'user.location': 'Location {city}',
|
|
264
|
+
'user.home': 'Home',
|
|
265
|
+
'user.profileLink': 'Website',
|
|
266
|
+
'user.loadFailed': 'Could not load the profile',
|
|
267
|
+
'user.close': 'Close',
|
|
268
|
+
'redPacket.outcome.win': 'Win',
|
|
269
|
+
'redPacket.outcome.lose': 'Lose',
|
|
270
|
+
'redPacket.outcome.tie': 'Tie',
|
|
271
|
+
|
|
272
|
+
'composer.send': 'Send',
|
|
273
|
+
'composer.sending': 'Sending…',
|
|
274
|
+
'error.network': 'Network request failed. Try again.',
|
|
275
|
+
'error.unauthorized': 'The session expired. Sign in again.',
|
|
276
|
+
'error.credentials': 'Wrong username or password.',
|
|
277
|
+
'error.mfa': 'A two-step code is required.',
|
|
278
|
+
'error.captcha': 'FishPi requires a human-verification challenge. Complete it on the FishPi website first.',
|
|
279
|
+
'error.forbidden': 'This account is not allowed to do that (a bound phone number may be required).',
|
|
280
|
+
'error.points': 'Not enough points.',
|
|
281
|
+
'error.rate': 'Too many requests. Wait a moment and try again.',
|
|
282
|
+
'error.server': 'The FishPi service is temporarily unavailable.',
|
|
283
|
+
'error.upload': 'Image upload failed. Try again.',
|
|
284
|
+
'error.generic': 'The operation failed. Try again.',
|
|
285
|
+
'error.dismiss': 'Dismiss',
|
|
286
|
+
'card.redPacket': 'Red packet',
|
|
287
|
+
'card.redPacketMeta': '{money} points · {got}/{count} claimed',
|
|
288
|
+
'card.music': 'Music',
|
|
289
|
+
'card.weather': 'Weather',
|
|
290
|
+
'card.unavailable': 'This message is not readable now',
|
|
291
|
+
'system.join': '{name} joined the chatroom',
|
|
292
|
+
'system.leave': '{name} left the chatroom',
|
|
293
|
+
'notify.title': '{name} · FishPi',
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** @returns {string} a UUID for idempotent sends, with a fallback for old engines. */
|
|
297
|
+
function uuid() {
|
|
298
|
+
try {
|
|
299
|
+
return globalThis.crypto.randomUUID()
|
|
300
|
+
} catch {
|
|
301
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** @returns {{mode: 'rich'|'plain', notifications: boolean}} stored display preferences. */
|
|
306
|
+
function readPrefs() {
|
|
307
|
+
const fallback = { mode: 'rich', notifications: false }
|
|
308
|
+
try {
|
|
309
|
+
const raw = localStorage.getItem(PREFS_KEY)
|
|
310
|
+
if (raw === null) return fallback
|
|
311
|
+
const parsed = JSON.parse(raw)
|
|
312
|
+
return {
|
|
313
|
+
mode: parsed?.mode === 'plain' ? 'plain' : 'rich',
|
|
314
|
+
notifications: parsed?.notifications === true,
|
|
315
|
+
}
|
|
316
|
+
} catch {
|
|
317
|
+
return fallback
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** @param {{mode: 'rich'|'plain', notifications: boolean}} prefs - preferences to persist. */
|
|
322
|
+
function writePrefs(prefs) {
|
|
323
|
+
try {
|
|
324
|
+
localStorage.setItem(PREFS_KEY, JSON.stringify(prefs))
|
|
325
|
+
} catch {
|
|
326
|
+
// Private browsing can refuse storage; the session still works.
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Local record of red packets this browser account has already claimed. */
|
|
331
|
+
const CLAIMED_KEY_PREFIX = 'fishpi-chat.claimed.v1.'
|
|
332
|
+
|
|
333
|
+
/** @param {string} userId - account id. @returns {string[]} claimed packet ids. */
|
|
334
|
+
function readClaimed(userId) {
|
|
335
|
+
try {
|
|
336
|
+
const raw = localStorage.getItem(`${CLAIMED_KEY_PREFIX}${userId}`)
|
|
337
|
+
if (raw === null) return []
|
|
338
|
+
const parsed = JSON.parse(raw)
|
|
339
|
+
return Array.isArray(parsed) ? parsed.map(String) : []
|
|
340
|
+
} catch {
|
|
341
|
+
return []
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** @param {string} userId - account id. @param {string[]} ids - claimed packet ids. */
|
|
346
|
+
function writeClaimed(userId, ids) {
|
|
347
|
+
if (userId === '') return
|
|
348
|
+
try {
|
|
349
|
+
localStorage.setItem(`${CLAIMED_KEY_PREFIX}${userId}`, JSON.stringify(ids))
|
|
350
|
+
} catch {
|
|
351
|
+
// Claim state is a display cache; the server remains authoritative.
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @param {string} path - route below `api/fishpi/`.
|
|
357
|
+
* @param {{ method?: string, body?: unknown, signal?: AbortSignal }} [options] - request shape.
|
|
358
|
+
* @returns {Promise<any>}
|
|
359
|
+
*/
|
|
360
|
+
async function call(path, options = {}) {
|
|
361
|
+
/** @type {Record<string, string>} */
|
|
362
|
+
const headers = { accept: 'application/json' }
|
|
363
|
+
/** @type {RequestInit} */
|
|
364
|
+
const init = { method: options.method ?? 'GET', headers, cache: 'no-store' }
|
|
365
|
+
if (options.body !== undefined) {
|
|
366
|
+
headers['content-type'] = 'application/json'
|
|
367
|
+
init.body = JSON.stringify(options.body)
|
|
368
|
+
}
|
|
369
|
+
if (options.signal !== undefined) init.signal = options.signal
|
|
370
|
+
else if (typeof AbortSignal.timeout === 'function') init.signal = AbortSignal.timeout(20_000)
|
|
371
|
+
let response
|
|
372
|
+
try {
|
|
373
|
+
response = await fetch(`${API}/${path}`, init)
|
|
374
|
+
} catch (error) {
|
|
375
|
+
if (options.signal?.aborted === true) throw error
|
|
376
|
+
const failure = new Error('network')
|
|
377
|
+
failure.code = 'network'
|
|
378
|
+
throw failure
|
|
379
|
+
}
|
|
380
|
+
let data = null
|
|
381
|
+
try {
|
|
382
|
+
data = await response.json()
|
|
383
|
+
} catch {
|
|
384
|
+
// The error below carries the status.
|
|
385
|
+
}
|
|
386
|
+
if (!response.ok || data?.ok === false) {
|
|
387
|
+
const failure = new Error(typeof data?.message === 'string' ? data.message : `HTTP ${response.status}`)
|
|
388
|
+
failure.code = typeof data?.code === 'string' ? data.code : `http_${response.status}`
|
|
389
|
+
failure.status = response.status
|
|
390
|
+
throw failure
|
|
391
|
+
}
|
|
392
|
+
return data ?? {}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @param {number} ms - wait length.
|
|
397
|
+
* @param {AbortSignal} signal - cancellation.
|
|
398
|
+
* @returns {Promise<void>}
|
|
399
|
+
*/
|
|
400
|
+
function sleep(ms, signal) {
|
|
401
|
+
return new Promise(resolve => {
|
|
402
|
+
if (signal.aborted) {
|
|
403
|
+
resolve()
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
const timer = setTimeout(() => {
|
|
407
|
+
signal.removeEventListener('abort', onAbort)
|
|
408
|
+
resolve()
|
|
409
|
+
}, ms)
|
|
410
|
+
const onAbort = () => {
|
|
411
|
+
clearTimeout(timer)
|
|
412
|
+
resolve()
|
|
413
|
+
}
|
|
414
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
415
|
+
})
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* @param {unknown} raw - a Host-normalized message.
|
|
420
|
+
* @returns {object|undefined}
|
|
421
|
+
*/
|
|
422
|
+
function normalizeMessage(raw) {
|
|
423
|
+
if (raw === null || typeof raw !== 'object') return undefined
|
|
424
|
+
const source = /** @type {Record<string, any>} */ (raw)
|
|
425
|
+
const id = source.id === undefined || source.id === null ? '' : String(source.id)
|
|
426
|
+
if (id === '') return undefined
|
|
427
|
+
const author = source.author !== null && typeof source.author === 'object' ? source.author : {}
|
|
428
|
+
return {
|
|
429
|
+
id,
|
|
430
|
+
createdAt: Number(source.createdAt) || 0,
|
|
431
|
+
type: typeof source.type === 'string' ? source.type : 'text',
|
|
432
|
+
content: typeof source.content === 'string' ? source.content : '',
|
|
433
|
+
contentHtml: typeof source.contentHtml === 'string' ? source.contentHtml : '',
|
|
434
|
+
author: {
|
|
435
|
+
id: author.id === undefined || author.id === null ? '' : String(author.id),
|
|
436
|
+
userName: typeof author.userName === 'string' ? author.userName : '',
|
|
437
|
+
userNickname: typeof author.userNickname === 'string' ? author.userNickname : '',
|
|
438
|
+
userAvatarURL: typeof author.userAvatarURL === 'string' ? author.userAvatarURL : '',
|
|
439
|
+
},
|
|
440
|
+
client: typeof source.client === 'string' ? source.client : '',
|
|
441
|
+
medals: Array.isArray(source.medals) ? source.medals : [],
|
|
442
|
+
card: source.card !== null && typeof source.card === 'object' ? source.card : {},
|
|
443
|
+
reactionsUnavailable: source.reactionsUnavailable === true,
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @param {object|undefined} user - a user record.
|
|
449
|
+
* @returns {string} `nickname(username)`, or whichever part exists.
|
|
450
|
+
*/
|
|
451
|
+
function displayUser(user) {
|
|
452
|
+
const nickname = typeof user?.userNickname === 'string' ? user.userNickname.trim() : ''
|
|
453
|
+
const username = typeof user?.userName === 'string' ? user.userName.trim() : ''
|
|
454
|
+
if (nickname !== '' && username !== '') return `${nickname}(${username})`
|
|
455
|
+
return nickname || username || '—'
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* @param {number} ms - timestamp.
|
|
460
|
+
* @returns {string} local `HH:mm`.
|
|
461
|
+
*/
|
|
462
|
+
function clock(ms) {
|
|
463
|
+
if (!Number.isFinite(ms) || ms <= 0) return ''
|
|
464
|
+
const date = new Date(ms)
|
|
465
|
+
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @param {number} ms - timestamp.
|
|
470
|
+
* @returns {string} a day bucket for separators.
|
|
471
|
+
*/
|
|
472
|
+
function dayKey(ms) {
|
|
473
|
+
const date = new Date(Number(ms) || 0)
|
|
474
|
+
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* @param {number} ms - timestamp.
|
|
479
|
+
* @param {Function} t - bound translate.
|
|
480
|
+
* @returns {string} a localized date separator.
|
|
481
|
+
*/
|
|
482
|
+
function dayLabel(ms, t) {
|
|
483
|
+
const date = new Date(Number(ms) || 0)
|
|
484
|
+
const today = new Date()
|
|
485
|
+
const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1)
|
|
486
|
+
if (dayKey(ms) === dayKey(today.getTime())) return t('day.today')
|
|
487
|
+
if (dayKey(ms) === dayKey(yesterday.getTime())) return t('day.yesterday')
|
|
488
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* @param {string} html - server-sanitized HTML.
|
|
493
|
+
* @returns {string} HTML whose links and images are hardened for an embedded panel.
|
|
494
|
+
*/
|
|
495
|
+
const htmlCache = new Map()
|
|
496
|
+
function prepareHtml(html, base) {
|
|
497
|
+
if (html === '') return ''
|
|
498
|
+
const cacheKey = `${base}\n${html}`
|
|
499
|
+
const cached = htmlCache.get(cacheKey)
|
|
500
|
+
if (cached !== undefined) return cached
|
|
501
|
+
const origin = typeof base === 'string' && base !== '' ? base : 'https://fishpi.cn'
|
|
502
|
+
const resolve = value => {
|
|
503
|
+
try {
|
|
504
|
+
const url = new URL(value, origin)
|
|
505
|
+
return url.protocol === 'http:' || url.protocol === 'https:' ? url.toString() : ''
|
|
506
|
+
} catch {
|
|
507
|
+
return ''
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
let output = html
|
|
511
|
+
try {
|
|
512
|
+
const template = document.createElement('template')
|
|
513
|
+
template.innerHTML = html
|
|
514
|
+
for (const element of [...template.content.querySelectorAll('*')]) {
|
|
515
|
+
for (const attribute of [...element.attributes]) {
|
|
516
|
+
if (/^on/iu.test(attribute.name)) element.removeAttribute(attribute.name)
|
|
517
|
+
}
|
|
518
|
+
const tag = element.tagName.toLowerCase()
|
|
519
|
+
if (['script', 'style', 'iframe', 'object', 'embed', 'form', 'input', 'button'].includes(tag)) {
|
|
520
|
+
element.remove()
|
|
521
|
+
continue
|
|
522
|
+
}
|
|
523
|
+
if (tag === 'a') {
|
|
524
|
+
const href = (element.getAttribute('href') ?? '').trim()
|
|
525
|
+
if (/^(javascript|data|vbscript):/iu.test(href)) {
|
|
526
|
+
element.removeAttribute('href')
|
|
527
|
+
} else if (href !== '' && !href.startsWith('#')) {
|
|
528
|
+
const resolved = resolve(href)
|
|
529
|
+
if (resolved !== '') element.setAttribute('href', resolved)
|
|
530
|
+
else element.removeAttribute('href')
|
|
531
|
+
}
|
|
532
|
+
element.setAttribute('target', '_blank')
|
|
533
|
+
element.setAttribute('rel', 'noopener noreferrer')
|
|
534
|
+
}
|
|
535
|
+
if (tag === 'img') {
|
|
536
|
+
const source = (element.getAttribute('src') ?? '').trim()
|
|
537
|
+
const resolved = resolve(source)
|
|
538
|
+
if (resolved === '') {
|
|
539
|
+
element.remove()
|
|
540
|
+
continue
|
|
541
|
+
}
|
|
542
|
+
element.setAttribute('src', resolved)
|
|
543
|
+
element.setAttribute('loading', 'lazy')
|
|
544
|
+
element.setAttribute('referrerpolicy', 'no-referrer')
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
output = template.innerHTML
|
|
548
|
+
} catch {
|
|
549
|
+
output = html
|
|
550
|
+
}
|
|
551
|
+
if (htmlCache.size > 200) htmlCache.clear()
|
|
552
|
+
htmlCache.set(cacheKey, output)
|
|
553
|
+
return output
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* @param {string} html - markup from the server.
|
|
558
|
+
* @param {string} [imageLabel] - text substituted for each image.
|
|
559
|
+
* @returns {string} its text content.
|
|
560
|
+
*/
|
|
561
|
+
function plainFromHtml(html, imageLabel = '') {
|
|
562
|
+
if (html === '') return ''
|
|
563
|
+
try {
|
|
564
|
+
const holder = document.createElement('div')
|
|
565
|
+
holder.innerHTML = html
|
|
566
|
+
if (imageLabel !== '') {
|
|
567
|
+
for (const image of holder.querySelectorAll('img')) {
|
|
568
|
+
image.replaceWith(document.createTextNode(imageLabel))
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return holder.textContent ?? ''
|
|
572
|
+
} catch {
|
|
573
|
+
return html
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Replace Markdown and HTML image syntax with a plain text label, leaving
|
|
579
|
+
* fenced and inline code untouched so copied code stays readable.
|
|
580
|
+
* @param {string} text - Markdown source.
|
|
581
|
+
* @param {string} label - text substituted for each image.
|
|
582
|
+
* @returns {string} source with images labelled.
|
|
583
|
+
*/
|
|
584
|
+
function replaceImages(text, label) {
|
|
585
|
+
const replaceSegment = segment => segment
|
|
586
|
+
.replace(/\[!\[[^\]]*\]\([^)]*\)\]\([^)]*\)/gu, label)
|
|
587
|
+
.replace(/!\[[^\]]*\]\([^)]*\)/gu, label)
|
|
588
|
+
.replace(/!\[[^\]]*\]\[[^\]]*\]/gu, label)
|
|
589
|
+
.replace(/<img\b[^>]*>/giu, label)
|
|
590
|
+
const code = /(```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`)/gu
|
|
591
|
+
let output = ''
|
|
592
|
+
let last = 0
|
|
593
|
+
let match
|
|
594
|
+
while ((match = code.exec(text)) !== null) {
|
|
595
|
+
output += replaceSegment(text.slice(last, match.index)) + match[0]
|
|
596
|
+
last = match.index + match[0].length
|
|
597
|
+
}
|
|
598
|
+
return output + replaceSegment(text.slice(last))
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* @param {object} message - normalized message.
|
|
603
|
+
* @param {Function} t - bound translate.
|
|
604
|
+
* @returns {string} plain-mode text with image source replaced by a label.
|
|
605
|
+
*/
|
|
606
|
+
function plainMessage(message, t) {
|
|
607
|
+
const label = `[${t('plain.image')}]`
|
|
608
|
+
if (message.content !== '') return replaceImages(message.content, label)
|
|
609
|
+
return plainFromHtml(message.contentHtml, label)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* @param {object} message - normalized message.
|
|
614
|
+
* @param {Function} t - bound translate.
|
|
615
|
+
* @returns {string} one-line text for notifications and accessibility.
|
|
616
|
+
*/
|
|
617
|
+
function messageSummary(message, t) {
|
|
618
|
+
if (message.type === 'redPacket') {
|
|
619
|
+
const card = message.card?.redPacket ?? message.card ?? {}
|
|
620
|
+
return `${t('card.redPacket')} ${typeof card.message === 'string' ? card.message : ''}`.trim()
|
|
621
|
+
}
|
|
622
|
+
if (message.type === 'music') {
|
|
623
|
+
const card = message.card?.music ?? message.card ?? {}
|
|
624
|
+
return `${t('card.music')} ${typeof card.title === 'string' ? card.title : ''}`.trim()
|
|
625
|
+
}
|
|
626
|
+
if (message.type === 'weather') {
|
|
627
|
+
const card = message.card?.weather ?? message.card ?? {}
|
|
628
|
+
return `${t('card.weather')} ${typeof card.t === 'string' ? card.t : ''}`.trim()
|
|
629
|
+
}
|
|
630
|
+
if (message.type === 'unavailable') return t('card.unavailable')
|
|
631
|
+
return replaceImages(message.content || plainFromHtml(message.contentHtml, `[${t('plain.image')}]`), `[${t('plain.image')}]`).slice(0, 160)
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* @param {string} code - stable failure code.
|
|
636
|
+
* @param {string|undefined} fallback - server text.
|
|
637
|
+
* @param {Function} t - bound translate.
|
|
638
|
+
* @returns {string}
|
|
639
|
+
*/
|
|
640
|
+
function localizedError(code, fallback, t) {
|
|
641
|
+
switch (code) {
|
|
642
|
+
case 'network': return t('error.network')
|
|
643
|
+
case 'unauthorized': return t('error.unauthorized')
|
|
644
|
+
case 'invalid_credentials': return t('error.credentials')
|
|
645
|
+
case 'mfa_required': return t('error.mfa')
|
|
646
|
+
case 'captcha_required': return t('error.captcha')
|
|
647
|
+
case 'forbidden': return t('error.forbidden')
|
|
648
|
+
case 'insufficient_points': return t('error.points')
|
|
649
|
+
case 'rate_limited': return t('error.rate')
|
|
650
|
+
case 'upload_failed': return t('error.upload')
|
|
651
|
+
case 'realtime_unavailable':
|
|
652
|
+
case 'internal':
|
|
653
|
+
case 'http_500':
|
|
654
|
+
case 'http_502':
|
|
655
|
+
case 'http_503': return t('error.server')
|
|
656
|
+
default: return fallback !== undefined && fallback !== '' ? fallback : t('error.generic')
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Shared reactive state for the chat tab, the header button, and Settings.
|
|
662
|
+
* The Host keeps the authoritative session; this store is a derived cache.
|
|
663
|
+
* @param {Function} t - bound translate used for system lines and notifications.
|
|
664
|
+
*/
|
|
665
|
+
function createStore(t) {
|
|
666
|
+
let state = {
|
|
667
|
+
loaded: false,
|
|
668
|
+
ready: false,
|
|
669
|
+
loggedIn: false,
|
|
670
|
+
user: null,
|
|
671
|
+
connection: 'disconnected',
|
|
672
|
+
messages: [],
|
|
673
|
+
hasMore: false,
|
|
674
|
+
loadingMessages: false,
|
|
675
|
+
loadingOlder: false,
|
|
676
|
+
sending: false,
|
|
677
|
+
uploadingImages: false,
|
|
678
|
+
loggingIn: false,
|
|
679
|
+
loginError: null,
|
|
680
|
+
mfaRequired: false,
|
|
681
|
+
topic: '',
|
|
682
|
+
online: 0,
|
|
683
|
+
onlineUsers: [],
|
|
684
|
+
cursor: 0,
|
|
685
|
+
unread: 0,
|
|
686
|
+
chatVisible: false,
|
|
687
|
+
error: null,
|
|
688
|
+
siteUrl: 'https://fishpi.cn',
|
|
689
|
+
prefs: readPrefs(),
|
|
690
|
+
redPacketId: null,
|
|
691
|
+
redPacketGesture: null,
|
|
692
|
+
redPacket: null,
|
|
693
|
+
redPacketLoading: false,
|
|
694
|
+
redPacketError: null,
|
|
695
|
+
redPacketClaiming: false,
|
|
696
|
+
redPacketClaim: null,
|
|
697
|
+
claimedPacketIds: [],
|
|
698
|
+
userInfoName: null,
|
|
699
|
+
userInfo: null,
|
|
700
|
+
userInfoMedals: [],
|
|
701
|
+
userInfoLoading: false,
|
|
702
|
+
userInfoError: null,
|
|
703
|
+
medalIcons: {},
|
|
704
|
+
}
|
|
705
|
+
let disposed = false
|
|
706
|
+
let controller = new AbortController()
|
|
707
|
+
let started = false
|
|
708
|
+
let claimedUserId = ''
|
|
709
|
+
let redPacketSeq = 0
|
|
710
|
+
const medalPending = new Set()
|
|
711
|
+
const listeners = new Set()
|
|
712
|
+
const store = {
|
|
713
|
+
getSnapshot: () => state,
|
|
714
|
+
subscribe: listener => {
|
|
715
|
+
listeners.add(listener)
|
|
716
|
+
return () => { listeners.delete(listener) }
|
|
717
|
+
},
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* @param {Partial<typeof state>} patch - state fields to replace.
|
|
722
|
+
*/
|
|
723
|
+
function set(patch) {
|
|
724
|
+
if (disposed) return
|
|
725
|
+
state = { ...state, ...patch }
|
|
726
|
+
for (const listener of [...listeners]) listener()
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function trim(messages) {
|
|
730
|
+
return messages.length > MAX_RETAINED ? messages.slice(messages.length - MAX_RETAINED) : messages
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* @param {object[]} messages - current list.
|
|
735
|
+
* @param {object} message - message to insert or replace.
|
|
736
|
+
* @returns {object[]} sorted, deduplicated list.
|
|
737
|
+
*/
|
|
738
|
+
function mergeOne(messages, message) {
|
|
739
|
+
const index = messages.findIndex(item => item.id === message.id)
|
|
740
|
+
if (index >= 0) {
|
|
741
|
+
const next = messages.slice()
|
|
742
|
+
next[index] = message
|
|
743
|
+
return next
|
|
744
|
+
}
|
|
745
|
+
const next = [...messages, message]
|
|
746
|
+
next.sort((left, right) => (left.createdAt - right.createdAt) || (Number(left.id) - Number(right.id)))
|
|
747
|
+
return next
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* @param {object} message - one normalized message.
|
|
752
|
+
* @param {boolean} isNew - whether the event announces a new message.
|
|
753
|
+
*/
|
|
754
|
+
function receive(message, isNew) {
|
|
755
|
+
const existing = state.messages.findIndex(item => item.id === message.id)
|
|
756
|
+
if (existing >= 0) {
|
|
757
|
+
set({ messages: mergeOne(state.messages, message) })
|
|
758
|
+
return
|
|
759
|
+
}
|
|
760
|
+
const own = message.author?.id !== undefined && message.author.id !== '' && message.author.id === state.user?.id
|
|
761
|
+
const hidden = !state.chatVisible || document.hidden || !document.hasFocus()
|
|
762
|
+
const next = mergeOne(state.messages, message)
|
|
763
|
+
if (isNew && !own && hidden) {
|
|
764
|
+
set({ messages: trim(next), unread: state.unread + 1 })
|
|
765
|
+
notify(message)
|
|
766
|
+
return
|
|
767
|
+
}
|
|
768
|
+
set({ messages: trim(next) })
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* @param {object} message - new message.
|
|
773
|
+
*/
|
|
774
|
+
function notify(message) {
|
|
775
|
+
if (!state.prefs.notifications) return
|
|
776
|
+
if (typeof Notification === 'undefined' || Notification.permission !== 'granted') return
|
|
777
|
+
const author = displayUser(message.author)
|
|
778
|
+
try {
|
|
779
|
+
const notification = new Notification(t('notify.title', { name: author }), {
|
|
780
|
+
body: messageSummary(message, t).slice(0, 140),
|
|
781
|
+
tag: 'fishpi-chat',
|
|
782
|
+
renotify: true,
|
|
783
|
+
})
|
|
784
|
+
notification.onclick = () => {
|
|
785
|
+
window.focus()
|
|
786
|
+
openChat()
|
|
787
|
+
notification.close()
|
|
788
|
+
}
|
|
789
|
+
} catch {
|
|
790
|
+
// A platform without a notification surface simply skips it.
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* @param {object} data - Host state payload.
|
|
796
|
+
*/
|
|
797
|
+
function applyState(data) {
|
|
798
|
+
const was = state.loggedIn
|
|
799
|
+
const incoming = Number(data.cursor) || 0
|
|
800
|
+
const restarted = state.cursor > 0 && incoming < state.cursor
|
|
801
|
+
const nextUserId = data.user?.id === undefined || data.user?.id === null ? '' : String(data.user.id)
|
|
802
|
+
const claimedPacketIds = nextUserId === claimedUserId
|
|
803
|
+
? state.claimedPacketIds
|
|
804
|
+
: (nextUserId === '' ? [] : readClaimed(nextUserId))
|
|
805
|
+
claimedUserId = nextUserId
|
|
806
|
+
set({
|
|
807
|
+
loaded: true,
|
|
808
|
+
ready: data.ready === true,
|
|
809
|
+
loggedIn: data.loggedIn === true,
|
|
810
|
+
user: data.user ?? null,
|
|
811
|
+
connection: typeof data.connection === 'string' ? data.connection : state.connection,
|
|
812
|
+
cursor: restarted ? incoming : Math.max(state.cursor, incoming),
|
|
813
|
+
mfaRequired: data.mfaRequired === true,
|
|
814
|
+
siteUrl: typeof data.siteUrl === 'string' && data.siteUrl !== '' ? data.siteUrl : state.siteUrl,
|
|
815
|
+
error: data.error === undefined ? state.error : data.error,
|
|
816
|
+
claimedPacketIds,
|
|
817
|
+
})
|
|
818
|
+
if (was && !data.loggedIn) {
|
|
819
|
+
set({
|
|
820
|
+
messages: [],
|
|
821
|
+
unread: 0,
|
|
822
|
+
topic: '',
|
|
823
|
+
online: 0,
|
|
824
|
+
redPacketId: null,
|
|
825
|
+
redPacketGesture: null,
|
|
826
|
+
redPacket: null,
|
|
827
|
+
redPacketError: null,
|
|
828
|
+
redPacketClaiming: false,
|
|
829
|
+
redPacketClaim: null,
|
|
830
|
+
claimedPacketIds: [],
|
|
831
|
+
userInfoName: null,
|
|
832
|
+
userInfo: null,
|
|
833
|
+
userInfoMedals: [],
|
|
834
|
+
userInfoLoading: false,
|
|
835
|
+
userInfoError: null,
|
|
836
|
+
medalIcons: {},
|
|
837
|
+
})
|
|
838
|
+
claimedUserId = ''
|
|
839
|
+
}
|
|
840
|
+
if ((!was && data.loggedIn) || restarted) void syncAll()
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** @param {object} event - one Host event envelope. */
|
|
844
|
+
function applyEvent(event) {
|
|
845
|
+
if (event === null || typeof event !== 'object') return
|
|
846
|
+
const data = event.data ?? {}
|
|
847
|
+
switch (event.type) {
|
|
848
|
+
case 'state': applyState(data); return
|
|
849
|
+
case 'connection': {
|
|
850
|
+
set({ connection: typeof data.state === 'string' ? data.state : state.connection })
|
|
851
|
+
if (data.state === 'connected') void syncAll()
|
|
852
|
+
return
|
|
853
|
+
}
|
|
854
|
+
case 'sync': {
|
|
855
|
+
void syncAll()
|
|
856
|
+
return
|
|
857
|
+
}
|
|
858
|
+
case 'message.created': {
|
|
859
|
+
const message = normalizeMessage(data.message)
|
|
860
|
+
if (message !== undefined) receive(message, true)
|
|
861
|
+
return
|
|
862
|
+
}
|
|
863
|
+
case 'message.updated': {
|
|
864
|
+
const message = normalizeMessage(data.message)
|
|
865
|
+
if (message !== undefined) receive(message, false)
|
|
866
|
+
return
|
|
867
|
+
}
|
|
868
|
+
case 'message.deleted': {
|
|
869
|
+
const id = data.messageId === undefined ? '' : String(data.messageId)
|
|
870
|
+
if (id !== '') set({ messages: state.messages.filter(message => message.id !== id) })
|
|
871
|
+
return
|
|
872
|
+
}
|
|
873
|
+
case 'topic': {
|
|
874
|
+
set({ topic: typeof data.text === 'string' ? data.text.slice(0, MAX_TOPIC) : '' })
|
|
875
|
+
return
|
|
876
|
+
}
|
|
877
|
+
case 'presence': {
|
|
878
|
+
const id = `presence-${data.id === undefined || data.id === '' ? Date.now() : data.id}`
|
|
879
|
+
if (state.messages.some(message => message.id === id)) return
|
|
880
|
+
const actor = data.actor ?? {}
|
|
881
|
+
const name = displayUser(actor)
|
|
882
|
+
const text = typeof data.text === 'string' && data.text !== ''
|
|
883
|
+
? data.text
|
|
884
|
+
: (data.kind === 'leave' ? t('system.leave', { name }) : t('system.join', { name }))
|
|
885
|
+
set({
|
|
886
|
+
messages: trim([...state.messages, {
|
|
887
|
+
id,
|
|
888
|
+
type: 'system',
|
|
889
|
+
createdAt: Number(data.createdAt) || Date.now(),
|
|
890
|
+
text,
|
|
891
|
+
author: {},
|
|
892
|
+
}]),
|
|
893
|
+
})
|
|
894
|
+
return
|
|
895
|
+
}
|
|
896
|
+
default: return
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** Reload the latest message window, topic, and online count. */
|
|
901
|
+
async function syncAll() {
|
|
902
|
+
if (disposed || !state.loggedIn) return
|
|
903
|
+
if (syncAll.running) {
|
|
904
|
+
syncAll.queued = true
|
|
905
|
+
return
|
|
906
|
+
}
|
|
907
|
+
syncAll.running = true
|
|
908
|
+
try {
|
|
909
|
+
await Promise.all([loadLatest(), loadTopic(), loadOnline()])
|
|
910
|
+
} finally {
|
|
911
|
+
syncAll.running = false
|
|
912
|
+
if (syncAll.queued) {
|
|
913
|
+
syncAll.queued = false
|
|
914
|
+
void syncAll()
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
syncAll.running = false
|
|
919
|
+
syncAll.queued = false
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Load the newest window. With an existing window the result is merged,
|
|
923
|
+
* so a reconnect does not discard pages loaded with “Load earlier”.
|
|
924
|
+
* @param {{ replace?: boolean }} [options] - true resets the window.
|
|
925
|
+
*/
|
|
926
|
+
async function loadLatest(options = {}) {
|
|
927
|
+
if (disposed || !state.loggedIn) return
|
|
928
|
+
const replace = options.replace === true || state.messages.length === 0
|
|
929
|
+
set({ loadingMessages: state.messages.length === 0 })
|
|
930
|
+
try {
|
|
931
|
+
const data = await call(`messages?size=${WINDOW_SIZE}`, { signal: controller.signal })
|
|
932
|
+
const list = Array.isArray(data.list) ? data.list.map(normalizeMessage).filter(Boolean) : []
|
|
933
|
+
const next = replace ? list : list.reduce((messages, message) => mergeOne(messages, message), state.messages)
|
|
934
|
+
set({
|
|
935
|
+
messages: trim(next),
|
|
936
|
+
hasMore: replace ? data.hasMore === true : state.hasMore || data.hasMore === true,
|
|
937
|
+
loadingMessages: false,
|
|
938
|
+
})
|
|
939
|
+
} catch (error) {
|
|
940
|
+
if (!disposed) set({ loadingMessages: false, error: { code: error.code ?? 'generic', message: error.message } })
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Load the page before the oldest loaded message. */
|
|
945
|
+
async function loadOlder() {
|
|
946
|
+
const first = state.messages.find(message => message.type !== 'system')
|
|
947
|
+
if (first === undefined || !state.hasMore || state.loadingOlder) return 0
|
|
948
|
+
set({ loadingOlder: true })
|
|
949
|
+
try {
|
|
950
|
+
const data = await call(`messages?size=${WINDOW_SIZE}&before=${encodeURIComponent(first.id)}`, { signal: controller.signal })
|
|
951
|
+
const older = Array.isArray(data.list) ? data.list.map(normalizeMessage).filter(Boolean) : []
|
|
952
|
+
const known = new Set(state.messages.map(message => message.id))
|
|
953
|
+
const fresh = older.filter(message => !known.has(message.id))
|
|
954
|
+
const next = [...fresh, ...state.messages]
|
|
955
|
+
next.sort((left, right) => (left.createdAt - right.createdAt) || (Number(left.id) - Number(right.id)))
|
|
956
|
+
set({ messages: next, hasMore: data.hasMore === true, loadingOlder: false })
|
|
957
|
+
return fresh.length
|
|
958
|
+
} catch (error) {
|
|
959
|
+
if (!disposed) set({ loadingOlder: false, error: { code: error.code ?? 'generic', message: error.message } })
|
|
960
|
+
return 0
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** Refresh the current topic. */
|
|
965
|
+
async function loadTopic() {
|
|
966
|
+
try {
|
|
967
|
+
const data = await call('topic', { signal: controller.signal })
|
|
968
|
+
if (!disposed) set({ topic: typeof data.text === 'string' ? data.text.slice(0, MAX_TOPIC) : '' })
|
|
969
|
+
} catch {
|
|
970
|
+
// A topic is secondary; the next sync retries it.
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/** Refresh the visible online count. */
|
|
975
|
+
async function loadOnline() {
|
|
976
|
+
try {
|
|
977
|
+
const data = await call('online', { signal: controller.signal })
|
|
978
|
+
if (!disposed) {
|
|
979
|
+
set({
|
|
980
|
+
online: Number(data.total) || 0,
|
|
981
|
+
onlineUsers: Array.isArray(data.list)
|
|
982
|
+
? data.list.filter(user => user !== null && typeof user === 'object').slice(0, 50)
|
|
983
|
+
: [],
|
|
984
|
+
})
|
|
985
|
+
}
|
|
986
|
+
} catch {
|
|
987
|
+
// The count is secondary; the next sync retries it.
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* @param {{ nameOrEmail: string, password: string, mfaCode?: string, remember: boolean }} input - login form.
|
|
993
|
+
* @returns {Promise<{ok: boolean, code?: string, message?: string, mfaRequired?: boolean}>}
|
|
994
|
+
*/
|
|
995
|
+
async function login(input) {
|
|
996
|
+
set({ loggingIn: true, loginError: null })
|
|
997
|
+
try {
|
|
998
|
+
const data = await call('login', { method: 'POST', body: input })
|
|
999
|
+
if (data.ok === false) {
|
|
1000
|
+
const failure = { ok: false, code: data.code, message: data.message, mfaRequired: data.mfaRequired === true }
|
|
1001
|
+
set({ loggingIn: false, loginError: failure, mfaRequired: failure.mfaRequired })
|
|
1002
|
+
return failure
|
|
1003
|
+
}
|
|
1004
|
+
const next = await call('state')
|
|
1005
|
+
set({
|
|
1006
|
+
loggingIn: false,
|
|
1007
|
+
loggedIn: true,
|
|
1008
|
+
user: data.user ?? next.user ?? null,
|
|
1009
|
+
messages: [],
|
|
1010
|
+
unread: 0,
|
|
1011
|
+
mfaRequired: false,
|
|
1012
|
+
loginError: null,
|
|
1013
|
+
error: null,
|
|
1014
|
+
cursor: Math.max(state.cursor, Number(next.cursor) || 0),
|
|
1015
|
+
})
|
|
1016
|
+
await syncAll()
|
|
1017
|
+
return { ok: true }
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
const failure = { ok: false, code: error.code, message: error.message }
|
|
1020
|
+
set({ loggingIn: false, loginError: failure })
|
|
1021
|
+
return failure
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Forget the account in Settings.
|
|
1027
|
+
* @returns {Promise<{ok: boolean}>} whether the Host acknowledged the sign-out.
|
|
1028
|
+
*/
|
|
1029
|
+
async function logout() {
|
|
1030
|
+
let ok = true
|
|
1031
|
+
try {
|
|
1032
|
+
await call('logout', { method: 'POST', body: {} })
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
ok = false
|
|
1035
|
+
set({ error: { code: error.code ?? 'generic', message: error.message } })
|
|
1036
|
+
}
|
|
1037
|
+
set({
|
|
1038
|
+
loggedIn: false,
|
|
1039
|
+
user: null,
|
|
1040
|
+
messages: [],
|
|
1041
|
+
unread: 0,
|
|
1042
|
+
topic: '',
|
|
1043
|
+
online: 0,
|
|
1044
|
+
onlineUsers: [],
|
|
1045
|
+
mfaRequired: false,
|
|
1046
|
+
redPacketId: null,
|
|
1047
|
+
redPacketGesture: null,
|
|
1048
|
+
redPacket: null,
|
|
1049
|
+
redPacketError: null,
|
|
1050
|
+
redPacketClaiming: false,
|
|
1051
|
+
redPacketClaim: null,
|
|
1052
|
+
claimedPacketIds: [],
|
|
1053
|
+
userInfoName: null,
|
|
1054
|
+
userInfo: null,
|
|
1055
|
+
userInfoMedals: [],
|
|
1056
|
+
userInfoLoading: false,
|
|
1057
|
+
userInfoError: null,
|
|
1058
|
+
medalIcons: {},
|
|
1059
|
+
})
|
|
1060
|
+
claimedUserId = ''
|
|
1061
|
+
return { ok }
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Resolve medal icons for message authors and merge them into the cache.
|
|
1066
|
+
* @param {object[]} messages - current message window.
|
|
1067
|
+
*/
|
|
1068
|
+
async function loadMedalIcons(messages) {
|
|
1069
|
+
if (disposed || !state.loggedIn) return
|
|
1070
|
+
const names = [...new Set(messages
|
|
1071
|
+
.filter(message => message.author?.userName && Array.isArray(message.medals) && message.medals.length > 0)
|
|
1072
|
+
.map(message => message.author.userName))]
|
|
1073
|
+
const missing = names.filter(name => !(name in state.medalIcons) && !medalPending.has(name))
|
|
1074
|
+
if (missing.length === 0) return
|
|
1075
|
+
for (const name of missing) medalPending.add(name)
|
|
1076
|
+
try {
|
|
1077
|
+
const data = await call(`medals?names=${encodeURIComponent(missing.join(','))}`, { signal: controller.signal })
|
|
1078
|
+
const map = data.medals !== null && typeof data.medals === 'object' ? data.medals : {}
|
|
1079
|
+
const medalIcons = { ...state.medalIcons }
|
|
1080
|
+
for (const name of missing) medalIcons[name] = Array.isArray(map[name]) ? map[name] : []
|
|
1081
|
+
set({ medalIcons })
|
|
1082
|
+
} catch {
|
|
1083
|
+
const medalIcons = { ...state.medalIcons }
|
|
1084
|
+
for (const name of missing) medalIcons[name] = []
|
|
1085
|
+
set({ medalIcons })
|
|
1086
|
+
} finally {
|
|
1087
|
+
for (const name of missing) medalPending.delete(name)
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* Open one user's public profile and medal icons.
|
|
1093
|
+
* @param {string} userName - public username.
|
|
1094
|
+
*/
|
|
1095
|
+
async function openUserInfo(userName) {
|
|
1096
|
+
const name = typeof userName === 'string' ? userName.trim() : ''
|
|
1097
|
+
if (name === '' || !/^[A-Za-z0-9_-]+$/u.test(name)) return
|
|
1098
|
+
set({
|
|
1099
|
+
userInfoName: name,
|
|
1100
|
+
userInfo: null,
|
|
1101
|
+
userInfoMedals: [],
|
|
1102
|
+
userInfoLoading: true,
|
|
1103
|
+
userInfoError: null,
|
|
1104
|
+
})
|
|
1105
|
+
try {
|
|
1106
|
+
const data = await call(`user?name=${encodeURIComponent(name)}`, { signal: controller.signal })
|
|
1107
|
+
if (state.userInfoName === name) {
|
|
1108
|
+
set({
|
|
1109
|
+
userInfo: data.profile ?? null,
|
|
1110
|
+
userInfoMedals: Array.isArray(data.medals) ? data.medals : [],
|
|
1111
|
+
userInfoLoading: false,
|
|
1112
|
+
})
|
|
1113
|
+
}
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
if (state.userInfoName === name) {
|
|
1116
|
+
set({
|
|
1117
|
+
userInfoLoading: false,
|
|
1118
|
+
userInfoError: { code: error.code ?? 'generic', message: error.message },
|
|
1119
|
+
})
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/** Close the user profile dialog. */
|
|
1125
|
+
function closeUserInfo() {
|
|
1126
|
+
set({
|
|
1127
|
+
userInfoName: null,
|
|
1128
|
+
userInfo: null,
|
|
1129
|
+
userInfoMedals: [],
|
|
1130
|
+
userInfoLoading: false,
|
|
1131
|
+
userInfoError: null,
|
|
1132
|
+
})
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Search usernames for an `@` mention candidate list.
|
|
1137
|
+
* @param {string} prefix - text typed after `@`.
|
|
1138
|
+
* @returns {Promise<object[]>} matching users.
|
|
1139
|
+
*/
|
|
1140
|
+
async function suggestUsers(prefix) {
|
|
1141
|
+
if (!state.loggedIn || prefix === '') return []
|
|
1142
|
+
try {
|
|
1143
|
+
const data = await call(`users?prefix=${encodeURIComponent(prefix)}`, { signal: controller.signal })
|
|
1144
|
+
return Array.isArray(data.list) ? data.list : []
|
|
1145
|
+
} catch {
|
|
1146
|
+
return []
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Upload one or more images through the Host's authenticated upload route.
|
|
1152
|
+
* @param {FileList|File[]} files - images selected or pasted by the user.
|
|
1153
|
+
* @returns {Promise<{ok: boolean, files?: {name: string, url: string}[]}>}
|
|
1154
|
+
*/
|
|
1155
|
+
async function uploadImages(files) {
|
|
1156
|
+
const images = [...files].filter(file => file !== null
|
|
1157
|
+
&& typeof file === 'object'
|
|
1158
|
+
&& typeof file.type === 'string'
|
|
1159
|
+
&& file.type.startsWith('image/'))
|
|
1160
|
+
if (images.length === 0) return { ok: false }
|
|
1161
|
+
set({ uploadingImages: true, error: null })
|
|
1162
|
+
try {
|
|
1163
|
+
const form = new FormData()
|
|
1164
|
+
for (const file of images) form.append('file', file, file.name || 'image.png')
|
|
1165
|
+
/** @type {RequestInit} */
|
|
1166
|
+
const init = { method: 'POST', body: form, cache: 'no-store' }
|
|
1167
|
+
if (typeof AbortSignal.timeout === 'function') init.signal = AbortSignal.timeout(60_000)
|
|
1168
|
+
let response
|
|
1169
|
+
try {
|
|
1170
|
+
response = await fetch(`${API}/upload`, init)
|
|
1171
|
+
} catch (error) {
|
|
1172
|
+
const failure = new Error('network')
|
|
1173
|
+
failure.code = 'network'
|
|
1174
|
+
throw failure
|
|
1175
|
+
}
|
|
1176
|
+
let data = null
|
|
1177
|
+
try {
|
|
1178
|
+
data = await response.json()
|
|
1179
|
+
} catch {
|
|
1180
|
+
// The status carries the failure.
|
|
1181
|
+
}
|
|
1182
|
+
if (!response.ok || data?.ok === false) {
|
|
1183
|
+
const failure = new Error(typeof data?.message === 'string' ? data.message : `HTTP ${response.status}`)
|
|
1184
|
+
failure.code = typeof data?.code === 'string' ? data.code : `http_${response.status}`
|
|
1185
|
+
throw failure
|
|
1186
|
+
}
|
|
1187
|
+
const uploaded = Array.isArray(data.files)
|
|
1188
|
+
? data.files.filter(file => file !== null && typeof file.url === 'string' && file.url !== '')
|
|
1189
|
+
: []
|
|
1190
|
+
set({ uploadingImages: false })
|
|
1191
|
+
return { ok: true, files: uploaded }
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
set({
|
|
1194
|
+
uploadingImages: false,
|
|
1195
|
+
error: { code: error.code ?? 'generic', message: error.message },
|
|
1196
|
+
})
|
|
1197
|
+
return { ok: false }
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* @param {string} content - composer text.
|
|
1203
|
+
* @returns {Promise<{ok: boolean}>}
|
|
1204
|
+
*/
|
|
1205
|
+
async function send(content) {
|
|
1206
|
+
if (!state.loggedIn) return { ok: false }
|
|
1207
|
+
set({ sending: true, error: null })
|
|
1208
|
+
try {
|
|
1209
|
+
const data = await call('send', { method: 'POST', body: { content, requestId: uuid() } })
|
|
1210
|
+
if (data.message !== null && data.message !== undefined) {
|
|
1211
|
+
const message = normalizeMessage(data.message)
|
|
1212
|
+
if (message !== undefined) set({ messages: trim(mergeOne(state.messages, message)) })
|
|
1213
|
+
}
|
|
1214
|
+
set({ sending: false })
|
|
1215
|
+
return { ok: true }
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
set({ sending: false, error: { code: error.code ?? 'generic', message: error.message } })
|
|
1218
|
+
return { ok: false }
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* @param {'rich'|'plain'} mode - message rendering mode.
|
|
1224
|
+
*/
|
|
1225
|
+
function setMode(mode) {
|
|
1226
|
+
const prefs = { ...state.prefs, mode }
|
|
1227
|
+
writePrefs(prefs)
|
|
1228
|
+
set({ prefs })
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* @param {boolean} notifications - desktop notification preference.
|
|
1233
|
+
*/
|
|
1234
|
+
function setNotifications(notifications) {
|
|
1235
|
+
const prefs = { ...state.prefs, notifications }
|
|
1236
|
+
writePrefs(prefs)
|
|
1237
|
+
set({ prefs })
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* @param {boolean} visible - whether a chat tab is on screen.
|
|
1242
|
+
*/
|
|
1243
|
+
function setChatVisible(visible) {
|
|
1244
|
+
if (visible && state.unread > 0) set({ chatVisible: true, unread: 0 })
|
|
1245
|
+
else set({ chatVisible: visible })
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/** Clear the unread count when the window and the chat tab are both visible. */
|
|
1249
|
+
function clearUnreadIfVisible() {
|
|
1250
|
+
if (state.chatVisible && state.unread > 0) set({ unread: 0 })
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/** Clear the inline failure banner. */
|
|
1254
|
+
function clearError() {
|
|
1255
|
+
set({ error: null })
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Open one red packet's detail and claim records.
|
|
1260
|
+
* @param {string} id - message id.
|
|
1261
|
+
* @param {number|null} [gesture] - a gesture picked on the card, preselected in the dialog.
|
|
1262
|
+
*/
|
|
1263
|
+
async function openRedPacket(id, gesture = null) {
|
|
1264
|
+
const clean = String(id)
|
|
1265
|
+
const seq = ++redPacketSeq
|
|
1266
|
+
set({
|
|
1267
|
+
redPacketId: clean,
|
|
1268
|
+
redPacketGesture: Number.isInteger(gesture) ? gesture : null,
|
|
1269
|
+
redPacket: null,
|
|
1270
|
+
redPacketError: null,
|
|
1271
|
+
redPacketLoading: true,
|
|
1272
|
+
redPacketClaim: null,
|
|
1273
|
+
})
|
|
1274
|
+
try {
|
|
1275
|
+
const data = await call(`red-packet?id=${encodeURIComponent(clean)}`, { signal: controller.signal })
|
|
1276
|
+
if (state.redPacketId === clean && seq === redPacketSeq) {
|
|
1277
|
+
set({ redPacket: data.detail ?? null, redPacketLoading: false })
|
|
1278
|
+
}
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
if (state.redPacketId === clean && seq === redPacketSeq) {
|
|
1281
|
+
set({
|
|
1282
|
+
redPacketLoading: false,
|
|
1283
|
+
redPacketError: { code: error.code ?? 'generic', message: error.message },
|
|
1284
|
+
})
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/** Close the red-packet dialog. */
|
|
1290
|
+
function closeRedPacket() {
|
|
1291
|
+
set({
|
|
1292
|
+
redPacketId: null,
|
|
1293
|
+
redPacketGesture: null,
|
|
1294
|
+
redPacket: null,
|
|
1295
|
+
redPacketError: null,
|
|
1296
|
+
redPacketLoading: false,
|
|
1297
|
+
redPacketClaiming: false,
|
|
1298
|
+
redPacketClaim: null,
|
|
1299
|
+
})
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Claim the open red packet after the user explicitly accepts any risk.
|
|
1304
|
+
* @param {{ gesture?: number, riskAccepted?: boolean }} options - RPS gesture and risk acknowledgement.
|
|
1305
|
+
* @returns {Promise<{ok: boolean}>}
|
|
1306
|
+
*/
|
|
1307
|
+
async function claimRedPacket(options = {}, packetId = state.redPacketId) {
|
|
1308
|
+
const id = packetId === null || packetId === undefined ? null : String(packetId)
|
|
1309
|
+
if (id === null) return { ok: false }
|
|
1310
|
+
const dialogOpen = state.redPacketId === id
|
|
1311
|
+
set(dialogOpen
|
|
1312
|
+
? { redPacketClaiming: true, redPacketError: null }
|
|
1313
|
+
: { redPacketClaiming: true })
|
|
1314
|
+
try {
|
|
1315
|
+
const data = await call('red-packet/claim', {
|
|
1316
|
+
method: 'POST',
|
|
1317
|
+
body: {
|
|
1318
|
+
id,
|
|
1319
|
+
requestId: uuid(),
|
|
1320
|
+
gesture: Number.isInteger(options.gesture) ? options.gesture : undefined,
|
|
1321
|
+
riskAccepted: options.riskAccepted === true,
|
|
1322
|
+
},
|
|
1323
|
+
})
|
|
1324
|
+
const claimedPacketIds = [...new Set([...state.claimedPacketIds, id])]
|
|
1325
|
+
writeClaimed(claimedUserId, claimedPacketIds)
|
|
1326
|
+
if (state.redPacketId === id) {
|
|
1327
|
+
redPacketSeq += 1
|
|
1328
|
+
set({
|
|
1329
|
+
redPacketClaiming: false,
|
|
1330
|
+
redPacketClaim: data.claim ?? null,
|
|
1331
|
+
redPacket: data.detail ?? state.redPacket,
|
|
1332
|
+
redPacketLoading: false,
|
|
1333
|
+
claimedPacketIds,
|
|
1334
|
+
})
|
|
1335
|
+
} else {
|
|
1336
|
+
set({ redPacketClaiming: false, claimedPacketIds })
|
|
1337
|
+
}
|
|
1338
|
+
return { ok: true, claim: data.claim ?? null }
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
if (state.redPacketId === id) {
|
|
1341
|
+
redPacketSeq += 1
|
|
1342
|
+
set({
|
|
1343
|
+
redPacketClaiming: false,
|
|
1344
|
+
redPacketLoading: false,
|
|
1345
|
+
redPacketError: { code: error.code ?? 'generic', message: error.message },
|
|
1346
|
+
})
|
|
1347
|
+
} else {
|
|
1348
|
+
set({
|
|
1349
|
+
redPacketClaiming: false,
|
|
1350
|
+
error: { code: error.code ?? 'generic', message: error.message },
|
|
1351
|
+
})
|
|
1352
|
+
}
|
|
1353
|
+
return { ok: false }
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** @returns {boolean} whether the Host routes are reachable. */
|
|
1358
|
+
function reachable() {
|
|
1359
|
+
return state.loaded
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/** Read the initial state and start the long-poll event loop. */
|
|
1363
|
+
async function init(signal) {
|
|
1364
|
+
if (started) return
|
|
1365
|
+
started = true
|
|
1366
|
+
controller = new AbortController()
|
|
1367
|
+
signal.addEventListener('abort', () => controller.abort(), { once: true })
|
|
1368
|
+
try {
|
|
1369
|
+
const data = await call('state', { signal: controller.signal })
|
|
1370
|
+
applyState(data)
|
|
1371
|
+
if (data.loggedIn === true) await syncAll()
|
|
1372
|
+
} catch (error) {
|
|
1373
|
+
if (!disposed) set({ loaded: true, error: { code: error.code ?? 'generic', message: error.message } })
|
|
1374
|
+
}
|
|
1375
|
+
void eventLoop(controller.signal)
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* @param {AbortSignal} signal - module lifetime.
|
|
1380
|
+
*/
|
|
1381
|
+
async function eventLoop(signal) {
|
|
1382
|
+
let failures = 0
|
|
1383
|
+
while (!disposed && !signal.aborted) {
|
|
1384
|
+
const since = state.cursor
|
|
1385
|
+
try {
|
|
1386
|
+
const data = await call(`events?since=${since}`, { signal })
|
|
1387
|
+
failures = 0
|
|
1388
|
+
if (data.reset === true) {
|
|
1389
|
+
set({ cursor: Number(data.cursor) || 0 })
|
|
1390
|
+
await syncAll()
|
|
1391
|
+
continue
|
|
1392
|
+
}
|
|
1393
|
+
if (Array.isArray(data.events) && data.events.length > 0) {
|
|
1394
|
+
for (const event of data.events) applyEvent(event)
|
|
1395
|
+
}
|
|
1396
|
+
if (Number.isFinite(Number(data.cursor))) {
|
|
1397
|
+
set({ cursor: Math.max(state.cursor, Number(data.cursor)) })
|
|
1398
|
+
}
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
if (disposed || signal.aborted) return
|
|
1401
|
+
failures += 1
|
|
1402
|
+
await sleep(Math.min(10_000, 1_000 * 2 ** Math.min(failures, 4)), signal)
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/** Stop all requests and stop publishing. */
|
|
1408
|
+
function dispose() {
|
|
1409
|
+
disposed = true
|
|
1410
|
+
controller.abort()
|
|
1411
|
+
listeners.clear()
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
Object.assign(store, {
|
|
1415
|
+
init,
|
|
1416
|
+
dispose,
|
|
1417
|
+
login,
|
|
1418
|
+
logout,
|
|
1419
|
+
send,
|
|
1420
|
+
suggestUsers,
|
|
1421
|
+
openUserInfo,
|
|
1422
|
+
closeUserInfo,
|
|
1423
|
+
loadMedalIcons,
|
|
1424
|
+
uploadImages,
|
|
1425
|
+
loadOlder,
|
|
1426
|
+
loadTopic,
|
|
1427
|
+
loadOnline,
|
|
1428
|
+
syncAll,
|
|
1429
|
+
setMode,
|
|
1430
|
+
setNotifications,
|
|
1431
|
+
setChatVisible,
|
|
1432
|
+
clearUnreadIfVisible,
|
|
1433
|
+
clearError,
|
|
1434
|
+
openRedPacket,
|
|
1435
|
+
closeRedPacket,
|
|
1436
|
+
claimRedPacket,
|
|
1437
|
+
reachable,
|
|
1438
|
+
})
|
|
1439
|
+
return store
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
const LOGO_ASSETS = new Map((LOGO_ANIMATION.assets ?? []).map(asset => [asset.id, asset]))
|
|
1443
|
+
const LOGO_LAYERS = [...(LOGO_ANIMATION.layers ?? [])].reverse()
|
|
1444
|
+
const LOGO_WIDTH = Number(LOGO_ANIMATION.w) || 800
|
|
1445
|
+
const LOGO_HEIGHT = Number(LOGO_ANIMATION.h) || 800
|
|
1446
|
+
const LOGO_FPS = Number(LOGO_ANIMATION.fr) || 25
|
|
1447
|
+
const LOGO_FRAMES = Number(LOGO_ANIMATION.op) || 75
|
|
1448
|
+
/** The site starts this composition at frame 27, where the mark is visible. */
|
|
1449
|
+
const LOGO_START = 27
|
|
1450
|
+
const LOGO_SPAN = Math.max(1, LOGO_FRAMES - LOGO_START)
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* Evaluate one Lottie property at a frame. The composition only animates
|
|
1454
|
+
* image-layer transforms, so linear interpolation between keyframes is
|
|
1455
|
+
* enough to reproduce it without a full Lottie player.
|
|
1456
|
+
* @param {object|undefined} property - Lottie property.
|
|
1457
|
+
* @param {number} frame - frame in `0..op`.
|
|
1458
|
+
* @returns {any} the raw value at that frame.
|
|
1459
|
+
*/
|
|
1460
|
+
function lottieValue(property, frame) {
|
|
1461
|
+
if (property === undefined || property === null) return undefined
|
|
1462
|
+
if (property.a !== 1 || !Array.isArray(property.k)) return property.k
|
|
1463
|
+
const keys = property.k
|
|
1464
|
+
if (keys.length === 0) return undefined
|
|
1465
|
+
if (frame <= keys[0].t) return keys[0].s
|
|
1466
|
+
for (let index = 0; index < keys.length - 1; index += 1) {
|
|
1467
|
+
const left = keys[index]
|
|
1468
|
+
const right = keys[index + 1]
|
|
1469
|
+
if (frame >= left.t && frame < right.t) {
|
|
1470
|
+
const end = left.e ?? right.s
|
|
1471
|
+
const ratio = (frame - left.t) / Math.max(1, right.t - left.t)
|
|
1472
|
+
if (Array.isArray(left.s) && Array.isArray(end)) {
|
|
1473
|
+
return left.s.map((value, item) => value + (end[item] - value) * ratio)
|
|
1474
|
+
}
|
|
1475
|
+
return left.s + (end - left.s) * ratio
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const last = keys[keys.length - 1]
|
|
1479
|
+
return last.e ?? last.s
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* The FishPi home-page `#logo-animate` composition, replayed as three
|
|
1484
|
+
* positioned image layers. It animates only while mounted, and holds the
|
|
1485
|
+
* site's frame 27 for reduced motion.
|
|
1486
|
+
* @param {{size?: number}} props - square edge in pixels.
|
|
1487
|
+
*/
|
|
1488
|
+
function AnimatedFishPiLogo({ size = 18 }) {
|
|
1489
|
+
const layerRefs = useRef([])
|
|
1490
|
+
|
|
1491
|
+
useEffect(() => {
|
|
1492
|
+
const images = layerRefs.current
|
|
1493
|
+
const unit = size / LOGO_WIDTH
|
|
1494
|
+
const apply = frame => {
|
|
1495
|
+
LOGO_LAYERS.forEach((layer, index) => {
|
|
1496
|
+
const image = images[index]
|
|
1497
|
+
if (image === null || image === undefined) return
|
|
1498
|
+
const visible = frame >= (layer.ip ?? 0) && frame < (layer.op ?? LOGO_FRAMES)
|
|
1499
|
+
const asset = LOGO_ASSETS.get(layer.refId)
|
|
1500
|
+
if (!visible || asset === undefined) {
|
|
1501
|
+
image.style.opacity = '0'
|
|
1502
|
+
return
|
|
1503
|
+
}
|
|
1504
|
+
const anchor = lottieValue(layer.ks?.a, frame) ?? [0, 0]
|
|
1505
|
+
const position = lottieValue(layer.ks?.p, frame) ?? [0, 0]
|
|
1506
|
+
const scale = lottieValue(layer.ks?.s, frame) ?? [100, 100]
|
|
1507
|
+
const rotation = Number(lottieValue(layer.ks?.r, frame)) || 0
|
|
1508
|
+
const opacity = Number(lottieValue(layer.ks?.o, frame)) || 0
|
|
1509
|
+
const scaleX = (Number(scale[0]) || 100) / 100 * unit
|
|
1510
|
+
const scaleY = (Number(scale[1]) || 100) / 100 * unit
|
|
1511
|
+
const anchorX = (Number(anchor[0]) || 0) * scaleX
|
|
1512
|
+
const anchorY = (Number(anchor[1]) || 0) * scaleY
|
|
1513
|
+
image.style.width = `${asset.w * scaleX}px`
|
|
1514
|
+
image.style.height = `${asset.h * scaleY}px`
|
|
1515
|
+
image.style.left = `${(Number(position[0]) || 0) * unit - anchorX}px`
|
|
1516
|
+
image.style.top = `${(Number(position[1]) || 0) * unit - anchorY}px`
|
|
1517
|
+
image.style.transformOrigin = `${anchorX}px ${anchorY}px`
|
|
1518
|
+
image.style.transform = `rotate(${rotation}deg)`
|
|
1519
|
+
image.style.opacity = String(Math.max(0, Math.min(1, opacity / 100)))
|
|
1520
|
+
})
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
const media = typeof window !== 'undefined' && typeof window.matchMedia === 'function'
|
|
1524
|
+
? window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
1525
|
+
: undefined
|
|
1526
|
+
if (media?.matches === true) {
|
|
1527
|
+
apply(LOGO_START)
|
|
1528
|
+
return undefined
|
|
1529
|
+
}
|
|
1530
|
+
let frameHandle
|
|
1531
|
+
let started
|
|
1532
|
+
const tick = now => {
|
|
1533
|
+
if (started === undefined) started = now
|
|
1534
|
+
apply(LOGO_START + ((now - started) / 1000 * LOGO_FPS) % LOGO_SPAN)
|
|
1535
|
+
frameHandle = requestAnimationFrame(tick)
|
|
1536
|
+
}
|
|
1537
|
+
frameHandle = requestAnimationFrame(tick)
|
|
1538
|
+
return () => cancelAnimationFrame(frameHandle)
|
|
1539
|
+
}, [size])
|
|
1540
|
+
|
|
1541
|
+
return h('span', {
|
|
1542
|
+
'aria-hidden': 'true',
|
|
1543
|
+
style: {
|
|
1544
|
+
position: 'relative',
|
|
1545
|
+
display: 'inline-block',
|
|
1546
|
+
flex: 'none',
|
|
1547
|
+
width: size,
|
|
1548
|
+
height: size,
|
|
1549
|
+
pointerEvents: 'none',
|
|
1550
|
+
verticalAlign: 'middle',
|
|
1551
|
+
},
|
|
1552
|
+
}, LOGO_LAYERS.map((layer, index) => {
|
|
1553
|
+
const asset = LOGO_ASSETS.get(layer.refId)
|
|
1554
|
+
if (asset === undefined) return null
|
|
1555
|
+
return h('img', {
|
|
1556
|
+
key: `${layer.ind ?? index}`,
|
|
1557
|
+
src: asset.p,
|
|
1558
|
+
alt: '',
|
|
1559
|
+
draggable: false,
|
|
1560
|
+
ref: element => { layerRefs.current[index] = element },
|
|
1561
|
+
style: {
|
|
1562
|
+
position: 'absolute',
|
|
1563
|
+
left: 0,
|
|
1564
|
+
top: 0,
|
|
1565
|
+
maxWidth: 'none',
|
|
1566
|
+
maxHeight: 'none',
|
|
1567
|
+
pointerEvents: 'none',
|
|
1568
|
+
userSelect: 'none',
|
|
1569
|
+
opacity: 0,
|
|
1570
|
+
},
|
|
1571
|
+
})
|
|
1572
|
+
}))
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
/** @param {object} props - `{size}` from the slot or a direct call. */
|
|
1576
|
+
function IconFish({ size = 18 }) {
|
|
1577
|
+
return h(AnimatedFishPiLogo, { size })
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/** The same fish mark for the settings navigation. */
|
|
1581
|
+
function SettingsIcon({ size = 16 }) {
|
|
1582
|
+
return h(IconFish, { size })
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
/**
|
|
1586
|
+
* @param {{url: string, name: string, size?: number}} props - avatar source and fallback initial.
|
|
1587
|
+
*/
|
|
1588
|
+
function Avatar({ url, name, size = 28 }) {
|
|
1589
|
+
const [failed, setFailed] = useState(false)
|
|
1590
|
+
useEffect(() => { setFailed(false) }, [url])
|
|
1591
|
+
if (url === '' || failed) {
|
|
1592
|
+
return h('span', {
|
|
1593
|
+
className: 'fc-avatar fc-avatar-fallback',
|
|
1594
|
+
style: { width: size, height: size, fontSize: Math.max(11, Math.round(size * 0.42)) },
|
|
1595
|
+
'aria-hidden': 'true',
|
|
1596
|
+
}, (name || '?').slice(0, 1).toUpperCase())
|
|
1597
|
+
}
|
|
1598
|
+
return h('img', {
|
|
1599
|
+
className: 'fc-avatar',
|
|
1600
|
+
src: url,
|
|
1601
|
+
width: size,
|
|
1602
|
+
height: size,
|
|
1603
|
+
alt: '',
|
|
1604
|
+
loading: 'lazy',
|
|
1605
|
+
referrerPolicy: 'no-referrer',
|
|
1606
|
+
onError: () => setFailed(true),
|
|
1607
|
+
})
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
/** @param {{state: string, t: Function}} props - transport state and copy. */
|
|
1611
|
+
function StatusDot({ state, t }) {
|
|
1612
|
+
const label = state === 'connected' ? t('status.connected') : state === 'connecting' ? t('status.connecting') : t('status.disconnected')
|
|
1613
|
+
return h('span', { className: `fc-status fc-status-${state}`, title: label, 'aria-label': label })
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* One red-packet card: type, progress, optional explicit confirmation, and
|
|
1618
|
+
* a direct claim. A checked confirmation makes a click claim; without it
|
|
1619
|
+
* the card opens the detail dialog.
|
|
1620
|
+
* @param {{message: object, card: object, t: Function}} props - message, card payload, copy.
|
|
1621
|
+
*/
|
|
1622
|
+
function RedPacketCard({ message, card, t }) {
|
|
1623
|
+
const store = sharedStore
|
|
1624
|
+
const state = useStore()
|
|
1625
|
+
const [confirmed, setConfirmed] = useState(false)
|
|
1626
|
+
const id = String(message.id)
|
|
1627
|
+
const type = typeof card.type === 'string' ? card.type : ''
|
|
1628
|
+
const typeLabel = redPacketTypeLabel(t, type)
|
|
1629
|
+
const isRps = type === 'rockPaperScissors'
|
|
1630
|
+
const risky = type === 'heartbeat' || isRps
|
|
1631
|
+
const count = Number(card.count) || 0
|
|
1632
|
+
const got = Number(card.got) || 0
|
|
1633
|
+
const finished = count > 0 && got >= count
|
|
1634
|
+
const claimed = state.claimedPacketIds.includes(id)
|
|
1635
|
+
const own = message.author?.id !== undefined
|
|
1636
|
+
&& String(message.author.id) === (state.user?.id ?? '')
|
|
1637
|
+
const ownBlocked = own && type !== 'heartbeat'
|
|
1638
|
+
const blocked = claimed || finished || ownBlocked
|
|
1639
|
+
const busy = state.redPacketClaiming
|
|
1640
|
+
const progress = t('card.redPacketMeta', {
|
|
1641
|
+
money: card.money ?? '-',
|
|
1642
|
+
got: card.got ?? 0,
|
|
1643
|
+
count: card.count ?? '-',
|
|
1644
|
+
})
|
|
1645
|
+
|
|
1646
|
+
const claim = async gesture => {
|
|
1647
|
+
if (blocked || busy) return
|
|
1648
|
+
if (isRps) {
|
|
1649
|
+
if (!Number.isInteger(gesture)) {
|
|
1650
|
+
void store.openRedPacket(id)
|
|
1651
|
+
return
|
|
1652
|
+
}
|
|
1653
|
+
} else if (!confirmed) {
|
|
1654
|
+
void store.openRedPacket(id)
|
|
1655
|
+
return
|
|
1656
|
+
}
|
|
1657
|
+
// Open the result dialog immediately; it shows the claim outcome or
|
|
1658
|
+
// failure as soon as the request settles.
|
|
1659
|
+
void store.openRedPacket(id, Number.isInteger(gesture) ? gesture : null)
|
|
1660
|
+
await store.claimRedPacket({
|
|
1661
|
+
riskAccepted: risky,
|
|
1662
|
+
gesture: Number.isInteger(gesture) ? gesture : undefined,
|
|
1663
|
+
}, id)
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
const onCardClick = () => {
|
|
1667
|
+
if (blocked) {
|
|
1668
|
+
void store.openRedPacket(id)
|
|
1669
|
+
return
|
|
1670
|
+
}
|
|
1671
|
+
void claim(null)
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
return h('div', {
|
|
1675
|
+
className: `fc-card fc-card-redpacket fc-card-button${blocked ? ' fc-card-blocked' : ''}`,
|
|
1676
|
+
role: 'button',
|
|
1677
|
+
tabIndex: 0,
|
|
1678
|
+
'aria-label': `${typeLabel}: ${progress}`,
|
|
1679
|
+
onClick: onCardClick,
|
|
1680
|
+
onKeyDown: event => {
|
|
1681
|
+
if (event.target !== event.currentTarget) return
|
|
1682
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
1683
|
+
event.preventDefault()
|
|
1684
|
+
onCardClick()
|
|
1685
|
+
}
|
|
1686
|
+
},
|
|
1687
|
+
},
|
|
1688
|
+
h('div', { className: 'fc-card-title' }, typeLabel),
|
|
1689
|
+
typeof card.message === 'string' && card.message !== ''
|
|
1690
|
+
? h('div', { className: 'fc-card-body' }, card.message)
|
|
1691
|
+
: null,
|
|
1692
|
+
h('div', { className: 'fc-card-meta' }, progress),
|
|
1693
|
+
blocked
|
|
1694
|
+
? h('div', { className: 'fc-card-state' },
|
|
1695
|
+
claimed
|
|
1696
|
+
? t('redPacket.cardClaimed')
|
|
1697
|
+
: ownBlocked
|
|
1698
|
+
? t('redPacket.own')
|
|
1699
|
+
: t('redPacket.cardFinished'))
|
|
1700
|
+
: h('div', { className: 'fc-card-controls' },
|
|
1701
|
+
isRps
|
|
1702
|
+
? h('div', { className: 'fc-gesture-row', role: 'group', 'aria-label': t('redPacket.gesture') },
|
|
1703
|
+
[[0, 'redPacket.shortRock', 'redPacket.rock'], [1, 'redPacket.shortScissors', 'redPacket.scissors'], [2, 'redPacket.shortPaper', 'redPacket.paper']].map(([value, shortKey, fullKey]) =>
|
|
1704
|
+
h('button', {
|
|
1705
|
+
key: value,
|
|
1706
|
+
type: 'button',
|
|
1707
|
+
className: 'fc-gesture-button',
|
|
1708
|
+
title: t(fullKey),
|
|
1709
|
+
'aria-label': t(fullKey),
|
|
1710
|
+
disabled: busy,
|
|
1711
|
+
onClick: event => {
|
|
1712
|
+
event.stopPropagation()
|
|
1713
|
+
void claim(value)
|
|
1714
|
+
},
|
|
1715
|
+
}, t(shortKey)),
|
|
1716
|
+
),
|
|
1717
|
+
)
|
|
1718
|
+
: h('label', { className: 'fc-card-check', onClick: event => event.stopPropagation() },
|
|
1719
|
+
h('input', {
|
|
1720
|
+
type: 'checkbox',
|
|
1721
|
+
checked: confirmed,
|
|
1722
|
+
disabled: busy,
|
|
1723
|
+
onChange: event => setConfirmed(event.target.checked),
|
|
1724
|
+
}),
|
|
1725
|
+
h('span', null, risky ? t('redPacket.confirmRisk') : t('redPacket.confirm')),
|
|
1726
|
+
),
|
|
1727
|
+
),
|
|
1728
|
+
)
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* @param {{message: object, mode: 'rich'|'plain', t: Function}} props - one message body.
|
|
1733
|
+
*/
|
|
1734
|
+
function MessageContent({ message, mode, t, siteUrl }) {
|
|
1735
|
+
if (message.type === 'unavailable') {
|
|
1736
|
+
return h('div', { className: 'fc-unavailable' }, t('card.unavailable'))
|
|
1737
|
+
}
|
|
1738
|
+
if (message.type === 'redPacket') {
|
|
1739
|
+
const card = message.card?.redPacket ?? message.card ?? {}
|
|
1740
|
+
return h(RedPacketCard, { message, card, t })
|
|
1741
|
+
}
|
|
1742
|
+
if (mode === 'plain') {
|
|
1743
|
+
return h('div', { className: 'fc-plain' }, message.type === 'text'
|
|
1744
|
+
? plainMessage(message, t)
|
|
1745
|
+
: messageSummary(message, t))
|
|
1746
|
+
}
|
|
1747
|
+
if (message.type === 'music') {
|
|
1748
|
+
const card = message.card?.music ?? message.card ?? {}
|
|
1749
|
+
return h('div', { className: 'fc-card fc-card-music' },
|
|
1750
|
+
h('div', { className: 'fc-card-title' }, t('card.music')),
|
|
1751
|
+
typeof card.title === 'string' && card.title !== '' ? h('div', { className: 'fc-card-body' }, card.title) : null,
|
|
1752
|
+
typeof card.from === 'string' && card.from !== '' ? h('div', { className: 'fc-card-meta' }, card.from) : null,
|
|
1753
|
+
)
|
|
1754
|
+
}
|
|
1755
|
+
if (message.type === 'weather') {
|
|
1756
|
+
const card = message.card?.weather ?? message.card ?? {}
|
|
1757
|
+
const first = value => typeof value === 'string' ? value.split(',')[0] : ''
|
|
1758
|
+
const description = first(card.st)
|
|
1759
|
+
const low = first(card.min)
|
|
1760
|
+
const high = first(card.max)
|
|
1761
|
+
const range = low !== '' && high !== '' ? `${low}~${high}` : ''
|
|
1762
|
+
return h('div', { className: 'fc-card fc-card-weather' },
|
|
1763
|
+
h('div', { className: 'fc-card-title' }, t('card.weather')),
|
|
1764
|
+
h('div', { className: 'fc-card-body' }, [first(card.date), description].filter(Boolean).join(' ')),
|
|
1765
|
+
h('div', { className: 'fc-card-meta' }, [range, typeof card.t === 'string' ? card.t : ''].filter(Boolean).join(' · ')),
|
|
1766
|
+
)
|
|
1767
|
+
}
|
|
1768
|
+
if (message.contentHtml !== '') {
|
|
1769
|
+
return h('div', {
|
|
1770
|
+
className: 'fc-html',
|
|
1771
|
+
dangerouslySetInnerHTML: { __html: prepareHtml(message.contentHtml, siteUrl) },
|
|
1772
|
+
})
|
|
1773
|
+
}
|
|
1774
|
+
return h('div', { className: 'fc-plain' }, message.content)
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* @param {{message: object, own: boolean, grouped: boolean, mode: string, t: Function}} props - one row.
|
|
1779
|
+
*/
|
|
1780
|
+
function MessageRow({ message, own, grouped, mode, t, siteUrl, medalIcons = [] }) {
|
|
1781
|
+
if (message.type === 'system') {
|
|
1782
|
+
return h('div', { className: 'fc-system' }, message.text)
|
|
1783
|
+
}
|
|
1784
|
+
const author = message.author ?? {}
|
|
1785
|
+
const name = displayUser(author)
|
|
1786
|
+
const avatarName = author.userNickname || author.userName || ''
|
|
1787
|
+
const medals = Array.isArray(message.medals) ? message.medals : []
|
|
1788
|
+
const resolvedMedals = medals
|
|
1789
|
+
.map(medal => {
|
|
1790
|
+
const icon = Array.isArray(medalIcons)
|
|
1791
|
+
? medalIcons.find(entry => (medal.id !== '' && entry.id === medal.id) || (medal.name !== '' && entry.name === medal.name))
|
|
1792
|
+
: undefined
|
|
1793
|
+
return icon?.url ? { ...medal, url: icon.url } : null
|
|
1794
|
+
})
|
|
1795
|
+
.filter(Boolean)
|
|
1796
|
+
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' },
|
|
1809
|
+
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 })),
|
|
1836
|
+
),
|
|
1837
|
+
)
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* @param {{t: Function, compact?: boolean, onDone?: Function}} props - login form.
|
|
1842
|
+
*/
|
|
1843
|
+
function LoginForm({ t, compact = false, onDone }) {
|
|
1844
|
+
const store = sharedStore
|
|
1845
|
+
const state = useStore()
|
|
1846
|
+
const id = React.useId()
|
|
1847
|
+
const [nameOrEmail, setNameOrEmail] = useState('')
|
|
1848
|
+
const [password, setPassword] = useState('')
|
|
1849
|
+
const [mfaCode, setMfaCode] = useState('')
|
|
1850
|
+
const [remember, setRemember] = useState(true)
|
|
1851
|
+
const [busy, setBusy] = useState(false)
|
|
1852
|
+
const [error, setError] = useState(null)
|
|
1853
|
+
const promptedMfa = state.mfaRequired || error?.mfaRequired === true
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* @param {SubmitEvent} event - form submit.
|
|
1857
|
+
*/
|
|
1858
|
+
const submit = async event => {
|
|
1859
|
+
event.preventDefault()
|
|
1860
|
+
if (busy) return
|
|
1861
|
+
setBusy(true)
|
|
1862
|
+
setError(null)
|
|
1863
|
+
const result = await store.login({ nameOrEmail, password, mfaCode, remember })
|
|
1864
|
+
setBusy(false)
|
|
1865
|
+
if (result.ok) {
|
|
1866
|
+
setPassword('')
|
|
1867
|
+
onDone?.()
|
|
1868
|
+
return
|
|
1869
|
+
}
|
|
1870
|
+
setError(result)
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
return h('form', { className: `fc-login${compact ? ' fc-login-compact' : ''}`, onSubmit: submit },
|
|
1874
|
+
h('div', { className: 'fc-field' },
|
|
1875
|
+
h('label', { className: 'fc-label', htmlFor: `${id}-account` }, t('login.account')),
|
|
1876
|
+
h('input', {
|
|
1877
|
+
id: `${id}-account`,
|
|
1878
|
+
className: 'fc-input',
|
|
1879
|
+
value: nameOrEmail,
|
|
1880
|
+
autoComplete: 'username',
|
|
1881
|
+
onChange: event => setNameOrEmail(event.target.value),
|
|
1882
|
+
}),
|
|
1883
|
+
),
|
|
1884
|
+
h('div', { className: 'fc-field' },
|
|
1885
|
+
h('label', { className: 'fc-label', htmlFor: `${id}-password` }, t('login.password')),
|
|
1886
|
+
h('input', {
|
|
1887
|
+
id: `${id}-password`,
|
|
1888
|
+
className: 'fc-input',
|
|
1889
|
+
type: 'password',
|
|
1890
|
+
value: password,
|
|
1891
|
+
autoComplete: 'current-password',
|
|
1892
|
+
onChange: event => setPassword(event.target.value),
|
|
1893
|
+
}),
|
|
1894
|
+
),
|
|
1895
|
+
h('div', { className: 'fc-field' },
|
|
1896
|
+
h('label', { className: 'fc-label', htmlFor: `${id}-mfa` }, t('login.mfa')),
|
|
1897
|
+
h('input', {
|
|
1898
|
+
id: `${id}-mfa`,
|
|
1899
|
+
className: 'fc-input',
|
|
1900
|
+
value: mfaCode,
|
|
1901
|
+
inputMode: 'numeric',
|
|
1902
|
+
autoComplete: 'one-time-code',
|
|
1903
|
+
placeholder: t('login.mfa'),
|
|
1904
|
+
onChange: event => setMfaCode(event.target.value),
|
|
1905
|
+
}),
|
|
1906
|
+
promptedMfa ? h('p', { className: 'fc-hint' }, t('login.needMfa')) : null,
|
|
1907
|
+
),
|
|
1908
|
+
h('label', { className: 'fc-check' },
|
|
1909
|
+
h('input', {
|
|
1910
|
+
type: 'checkbox',
|
|
1911
|
+
checked: remember,
|
|
1912
|
+
onChange: event => setRemember(event.target.checked),
|
|
1913
|
+
}),
|
|
1914
|
+
h('span', null, t('login.remember')),
|
|
1915
|
+
),
|
|
1916
|
+
error === null
|
|
1917
|
+
? null
|
|
1918
|
+
: h('p', { className: 'fc-error', role: 'alert' }, localizedError(error.code, error.message, t)),
|
|
1919
|
+
h('div', { className: 'fc-login-actions' },
|
|
1920
|
+
h('button', { className: 'fc-button fc-button-primary', type: 'submit', disabled: busy || nameOrEmail === '' || password === '' },
|
|
1921
|
+
busy ? t('login.busy') : t('login.submit'),
|
|
1922
|
+
),
|
|
1923
|
+
h('a', {
|
|
1924
|
+
className: 'fc-button fc-register',
|
|
1925
|
+
href: REGISTER_URL,
|
|
1926
|
+
target: '_blank',
|
|
1927
|
+
rel: 'noopener noreferrer',
|
|
1928
|
+
}, t('login.register')),
|
|
1929
|
+
),
|
|
1930
|
+
compact ? null : h('p', { className: 'fc-hint' }, t('login.hint')),
|
|
1931
|
+
)
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
/**
|
|
1935
|
+
* @param {{t: Function}} props - account card.
|
|
1936
|
+
*/
|
|
1937
|
+
function AccountCard({ t }) {
|
|
1938
|
+
const store = sharedStore
|
|
1939
|
+
const state = useStore()
|
|
1940
|
+
const [busy, setBusy] = useState(false)
|
|
1941
|
+
if (!state.loggedIn) {
|
|
1942
|
+
return h('div', { className: 'fc-panel' },
|
|
1943
|
+
h('p', { className: 'fc-hint' }, t('login.hint')),
|
|
1944
|
+
h(LoginForm, { t }),
|
|
1945
|
+
)
|
|
1946
|
+
}
|
|
1947
|
+
const name = displayUser(state.user)
|
|
1948
|
+
const avatarName = state.user?.userNickname || state.user?.userName || ''
|
|
1949
|
+
return h('div', { className: 'fc-panel fc-account' },
|
|
1950
|
+
h(Avatar, { url: state.user?.userAvatarURL ?? '', name: avatarName, size: 36 }),
|
|
1951
|
+
h('div', { className: 'fc-account-body' },
|
|
1952
|
+
h('div', { className: 'fc-account-name' }, name),
|
|
1953
|
+
),
|
|
1954
|
+
h('button', {
|
|
1955
|
+
className: 'fc-button',
|
|
1956
|
+
type: 'button',
|
|
1957
|
+
disabled: busy,
|
|
1958
|
+
onClick: async () => {
|
|
1959
|
+
setBusy(true)
|
|
1960
|
+
await store.logout()
|
|
1961
|
+
setBusy(false)
|
|
1962
|
+
},
|
|
1963
|
+
}, t('logout')),
|
|
1964
|
+
)
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
/**
|
|
1968
|
+
* @param {{t: Function}} props - the Settings section page.
|
|
1969
|
+
*/
|
|
1970
|
+
function SettingsSection({ t }) {
|
|
1971
|
+
const store = sharedStore
|
|
1972
|
+
const state = useStore()
|
|
1973
|
+
const [notificationError, setNotificationError] = useState(false)
|
|
1974
|
+
const supported = typeof Notification !== 'undefined'
|
|
1975
|
+
|
|
1976
|
+
const toggleNotifications = async () => {
|
|
1977
|
+
setNotificationError(false)
|
|
1978
|
+
if (state.prefs.notifications) {
|
|
1979
|
+
store.setNotifications(false)
|
|
1980
|
+
return
|
|
1981
|
+
}
|
|
1982
|
+
if (!supported) {
|
|
1983
|
+
setNotificationError(true)
|
|
1984
|
+
return
|
|
1985
|
+
}
|
|
1986
|
+
try {
|
|
1987
|
+
let permission = Notification.permission
|
|
1988
|
+
if (permission === 'default') permission = await Notification.requestPermission()
|
|
1989
|
+
if (permission !== 'granted') {
|
|
1990
|
+
setNotificationError(true)
|
|
1991
|
+
store.setNotifications(false)
|
|
1992
|
+
return
|
|
1993
|
+
}
|
|
1994
|
+
store.setNotifications(true)
|
|
1995
|
+
} catch {
|
|
1996
|
+
setNotificationError(true)
|
|
1997
|
+
store.setNotifications(false)
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
return h('div', { className: 'fc-settings' },
|
|
2002
|
+
h(Style),
|
|
2003
|
+
state.error === null
|
|
2004
|
+
? null
|
|
2005
|
+
: h('div', { className: 'fc-banner', role: 'alert' },
|
|
2006
|
+
h('span', null, localizedError(state.error.code, state.error.message, t)),
|
|
2007
|
+
h('button', {
|
|
2008
|
+
type: 'button',
|
|
2009
|
+
className: 'fc-icon-button',
|
|
2010
|
+
'aria-label': t('error.dismiss'),
|
|
2011
|
+
title: t('error.dismiss'),
|
|
2012
|
+
onClick: () => store.clearError(),
|
|
2013
|
+
}, '×'),
|
|
2014
|
+
),
|
|
2015
|
+
h('section', { className: 'fc-section' },
|
|
2016
|
+
h('h2', { className: 'fc-section-title' }, t('settings.account')),
|
|
2017
|
+
h(AccountCard, { t }),
|
|
2018
|
+
),
|
|
2019
|
+
h('section', { className: 'fc-section' },
|
|
2020
|
+
h('h2', { className: 'fc-section-title' }, t('settings.display')),
|
|
2021
|
+
h('p', { className: 'fc-hint' }, t('settings.display.hint')),
|
|
2022
|
+
h('div', { className: 'fc-segmented', role: 'group', 'aria-label': t('settings.display') },
|
|
2023
|
+
h('button', {
|
|
2024
|
+
type: 'button',
|
|
2025
|
+
className: `fc-segment${state.prefs.mode === 'rich' ? ' fc-segment-active' : ''}`,
|
|
2026
|
+
'aria-pressed': state.prefs.mode === 'rich',
|
|
2027
|
+
onClick: () => store.setMode('rich'),
|
|
2028
|
+
}, t('settings.display.rich')),
|
|
2029
|
+
h('button', {
|
|
2030
|
+
type: 'button',
|
|
2031
|
+
className: `fc-segment${state.prefs.mode === 'plain' ? ' fc-segment-active' : ''}`,
|
|
2032
|
+
'aria-pressed': state.prefs.mode === 'plain',
|
|
2033
|
+
onClick: () => store.setMode('plain'),
|
|
2034
|
+
}, t('settings.display.plain')),
|
|
2035
|
+
),
|
|
2036
|
+
),
|
|
2037
|
+
h('section', { className: 'fc-section' },
|
|
2038
|
+
h('div', { className: 'fc-row' },
|
|
2039
|
+
h('div', { className: 'fc-row-body' },
|
|
2040
|
+
h('div', { className: 'fc-row-title' }, t('settings.notifications')),
|
|
2041
|
+
h('div', { className: 'fc-hint' }, t('settings.notifications.hint')),
|
|
2042
|
+
),
|
|
2043
|
+
h('button', {
|
|
2044
|
+
type: 'button',
|
|
2045
|
+
role: 'switch',
|
|
2046
|
+
'aria-checked': state.prefs.notifications,
|
|
2047
|
+
'aria-label': t('settings.notifications'),
|
|
2048
|
+
className: `fc-switch${state.prefs.notifications ? ' fc-switch-on' : ''}`,
|
|
2049
|
+
onClick: () => { void toggleNotifications() },
|
|
2050
|
+
}, h('span', { className: 'fc-switch-thumb' })),
|
|
2051
|
+
),
|
|
2052
|
+
notificationError
|
|
2053
|
+
? h('p', { className: 'fc-error', role: 'alert' }, supported ? t('settings.notifications.denied') : t('settings.notifications.unsupported'))
|
|
2054
|
+
: null,
|
|
2055
|
+
),
|
|
2056
|
+
h('p', { className: 'fc-note' }, t('settings.credentialNote')),
|
|
2057
|
+
h('p', { className: 'fc-note' }, t('settings.version')),
|
|
2058
|
+
)
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
/**
|
|
2062
|
+
* A visible fallback for a render failure in the tab body, so a crash is
|
|
2063
|
+
* never an empty pane and the message can be reported without DevTools.
|
|
2064
|
+
*/
|
|
2065
|
+
class ChatBoundary extends React.Component {
|
|
2066
|
+
constructor(props) {
|
|
2067
|
+
super(props)
|
|
2068
|
+
this.state = { error: null }
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
static getDerivedStateFromError(error) {
|
|
2072
|
+
return { error }
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
componentDidCatch(error, info) {
|
|
2076
|
+
console.error('[fishpi-chat] chat panel crashed', error, info)
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
render() {
|
|
2080
|
+
if (this.state.error !== null) {
|
|
2081
|
+
const message = this.state.error instanceof Error ? this.state.error.message : String(this.state.error)
|
|
2082
|
+
const title = typeof this.props.t === 'function' ? this.props.t('error.crash') : 'FishPi chat error'
|
|
2083
|
+
return h('div', { className: 'fc-crash' }, h(Style), `${title}: ${message}`)
|
|
2084
|
+
}
|
|
2085
|
+
return this.props.children
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/** Slot entry for the chat body: boundary plus the real panel. */
|
|
2090
|
+
function ChatTabBody(props) {
|
|
2091
|
+
return h(ChatBoundary, { t: props.t }, h(ChatPanel, props))
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/**
|
|
2095
|
+
* @param {Function} t - bound translate.
|
|
2096
|
+
* @param {string} type - red-packet type id.
|
|
2097
|
+
* @returns {string} the localized type label.
|
|
2098
|
+
*/
|
|
2099
|
+
function redPacketTypeLabel(t, type) {
|
|
2100
|
+
const key = `redPacket.type.${type}`
|
|
2101
|
+
const label = t(key)
|
|
2102
|
+
return label === key ? t('redPacket.title') : label
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* @param {unknown} value - millisecond timestamp or a preformatted legacy string.
|
|
2107
|
+
* @returns {string} display text.
|
|
2108
|
+
*/
|
|
2109
|
+
function claimTime(value) {
|
|
2110
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
2111
|
+
try {
|
|
2112
|
+
return new Date(value).toLocaleString()
|
|
2113
|
+
} catch {
|
|
2114
|
+
return ''
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
return typeof value === 'string' ? value : ''
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* @param {object} detail - red-packet detail from the Host.
|
|
2122
|
+
* @returns {Array<{user: object, amount: number, time: unknown, gesture?: number, outcome?: string}>}
|
|
2123
|
+
*/
|
|
2124
|
+
function redPacketClaims(detail) {
|
|
2125
|
+
if (Array.isArray(detail?.claims)) {
|
|
2126
|
+
return detail.claims.map(entry => ({
|
|
2127
|
+
user: entry?.user ?? {},
|
|
2128
|
+
amount: Number(entry?.amount) || 0,
|
|
2129
|
+
time: entry?.claimedAt,
|
|
2130
|
+
gesture: entry?.gesture,
|
|
2131
|
+
outcome: entry?.outcome,
|
|
2132
|
+
}))
|
|
2133
|
+
}
|
|
2134
|
+
if (Array.isArray(detail?.who)) {
|
|
2135
|
+
return detail.who.map(entry => ({
|
|
2136
|
+
user: { userName: entry?.userName ?? '', userAvatarURL: entry?.avatar ?? '' },
|
|
2137
|
+
amount: Number(entry?.userMoney) || 0,
|
|
2138
|
+
time: entry?.time,
|
|
2139
|
+
}))
|
|
2140
|
+
}
|
|
2141
|
+
return []
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
/** Public user profile, with medal icons only. */
|
|
2145
|
+
function UserInfoDialog({ t }) {
|
|
2146
|
+
const store = sharedStore
|
|
2147
|
+
const state = useStore()
|
|
2148
|
+
const name = state.userInfoName
|
|
2149
|
+
const profile = state.userInfo
|
|
2150
|
+
|
|
2151
|
+
useEffect(() => {
|
|
2152
|
+
if (name === null) return undefined
|
|
2153
|
+
const onKey = event => {
|
|
2154
|
+
if (event.key === 'Escape') store.closeUserInfo()
|
|
2155
|
+
}
|
|
2156
|
+
document.addEventListener('keydown', onKey)
|
|
2157
|
+
return () => { document.removeEventListener('keydown', onKey) }
|
|
2158
|
+
}, [name, store])
|
|
2159
|
+
|
|
2160
|
+
if (name === null) return null
|
|
2161
|
+
|
|
2162
|
+
const error = state.userInfoError
|
|
2163
|
+
const medals = Array.isArray(state.userInfoMedals) ? state.userInfoMedals : []
|
|
2164
|
+
const identity = profile === null
|
|
2165
|
+
? []
|
|
2166
|
+
: [
|
|
2167
|
+
profile.userNo === '' ? '' : t('user.number', { number: profile.userNo }),
|
|
2168
|
+
profile.userCity === '' ? '' : t('user.location', { city: profile.userCity }),
|
|
2169
|
+
].filter(Boolean)
|
|
2170
|
+
const stats = profile === null
|
|
2171
|
+
? []
|
|
2172
|
+
: [
|
|
2173
|
+
profile.userPoint === undefined ? '' : t('user.points', { points: profile.userPoint }),
|
|
2174
|
+
profile.onlineMinute === undefined ? '' : t('user.online', { minutes: profile.onlineMinute }),
|
|
2175
|
+
].filter(Boolean)
|
|
2176
|
+
const memberUrl = profile === null
|
|
2177
|
+
? ''
|
|
2178
|
+
: `${state.siteUrl.replace(/\/+$/u, '')}/member/${encodeURIComponent(profile.userName || name)}`
|
|
2179
|
+
|
|
2180
|
+
return h('div', {
|
|
2181
|
+
className: 'fc-modal-mask',
|
|
2182
|
+
role: 'presentation',
|
|
2183
|
+
onClick: () => store.closeUserInfo(),
|
|
2184
|
+
},
|
|
2185
|
+
h('div', {
|
|
2186
|
+
className: 'fc-modal',
|
|
2187
|
+
role: 'dialog',
|
|
2188
|
+
'aria-modal': 'true',
|
|
2189
|
+
'aria-label': t('user.title'),
|
|
2190
|
+
onClick: event => event.stopPropagation(),
|
|
2191
|
+
},
|
|
2192
|
+
h('div', { className: 'fc-modal-head' },
|
|
2193
|
+
h('div', { className: 'fc-modal-title' }, t('user.title')),
|
|
2194
|
+
h('button', {
|
|
2195
|
+
type: 'button',
|
|
2196
|
+
className: 'fc-icon-button',
|
|
2197
|
+
'aria-label': t('user.close'),
|
|
2198
|
+
title: t('user.close'),
|
|
2199
|
+
onClick: () => store.closeUserInfo(),
|
|
2200
|
+
}, '×'),
|
|
2201
|
+
),
|
|
2202
|
+
state.userInfoLoading && profile === null
|
|
2203
|
+
? h('p', { className: 'fc-hint' }, t('loading'))
|
|
2204
|
+
: null,
|
|
2205
|
+
error === null
|
|
2206
|
+
? null
|
|
2207
|
+
: h('div', { className: 'fc-banner', role: 'alert' },
|
|
2208
|
+
h('span', null, localizedError(error.code, error.message, t)),
|
|
2209
|
+
h('button', {
|
|
2210
|
+
type: 'button',
|
|
2211
|
+
className: 'fc-icon-button',
|
|
2212
|
+
'aria-label': t('redPacket.retry'),
|
|
2213
|
+
title: t('redPacket.retry'),
|
|
2214
|
+
onClick: () => { void store.openUserInfo(name) },
|
|
2215
|
+
}, '⟳'),
|
|
2216
|
+
),
|
|
2217
|
+
profile === null
|
|
2218
|
+
? null
|
|
2219
|
+
: h('div', { className: 'fc-user-body' },
|
|
2220
|
+
h('div', { className: 'fc-user-head' },
|
|
2221
|
+
h(Avatar, {
|
|
2222
|
+
url: profile.userAvatarURL ?? '',
|
|
2223
|
+
name: profile.userNickname || profile.userName || '',
|
|
2224
|
+
size: 56,
|
|
2225
|
+
}),
|
|
2226
|
+
h('div', { className: 'fc-user-heading' },
|
|
2227
|
+
h('div', { className: 'fc-user-name-line' },
|
|
2228
|
+
h('div', { className: 'fc-user-name' }, displayUser(profile)),
|
|
2229
|
+
h('a', {
|
|
2230
|
+
className: 'fc-user-home-link',
|
|
2231
|
+
href: memberUrl,
|
|
2232
|
+
target: '_blank',
|
|
2233
|
+
rel: 'noopener noreferrer',
|
|
2234
|
+
}, t('user.home')),
|
|
2235
|
+
),
|
|
2236
|
+
profile.userRole !== ''
|
|
2237
|
+
? h('div', { className: 'fc-user-role' }, profile.userRole)
|
|
2238
|
+
: null,
|
|
2239
|
+
identity.length > 0
|
|
2240
|
+
? h('div', { className: 'fc-user-meta' }, identity.join(' · '))
|
|
2241
|
+
: null,
|
|
2242
|
+
stats.length > 0
|
|
2243
|
+
? h('div', { className: 'fc-user-meta' }, stats.join(' · '))
|
|
2244
|
+
: null,
|
|
2245
|
+
),
|
|
2246
|
+
),
|
|
2247
|
+
profile.userIntro !== ''
|
|
2248
|
+
? h('div', { className: 'fc-user-intro' }, profile.userIntro)
|
|
2249
|
+
: null,
|
|
2250
|
+
profile.userURL !== ''
|
|
2251
|
+
? h('div', { className: 'fc-user-links' },
|
|
2252
|
+
h('a', {
|
|
2253
|
+
className: 'fc-user-profile-link',
|
|
2254
|
+
href: profile.userURL,
|
|
2255
|
+
target: '_blank',
|
|
2256
|
+
rel: 'noopener noreferrer',
|
|
2257
|
+
}, t('user.profileLink')),
|
|
2258
|
+
)
|
|
2259
|
+
: null,
|
|
2260
|
+
medals.length > 0
|
|
2261
|
+
? h('div', { className: 'fc-user-medals-section' },
|
|
2262
|
+
h('div', { className: 'fc-modal-section-title' }, t('user.medals')),
|
|
2263
|
+
h('div', { className: 'fc-user-medals' },
|
|
2264
|
+
medals.map(medal => h('div', { className: 'fc-medal-row', key: medal.id || medal.name || medal.url },
|
|
2265
|
+
h('img', {
|
|
2266
|
+
className: 'fc-medal-icon',
|
|
2267
|
+
src: medal.url,
|
|
2268
|
+
alt: medal.name,
|
|
2269
|
+
title: [medal.name, medal.description].filter(Boolean).join(' · '),
|
|
2270
|
+
loading: 'lazy',
|
|
2271
|
+
referrerPolicy: 'no-referrer',
|
|
2272
|
+
onError: event => { event.currentTarget.style.display = 'none' },
|
|
2273
|
+
}),
|
|
2274
|
+
h('div', { className: 'fc-medal-text' },
|
|
2275
|
+
h('div', { className: 'fc-medal-name' }, medal.name),
|
|
2276
|
+
medal.description !== ''
|
|
2277
|
+
? h('div', { className: 'fc-medal-meta' }, medal.description)
|
|
2278
|
+
: null,
|
|
2279
|
+
),
|
|
2280
|
+
)),
|
|
2281
|
+
),
|
|
2282
|
+
)
|
|
2283
|
+
: null,
|
|
2284
|
+
),
|
|
2285
|
+
),
|
|
2286
|
+
)
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
/** Red-packet detail and claim dialog. */
|
|
2290
|
+
function RedPacketDialog({ t }) {
|
|
2291
|
+
const store = sharedStore
|
|
2292
|
+
const state = useStore()
|
|
2293
|
+
const id = state.redPacketId
|
|
2294
|
+
const [riskAccepted, setRiskAccepted] = useState(false)
|
|
2295
|
+
const [gesture, setGesture] = useState(null)
|
|
2296
|
+
|
|
2297
|
+
useEffect(() => {
|
|
2298
|
+
setRiskAccepted(false)
|
|
2299
|
+
const initial = sharedStore.getSnapshot().redPacketGesture
|
|
2300
|
+
setGesture(Number.isInteger(initial) ? initial : null)
|
|
2301
|
+
}, [id])
|
|
2302
|
+
|
|
2303
|
+
useEffect(() => {
|
|
2304
|
+
if (id === null) return undefined
|
|
2305
|
+
const onKey = event => {
|
|
2306
|
+
if (event.key === 'Escape') store.closeRedPacket()
|
|
2307
|
+
}
|
|
2308
|
+
document.addEventListener('keydown', onKey)
|
|
2309
|
+
return () => { document.removeEventListener('keydown', onKey) }
|
|
2310
|
+
}, [id, store])
|
|
2311
|
+
|
|
2312
|
+
if (id === null) return null
|
|
2313
|
+
|
|
2314
|
+
const detail = state.redPacket
|
|
2315
|
+
const error = state.redPacketError
|
|
2316
|
+
const claim = state.redPacketClaim
|
|
2317
|
+
const myClaim = detail?.currentUserClaim ?? claim
|
|
2318
|
+
const type = typeof detail?.type === 'string' ? detail.type : ''
|
|
2319
|
+
const isRps = type === 'rockPaperScissors'
|
|
2320
|
+
const risky = type === 'heartbeat' || isRps
|
|
2321
|
+
const needsRiskCheck = type === 'heartbeat'
|
|
2322
|
+
const count = Number(detail?.count) || 0
|
|
2323
|
+
const got = Number(detail?.got) || 0
|
|
2324
|
+
const finished = detail !== null && count > 0 && got >= count
|
|
2325
|
+
const claims = detail === null ? [] : redPacketClaims(detail)
|
|
2326
|
+
const own = detail?.sender?.id !== undefined
|
|
2327
|
+
&& String(detail.sender.id) === (state.user?.id ?? '')
|
|
2328
|
+
const canClaim = detail !== null
|
|
2329
|
+
&& detail.legacy !== true
|
|
2330
|
+
&& !finished
|
|
2331
|
+
&& myClaim === null
|
|
2332
|
+
&& !state.redPacketClaiming
|
|
2333
|
+
&& !(own && type !== 'heartbeat')
|
|
2334
|
+
&& (!needsRiskCheck || riskAccepted)
|
|
2335
|
+
&& (!isRps || gesture !== null)
|
|
2336
|
+
|
|
2337
|
+
const amountText = value => {
|
|
2338
|
+
const amount = Number(value) || 0
|
|
2339
|
+
return amount > 0 ? `+${amount}` : String(amount)
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
const submit = async () => {
|
|
2343
|
+
if (!canClaim) return
|
|
2344
|
+
await store.claimRedPacket({
|
|
2345
|
+
riskAccepted: isRps ? true : riskAccepted,
|
|
2346
|
+
gesture: isRps && gesture !== null ? gesture : undefined,
|
|
2347
|
+
})
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
const close = h('button', {
|
|
2351
|
+
type: 'button',
|
|
2352
|
+
className: 'fc-icon-button',
|
|
2353
|
+
'aria-label': t('redPacket.close'),
|
|
2354
|
+
title: t('redPacket.close'),
|
|
2355
|
+
onClick: () => store.closeRedPacket(),
|
|
2356
|
+
}, '×')
|
|
2357
|
+
|
|
2358
|
+
const dialogTitle = detail === null ? t('redPacket.title') : redPacketTypeLabel(t, detail.type)
|
|
2359
|
+
const header = h('div', { className: 'fc-modal-head' },
|
|
2360
|
+
h('div', { className: 'fc-modal-title' }, dialogTitle),
|
|
2361
|
+
close,
|
|
2362
|
+
)
|
|
2363
|
+
|
|
2364
|
+
const claimRows = claims.length === 0
|
|
2365
|
+
? h('p', { className: 'fc-hint' }, t('redPacket.noClaims'))
|
|
2366
|
+
: h('div', { className: 'fc-claims' }, claims.map((entry, index) => {
|
|
2367
|
+
const name = displayUser(entry.user)
|
|
2368
|
+
const avatarName = entry.user?.userNickname || entry.user?.userName || ''
|
|
2369
|
+
return h('div', { className: 'fc-claim-row', key: `${index}-${name}` },
|
|
2370
|
+
entry.user?.userName
|
|
2371
|
+
? h('button', {
|
|
2372
|
+
type: 'button',
|
|
2373
|
+
className: 'fc-avatar-button',
|
|
2374
|
+
'aria-label': name,
|
|
2375
|
+
onClick: () => { void sharedStore.openUserInfo(entry.user.userName) },
|
|
2376
|
+
}, h(Avatar, { url: entry.user?.userAvatarURL ?? '', name: avatarName, size: 22 }))
|
|
2377
|
+
: h(Avatar, { url: entry.user?.userAvatarURL ?? '', name: avatarName, size: 22 }),
|
|
2378
|
+
entry.user?.userName
|
|
2379
|
+
? h('button', {
|
|
2380
|
+
type: 'button',
|
|
2381
|
+
className: 'fc-claim-name fc-user-link',
|
|
2382
|
+
onClick: () => { void sharedStore.openUserInfo(entry.user.userName) },
|
|
2383
|
+
}, name)
|
|
2384
|
+
: h('span', { className: 'fc-claim-name' }, name),
|
|
2385
|
+
entry.outcome === undefined ? null : h('span', { className: 'fc-claim-outcome' }, t(`redPacket.outcome.${entry.outcome}`)),
|
|
2386
|
+
h('span', { className: `fc-claim-amount${entry.amount < 0 ? ' fc-claim-negative' : ''}` }, amountText(entry.amount)),
|
|
2387
|
+
h('span', { className: 'fc-claim-time' }, claimTime(entry.time)),
|
|
2388
|
+
)
|
|
2389
|
+
}))
|
|
2390
|
+
|
|
2391
|
+
let footer = null
|
|
2392
|
+
if (detail !== null && detail.legacy === true) {
|
|
2393
|
+
footer = h('p', { className: 'fc-hint' }, t('redPacket.legacy'))
|
|
2394
|
+
} else if (myClaim !== null && myClaim !== undefined) {
|
|
2395
|
+
// The claims list already carries this account's amount; keep the
|
|
2396
|
+
// detail neutral instead of repeating a personal ledger line.
|
|
2397
|
+
footer = null
|
|
2398
|
+
} else if (finished) {
|
|
2399
|
+
footer = h('p', { className: 'fc-hint' }, t('redPacket.finished'))
|
|
2400
|
+
} else if (own && type !== 'heartbeat') {
|
|
2401
|
+
footer = h('p', { className: 'fc-hint' }, t('redPacket.own'))
|
|
2402
|
+
} else if (detail !== null) {
|
|
2403
|
+
footer = h('div', { className: 'fc-claim-actions' },
|
|
2404
|
+
risky
|
|
2405
|
+
? h('p', { className: 'fc-modal-warning' }, isRps ? t('redPacket.riskRps') : t('redPacket.riskHeartbeat'))
|
|
2406
|
+
: null,
|
|
2407
|
+
needsRiskCheck
|
|
2408
|
+
? h('label', { className: 'fc-check' },
|
|
2409
|
+
h('input', {
|
|
2410
|
+
type: 'checkbox',
|
|
2411
|
+
checked: riskAccepted,
|
|
2412
|
+
onChange: event => setRiskAccepted(event.target.checked),
|
|
2413
|
+
}),
|
|
2414
|
+
h('span', null, t('redPacket.riskAccept')),
|
|
2415
|
+
)
|
|
2416
|
+
: null,
|
|
2417
|
+
isRps
|
|
2418
|
+
? h('div', { className: 'fc-gestures', role: 'group', 'aria-label': t('redPacket.gesture') },
|
|
2419
|
+
[[0, 'redPacket.shortRock', 'redPacket.rock'], [1, 'redPacket.shortScissors', 'redPacket.scissors'], [2, 'redPacket.shortPaper', 'redPacket.paper']].map(([value, shortKey, fullKey]) =>
|
|
2420
|
+
h('button', {
|
|
2421
|
+
key: value,
|
|
2422
|
+
type: 'button',
|
|
2423
|
+
className: `fc-segment${gesture === value ? ' fc-segment-active' : ''}`,
|
|
2424
|
+
'aria-pressed': gesture === value,
|
|
2425
|
+
title: t(fullKey),
|
|
2426
|
+
'aria-label': t(fullKey),
|
|
2427
|
+
onClick: () => setGesture(value),
|
|
2428
|
+
}, t(shortKey)),
|
|
2429
|
+
),
|
|
2430
|
+
)
|
|
2431
|
+
: null,
|
|
2432
|
+
h('button', {
|
|
2433
|
+
type: 'button',
|
|
2434
|
+
className: 'fc-button fc-button-primary',
|
|
2435
|
+
disabled: !canClaim,
|
|
2436
|
+
onClick: () => { void submit() },
|
|
2437
|
+
}, state.redPacketClaiming ? t('redPacket.claiming') : t('redPacket.claim')),
|
|
2438
|
+
)
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
return h('div', {
|
|
2442
|
+
className: 'fc-modal-mask',
|
|
2443
|
+
role: 'presentation',
|
|
2444
|
+
onClick: () => store.closeRedPacket(),
|
|
2445
|
+
},
|
|
2446
|
+
h('div', {
|
|
2447
|
+
className: 'fc-modal',
|
|
2448
|
+
role: 'dialog',
|
|
2449
|
+
'aria-modal': 'true',
|
|
2450
|
+
'aria-label': dialogTitle,
|
|
2451
|
+
onClick: event => event.stopPropagation(),
|
|
2452
|
+
},
|
|
2453
|
+
header,
|
|
2454
|
+
state.redPacketLoading && detail === null
|
|
2455
|
+
? h('p', { className: 'fc-hint' }, t('loading'))
|
|
2456
|
+
: null,
|
|
2457
|
+
error === null
|
|
2458
|
+
? null
|
|
2459
|
+
: h('div', { className: 'fc-banner', role: 'alert' },
|
|
2460
|
+
h('span', null, localizedError(error.code, error.message, t)),
|
|
2461
|
+
h('button', {
|
|
2462
|
+
type: 'button',
|
|
2463
|
+
className: 'fc-icon-button',
|
|
2464
|
+
'aria-label': t('redPacket.retry'),
|
|
2465
|
+
title: t('redPacket.retry'),
|
|
2466
|
+
onClick: () => { void store.openRedPacket(id) },
|
|
2467
|
+
}, '⟳'),
|
|
2468
|
+
),
|
|
2469
|
+
detail === null
|
|
2470
|
+
? null
|
|
2471
|
+
: h('div', { className: 'fc-modal-body' },
|
|
2472
|
+
h('div', { className: 'fc-card-meta' },
|
|
2473
|
+
redPacketTypeLabel(t, type),
|
|
2474
|
+
detail.sender !== null && detail.sender !== undefined
|
|
2475
|
+
? ' · '
|
|
2476
|
+
: '',
|
|
2477
|
+
detail.sender?.userName
|
|
2478
|
+
? h('button', {
|
|
2479
|
+
type: 'button',
|
|
2480
|
+
className: 'fc-user-link',
|
|
2481
|
+
onClick: () => { void sharedStore.openUserInfo(detail.sender.userName) },
|
|
2482
|
+
}, t('redPacket.from', { name: displayUser(detail.sender) }))
|
|
2483
|
+
: detail.sender !== null && detail.sender !== undefined
|
|
2484
|
+
? t('redPacket.from', { name: displayUser(detail.sender) })
|
|
2485
|
+
: null,
|
|
2486
|
+
),
|
|
2487
|
+
typeof detail.message === 'string' && detail.message !== ''
|
|
2488
|
+
? h('div', { className: 'fc-modal-message' }, detail.message)
|
|
2489
|
+
: null,
|
|
2490
|
+
h('div', { className: 'fc-redpacket-progress' },
|
|
2491
|
+
h('span', { style: { width: count > 0 ? `${Math.min(100, got / count * 100)}%` : '0%' } }),
|
|
2492
|
+
),
|
|
2493
|
+
h('div', { className: 'fc-card-meta' }, [
|
|
2494
|
+
t('redPacket.progress', { got, count }),
|
|
2495
|
+
detail.poolPoints === undefined ? '' : t('redPacket.pool', { points: detail.poolPoints }),
|
|
2496
|
+
].filter(Boolean).join(' · ')),
|
|
2497
|
+
h('div', { className: 'fc-modal-section-title' }, t('redPacket.claims')),
|
|
2498
|
+
claimRows,
|
|
2499
|
+
),
|
|
2500
|
+
footer,
|
|
2501
|
+
),
|
|
2502
|
+
)
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
/**
|
|
2506
|
+
* @param {{useTabInfo: Function, t: Function}} props - the right-Sidebar tab body.
|
|
2507
|
+
*/
|
|
2508
|
+
function ChatPanel({ useTabInfo, t }) {
|
|
2509
|
+
const store = sharedStore
|
|
2510
|
+
const state = useStore()
|
|
2511
|
+
const info = useTabInfo()
|
|
2512
|
+
const visible = info?.tab?.visible === true
|
|
2513
|
+
const mode = state.prefs.mode
|
|
2514
|
+
const [draft, setDraft] = useState('')
|
|
2515
|
+
const [atBottom, setAtBottom] = useState(true)
|
|
2516
|
+
const [mention, setMention] = useState({ open: false, items: [], index: 0, start: 0, end: 0, query: '' })
|
|
2517
|
+
const mentionTimerRef = useRef()
|
|
2518
|
+
const mentionSeqRef = useRef(0)
|
|
2519
|
+
const scrollRef = useRef(null)
|
|
2520
|
+
const textareaRef = useRef(null)
|
|
2521
|
+
const fileInputRef = useRef(null)
|
|
2522
|
+
const stickRef = useRef(true)
|
|
2523
|
+
const restoreRef = useRef(null)
|
|
2524
|
+
|
|
2525
|
+
useEffect(() => {
|
|
2526
|
+
store.setChatVisible(visible)
|
|
2527
|
+
return () => { store.setChatVisible(false) }
|
|
2528
|
+
}, [visible])
|
|
2529
|
+
|
|
2530
|
+
useLayoutEffect(() => {
|
|
2531
|
+
const element = scrollRef.current
|
|
2532
|
+
if (element === null) return
|
|
2533
|
+
if (restoreRef.current !== null) {
|
|
2534
|
+
const { height, top } = restoreRef.current
|
|
2535
|
+
restoreRef.current = null
|
|
2536
|
+
element.scrollTop = top + (element.scrollHeight - height)
|
|
2537
|
+
return
|
|
2538
|
+
}
|
|
2539
|
+
if (stickRef.current) element.scrollTop = element.scrollHeight
|
|
2540
|
+
}, [state.messages])
|
|
2541
|
+
|
|
2542
|
+
useEffect(() => {
|
|
2543
|
+
void store.loadMedalIcons(state.messages)
|
|
2544
|
+
}, [state.messages])
|
|
2545
|
+
|
|
2546
|
+
useEffect(() => {
|
|
2547
|
+
const element = textareaRef.current
|
|
2548
|
+
if (element === null) return
|
|
2549
|
+
element.style.height = 'auto'
|
|
2550
|
+
element.style.height = `${element.scrollHeight}px`
|
|
2551
|
+
}, [draft])
|
|
2552
|
+
|
|
2553
|
+
const onScroll = useCallback(() => {
|
|
2554
|
+
const element = scrollRef.current
|
|
2555
|
+
if (element === null) return
|
|
2556
|
+
const near = element.scrollHeight - element.scrollTop - element.clientHeight < 80
|
|
2557
|
+
stickRef.current = near
|
|
2558
|
+
setAtBottom(near)
|
|
2559
|
+
}, [])
|
|
2560
|
+
|
|
2561
|
+
const loadOlder = async () => {
|
|
2562
|
+
const element = scrollRef.current
|
|
2563
|
+
if (element !== null) restoreRef.current = { height: element.scrollHeight, top: element.scrollTop }
|
|
2564
|
+
const added = await store.loadOlder()
|
|
2565
|
+
if (added === 0) restoreRef.current = null
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
const doSend = async () => {
|
|
2569
|
+
const content = draft.trim()
|
|
2570
|
+
if (content === '' || state.sending) return
|
|
2571
|
+
stickRef.current = true
|
|
2572
|
+
const result = await store.send(content)
|
|
2573
|
+
if (result.ok) setDraft(current => current === content ? '' : current)
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
const onKeyDown = event => {
|
|
2577
|
+
if (event.isComposing === true || event.nativeEvent?.isComposing === true) return
|
|
2578
|
+
if (mention.open) {
|
|
2579
|
+
if (event.key === 'Escape') {
|
|
2580
|
+
event.preventDefault()
|
|
2581
|
+
closeMention()
|
|
2582
|
+
return
|
|
2583
|
+
}
|
|
2584
|
+
if (mention.items.length > 0) {
|
|
2585
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
2586
|
+
event.preventDefault()
|
|
2587
|
+
const direction = event.key === 'ArrowDown' ? 1 : -1
|
|
2588
|
+
setMention(current => ({
|
|
2589
|
+
...current,
|
|
2590
|
+
index: (current.index + direction + current.items.length) % current.items.length,
|
|
2591
|
+
}))
|
|
2592
|
+
return
|
|
2593
|
+
}
|
|
2594
|
+
if (event.key === 'Enter' || event.key === 'Tab') {
|
|
2595
|
+
event.preventDefault()
|
|
2596
|
+
selectMention(mention.items[mention.index] ?? mention.items[0])
|
|
2597
|
+
return
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
if (event.key !== 'Enter' || event.shiftKey || event.isComposing === true || event.nativeEvent?.isComposing === true) return
|
|
2602
|
+
event.preventDefault()
|
|
2603
|
+
void doSend()
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
const appendFiles = async files => {
|
|
2607
|
+
const images = [...files].filter(file => file !== null
|
|
2608
|
+
&& typeof file === 'object'
|
|
2609
|
+
&& typeof file.type === 'string'
|
|
2610
|
+
&& file.type.startsWith('image/'))
|
|
2611
|
+
if (images.length === 0 || state.uploadingImages) return
|
|
2612
|
+
const result = await store.uploadImages(images)
|
|
2613
|
+
if (!result.ok || !Array.isArray(result.files) || result.files.length === 0) return
|
|
2614
|
+
const markdown = result.files
|
|
2615
|
+
.map(file => ``)
|
|
2616
|
+
.join('\n')
|
|
2617
|
+
setDraft(current => {
|
|
2618
|
+
const existing = current.replace(/\s+$/u, '')
|
|
2619
|
+
return existing === '' ? markdown : `${existing}\n${markdown}`
|
|
2620
|
+
})
|
|
2621
|
+
requestAnimationFrame(() => textareaRef.current?.focus())
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
const onPaste = event => {
|
|
2625
|
+
const files = [...(event.clipboardData?.files ?? [])]
|
|
2626
|
+
.filter(file => file.type.startsWith('image/'))
|
|
2627
|
+
if (files.length === 0) {
|
|
2628
|
+
for (const item of event.clipboardData?.items ?? []) {
|
|
2629
|
+
if (item.kind !== 'file' || !item.type.startsWith('image/')) continue
|
|
2630
|
+
const file = item.getAsFile()
|
|
2631
|
+
if (file !== null) files.push(file)
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
if (files.length === 0) return
|
|
2635
|
+
event.preventDefault()
|
|
2636
|
+
void appendFiles(files)
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
const closeMention = () => {
|
|
2640
|
+
clearTimeout(mentionTimerRef.current)
|
|
2641
|
+
setMention(current => current.open || current.items.length > 0
|
|
2642
|
+
? { open: false, items: [], index: 0, start: 0, end: 0, query: '' }
|
|
2643
|
+
: current)
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
const updateMention = (value, cursor) => {
|
|
2647
|
+
const before = value.slice(0, cursor)
|
|
2648
|
+
const match = /(^|[^\w-])@([A-Za-z0-9_-]{0,64})$/u.exec(before)
|
|
2649
|
+
if (match === null) {
|
|
2650
|
+
closeMention()
|
|
2651
|
+
return
|
|
2652
|
+
}
|
|
2653
|
+
const query = match[2]
|
|
2654
|
+
const start = cursor - query.length - 1
|
|
2655
|
+
if (query === '') {
|
|
2656
|
+
clearTimeout(mentionTimerRef.current)
|
|
2657
|
+
mentionSeqRef.current += 1
|
|
2658
|
+
setMention({
|
|
2659
|
+
open: true,
|
|
2660
|
+
items: state.onlineUsers.slice(0, 8),
|
|
2661
|
+
index: 0,
|
|
2662
|
+
start,
|
|
2663
|
+
end: cursor,
|
|
2664
|
+
query,
|
|
2665
|
+
})
|
|
2666
|
+
return
|
|
2667
|
+
}
|
|
2668
|
+
const lowered = query.toLowerCase()
|
|
2669
|
+
const localMatches = state.onlineUsers.filter(user => (
|
|
2670
|
+
typeof user.userName === 'string' && user.userName.toLowerCase().includes(lowered)
|
|
2671
|
+
) || (
|
|
2672
|
+
typeof user.userNickname === 'string' && user.userNickname.toLowerCase().includes(lowered)
|
|
2673
|
+
)).slice(0, 8)
|
|
2674
|
+
setMention(current => ({
|
|
2675
|
+
open: true,
|
|
2676
|
+
items: current.query === query ? current.items : localMatches,
|
|
2677
|
+
index: 0,
|
|
2678
|
+
start,
|
|
2679
|
+
end: cursor,
|
|
2680
|
+
query,
|
|
2681
|
+
}))
|
|
2682
|
+
clearTimeout(mentionTimerRef.current)
|
|
2683
|
+
const seq = ++mentionSeqRef.current
|
|
2684
|
+
mentionTimerRef.current = setTimeout(async () => {
|
|
2685
|
+
const items = await store.suggestUsers(query)
|
|
2686
|
+
if (seq !== mentionSeqRef.current) return
|
|
2687
|
+
const seen = new Set()
|
|
2688
|
+
const merged = [...localMatches, ...items].filter(user => {
|
|
2689
|
+
const key = `${user.id ?? ''}:${(user.userName ?? '').toLowerCase()}`
|
|
2690
|
+
if (seen.has(key)) return false
|
|
2691
|
+
seen.add(key)
|
|
2692
|
+
return true
|
|
2693
|
+
}).slice(0, 8)
|
|
2694
|
+
setMention(current => current.open && current.query === query
|
|
2695
|
+
? { ...current, items: merged, index: 0 }
|
|
2696
|
+
: current)
|
|
2697
|
+
}, 180)
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
const selectMention = user => {
|
|
2701
|
+
const userName = typeof user?.userName === 'string' ? user.userName : ''
|
|
2702
|
+
if (userName === '') {
|
|
2703
|
+
closeMention()
|
|
2704
|
+
return
|
|
2705
|
+
}
|
|
2706
|
+
const inserted = `@${userName} `
|
|
2707
|
+
const next = draft.slice(0, mention.start) + inserted + draft.slice(mention.end)
|
|
2708
|
+
setDraft(next)
|
|
2709
|
+
closeMention()
|
|
2710
|
+
requestAnimationFrame(() => {
|
|
2711
|
+
const element = textareaRef.current
|
|
2712
|
+
if (element === null) return
|
|
2713
|
+
element.focus()
|
|
2714
|
+
const position = mention.start + inserted.length
|
|
2715
|
+
element.setSelectionRange(position, position)
|
|
2716
|
+
})
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
const retry = async () => {
|
|
2720
|
+
store.clearError()
|
|
2721
|
+
await store.syncAll()
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
const header = h('div', { className: 'fc-header' },
|
|
2725
|
+
h('div', { className: 'fc-header-main' },
|
|
2726
|
+
h('span', { className: 'fc-title' }, t('tabTitle')),
|
|
2727
|
+
h(StatusDot, { state: state.connection, t }),
|
|
2728
|
+
state.connection === 'connected'
|
|
2729
|
+
? null
|
|
2730
|
+
: h('span', { className: 'fc-status-text' }, state.connection === 'connecting' ? t('status.connecting') : t('status.disconnected')),
|
|
2731
|
+
state.loggedIn && state.user?.userName
|
|
2732
|
+
? h('button', {
|
|
2733
|
+
type: 'button',
|
|
2734
|
+
className: 'fc-meta fc-user-link',
|
|
2735
|
+
onClick: () => { void store.openUserInfo(state.user.userName) },
|
|
2736
|
+
}, displayUser(state.user))
|
|
2737
|
+
: state.loggedIn
|
|
2738
|
+
? h('span', { className: 'fc-meta' }, displayUser(state.user))
|
|
2739
|
+
: null,
|
|
2740
|
+
),
|
|
2741
|
+
h('div', { className: 'fc-header-actions' },
|
|
2742
|
+
h('span', { className: 'fc-meta' }, t('online', { count: state.online })),
|
|
2743
|
+
state.loggedIn
|
|
2744
|
+
? h('button', {
|
|
2745
|
+
type: 'button',
|
|
2746
|
+
className: 'fc-icon-button',
|
|
2747
|
+
title: t('refresh'),
|
|
2748
|
+
'aria-label': t('refresh'),
|
|
2749
|
+
onClick: () => { void retry() },
|
|
2750
|
+
}, h('span', { 'aria-hidden': 'true' }, '⟳'))
|
|
2751
|
+
: null,
|
|
2752
|
+
),
|
|
2753
|
+
state.topic !== ''
|
|
2754
|
+
? h('div', { className: 'fc-topic', title: state.topic }, `${t('topic')}: ${state.topic}`)
|
|
2755
|
+
: null,
|
|
2756
|
+
)
|
|
2757
|
+
|
|
2758
|
+
const errorBanner = state.error === null
|
|
2759
|
+
? null
|
|
2760
|
+
: h('div', { className: 'fc-banner', role: 'alert' },
|
|
2761
|
+
h('span', null, localizedError(state.error.code, state.error.message, t)),
|
|
2762
|
+
h('button', {
|
|
2763
|
+
type: 'button',
|
|
2764
|
+
className: 'fc-icon-button',
|
|
2765
|
+
'aria-label': t('error.dismiss'),
|
|
2766
|
+
title: t('error.dismiss'),
|
|
2767
|
+
onClick: () => store.clearError(),
|
|
2768
|
+
}, '×'),
|
|
2769
|
+
)
|
|
2770
|
+
|
|
2771
|
+
if (!state.loaded) {
|
|
2772
|
+
return h('div', { className: 'fc-root' },
|
|
2773
|
+
h(Style), header, h('div', { className: 'fc-empty' }, t('loading')),
|
|
2774
|
+
h(RedPacketDialog, { t }), h(UserInfoDialog, { t }))
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
if (!state.loggedIn) {
|
|
2778
|
+
return h('div', { className: 'fc-root' },
|
|
2779
|
+
h(Style),
|
|
2780
|
+
header,
|
|
2781
|
+
errorBanner,
|
|
2782
|
+
h('div', { className: 'fc-login-wrap' },
|
|
2783
|
+
h('div', { className: 'fc-login-title' }, t('login.title')),
|
|
2784
|
+
h(LoginForm, { t, compact: true }),
|
|
2785
|
+
),
|
|
2786
|
+
h(RedPacketDialog, { t }),
|
|
2787
|
+
h(UserInfoDialog, { t }),
|
|
2788
|
+
)
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
let previous = null
|
|
2792
|
+
const rows = []
|
|
2793
|
+
for (const message of state.messages) {
|
|
2794
|
+
const authorId = message.author?.id ?? ''
|
|
2795
|
+
const authorName = message.author?.userName ?? ''
|
|
2796
|
+
const dateChanged = previous === null || dayKey(message.createdAt) !== dayKey(previous.createdAt)
|
|
2797
|
+
if (dateChanged) rows.push(h('div', { className: 'fc-day', key: `day-${message.id}` }, dayLabel(message.createdAt, t)))
|
|
2798
|
+
const grouped = !dateChanged
|
|
2799
|
+
&& previous !== null
|
|
2800
|
+
&& message.type === 'text'
|
|
2801
|
+
&& previous.type === 'text'
|
|
2802
|
+
&& 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
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
const body = state.loadingMessages && state.messages.length === 0
|
|
2819
|
+
? h('div', { className: 'fc-empty' }, t('loading'))
|
|
2820
|
+
: state.messages.length === 0
|
|
2821
|
+
? h('div', { className: 'fc-empty' }, t('empty'))
|
|
2822
|
+
: h('div', { className: 'fc-list', ref: scrollRef, onScroll, role: 'log', 'aria-label': t('messages') },
|
|
2823
|
+
state.hasMore
|
|
2824
|
+
? h('button', {
|
|
2825
|
+
type: 'button',
|
|
2826
|
+
className: 'fc-load-older',
|
|
2827
|
+
disabled: state.loadingOlder,
|
|
2828
|
+
onClick: () => { void loadOlder() },
|
|
2829
|
+
}, state.loadingOlder ? t('loading') : t('loadOlder'))
|
|
2830
|
+
: null,
|
|
2831
|
+
rows,
|
|
2832
|
+
)
|
|
2833
|
+
|
|
2834
|
+
return h('div', { className: 'fc-root' },
|
|
2835
|
+
h(Style),
|
|
2836
|
+
header,
|
|
2837
|
+
errorBanner,
|
|
2838
|
+
body,
|
|
2839
|
+
state.messages.length > 0 && !atBottom
|
|
2840
|
+
? h('button', {
|
|
2841
|
+
type: 'button',
|
|
2842
|
+
className: 'fc-jump',
|
|
2843
|
+
'aria-label': t('jump'),
|
|
2844
|
+
title: t('jump'),
|
|
2845
|
+
onClick: () => {
|
|
2846
|
+
stickRef.current = true
|
|
2847
|
+
setAtBottom(true)
|
|
2848
|
+
const element = scrollRef.current
|
|
2849
|
+
if (element !== null) element.scrollTop = element.scrollHeight
|
|
2850
|
+
},
|
|
2851
|
+
}, '↓')
|
|
2852
|
+
: null,
|
|
2853
|
+
h('div', { className: 'fc-composer' },
|
|
2854
|
+
mention.open
|
|
2855
|
+
? h('div', {
|
|
2856
|
+
className: 'fc-mention-popover',
|
|
2857
|
+
id: 'fc-mention-list',
|
|
2858
|
+
role: 'listbox',
|
|
2859
|
+
'aria-label': t('mention.title'),
|
|
2860
|
+
},
|
|
2861
|
+
mention.items.length === 0
|
|
2862
|
+
? h('div', { className: 'fc-mention-empty' }, mention.query === '' ? t('mention.hint') : t('mention.empty'))
|
|
2863
|
+
: mention.items.map((user, index) => h('button', {
|
|
2864
|
+
key: `${user.id || user.userName || index}-${index}`,
|
|
2865
|
+
type: 'button',
|
|
2866
|
+
role: 'option',
|
|
2867
|
+
tabIndex: -1,
|
|
2868
|
+
'aria-selected': index === mention.index,
|
|
2869
|
+
className: 'fc-mention-option',
|
|
2870
|
+
onMouseDown: event => event.preventDefault(),
|
|
2871
|
+
onClick: () => selectMention(user),
|
|
2872
|
+
},
|
|
2873
|
+
h(Avatar, {
|
|
2874
|
+
url: user.userAvatarURL ?? '',
|
|
2875
|
+
name: user.userNickname || user.userName || '',
|
|
2876
|
+
size: 22,
|
|
2877
|
+
}),
|
|
2878
|
+
h('span', { className: 'fc-mention-name' }, displayUser(user)),
|
|
2879
|
+
)),
|
|
2880
|
+
)
|
|
2881
|
+
: null,
|
|
2882
|
+
h('div', { className: 'fc-composer-row' },
|
|
2883
|
+
h('button', {
|
|
2884
|
+
type: 'button',
|
|
2885
|
+
className: 'fc-plus',
|
|
2886
|
+
title: t('composer.addImage'),
|
|
2887
|
+
'aria-label': t('composer.addImage'),
|
|
2888
|
+
disabled: state.uploadingImages,
|
|
2889
|
+
onClick: () => fileInputRef.current?.click(),
|
|
2890
|
+
}, '+'),
|
|
2891
|
+
h('textarea', {
|
|
2892
|
+
ref: textareaRef,
|
|
2893
|
+
className: 'fc-textarea',
|
|
2894
|
+
rows: 1,
|
|
2895
|
+
value: draft,
|
|
2896
|
+
'aria-label': t('composer.label'),
|
|
2897
|
+
'aria-autocomplete': 'list',
|
|
2898
|
+
'aria-expanded': mention.open,
|
|
2899
|
+
'aria-controls': mention.open ? 'fc-mention-list' : undefined,
|
|
2900
|
+
placeholder: t('composer.placeholder'),
|
|
2901
|
+
onChange: event => {
|
|
2902
|
+
const value = event.target.value
|
|
2903
|
+
setDraft(value)
|
|
2904
|
+
updateMention(value, event.target.selectionStart ?? value.length)
|
|
2905
|
+
},
|
|
2906
|
+
onKeyDown,
|
|
2907
|
+
onPaste,
|
|
2908
|
+
onBlur: () => { window.setTimeout(() => closeMention(), 120) },
|
|
2909
|
+
maxLength: 4096,
|
|
2910
|
+
}),
|
|
2911
|
+
h('button', {
|
|
2912
|
+
type: 'button',
|
|
2913
|
+
className: 'fc-button fc-button-primary fc-send',
|
|
2914
|
+
disabled: draft.trim() === '' || state.sending || state.uploadingImages,
|
|
2915
|
+
onClick: () => { void doSend() },
|
|
2916
|
+
}, state.sending ? t('composer.sending') : t('composer.send')),
|
|
2917
|
+
),
|
|
2918
|
+
h('input', {
|
|
2919
|
+
ref: fileInputRef,
|
|
2920
|
+
type: 'file',
|
|
2921
|
+
accept: 'image/*',
|
|
2922
|
+
multiple: true,
|
|
2923
|
+
style: { display: 'none' },
|
|
2924
|
+
onChange: event => {
|
|
2925
|
+
const files = [...(event.target.files ?? [])]
|
|
2926
|
+
event.target.value = ''
|
|
2927
|
+
if (files.length > 0) void appendFiles(files)
|
|
2928
|
+
},
|
|
2929
|
+
}),
|
|
2930
|
+
h('div', { className: 'fc-composer-foot' },
|
|
2931
|
+
h('span', { className: `fc-count${draft.length > 3800 ? ' fc-count-warn' : ''}` },
|
|
2932
|
+
state.uploadingImages
|
|
2933
|
+
? t('composer.uploading')
|
|
2934
|
+
: draft.length > 0 ? `${draft.length}/4096` : ''),
|
|
2935
|
+
),
|
|
2936
|
+
),
|
|
2937
|
+
h(RedPacketDialog, { t }),
|
|
2938
|
+
h(UserInfoDialog, { t }),
|
|
2939
|
+
)
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
/** Live tab chip: unread count beside the title. */
|
|
2943
|
+
function ChatTabTitle({ t }) {
|
|
2944
|
+
const state = useStore()
|
|
2945
|
+
return h('span', null, state.unread > 0 ? `${t('tabTitle')} · ${state.unread}` : t('tabTitle'))
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
/** Session-header chat button with an unread dot. */
|
|
2949
|
+
function HeaderButton({ t }) {
|
|
2950
|
+
const state = useStore()
|
|
2951
|
+
const unread = state.unread
|
|
2952
|
+
return h('button', {
|
|
2953
|
+
type: 'button',
|
|
2954
|
+
className: 'fc-header-entry',
|
|
2955
|
+
title: unread > 0 ? `${t('open')} (${unread})` : t('open'),
|
|
2956
|
+
'aria-label': unread > 0 ? `${t('open')} (${unread})` : t('open'),
|
|
2957
|
+
onClick: () => openChat(),
|
|
2958
|
+
},
|
|
2959
|
+
h(IconFish, { size: 17 }),
|
|
2960
|
+
unread > 0 ? h('span', { className: 'fc-badge', 'aria-hidden': 'true' }) : null,
|
|
2961
|
+
)
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
/** @type {ReturnType<createStore>|undefined} */
|
|
2965
|
+
let sharedStore
|
|
2966
|
+
/** @type {object|undefined} */
|
|
2967
|
+
let sharedContext
|
|
2968
|
+
|
|
2969
|
+
/**
|
|
2970
|
+
* @param {object} styleProps - unused; keeps the component signature stable.
|
|
2971
|
+
* @returns {object} a `<style>` element scoped to `fc-` classes.
|
|
2972
|
+
*/
|
|
2973
|
+
function Style() {
|
|
2974
|
+
return h('style', null, `
|
|
2975
|
+
.fc-root {
|
|
2976
|
+
display: flex;
|
|
2977
|
+
flex: 1 1 auto;
|
|
2978
|
+
flex-direction: column;
|
|
2979
|
+
width: 100%;
|
|
2980
|
+
height: 100%;
|
|
2981
|
+
min-width: 0;
|
|
2982
|
+
min-height: 0;
|
|
2983
|
+
position: relative;
|
|
2984
|
+
color: var(--dsw-alias-label-primary);
|
|
2985
|
+
font-size: var(--dsh-content-font-size, 14px);
|
|
2986
|
+
}
|
|
2987
|
+
.fc-crash {
|
|
2988
|
+
padding: 20px;
|
|
2989
|
+
color: var(--dsw-alias-state-error-primary);
|
|
2990
|
+
font-size: 13px;
|
|
2991
|
+
line-height: 20px;
|
|
2992
|
+
overflow-wrap: anywhere;
|
|
2993
|
+
white-space: pre-wrap;
|
|
2994
|
+
}
|
|
2995
|
+
.fc-header {
|
|
2996
|
+
flex: none;
|
|
2997
|
+
display: flex;
|
|
2998
|
+
flex-wrap: wrap;
|
|
2999
|
+
align-items: center;
|
|
3000
|
+
gap: 4px 8px;
|
|
3001
|
+
padding: 8px 12px;
|
|
3002
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
3003
|
+
}
|
|
3004
|
+
.fc-header-main { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
|
|
3005
|
+
.fc-header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
|
|
3006
|
+
.fc-topic { flex-basis: 100%; }
|
|
3007
|
+
.fc-title { font-size: 13px; font-weight: 500; }
|
|
3008
|
+
.fc-meta { color: var(--dsw-alias-label-tertiary); font-size: 12px; white-space: nowrap; }
|
|
3009
|
+
.fc-topic {
|
|
3010
|
+
overflow: hidden;
|
|
3011
|
+
color: var(--dsw-alias-label-secondary);
|
|
3012
|
+
font-size: 12px;
|
|
3013
|
+
line-height: 17px;
|
|
3014
|
+
text-overflow: ellipsis;
|
|
3015
|
+
white-space: nowrap;
|
|
3016
|
+
}
|
|
3017
|
+
.fc-status { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--dsw-alias-label-tertiary); }
|
|
3018
|
+
.fc-status-text { color: var(--dsw-alias-label-tertiary); font-size: 11px; white-space: nowrap; }
|
|
3019
|
+
.fc-status-connected { background: var(--dsw-alias-state-success-primary); }
|
|
3020
|
+
.fc-status-connecting { background: var(--dsw-alias-state-warn-primary); }
|
|
3021
|
+
.fc-status-disconnected { background: var(--dsw-alias-state-error-primary); }
|
|
3022
|
+
.fc-icon-button {
|
|
3023
|
+
display: inline-flex;
|
|
3024
|
+
align-items: center;
|
|
3025
|
+
justify-content: center;
|
|
3026
|
+
width: 24px;
|
|
3027
|
+
height: 24px;
|
|
3028
|
+
padding: 0;
|
|
3029
|
+
border: 0;
|
|
3030
|
+
border-radius: 6px;
|
|
3031
|
+
background: transparent;
|
|
3032
|
+
color: var(--dsw-alias-label-tertiary);
|
|
3033
|
+
font: inherit;
|
|
3034
|
+
font-size: 15px;
|
|
3035
|
+
cursor: pointer;
|
|
3036
|
+
}
|
|
3037
|
+
.fc-icon-button:hover { color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-interactive-bg-hover); }
|
|
3038
|
+
.fc-banner {
|
|
3039
|
+
display: flex;
|
|
3040
|
+
align-items: center;
|
|
3041
|
+
gap: 8px;
|
|
3042
|
+
margin: 6px 12px 0;
|
|
3043
|
+
padding: 6px 10px;
|
|
3044
|
+
border: 1px solid color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, transparent);
|
|
3045
|
+
border-radius: var(--dsw-radius-md);
|
|
3046
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
3047
|
+
background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, var(--dsw-alias-bg-layer-2));
|
|
3048
|
+
color: var(--dsw-alias-state-error-primary);
|
|
3049
|
+
font-size: 12px;
|
|
3050
|
+
line-height: 17px;
|
|
3051
|
+
}
|
|
3052
|
+
.fc-banner > span { flex: 1; min-width: 0; }
|
|
3053
|
+
.fc-list {
|
|
3054
|
+
flex: 1;
|
|
3055
|
+
min-height: 0;
|
|
3056
|
+
overflow-y: auto;
|
|
3057
|
+
overflow-x: hidden;
|
|
3058
|
+
padding: 8px 12px 12px;
|
|
3059
|
+
overscroll-behavior: contain;
|
|
3060
|
+
}
|
|
3061
|
+
.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; }
|
|
3064
|
+
.fc-msg.fc-own { flex-direction: row-reverse; }
|
|
3065
|
+
.fc-msg.fc-own .fc-msg-body { display: flex; flex-direction: column; align-items: flex-end; }
|
|
3066
|
+
.fc-msg.fc-own .fc-msg-head { flex-direction: row-reverse; }
|
|
3067
|
+
.fc-msg.fc-own .fc-msg-content { max-width: 100%; text-align: left; }
|
|
3068
|
+
.fc-msg.fc-own .fc-msg-name { color: var(--dsw-alias-brand-text); }
|
|
3069
|
+
.fc-avatar { flex: none; border-radius: 50%; object-fit: cover; background: var(--dsw-alias-bg-layer-2); }
|
|
3070
|
+
.fc-avatar-button {
|
|
3071
|
+
display: inline-flex;
|
|
3072
|
+
flex: none;
|
|
3073
|
+
padding: 0;
|
|
3074
|
+
border: 0;
|
|
3075
|
+
border-radius: 50%;
|
|
3076
|
+
background: none;
|
|
3077
|
+
cursor: pointer;
|
|
3078
|
+
}
|
|
3079
|
+
.fc-avatar-button:hover { opacity: 0.85; }
|
|
3080
|
+
.fc-avatar-button:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 1px; }
|
|
3081
|
+
.fc-avatar-spacer { flex: none; width: 28px; }
|
|
3082
|
+
.fc-avatar-fallback {
|
|
3083
|
+
display: inline-flex;
|
|
3084
|
+
align-items: center;
|
|
3085
|
+
justify-content: center;
|
|
3086
|
+
color: var(--dsw-alias-label-secondary);
|
|
3087
|
+
font-weight: 500;
|
|
3088
|
+
}
|
|
3089
|
+
.fc-msg-body { min-width: 0; flex: 1; }
|
|
3090
|
+
.fc-msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
|
|
3091
|
+
.fc-msg-name { overflow: hidden; font-size: 12px; font-weight: 500; color: var(--dsw-alias-label-secondary); text-overflow: ellipsis; white-space: nowrap; }
|
|
3092
|
+
.fc-user-link {
|
|
3093
|
+
padding: 0;
|
|
3094
|
+
border: 0;
|
|
3095
|
+
background: none;
|
|
3096
|
+
color: inherit;
|
|
3097
|
+
font: inherit;
|
|
3098
|
+
text-align: inherit;
|
|
3099
|
+
cursor: pointer;
|
|
3100
|
+
}
|
|
3101
|
+
.fc-user-link:hover { text-decoration: underline; color: var(--dsw-alias-link); }
|
|
3102
|
+
.fc-msg-time { flex: none; color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
3103
|
+
.fc-msg-medals { display: inline-flex; flex: none; align-items: center; gap: 2px; }
|
|
3104
|
+
.fc-msg-medal { width: 14px; height: 14px; border-radius: 3px; object-fit: cover; background: var(--dsw-alias-bg-layer-2); }
|
|
3105
|
+
.fc-msg-content { margin-top: 3px; min-width: 0; overflow-wrap: anywhere; line-height: 1.55; }
|
|
3106
|
+
.fc-html > :first-child, .fc-plain > :first-child { margin-top: 0; }
|
|
3107
|
+
.fc-html > :last-child, .fc-plain > :last-child { margin-bottom: 0; }
|
|
3108
|
+
.fc-html p, .fc-plain p { margin: 0 0 6px; }
|
|
3109
|
+
.fc-html a, .fc-plain a { color: var(--dsw-alias-link); text-decoration: none; }
|
|
3110
|
+
.fc-html a:hover, .fc-plain a:hover { text-decoration: underline; }
|
|
3111
|
+
.fc-html img { display: block; max-width: 100%; max-height: 320px; margin: 6px 0; border-radius: var(--dsw-radius-md); }
|
|
3112
|
+
.fc-html pre, .fc-plain pre {
|
|
3113
|
+
overflow-x: auto;
|
|
3114
|
+
margin: 6px 0;
|
|
3115
|
+
padding: 8px 10px;
|
|
3116
|
+
border-radius: var(--dsw-radius-md);
|
|
3117
|
+
background: var(--dsw-alias-markdown-code-block);
|
|
3118
|
+
font-family: var(--ds-font-family-code, ui-monospace, monospace);
|
|
3119
|
+
font-size: 12px;
|
|
3120
|
+
}
|
|
3121
|
+
.fc-html code, .fc-plain code {
|
|
3122
|
+
padding: 1px 4px;
|
|
3123
|
+
border-radius: 4px;
|
|
3124
|
+
background: var(--dsw-alias-markdown-inline-code);
|
|
3125
|
+
font-family: var(--ds-font-family-code, ui-monospace, monospace);
|
|
3126
|
+
font-size: 0.92em;
|
|
3127
|
+
}
|
|
3128
|
+
.fc-html blockquote, .fc-plain blockquote {
|
|
3129
|
+
margin: 6px 0;
|
|
3130
|
+
padding-left: 10px;
|
|
3131
|
+
border-left: 3px solid var(--dsw-alias-border-l2);
|
|
3132
|
+
color: var(--dsw-alias-label-secondary);
|
|
3133
|
+
}
|
|
3134
|
+
.fc-html ul, .fc-html ol, .fc-plain ul, .fc-plain ol { margin: 4px 0; padding-left: 22px; }
|
|
3135
|
+
.fc-html table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
|
|
3136
|
+
.fc-html th, .fc-html td { padding: 3px 6px; border: 1px solid var(--dsw-alias-border-l2); }
|
|
3137
|
+
.fc-plain { white-space: pre-wrap; }
|
|
3138
|
+
.fc-system { margin: 12px 0 4px; color: var(--dsw-alias-label-tertiary); font-size: 11px; text-align: center; }
|
|
3139
|
+
.fc-card {
|
|
3140
|
+
display: flex;
|
|
3141
|
+
flex-direction: column;
|
|
3142
|
+
gap: 3px;
|
|
3143
|
+
margin-top: 4px;
|
|
3144
|
+
padding: 8px 10px;
|
|
3145
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3146
|
+
border-radius: var(--dsw-radius-md);
|
|
3147
|
+
background: var(--dsw-alias-card-fill);
|
|
3148
|
+
}
|
|
3149
|
+
.fc-card-redpacket { border-color: var(--dsw-alias-state-warn-primary); }
|
|
3150
|
+
.fc-card-button {
|
|
3151
|
+
width: fit-content;
|
|
3152
|
+
max-width: 100%;
|
|
3153
|
+
box-sizing: border-box;
|
|
3154
|
+
appearance: none;
|
|
3155
|
+
font: inherit;
|
|
3156
|
+
color: inherit;
|
|
3157
|
+
text-align: left;
|
|
3158
|
+
cursor: pointer;
|
|
3159
|
+
}
|
|
3160
|
+
.fc-card-button:hover { background: var(--dsw-alias-card-fill-hover); }
|
|
3161
|
+
.fc-card-blocked { cursor: default; }
|
|
3162
|
+
.fc-card-controls { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
|
|
3163
|
+
.fc-card-check {
|
|
3164
|
+
display: flex;
|
|
3165
|
+
align-items: center;
|
|
3166
|
+
gap: 6px;
|
|
3167
|
+
color: var(--dsw-alias-label-secondary);
|
|
3168
|
+
font-size: 11px;
|
|
3169
|
+
line-height: 16px;
|
|
3170
|
+
cursor: pointer;
|
|
3171
|
+
}
|
|
3172
|
+
.fc-card-check input { margin: 0; accent-color: var(--dsw-alias-state-business-primary); }
|
|
3173
|
+
.fc-card-state { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
3174
|
+
.fc-gesture-row { display: flex; gap: 6px; margin-top: 4px; }
|
|
3175
|
+
.fc-gesture-button {
|
|
3176
|
+
display: inline-flex;
|
|
3177
|
+
align-items: center;
|
|
3178
|
+
justify-content: center;
|
|
3179
|
+
width: 26px;
|
|
3180
|
+
height: 26px;
|
|
3181
|
+
padding: 0;
|
|
3182
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3183
|
+
border-radius: var(--dsw-radius-sm);
|
|
3184
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
3185
|
+
color: var(--dsw-alias-label-secondary);
|
|
3186
|
+
cursor: pointer;
|
|
3187
|
+
}
|
|
3188
|
+
.fc-gesture-button:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
3189
|
+
.fc-gesture-button:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 1px; }
|
|
3190
|
+
.fc-gesture-button:disabled { opacity: 0.4; cursor: default; }
|
|
3191
|
+
.fc-card-title { font-size: 12px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
|
|
3192
|
+
.fc-card-body { font-size: 13px; }
|
|
3193
|
+
.fc-card-meta { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
3194
|
+
.fc-modal-mask {
|
|
3195
|
+
position: absolute;
|
|
3196
|
+
inset: 0;
|
|
3197
|
+
z-index: 30;
|
|
3198
|
+
display: flex;
|
|
3199
|
+
align-items: center;
|
|
3200
|
+
justify-content: center;
|
|
3201
|
+
padding: 12px;
|
|
3202
|
+
box-sizing: border-box;
|
|
3203
|
+
background: var(--dsw-alias-bg-mask-1);
|
|
3204
|
+
backdrop-filter: var(--dsw-mask-blur);
|
|
3205
|
+
}
|
|
3206
|
+
.fc-modal {
|
|
3207
|
+
display: flex;
|
|
3208
|
+
flex-direction: column;
|
|
3209
|
+
gap: 8px;
|
|
3210
|
+
width: 100%;
|
|
3211
|
+
max-width: 400px;
|
|
3212
|
+
max-height: 100%;
|
|
3213
|
+
overflow: auto;
|
|
3214
|
+
padding: 14px;
|
|
3215
|
+
box-sizing: border-box;
|
|
3216
|
+
border-radius: var(--dsw-radius-lg);
|
|
3217
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
3218
|
+
box-shadow: var(--dsw-elevation-prominent);
|
|
3219
|
+
color: var(--dsw-alias-label-primary);
|
|
3220
|
+
}
|
|
3221
|
+
.fc-modal-head { display: flex; align-items: center; gap: 8px; }
|
|
3222
|
+
.fc-modal-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; }
|
|
3223
|
+
.fc-modal-body { display: flex; flex-direction: column; gap: 6px; }
|
|
3224
|
+
.fc-modal-message { font-size: 13px; line-height: 19px; overflow-wrap: anywhere; }
|
|
3225
|
+
.fc-modal-section-title { margin-top: 4px; color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
3226
|
+
.fc-modal-warning {
|
|
3227
|
+
margin: 0;
|
|
3228
|
+
padding: 8px 10px;
|
|
3229
|
+
border-radius: var(--dsw-radius-md);
|
|
3230
|
+
background: var(--dsw-alias-state-warn-tertiary);
|
|
3231
|
+
color: var(--dsw-alias-state-warn-label);
|
|
3232
|
+
font-size: 12px;
|
|
3233
|
+
line-height: 18px;
|
|
3234
|
+
}
|
|
3235
|
+
.fc-redpacket-progress { height: 4px; overflow: hidden; border-radius: 999px; background: var(--dsw-alias-bg-layer-3); }
|
|
3236
|
+
.fc-redpacket-progress > span { display: block; height: 100%; background: var(--dsw-alias-state-warn-primary); }
|
|
3237
|
+
.fc-claims { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; padding-right: 2px; }
|
|
3238
|
+
.fc-claim-row { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; }
|
|
3239
|
+
.fc-claim-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3240
|
+
.fc-claim-outcome { color: var(--dsw-alias-label-secondary); font-size: 11px; }
|
|
3241
|
+
.fc-claim-amount { color: var(--dsw-alias-state-success-primary); font-variant-numeric: tabular-nums; }
|
|
3242
|
+
.fc-claim-negative { color: var(--dsw-alias-state-error-primary); }
|
|
3243
|
+
.fc-claim-time { color: var(--dsw-alias-label-tertiary); font-size: 10px; white-space: nowrap; }
|
|
3244
|
+
.fc-claim-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
|
|
3245
|
+
.fc-user-body { display: flex; flex-direction: column; gap: 10px; }
|
|
3246
|
+
.fc-user-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
|
3247
|
+
.fc-user-heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
3248
|
+
.fc-user-name-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
3249
|
+
.fc-user-name { overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
|
|
3250
|
+
.fc-user-home-link {
|
|
3251
|
+
flex: none;
|
|
3252
|
+
padding: 1px 8px;
|
|
3253
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3254
|
+
border-radius: 999px;
|
|
3255
|
+
color: var(--dsw-alias-link);
|
|
3256
|
+
font-size: 11px;
|
|
3257
|
+
line-height: 16px;
|
|
3258
|
+
text-decoration: none;
|
|
3259
|
+
}
|
|
3260
|
+
.fc-user-home-link:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
3261
|
+
.fc-user-role { color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
3262
|
+
.fc-user-meta { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
3263
|
+
.fc-user-intro { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 19px; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
3264
|
+
.fc-user-links { display: flex; flex-wrap: wrap; gap: 12px; }
|
|
3265
|
+
.fc-user-profile-link { color: var(--dsw-alias-link); font-size: 12px; text-decoration: none; }
|
|
3266
|
+
.fc-user-profile-link:hover { text-decoration: underline; }
|
|
3267
|
+
.fc-user-medals-section { display: flex; flex-direction: column; gap: 6px; }
|
|
3268
|
+
.fc-user-medals { display: flex; flex-direction: column; gap: 8px; }
|
|
3269
|
+
.fc-medal-row { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
|
|
3270
|
+
.fc-medal-icon { flex: none; width: 22px; height: 22px; border-radius: 4px; object-fit: cover; background: var(--dsw-alias-bg-layer-2); }
|
|
3271
|
+
.fc-medal-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
|
|
3272
|
+
.fc-medal-name { font-size: 12px; font-weight: 500; }
|
|
3273
|
+
.fc-medal-meta { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; overflow-wrap: anywhere; }
|
|
3274
|
+
.fc-gestures { display: flex; gap: 2px; }
|
|
3275
|
+
.fc-unavailable { color: var(--dsw-alias-label-tertiary); font-style: italic; }
|
|
3276
|
+
.fc-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; color: var(--dsw-alias-label-tertiary); font-size: 12px; text-align: center; }
|
|
3277
|
+
.fc-load-older {
|
|
3278
|
+
display: block;
|
|
3279
|
+
width: 100%;
|
|
3280
|
+
margin: 4px 0 2px;
|
|
3281
|
+
padding: 4px;
|
|
3282
|
+
border: 0;
|
|
3283
|
+
border-radius: var(--dsw-radius-sm);
|
|
3284
|
+
background: transparent;
|
|
3285
|
+
color: var(--dsw-alias-label-tertiary);
|
|
3286
|
+
font: inherit;
|
|
3287
|
+
font-size: 11px;
|
|
3288
|
+
cursor: pointer;
|
|
3289
|
+
}
|
|
3290
|
+
.fc-load-older:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); }
|
|
3291
|
+
.fc-jump {
|
|
3292
|
+
position: absolute;
|
|
3293
|
+
right: 16px;
|
|
3294
|
+
bottom: 108px;
|
|
3295
|
+
display: inline-flex;
|
|
3296
|
+
align-items: center;
|
|
3297
|
+
justify-content: center;
|
|
3298
|
+
width: 28px;
|
|
3299
|
+
height: 28px;
|
|
3300
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3301
|
+
border-radius: 50%;
|
|
3302
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
3303
|
+
color: var(--dsw-alias-label-secondary);
|
|
3304
|
+
box-shadow: var(--dsw-shadow-lv1);
|
|
3305
|
+
cursor: pointer;
|
|
3306
|
+
}
|
|
3307
|
+
.fc-composer { position: relative; flex: none; display: flex; flex-direction: column; gap: 4px; padding: 8px 12px 10px; border-top: 1px solid var(--dsw-alias-border-l2); }
|
|
3308
|
+
.fc-mention-popover {
|
|
3309
|
+
position: absolute;
|
|
3310
|
+
left: 12px;
|
|
3311
|
+
right: 12px;
|
|
3312
|
+
bottom: calc(100% + 4px);
|
|
3313
|
+
z-index: 20;
|
|
3314
|
+
max-height: 240px;
|
|
3315
|
+
overflow-y: auto;
|
|
3316
|
+
padding: 4px;
|
|
3317
|
+
box-sizing: border-box;
|
|
3318
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3319
|
+
border-radius: var(--dsw-radius-md);
|
|
3320
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
3321
|
+
box-shadow: var(--dsw-elevation-prominent);
|
|
3322
|
+
}
|
|
3323
|
+
.fc-mention-option {
|
|
3324
|
+
display: flex;
|
|
3325
|
+
align-items: center;
|
|
3326
|
+
gap: 8px;
|
|
3327
|
+
width: 100%;
|
|
3328
|
+
padding: 6px 8px;
|
|
3329
|
+
border: 0;
|
|
3330
|
+
border-radius: 6px;
|
|
3331
|
+
background: transparent;
|
|
3332
|
+
color: var(--dsw-alias-label-primary);
|
|
3333
|
+
font: inherit;
|
|
3334
|
+
font-size: 12px;
|
|
3335
|
+
text-align: left;
|
|
3336
|
+
cursor: pointer;
|
|
3337
|
+
}
|
|
3338
|
+
.fc-mention-option:hover, .fc-mention-option[aria-selected="true"] { background: var(--dsw-alias-interactive-bg-hover); }
|
|
3339
|
+
.fc-mention-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3340
|
+
.fc-mention-empty { padding: 8px; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
3341
|
+
.fc-composer-row { display: flex; align-items: flex-end; gap: 6px; }
|
|
3342
|
+
.fc-plus {
|
|
3343
|
+
flex: none;
|
|
3344
|
+
width: 32px;
|
|
3345
|
+
height: 32px;
|
|
3346
|
+
padding: 0;
|
|
3347
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3348
|
+
border-radius: var(--dsw-radius-md);
|
|
3349
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
3350
|
+
color: var(--dsw-alias-label-secondary);
|
|
3351
|
+
font: inherit;
|
|
3352
|
+
font-size: 20px;
|
|
3353
|
+
line-height: 1;
|
|
3354
|
+
cursor: pointer;
|
|
3355
|
+
}
|
|
3356
|
+
.fc-plus:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
3357
|
+
.fc-plus:disabled { opacity: 0.45; cursor: default; }
|
|
3358
|
+
.fc-send { flex: none; height: 32px; }
|
|
3359
|
+
.fc-textarea {
|
|
3360
|
+
flex: 1;
|
|
3361
|
+
min-width: 0;
|
|
3362
|
+
width: auto;
|
|
3363
|
+
box-sizing: border-box;
|
|
3364
|
+
min-height: 32px;
|
|
3365
|
+
overflow: hidden;
|
|
3366
|
+
resize: none;
|
|
3367
|
+
padding: 7px 10px;
|
|
3368
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3369
|
+
border-radius: var(--dsw-radius-md);
|
|
3370
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
3371
|
+
color: var(--dsw-alias-label-primary);
|
|
3372
|
+
font: inherit;
|
|
3373
|
+
font-size: 13px;
|
|
3374
|
+
line-height: 18px;
|
|
3375
|
+
outline: none;
|
|
3376
|
+
}
|
|
3377
|
+
.fc-textarea:focus { border-color: var(--dsw-alias-state-business-primary); }
|
|
3378
|
+
.fc-composer-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
|
|
3379
|
+
.fc-count { margin-right: auto; color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
3380
|
+
.fc-count-warn { color: var(--dsw-alias-state-warn-primary); }
|
|
3381
|
+
.fc-button {
|
|
3382
|
+
display: inline-flex;
|
|
3383
|
+
align-items: center;
|
|
3384
|
+
justify-content: center;
|
|
3385
|
+
height: 30px;
|
|
3386
|
+
padding: 0 12px;
|
|
3387
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3388
|
+
border-radius: var(--dsw-radius-md);
|
|
3389
|
+
background: var(--dsw-alias-button-elevated-fill);
|
|
3390
|
+
color: var(--dsw-alias-label-primary);
|
|
3391
|
+
font: inherit;
|
|
3392
|
+
font-size: 12px;
|
|
3393
|
+
cursor: pointer;
|
|
3394
|
+
white-space: nowrap;
|
|
3395
|
+
}
|
|
3396
|
+
.fc-button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
3397
|
+
.fc-button:disabled { opacity: 0.45; cursor: default; }
|
|
3398
|
+
.fc-button-primary {
|
|
3399
|
+
border-color: transparent;
|
|
3400
|
+
background: var(--dsw-alias-button-primary-fill);
|
|
3401
|
+
color: var(--dsw-alias-label-primary-foreground);
|
|
3402
|
+
}
|
|
3403
|
+
.fc-button-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }
|
|
3404
|
+
.fc-login-wrap { flex: 1; overflow-y: auto; padding: 20px 16px; }
|
|
3405
|
+
.fc-login-title { margin-bottom: 4px; font-size: 13px; font-weight: 500; }
|
|
3406
|
+
.fc-login { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
|
|
3407
|
+
.fc-login-actions { display: flex; align-items: center; gap: 8px; }
|
|
3408
|
+
.fc-register { text-decoration: none; }
|
|
3409
|
+
.fc-field { display: flex; flex-direction: column; gap: 5px; }
|
|
3410
|
+
.fc-label { color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
3411
|
+
.fc-input {
|
|
3412
|
+
box-sizing: border-box;
|
|
3413
|
+
width: 100%;
|
|
3414
|
+
height: 32px;
|
|
3415
|
+
padding: 0 10px;
|
|
3416
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3417
|
+
border-radius: var(--dsw-radius-md);
|
|
3418
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
3419
|
+
color: var(--dsw-alias-label-primary);
|
|
3420
|
+
font: inherit;
|
|
3421
|
+
font-size: 13px;
|
|
3422
|
+
outline: none;
|
|
3423
|
+
}
|
|
3424
|
+
.fc-input:focus { border-color: var(--dsw-alias-state-business-primary); }
|
|
3425
|
+
.fc-input:focus-visible, .fc-textarea:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 1px; }
|
|
3426
|
+
.fc-check { display: flex; align-items: center; gap: 7px; color: var(--dsw-alias-label-secondary); font-size: 12px; cursor: pointer; }
|
|
3427
|
+
.fc-hint { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
3428
|
+
.fc-note { margin: 12px 0 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
3429
|
+
.fc-error { margin: 0; color: var(--dsw-alias-state-error-primary); font-size: 12px; line-height: 18px; }
|
|
3430
|
+
.fc-settings { display: flex; flex-direction: column; gap: 24px; padding: 20px 0 32px; box-sizing: border-box; }
|
|
3431
|
+
.fc-settings .fc-button { height: 34px; font-size: 13px; }
|
|
3432
|
+
.fc-settings .fc-panel { border-radius: var(--dsw-radius-lg); padding: 16px 18px; border: 1px solid var(--dsw-alias-settings-card-stroke); }
|
|
3433
|
+
.fc-settings .fc-hint, .fc-settings .fc-note { font-size: 13px; line-height: 19px; }
|
|
3434
|
+
.fc-section { display: flex; flex-direction: column; gap: 8px; }
|
|
3435
|
+
.fc-section-title { margin: 0; color: var(--dsw-alias-label-primary); font-size: 14px; font-weight: 500; line-height: 20px; }
|
|
3436
|
+
.fc-panel {
|
|
3437
|
+
display: flex;
|
|
3438
|
+
flex-direction: column;
|
|
3439
|
+
gap: 10px;
|
|
3440
|
+
padding: 14px 16px;
|
|
3441
|
+
border-radius: var(--dsw-radius-md);
|
|
3442
|
+
background: var(--dsw-alias-bg-module-platform);
|
|
3443
|
+
}
|
|
3444
|
+
.fc-account { flex-direction: row; align-items: center; }
|
|
3445
|
+
.fc-account-body { min-width: 0; flex: 1; }
|
|
3446
|
+
.fc-account-name { overflow: hidden; font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
|
|
3447
|
+
.fc-account-meta { color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
3448
|
+
.fc-segmented {
|
|
3449
|
+
display: inline-flex;
|
|
3450
|
+
gap: 2px;
|
|
3451
|
+
align-self: flex-start;
|
|
3452
|
+
padding: 2px;
|
|
3453
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
3454
|
+
border-radius: var(--dsw-radius-md);
|
|
3455
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
3456
|
+
}
|
|
3457
|
+
.fc-segment {
|
|
3458
|
+
height: 26px;
|
|
3459
|
+
padding: 0 12px;
|
|
3460
|
+
border: 0;
|
|
3461
|
+
border-radius: 6px;
|
|
3462
|
+
background: transparent;
|
|
3463
|
+
color: var(--dsw-alias-label-secondary);
|
|
3464
|
+
font: inherit;
|
|
3465
|
+
font-size: 12px;
|
|
3466
|
+
cursor: pointer;
|
|
3467
|
+
}
|
|
3468
|
+
.fc-segment-active { background: var(--dsw-alias-button-elevated-fill); color: var(--dsw-alias-label-primary); box-shadow: var(--dsw-shadow-lv1); }
|
|
3469
|
+
.fc-row { display: flex; align-items: center; gap: 16px; }
|
|
3470
|
+
.fc-row-body { min-width: 0; flex: 1; }
|
|
3471
|
+
.fc-row-title { font-size: 13px; }
|
|
3472
|
+
.fc-switch {
|
|
3473
|
+
position: relative;
|
|
3474
|
+
flex: none;
|
|
3475
|
+
width: 36px;
|
|
3476
|
+
height: 20px;
|
|
3477
|
+
padding: 0;
|
|
3478
|
+
border: 0;
|
|
3479
|
+
border-radius: 999px;
|
|
3480
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
3481
|
+
cursor: pointer;
|
|
3482
|
+
transition: background 120ms ease;
|
|
3483
|
+
}
|
|
3484
|
+
.fc-switch-on { background: var(--dsw-alias-state-business-primary); }
|
|
3485
|
+
.fc-switch-thumb {
|
|
3486
|
+
position: absolute;
|
|
3487
|
+
top: 2px;
|
|
3488
|
+
left: 2px;
|
|
3489
|
+
width: 16px;
|
|
3490
|
+
height: 16px;
|
|
3491
|
+
border-radius: 50%;
|
|
3492
|
+
background: var(--dsw-alias-switch-thumb);
|
|
3493
|
+
transition: transform 120ms ease;
|
|
3494
|
+
}
|
|
3495
|
+
.fc-switch-on .fc-switch-thumb { transform: translateX(16px); }
|
|
3496
|
+
.fc-header-entry {
|
|
3497
|
+
position: relative;
|
|
3498
|
+
display: inline-flex;
|
|
3499
|
+
align-items: center;
|
|
3500
|
+
justify-content: center;
|
|
3501
|
+
width: 28px;
|
|
3502
|
+
height: 28px;
|
|
3503
|
+
padding: 0;
|
|
3504
|
+
border: 0;
|
|
3505
|
+
border-radius: 28px;
|
|
3506
|
+
background: transparent;
|
|
3507
|
+
color: var(--dsw-alias-label-tertiary);
|
|
3508
|
+
cursor: pointer;
|
|
3509
|
+
}
|
|
3510
|
+
.fc-header-entry:hover { color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-interactive-bg-hover); }
|
|
3511
|
+
.fc-header-entry:focus-visible { outline: 2px solid var(--dsw-focus-ring-color); outline-offset: 1px; }
|
|
3512
|
+
.fc-badge {
|
|
3513
|
+
position: absolute;
|
|
3514
|
+
top: 4px;
|
|
3515
|
+
right: 4px;
|
|
3516
|
+
width: 6px;
|
|
3517
|
+
height: 6px;
|
|
3518
|
+
border-radius: 50%;
|
|
3519
|
+
background: var(--dsw-alias-state-business-primary);
|
|
3520
|
+
box-shadow: 0 0 0 2px var(--dsw-alias-bg-base);
|
|
3521
|
+
}
|
|
3522
|
+
@media (prefers-reduced-motion: reduce) {
|
|
3523
|
+
.fc-switch, .fc-switch-thumb { transition: none; }
|
|
3524
|
+
}
|
|
3525
|
+
`)
|
|
3526
|
+
}
|
|
3527
|
+
|
|
3528
|
+
/** Open the chat tab in the on-screen Session, ignoring the no-Session error. */
|
|
3529
|
+
function openChat() {
|
|
3530
|
+
try {
|
|
3531
|
+
sharedContext?.sidebarRight.openTab(TAB_KIND)
|
|
3532
|
+
} catch {
|
|
3533
|
+
// Without a Session there is no right Sidebar to open into.
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
/** React hook bound to the module's single store. */
|
|
3538
|
+
function useStore() {
|
|
3539
|
+
return useSyncExternalStore(sharedStore.subscribe, sharedStore.getSnapshot, sharedStore.getSnapshot)
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
return {
|
|
3543
|
+
inject: ['slots', 'locale', 'sidebarRightTabs', 'sidebarRight'],
|
|
3544
|
+
apply(ctx) {
|
|
3545
|
+
sharedContext = ctx
|
|
3546
|
+
const t = ctx.locale.bind(NS)
|
|
3547
|
+
sharedStore = createStore(t)
|
|
3548
|
+
|
|
3549
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'fishpi-chat copy')
|
|
3550
|
+
|
|
3551
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
3552
|
+
id: TAB_ID,
|
|
3553
|
+
kind: TAB_KIND,
|
|
3554
|
+
keepMounted: true,
|
|
3555
|
+
priority: 'extension',
|
|
3556
|
+
title: () => t('tabTitle'),
|
|
3557
|
+
guide: [{
|
|
3558
|
+
id: 'open',
|
|
3559
|
+
order: 6,
|
|
3560
|
+
title: () => t('guide.title'),
|
|
3561
|
+
description: () => t('guide.description'),
|
|
3562
|
+
icon: IconFish,
|
|
3563
|
+
}],
|
|
3564
|
+
}), 'fishpi-chat tab type')
|
|
3565
|
+
|
|
3566
|
+
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
3567
|
+
name: 'sidebar.right.pane.tab',
|
|
3568
|
+
key: TAB_ID,
|
|
3569
|
+
locale: NS,
|
|
3570
|
+
}, ChatTabBody)), 'fishpi-chat tab body')
|
|
3571
|
+
|
|
3572
|
+
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
3573
|
+
name: 'sidebar.right.pane.tab.title',
|
|
3574
|
+
key: TAB_ID,
|
|
3575
|
+
locale: NS,
|
|
3576
|
+
}, ChatTabTitle)), 'fishpi-chat tab title')
|
|
3577
|
+
|
|
3578
|
+
ctx.effect(() => ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
3579
|
+
name: 'conversation.session.header.utilities',
|
|
3580
|
+
id: 'fishpi-chat',
|
|
3581
|
+
order: -6,
|
|
3582
|
+
locale: NS,
|
|
3583
|
+
}, HeaderButton)), 'fishpi-chat header button')
|
|
3584
|
+
|
|
3585
|
+
ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
3586
|
+
name: 'settings.section',
|
|
3587
|
+
id: 'fishpi-chat',
|
|
3588
|
+
order: 40,
|
|
3589
|
+
label: () => t('nav'),
|
|
3590
|
+
locale: NS,
|
|
3591
|
+
}, SettingsSection)), 'fishpi-chat settings section')
|
|
3592
|
+
|
|
3593
|
+
ctx.effect(() => ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
3594
|
+
name: 'settings.section.icon',
|
|
3595
|
+
id: 'fishpi-chat',
|
|
3596
|
+
locale: NS,
|
|
3597
|
+
}, SettingsIcon)), 'fishpi-chat settings icon')
|
|
3598
|
+
|
|
3599
|
+
const lifetime = new AbortController()
|
|
3600
|
+
const ownStore = sharedStore
|
|
3601
|
+
const onVisibility = () => { sharedStore?.clearUnreadIfVisible() }
|
|
3602
|
+
document.addEventListener('visibilitychange', onVisibility)
|
|
3603
|
+
ctx.effect(() => () => {
|
|
3604
|
+
document.removeEventListener('visibilitychange', onVisibility)
|
|
3605
|
+
lifetime.abort()
|
|
3606
|
+
if (sharedStore === ownStore) ownStore.dispose()
|
|
3607
|
+
}, 'fishpi-chat lifetime')
|
|
3608
|
+
|
|
3609
|
+
void sharedStore.init(lifetime.signal)
|
|
3610
|
+
},
|
|
3611
|
+
}
|
|
3612
|
+
},
|
|
3613
|
+
})
|
|
3614
|
+
;
|