oh-my-dws 0.0.2 → 0.0.3
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 +17 -5
- package/bin/oh-my-dws.js +2 -2
- package/docs//344/275/277/347/224/250/350/257/264/346/230/216.md +104 -5
- package/package.json +1 -1
- package/src/actions.js +590 -63
- package/src/ai.js +300 -0
- package/src/archive.js +17 -8
- package/src/auth.js +33 -1
- package/src/avatars.js +143 -0
- package/src/contacts.js +563 -0
- package/src/layout.js +63 -0
- package/src/listen.js +289 -0
- package/src/media.js +12 -1
- package/src/rev.js +23 -0
- package/src/server.js +385 -7
- package/src/settings.js +51 -0
- package/src/sync.js +213 -0
- package/web/index.html +2136 -74
package/web/index.html
CHANGED
|
@@ -53,8 +53,77 @@
|
|
|
53
53
|
.userPanel .uacts button{flex:1;padding:4px 6px;font-size:12px;white-space:nowrap}
|
|
54
54
|
.userPanel .uacts button#uLogout{color:var(--err)}
|
|
55
55
|
.userPanel .uacts button#uLogout:hover:not(:disabled){background:#fdeeee;border-color:#f0c9c9}
|
|
56
|
+
.userPanel .uai{margin-top:11px;padding-top:10px;border-top:1px dashed var(--line)}
|
|
57
|
+
.userPanel .uai .uaiRow{display:flex;align-items:center;gap:8px}
|
|
58
|
+
.userPanel .uai .uaiState{flex:1;min-width:0;font-size:11.5px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
59
|
+
.userPanel .uai button{padding:3px 9px;font-size:12px;flex:0 0 auto}
|
|
60
|
+
.userPanel .ulisten{margin-top:11px;padding-top:10px;border-top:1px dashed var(--line);font-size:11.5px;color:var(--muted);line-height:1.65}
|
|
61
|
+
.userPanel .ulisten .uhead{display:flex;align-items:center;gap:6px;margin-bottom:4px}
|
|
62
|
+
.userPanel .ulisten .uhead b{color:var(--text);font-size:12px}
|
|
63
|
+
.userPanel .ulisten .uhead .spacerL{flex:1}
|
|
64
|
+
.userPanel .ulisten button{padding:2px 8px;font-size:11.5px;border-radius:6px}
|
|
65
|
+
.userPanel .ulisten .urow{display:flex;align-items:center;gap:6px}
|
|
66
|
+
.userPanel .ulisten .urow .ok{color:#0f7b46}
|
|
67
|
+
.userPanel .ulisten .urow .bad{color:#9c4b45}
|
|
56
68
|
.userPanel .uerr{color:var(--err);font-size:11px;margin-top:8px;word-break:break-all;line-height:1.5}
|
|
57
69
|
|
|
70
|
+
/* 常用联系人(可收起) */
|
|
71
|
+
.sideScroll{flex:1;min-height:0;overflow:auto}
|
|
72
|
+
.contacts{flex:none;display:flex;flex-direction:column}
|
|
73
|
+
.contacts .cHead{display:flex;align-items:center;gap:6px;padding:8px 10px 6px}
|
|
74
|
+
.contacts .cChev{width:16px;flex:0 0 16px;padding:0;border:none;background:transparent;color:var(--muted);font-size:10px;line-height:1}
|
|
75
|
+
.contacts .cChev:hover{color:var(--text)}
|
|
76
|
+
.contacts .cChev .chev::before{content:"▾"}
|
|
77
|
+
.contacts.closed .cChev .chev::before{content:"▸"}
|
|
78
|
+
.contacts .cToggle{flex:1;display:flex;align-items:center;gap:5px;border:none;background:transparent;
|
|
79
|
+
padding:2px 4px;border-radius:6px;font-size:11.5px;font-weight:600;letter-spacing:.4px;color:var(--muted);text-align:left}
|
|
80
|
+
.contacts .cToggle:hover{background:#f4f6f9;color:var(--text)}
|
|
81
|
+
.contacts .cToggle .chev{display:inline-block;font-size:10px;color:var(--muted)}
|
|
82
|
+
.contacts .cToggle .chev::before{content:"▾"}
|
|
83
|
+
.contacts.closed .cToggle .chev::before{content:"▸"}
|
|
84
|
+
.contacts .cCnt{font-weight:400}
|
|
85
|
+
.contacts .cAdd{width:22px;height:22px;padding:0;border-radius:6px;font-size:13px;line-height:1;color:var(--muted)}
|
|
86
|
+
.contacts .cAdd:hover{color:var(--brand);background:var(--brand-soft);border-color:#cddcff}
|
|
87
|
+
.contacts .cList{overflow:visible;padding:0 6px 4px}
|
|
88
|
+
.contacts.closed .cList{display:none}
|
|
89
|
+
.contacts .cEmpty{padding:2px 10px 7px;font-size:11.5px;color:var(--muted);line-height:1.5}
|
|
90
|
+
.cItem{position:relative;display:flex;align-items:center;gap:7px;padding:5px 7px;border-radius:8px;
|
|
91
|
+
cursor:pointer;border:1px solid transparent}
|
|
92
|
+
.cItem:hover{background:#f7f9fc}
|
|
93
|
+
.cItem.active{background:var(--brand-soft);border-color:#cddcff}
|
|
94
|
+
.cItem .cav{width:26px;height:26px;border-radius:50%;flex:0 0 26px;display:flex;align-items:center;
|
|
95
|
+
justify-content:center;color:#fff;font-size:12px;font-weight:600}
|
|
96
|
+
.cItem .cmain{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px}
|
|
97
|
+
.cItem .crow{display:flex;align-items:baseline;gap:6px;min-width:0}
|
|
98
|
+
.cItem .cnm{flex:1;min-width:0;font-size:12.5px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
99
|
+
.cItem .ctime{flex:0 0 auto;font-size:10.5px;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
100
|
+
.cItem .cprev{font-size:11.5px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
101
|
+
.cItem .cprev.empty{color:#b6bcc6;font-style:italic}
|
|
102
|
+
.cItem:hover .ctime{visibility:hidden}
|
|
103
|
+
.cItem .cacts{position:absolute;top:5px;right:5px;display:none;align-items:center;gap:2px}
|
|
104
|
+
.cItem:hover .cacts{display:flex}
|
|
105
|
+
.cItem .cacts button{width:18px;height:18px;padding:0;border:none;background:transparent;border-radius:5px;
|
|
106
|
+
color:var(--muted);font-size:11px;line-height:1;display:flex;align-items:center;justify-content:center}
|
|
107
|
+
.cItem .cacts button:hover{background:#eef2f8;color:var(--text)}
|
|
108
|
+
.cItem .cacts button.del:hover{background:#f7f0ef;color:#9c4b45}
|
|
109
|
+
.cItem[draggable="true"]{cursor:grab}
|
|
110
|
+
.cItem.dragging{opacity:.45;cursor:grabbing}
|
|
111
|
+
.cItem.dropBefore{box-shadow:inset 0 2px 0 var(--brand)}
|
|
112
|
+
.cItem.dropAfter{box-shadow:inset 0 -2px 0 var(--brand)}
|
|
113
|
+
.cItem .cav img{width:100%;height:100%;border-radius:50%;object-fit:cover;display:block}
|
|
114
|
+
.cItem .cav.hasImg{background:#f2f4f7!important}
|
|
115
|
+
.cItem.pinned{background:#fffdf5;border-color:#f2e8cf}
|
|
116
|
+
.cItem.pinned.active{background:var(--brand-soft);border-color:#cddcff}
|
|
117
|
+
.cItem .cpinTag{font-size:10px;color:#b08900;margin-left:4px}
|
|
118
|
+
.cItem .cunread{min-width:17px;height:17px;padding:0 5px;border-radius:99px;background:#f03e3e;color:#fff;
|
|
119
|
+
font-size:10.5px;line-height:17px;text-align:center;font-weight:600;flex:0 0 auto}
|
|
120
|
+
.cHead .cUnread{min-width:16px;height:16px;padding:0 5px;border-radius:99px;background:#f03e3e;color:#fff;
|
|
121
|
+
font-size:10px;line-height:16px;text-align:center;font-weight:600;margin-left:4px}
|
|
122
|
+
.gsec .secUnread{min-width:16px;height:16px;padding:0 4px;border-radius:99px;background:#f03e3e;color:#fff;
|
|
123
|
+
font-size:10px;line-height:16px;text-align:center;font-weight:600;margin-left:6px}
|
|
124
|
+
.rail .railUnread{min-width:22px;height:15px;padding:0 4px;border-radius:99px;background:#f03e3e;color:#fff;
|
|
125
|
+
font-size:9.5px;line-height:15px;text-align:center;font-weight:600}
|
|
126
|
+
|
|
58
127
|
.layout{flex:1;display:flex;min-height:0}
|
|
59
128
|
|
|
60
129
|
aside{width:310px;flex:none;min-width:200px;max-width:62vw;background:var(--panel);border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0;position:relative}
|
|
@@ -89,17 +158,57 @@
|
|
|
89
158
|
border-radius:6px;color:var(--muted);font-size:14px;line-height:1;display:none;align-items:center;justify-content:center}
|
|
90
159
|
.gitem:hover .moreBtn{display:flex}
|
|
91
160
|
.gitem .moreBtn:hover{background:#e9eef7;color:var(--text)}
|
|
161
|
+
.gitem .gacts{position:absolute;top:7px;right:6px;display:none;align-items:center;gap:2px}
|
|
162
|
+
.gitem:hover .gacts{display:flex}
|
|
163
|
+
.gitem .gacts button{width:20px;height:20px;padding:0;border:none;background:transparent;border-radius:5px;
|
|
164
|
+
color:var(--muted);font-size:11px;line-height:1;display:flex;align-items:center;justify-content:center}
|
|
165
|
+
.gitem .gacts button:hover{background:#e9eef7;color:var(--text)}
|
|
166
|
+
.gitem:hover .gname{padding-right:66px}
|
|
167
|
+
.gitem[draggable="true"]{cursor:grab}
|
|
168
|
+
.gitem.dragging{opacity:.45;cursor:grabbing}
|
|
169
|
+
.gitem.dropBefore{box-shadow:inset 0 2px 0 var(--brand)}
|
|
170
|
+
.gitem.dropAfter{box-shadow:inset 0 -2px 0 var(--brand)}
|
|
171
|
+
.gitem.pinned{background:#fffdf5;border-color:#f2e8cf}
|
|
172
|
+
.gitem.pinned.active{background:var(--brand-soft);border-color:#cddcff}
|
|
173
|
+
.gitem .pinTag{font-size:10px;color:#b08900;margin-left:5px;vertical-align:1px}
|
|
174
|
+
.gitem.picked{background:#eef4ff;border-color:#9fbcff}
|
|
175
|
+
.gitem .pickBox{position:absolute;top:9px;right:8px;width:16px;height:16px;border-radius:4px;
|
|
176
|
+
border:1.5px solid #c3cbd8;background:#fff;display:none;align-items:center;justify-content:center;font-size:11px;color:#fff}
|
|
177
|
+
.glist.picking .gitem .pickBox{display:flex}
|
|
178
|
+
.glist.picking .gitem .gacts,.glist.picking .gitem .moreBtn{display:none}
|
|
179
|
+
.glist.picking .gitem .gname{padding-right:26px}
|
|
180
|
+
.gitem.picked .pickBox{background:var(--brand);border-color:var(--brand)}
|
|
181
|
+
/* 多选工具条 */
|
|
182
|
+
.pickBar{position:absolute;left:8px;right:8px;bottom:8px;z-index:8;display:none;align-items:center;gap:8px;
|
|
183
|
+
background:#20242b;color:#fff;border-radius:10px;padding:7px 10px;font-size:12px;
|
|
184
|
+
box-shadow:0 8px 22px rgba(0,0,0,.22)}
|
|
185
|
+
.pickBar.show{display:flex}
|
|
186
|
+
.pickBar .pcount{flex:1}
|
|
187
|
+
.pickBar button{padding:3px 10px;font-size:12px;border-radius:7px;border:1px solid rgba(255,255,255,.22);
|
|
188
|
+
background:transparent;color:#fff}
|
|
189
|
+
.pickBar button:hover{background:rgba(255,255,255,.14);border-color:rgba(255,255,255,.3)}
|
|
190
|
+
.pickBar button.del{background:#c0524c;border-color:#c0524c}
|
|
191
|
+
.pickBar button.del:hover{background:#a8453f;border-color:#a8453f}
|
|
92
192
|
/* 搜索框默认收起,右键菜单「搜索群」时才出现 */
|
|
93
193
|
aside .filter{padding:10px 12px;border-bottom:1px solid var(--line);display:none}
|
|
94
194
|
aside .filter.show{display:block}
|
|
95
195
|
aside .filter input{width:100%}
|
|
96
|
-
.glist{overflow:
|
|
196
|
+
.glist{overflow:visible;flex:none;padding:6px}
|
|
97
197
|
.gitem{padding:9px 10px;border-radius:10px;cursor:pointer;border:1px solid transparent;margin-bottom:4px}
|
|
98
198
|
.gitem:hover{background:#f7f9fc}
|
|
99
199
|
.gitem.active{background:var(--brand-soft);border-color:#cddcff}
|
|
100
200
|
.gitem .gname{font-weight:600;font-size:13px;line-height:1.4;word-break:break-all;padding-right:22px}
|
|
201
|
+
.gitem .secChev{width:14px;height:14px;padding:0;margin-right:2px;border:none;background:transparent;
|
|
202
|
+
border-radius:4px;color:var(--muted);font-size:10px;line-height:1;vertical-align:1px}
|
|
203
|
+
.gitem .secChev:hover{background:#e9eef7;color:var(--text)}
|
|
101
204
|
.gitem .gmeta{color:var(--muted);font-size:12px;margin-top:3px;display:flex;gap:8px;flex-wrap:wrap}
|
|
102
|
-
.gsec{font-size:11px;color:var(--muted);
|
|
205
|
+
.gsec{display:flex;align-items:center;gap:5px;cursor:pointer;user-select:none;font-size:11px;color:var(--muted);
|
|
206
|
+
font-weight:600;letter-spacing:.6px;padding:8px 10px 3px;border-radius:6px}
|
|
207
|
+
.gsec:hover{color:var(--text);background:#f6f8fb}
|
|
208
|
+
.gsec .chev{font-size:10px;color:var(--muted)}
|
|
209
|
+
.gsec .chev::before{content:"▾"}
|
|
210
|
+
.gsec.closed .chev::before{content:"▸"}
|
|
211
|
+
.gsec .secN{margin-left:auto;font-weight:400;letter-spacing:0;color:var(--muted)}
|
|
103
212
|
.gitem.dm{background:#fbfaff;border-color:#eee9fb}
|
|
104
213
|
.gitem.dm.active{background:var(--brand-soft);border-color:#cddcff}
|
|
105
214
|
.dmTag{font-size:10px;color:#6b4ec9;background:#f0ebff;border-radius:99px;padding:1px 6px;margin-left:6px;vertical-align:1px}
|
|
@@ -116,6 +225,10 @@
|
|
|
116
225
|
.gchild.active{background:var(--brand-soft);color:var(--brand);font-weight:600}
|
|
117
226
|
.gchild .nm{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
118
227
|
.gchild .ct{font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
228
|
+
.gchild .unTag{font-size:9.5px;color:#8a6d00;background:#fff6dd;border-radius:99px;padding:0 5px;margin-left:5px}
|
|
229
|
+
.gchild.unarchived .nm{color:#6b6355}
|
|
230
|
+
.gchild.gmoresrc{color:var(--brand);font-size:11.5px;justify-content:center;padding:6px}
|
|
231
|
+
.gchild.gmoresrc:hover{background:var(--brand-soft)}
|
|
119
232
|
.gchild.active .ct{color:var(--brand)}
|
|
120
233
|
.gitem .dot{width:6px;height:6px;border-radius:50%;background:var(--ok);display:inline-block;margin-right:4px;vertical-align:1px}
|
|
121
234
|
.gitem .dot.off{background:transparent;border:1px solid #cfd5df;width:6px;height:6px}
|
|
@@ -158,6 +271,11 @@
|
|
|
158
271
|
.jump{position:absolute;right:20px;top:58px;border-radius:99px;padding:5px 13px;font-size:12px;
|
|
159
272
|
background:#20242b;color:#fff;border-color:#20242b;box-shadow:0 6px 18px rgba(0,0,0,.22);display:none;z-index:5}
|
|
160
273
|
.jump.show{display:block}
|
|
274
|
+
.newPill{position:absolute;left:50%;top:8px;transform:translateX(-50%);z-index:9;display:none;
|
|
275
|
+
padding:5px 14px;font-size:12px;border-radius:99px;background:var(--brand);color:#fff;
|
|
276
|
+
border-color:var(--brand);box-shadow:0 6px 18px rgba(47,111,237,.35)}
|
|
277
|
+
.newPill.show{display:block}
|
|
278
|
+
.newPill:hover:not(:disabled){background:#255fd6;border-color:#255fd6;color:#fff}
|
|
161
279
|
.jump:hover:not(:disabled){background:#000;border-color:#000;color:#fff}
|
|
162
280
|
|
|
163
281
|
.composerFab{position:absolute;right:20px;bottom:16px;border-radius:99px;padding:8px 16px;font-size:13px;
|
|
@@ -178,6 +296,20 @@
|
|
|
178
296
|
.composer .cbar label{display:flex;align-items:center;gap:4px;cursor:pointer}
|
|
179
297
|
.composer .cbar .spacerL{flex:1}
|
|
180
298
|
.composer button{padding:5px 16px}
|
|
299
|
+
.composer .aiBtn{background:linear-gradient(135deg,#7c5cff,#2f6fed);border-color:transparent;color:#fff}
|
|
300
|
+
.composer .aiBtn:hover:not(:disabled){background:linear-gradient(135deg,#6f4dff,#2a63d9);border-color:transparent;color:#fff}
|
|
301
|
+
.composer .aiBtn:active{transform:translateY(1px)}
|
|
302
|
+
.composer .imgStrip{display:none;gap:8px;flex-wrap:wrap;margin-bottom:8px}
|
|
303
|
+
.composer .imgStrip.show{display:flex}
|
|
304
|
+
.composer .imgStrip .thumb{position:relative;width:64px;height:64px;border-radius:8px;overflow:hidden;border:1px solid var(--line);background:#f7f8fa}
|
|
305
|
+
.composer .imgStrip .thumb img{width:100%;height:100%;object-fit:cover;display:block}
|
|
306
|
+
.composer .imgStrip .thumb button{position:absolute;top:2px;right:2px;width:16px;height:16px;padding:0;border:none;
|
|
307
|
+
border-radius:50%;background:rgba(0,0,0,.55);color:#fff;font-size:11px;line-height:16px}
|
|
308
|
+
.composer .imgStrip .thumb button:hover{background:rgba(0,0,0,.75)}
|
|
309
|
+
.composer .aiRow{display:none;gap:6px;align-items:center;margin-top:8px}
|
|
310
|
+
.composer .aiRow.show{display:flex}
|
|
311
|
+
.composer .aiRow input{flex:1;font-size:12.5px;padding:5px 9px}
|
|
312
|
+
.composer .aiRow .aiCfg{width:28px;padding:0;font-size:12px;color:var(--muted)}
|
|
181
313
|
.msg{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:10px 14px;margin-bottom:10px;
|
|
182
314
|
display:flex;gap:10px;align-items:flex-start}
|
|
183
315
|
.av{width:34px;height:34px;border-radius:50%;flex:0 0 34px;display:flex;align-items:center;justify-content:center;
|
|
@@ -190,6 +322,15 @@
|
|
|
190
322
|
.quote .qt{white-space:pre-wrap;word-break:break-word;display:inline}
|
|
191
323
|
.quote .qmiss{color:var(--muted)}
|
|
192
324
|
.msg.new{border-color:#bcd0ff;box-shadow:0 0 0 3px var(--brand-soft)}
|
|
325
|
+
.msg.unread{border-color:#f5c2c0;box-shadow:0 0 0 3px #fdf1f0}
|
|
326
|
+
.msg .unreadDot{width:7px;height:7px;border-radius:50%;background:#f03e3e;display:inline-block;margin-right:5px;vertical-align:1px}
|
|
327
|
+
.msg .freshTag{font-size:10px;color:#fff;background:#f03e3e;border-radius:99px;padding:1px 6px;margin-left:2px}
|
|
328
|
+
.msg.recalled{background:#fafbfc;border-style:dashed}
|
|
329
|
+
.msg.recalled .who{color:var(--muted);font-weight:600}
|
|
330
|
+
.msg .recalledText{color:var(--muted);font-size:12.5px;font-style:italic;display:flex;align-items:center;gap:6px}
|
|
331
|
+
.msg .recalledTag{font-size:10.5px;color:#8a6d00;background:#fff6dd;border-radius:99px;padding:1px 7px;font-style:normal}
|
|
332
|
+
.av img{width:100%;height:100%;border-radius:50%;object-fit:cover;display:block}
|
|
333
|
+
.av.hasImg{background:#f2f4f7}
|
|
193
334
|
.msg .meta{display:flex;gap:10px;align-items:baseline;font-size:12px;color:var(--muted);margin-bottom:6px;flex-wrap:wrap}
|
|
194
335
|
.msg .who{font-weight:600;color:var(--text);font-size:13px}
|
|
195
336
|
.msg .id{font-family:var(--mono);font-size:10.5px;color:#9aa1ad}
|
|
@@ -215,6 +356,9 @@
|
|
|
215
356
|
.lightbox .lbClose:hover{background:rgba(255,255,255,.26)}
|
|
216
357
|
.lightbox .lbHint{position:absolute;bottom:14px;left:0;right:0;text-align:center;color:#aeb6c2;font-size:12px}
|
|
217
358
|
.mark{background:#fff3b0;border-radius:3px;padding:0 1px}
|
|
359
|
+
.loadMore{display:block;width:100%;margin:10px 0 4px;padding:8px 10px;font-size:12.5px;color:var(--muted);border-style:dashed}
|
|
360
|
+
.loadMore:hover{color:var(--brand);border-color:#cddcff;background:var(--brand-soft)}
|
|
361
|
+
.loadNote{font-size:11.5px;color:var(--muted);text-align:center;margin:2px 0 10px}
|
|
218
362
|
.dateSep{display:flex;align-items:center;gap:10px;color:var(--muted);font-size:12px;margin:16px 2px 10px}
|
|
219
363
|
.msgs > .dateSep:first-child{margin-top:6px}
|
|
220
364
|
.dateSep::before,.dateSep::after{content:"";flex:1;height:1px;background:var(--line)}
|
|
@@ -255,6 +399,26 @@
|
|
|
255
399
|
button:not(.primary) .spin{border-color:#c9d0da;border-top-color:var(--brand)}
|
|
256
400
|
@keyframes sp{to{transform:rotate(360deg)}}
|
|
257
401
|
|
|
402
|
+
.stTabs{width:150px;flex:none;border-right:1px solid var(--line);padding:8px;display:flex;flex-direction:column;gap:2px;background:#fafbfc}
|
|
403
|
+
.stTabs button{border:none;background:transparent;text-align:left;padding:8px 10px;border-radius:8px;font-size:13px;color:#4a5160}
|
|
404
|
+
.stTabs button:hover{background:#eef2f8}
|
|
405
|
+
.stTabs button.on{background:var(--brand-soft);color:var(--brand);font-weight:600}
|
|
406
|
+
.stBody{flex:1;min-width:0;overflow:auto;padding:16px 18px}
|
|
407
|
+
.stBody h4{margin:0 0 4px;font-size:13.5px}
|
|
408
|
+
.stBody .stHint{font-size:12px;color:var(--muted);line-height:1.6;margin-bottom:12px}
|
|
409
|
+
.stBody .stRow{display:flex;align-items:center;gap:8px;margin-bottom:10px;flex-wrap:wrap}
|
|
410
|
+
.stBody label.stL{display:block;font-size:12px;color:var(--muted);margin:10px 0 4px}
|
|
411
|
+
.stBody input[type=text],.stBody input[type=number],.stBody input:not([type]),.stBody textarea{width:100%;font-size:12.5px}
|
|
412
|
+
.stBody .kv{display:grid;grid-template-columns:130px 1fr;gap:6px 12px;font-size:12.5px;margin-bottom:12px}
|
|
413
|
+
.stBody .kv dt{color:var(--muted)}
|
|
414
|
+
.stBody .kv dd{margin:0;font-family:var(--mono);font-size:11.5px;word-break:break-all}
|
|
415
|
+
.stBody .logBox{background:#0f1115;color:#cfd6e4;border-radius:10px;padding:10px 12px;font-family:var(--mono);font-size:11px;
|
|
416
|
+
line-height:1.55;max-height:300px;overflow:auto;white-space:pre-wrap;word-break:break-all}
|
|
417
|
+
.stBody table.proc{width:100%;border-collapse:collapse;font-size:12px}
|
|
418
|
+
.stBody table.proc th,.stBody table.proc td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line);white-space:nowrap}
|
|
419
|
+
.stBody table.proc th{color:var(--muted);font-weight:600}
|
|
420
|
+
.stBody .ok{color:#0f7b46}
|
|
421
|
+
.stBody .bad{color:#9c4b45}
|
|
258
422
|
.ctxmenu{position:fixed;z-index:30;min-width:200px;background:#fff;border:1px solid var(--line);
|
|
259
423
|
border-radius:10px;box-shadow:0 12px 32px rgba(16,24,40,.18);padding:6px;display:none}
|
|
260
424
|
/* 尾巴:指向右键的那一行 / 右键位置 */
|
|
@@ -289,8 +453,25 @@
|
|
|
289
453
|
</div>
|
|
290
454
|
<div class="userPanel" id="userPanel"></div>
|
|
291
455
|
</div>
|
|
456
|
+
<div class="sideScroll" id="sideScroll">
|
|
457
|
+
<div class="contacts" id="contactsBox">
|
|
458
|
+
<div class="cHead">
|
|
459
|
+
<button class="cChev" id="contactsToggle" title="展开 / 收起常用联系人"><span class="chev"></span></button>
|
|
460
|
+
<button class="cToggle" id="contactsTitle" title="查看所有私聊消息(谁跟我说过话)">
|
|
461
|
+
常用联系人<span class="cCnt" id="contactsCount"></span>
|
|
462
|
+
</button>
|
|
463
|
+
<button class="cAdd" id="contactsAdd" title="添加常用联系人">+</button>
|
|
464
|
+
</div>
|
|
465
|
+
<div class="cList" id="contactsList"></div>
|
|
466
|
+
</div>
|
|
292
467
|
<div class="filter" id="gsearchWrap"><input id="gsearch" placeholder="搜索群名…(Esc 收起)"></div>
|
|
293
468
|
<div class="glist" id="glist"></div>
|
|
469
|
+
</div>
|
|
470
|
+
<div class="pickBar" id="pickBar">
|
|
471
|
+
<span class="pcount" id="pickCount">已选 0 个会话</span>
|
|
472
|
+
<button class="del" id="pickDel">删除</button>
|
|
473
|
+
<button id="pickCancel">取消</button>
|
|
474
|
+
</div>
|
|
294
475
|
<button class="collapseTab" id="collapseTab" title="收起侧栏(⌘/Ctrl + B)">«</button>
|
|
295
476
|
<div class="resizer" id="resizer" title="拖动调整宽度,双击恢复默认(310px)"></div>
|
|
296
477
|
</aside>
|
|
@@ -299,6 +480,7 @@
|
|
|
299
480
|
<button id="expandBtn" title="展开侧栏(⌘/Ctrl + B)">»</button>
|
|
300
481
|
<div class="railDiv"></div>
|
|
301
482
|
<div class="railAv" id="railAv" title="当前会话(点击展开侧栏)"></div>
|
|
483
|
+
<span class="railUnread" id="railUnread" style="display:none"></span>
|
|
302
484
|
</div>
|
|
303
485
|
|
|
304
486
|
<main>
|
|
@@ -321,6 +503,7 @@
|
|
|
321
503
|
<button id="ctxMembersItem" data-need-group>👥 成员 / 人员 ID</button>
|
|
322
504
|
<button id="ctxPullItem" data-need-group>🔄 拉取最新消息</button>
|
|
323
505
|
<button id="ctxCopyItem" data-need-group>📋 复制会话 ID</button>
|
|
506
|
+
<button id="ctxResetMentions" data-need-group style="display:none">🧹 清空 @我 并从今天重新汇总</button>
|
|
324
507
|
<button class="danger" id="ctxDelItem" data-need-group>🗑 删除归档</button>
|
|
325
508
|
<div class="ctxSep" data-need-group></div>
|
|
326
509
|
<button id="ctxSearchItem">🔍 搜索群…</button>
|
|
@@ -350,6 +533,118 @@
|
|
|
350
533
|
</div>
|
|
351
534
|
</div>
|
|
352
535
|
|
|
536
|
+
<div class="modal" id="settingsModal">
|
|
537
|
+
<div class="card" style="width:min(920px,94vw);height:min(620px,86vh)">
|
|
538
|
+
<header>设置<button id="stClose">×</button></header>
|
|
539
|
+
<div style="display:flex;flex:1;min-height:0">
|
|
540
|
+
<div class="stTabs">
|
|
541
|
+
<button data-tab="ai" class="on">AI 模型</button>
|
|
542
|
+
<button data-tab="monitor">监控 / 日志</button>
|
|
543
|
+
<button data-tab="procs">进程</button>
|
|
544
|
+
<button data-tab="general">通用</button>
|
|
545
|
+
</div>
|
|
546
|
+
<div class="stBody" id="stBody"></div>
|
|
547
|
+
</div>
|
|
548
|
+
<footer><button id="stClose2">关闭</button></footer>
|
|
549
|
+
</div>
|
|
550
|
+
</div>
|
|
551
|
+
|
|
552
|
+
<div class="ctxmenu" id="msgCtx">
|
|
553
|
+
<div class="ctxTitle" id="msgCtxTitle">消息</div>
|
|
554
|
+
<button id="msgCtxRecall">↩️ 撤回这条消息</button>
|
|
555
|
+
<button id="msgCtxCopy">📋 复制消息内容</button>
|
|
556
|
+
</div>
|
|
557
|
+
|
|
558
|
+
<div class="modal" id="aiSumModal">
|
|
559
|
+
<div class="card" style="width:min(620px,92vw)">
|
|
560
|
+
<header>AI 总结<button id="asClose">×</button></header>
|
|
561
|
+
<div class="body">
|
|
562
|
+
<div id="asMeta" style="font-size:12px;color:var(--muted);margin-bottom:10px"></div>
|
|
563
|
+
<div id="asText" style="white-space:pre-wrap;font-size:13px;line-height:1.75;min-height:80px"></div>
|
|
564
|
+
</div>
|
|
565
|
+
<footer>
|
|
566
|
+
<button id="asCopy">复制</button>
|
|
567
|
+
<button id="asAgain">重新总结</button>
|
|
568
|
+
<button id="asClose2">关闭</button>
|
|
569
|
+
</footer>
|
|
570
|
+
</div>
|
|
571
|
+
</div>
|
|
572
|
+
|
|
573
|
+
<div class="modal" id="aiModal">
|
|
574
|
+
<div class="card" style="width:min(520px,92vw)">
|
|
575
|
+
<header>AI 设置<button id="aiClose">×</button></header>
|
|
576
|
+
<div class="body">
|
|
577
|
+
<div style="font-size:12.5px;color:var(--muted);margin-bottom:12px;line-height:1.6">
|
|
578
|
+
任意 OpenAI 兼容接口即可(`POST /chat/completions`)。留空表示沿用环境变量或 pi 的配置。
|
|
579
|
+
</div>
|
|
580
|
+
<label style="display:block;font-size:12px;color:var(--muted);margin-bottom:4px">接口地址</label>
|
|
581
|
+
<input id="aiBase" placeholder="https://api.deepseek.com" style="width:100%;margin-bottom:10px;font-size:12.5px">
|
|
582
|
+
<label style="display:block;font-size:12px;color:var(--muted);margin-bottom:4px">模型</label>
|
|
583
|
+
<input id="aiModel" placeholder="deepseek-chat" style="width:100%;margin-bottom:10px;font-size:12.5px">
|
|
584
|
+
<label style="display:block;font-size:12px;color:var(--muted);margin-bottom:4px">API Key</label>
|
|
585
|
+
<input id="aiKey" placeholder="留空表示不修改" style="width:100%;margin-bottom:10px;font-size:12.5px">
|
|
586
|
+
<label style="display:block;font-size:12px;color:var(--muted);margin-bottom:4px">额外人设 / 要求(可空)</label>
|
|
587
|
+
<textarea id="aiSys" placeholder="例如:我是研发,回复要短、给结论、别客套" style="width:100%;min-height:56px;font:inherit;font-size:12.5px;border:1px solid var(--line);border-radius:8px;padding:6px 9px"></textarea>
|
|
588
|
+
<div id="aiStatus" style="font-size:12px;color:var(--muted);margin-top:10px"></div>
|
|
589
|
+
</div>
|
|
590
|
+
<footer>
|
|
591
|
+
<button id="aiTest">测试连接</button>
|
|
592
|
+
<button id="aiReset">清空自定义</button>
|
|
593
|
+
<button class="primary" id="aiSave">保存</button>
|
|
594
|
+
</footer>
|
|
595
|
+
</div>
|
|
596
|
+
</div>
|
|
597
|
+
|
|
598
|
+
<div class="modal" id="avatarModal">
|
|
599
|
+
<div class="card" style="width:min(440px,92vw)">
|
|
600
|
+
<header>设置头像<button id="amClose">×</button></header>
|
|
601
|
+
<div class="body">
|
|
602
|
+
<div style="display:flex;align-items:center;gap:12px;margin-bottom:14px">
|
|
603
|
+
<span id="amPreview" style="width:48px;height:48px;border-radius:50%;background:#f2f4f7;flex:0 0 48px;
|
|
604
|
+
display:flex;align-items:center;justify-content:center;overflow:hidden;color:var(--muted);font-size:12px">预览</span>
|
|
605
|
+
<div style="font-size:12.5px;color:var(--muted);line-height:1.6">
|
|
606
|
+
钉钉接口不返回头像,这里设的是本地头像(存在 <code>_媒体/头像/</code>)。
|
|
607
|
+
</div>
|
|
608
|
+
</div>
|
|
609
|
+
<div style="display:flex;gap:8px;margin-bottom:10px">
|
|
610
|
+
<button class="primary" id="amFile">选择本地图片…</button>
|
|
611
|
+
<button id="amClear">清除头像</button>
|
|
612
|
+
</div>
|
|
613
|
+
<div style="font-size:12px;color:var(--muted);margin-bottom:6px">或粘贴一个图片链接</div>
|
|
614
|
+
<div style="display:flex;gap:8px">
|
|
615
|
+
<input id="amUrl" placeholder="https://…/avatar.png" style="flex:1;font-size:12px">
|
|
616
|
+
<button id="amUrlOk">使用链接</button>
|
|
617
|
+
</div>
|
|
618
|
+
<div style="font-size:11.5px;color:var(--muted);margin-top:10px">也可以直接把图片拖到左侧联系人条目上。</div>
|
|
619
|
+
</div>
|
|
620
|
+
<footer><button id="amCancel">关闭</button></footer>
|
|
621
|
+
</div>
|
|
622
|
+
</div>
|
|
623
|
+
|
|
624
|
+
<div class="modal" id="contactModal">
|
|
625
|
+
<div class="card" style="width:min(780px,94vw)">
|
|
626
|
+
<header>添加常用联系人(单聊)<button id="cmClose">×</button></header>
|
|
627
|
+
<div class="body">
|
|
628
|
+
<div style="display:flex;gap:8px;margin-bottom:6px">
|
|
629
|
+
<input id="cmQuery" placeholder="搜索你的钉钉单聊:对方姓名 / openConversationId" style="flex:1">
|
|
630
|
+
<button id="cmReload" title="重新读取钉钉单聊列表">刷新列表</button>
|
|
631
|
+
</div>
|
|
632
|
+
<div id="cmHint" style="font-size:12px;color:var(--muted);margin:0 0 8px"></div>
|
|
633
|
+
<div id="cmList" style="max-height:44vh;overflow:auto;color:var(--muted);font-size:13px">加载中…</div>
|
|
634
|
+
<div style="margin-top:14px;padding-top:12px;border-top:1px dashed var(--line)">
|
|
635
|
+
<div style="font-size:12px;color:var(--muted);margin-bottom:8px">或手动填写(单聊 openConversationId 可从单聊会话标题处复制;只填 openDingTalkId 也能发单聊,但没有会话历史)</div>
|
|
636
|
+
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
|
637
|
+
<input id="cmName" placeholder="姓名" style="flex:1;min-width:110px">
|
|
638
|
+
<input id="cmCid" placeholder="单聊 openConversationId" style="flex:2;min-width:200px;font-family:var(--mono);font-size:12px">
|
|
639
|
+
<input id="cmOpenId" placeholder="openDingTalkId(可空)" style="flex:1.5;min-width:170px;font-family:var(--mono);font-size:12px">
|
|
640
|
+
<button class="primary" id="cmAddBtn">添加</button>
|
|
641
|
+
</div>
|
|
642
|
+
</div>
|
|
643
|
+
</div>
|
|
644
|
+
<footer><button id="cmCancel">关闭</button></footer>
|
|
645
|
+
</div>
|
|
646
|
+
</div>
|
|
647
|
+
|
|
353
648
|
<div class="modal" id="membersModal">
|
|
354
649
|
<div class="card">
|
|
355
650
|
<header><span id="memTitle">成员</span><button id="memClose">×</button></header>
|
|
@@ -399,6 +694,98 @@ async function api(url, opts){
|
|
|
399
694
|
return j;
|
|
400
695
|
}
|
|
401
696
|
|
|
697
|
+
/* ---------------- 会话列表布局(顺序 / 置顶)与多选 ---------------- */
|
|
698
|
+
let GLAYOUT = { order: [], pinned: [] };
|
|
699
|
+
const GPICK = new Set();
|
|
700
|
+
let GDRAG = null;
|
|
701
|
+
|
|
702
|
+
async function loadLayout(){
|
|
703
|
+
try{
|
|
704
|
+
const j = await api("/api/layout");
|
|
705
|
+
GLAYOUT = { order: j.order || [], pinned: j.pinned || [] };
|
|
706
|
+
}catch{ GLAYOUT = { order: [], pinned: [] }; }
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
async function saveLayout(patch){
|
|
710
|
+
if(patch.keys){
|
|
711
|
+
GLAYOUT.order = patch.keys.slice();
|
|
712
|
+
await api("/api/layout", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
713
|
+
body: JSON.stringify({keys: patch.keys})});
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if(patch.pin){
|
|
717
|
+
const { short, pinned } = patch.pin;
|
|
718
|
+
GLAYOUT.pinned = pinned
|
|
719
|
+
? [...new Set([...GLAYOUT.pinned, short])]
|
|
720
|
+
: GLAYOUT.pinned.filter(x => x !== short);
|
|
721
|
+
await api("/api/layout", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
722
|
+
body: JSON.stringify({action:"pin", short, pinned})});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
async function togglePinGroup(short){
|
|
727
|
+
const pinned = GLAYOUT.pinned.includes(short);
|
|
728
|
+
try{
|
|
729
|
+
await saveLayout({ pin: { short, pinned: !pinned } });
|
|
730
|
+
await loadGroups(false);
|
|
731
|
+
toast(pinned ? "已取消置顶" : "已置顶到最前");
|
|
732
|
+
}catch(e){ toast("操作失败:" + e.message, true); }
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function togglePick(short){
|
|
736
|
+
if(GPICK.has(short)) GPICK.delete(short); else GPICK.add(short);
|
|
737
|
+
const el = document.querySelector(`.gitem[data-short="${CSS.escape(short)}"]`);
|
|
738
|
+
if(el) el.classList.toggle("picked", GPICK.has(short));
|
|
739
|
+
$("#glist").classList.toggle("picking", GPICK.size > 0);
|
|
740
|
+
renderPickBar();
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function clearPick(){
|
|
744
|
+
GPICK.clear();
|
|
745
|
+
$("#glist").classList.remove("picking");
|
|
746
|
+
$("#glist").querySelectorAll(".gitem.picked").forEach(el => el.classList.remove("picked"));
|
|
747
|
+
renderPickBar();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function renderPickBar(){
|
|
751
|
+
const bar = $("#pickBar");
|
|
752
|
+
if(!bar) return;
|
|
753
|
+
bar.classList.toggle("show", GPICK.size > 0);
|
|
754
|
+
const n = $("#pickCount");
|
|
755
|
+
if(n) n.textContent = `已选 ${GPICK.size} 个会话`;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
async function deletePicked(){
|
|
759
|
+
const shorts = [...GPICK];
|
|
760
|
+
if(!shorts.length) return;
|
|
761
|
+
const names = shorts.map(s2 => (GROUPS.find(g => g.short === s2) || {}).name || s2);
|
|
762
|
+
if(!confirm(`删除 ${shorts.length} 个归档?\n\n${names.slice(0, 8).join("\n")}${names.length > 8 ? `\n… 等 ${names.length} 个` : ""}\n\n会移到 _回收站,可手动恢复。`)) return;
|
|
763
|
+
const btn = $("#pickDel");
|
|
764
|
+
const html = btn ? btn.innerHTML : "";
|
|
765
|
+
if(btn){ btn.disabled = true; btn.innerHTML = `<span class="spin"></span>删除中`; }
|
|
766
|
+
let ok = 0, fail = [];
|
|
767
|
+
for(const short of shorts){
|
|
768
|
+
try{
|
|
769
|
+
await api("/api/delete", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
770
|
+
body: JSON.stringify({short})});
|
|
771
|
+
ok += 1;
|
|
772
|
+
}catch(e){ fail.push(short + ":" + e.message); }
|
|
773
|
+
}
|
|
774
|
+
if(btn){ btn.disabled = false; btn.innerHTML = html; }
|
|
775
|
+
clearPick();
|
|
776
|
+
shorts.forEach(x => MSG_CACHE.delete(x));
|
|
777
|
+
if(CUR && shorts.includes(CUR.short)){
|
|
778
|
+
CUR = null; MSGS = [];
|
|
779
|
+
$("#workspace").style.display = "none";
|
|
780
|
+
$("#empty").style.display = "flex";
|
|
781
|
+
}
|
|
782
|
+
await loadGroups(false);
|
|
783
|
+
toast(fail.length ? `删除完成:成功 ${ok},失败 ${fail.length}` : `已删除 ${ok} 个归档(进 _回收站)`, fail.length > 0);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
$("#pickCancel").onclick = clearPick;
|
|
787
|
+
$("#pickDel").onclick = deletePicked;
|
|
788
|
+
|
|
402
789
|
/* ---------------- 群列表 ---------------- */
|
|
403
790
|
async function loadGroups(keep){
|
|
404
791
|
const j = await api("/api/groups");
|
|
@@ -410,49 +797,145 @@ async function loadGroups(keep){
|
|
|
410
797
|
function renderGroups(){
|
|
411
798
|
const q = $("#gsearch").value.trim().toLowerCase();
|
|
412
799
|
const hit = g => !q || g.name.toLowerCase().includes(q) || g.short.toLowerCase().includes(q);
|
|
413
|
-
const item = g =>
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
800
|
+
const item = g => {
|
|
801
|
+
const pinned = GLAYOUT.pinned.includes(g.short);
|
|
802
|
+
const picked = GPICK.has(g.short);
|
|
803
|
+
return `
|
|
804
|
+
<div class="gitem ${g.kind==="dm"?"dm":""} ${g.kind==="mentions"?"atAgg":""} ${pinned?"pinned":""} ${picked?"picked":""} ${CUR && CUR.short===g.short && !FILTER.group ? "active":""}" data-short="${esc(g.short)}" data-kind="${esc(g.kind)}">
|
|
805
|
+
<span class="pickBox">✓</span>
|
|
806
|
+
<span class="gacts">
|
|
807
|
+
<button class="gpin" title="${pinned?"取消置顶":"置顶到最前"}">${pinned?"📌":"⇧"}</button>
|
|
808
|
+
<button class="gpick" title="多选">☑</button>
|
|
809
|
+
<button class="moreBtn" title="更多操作(等同右键)">⋯</button>
|
|
810
|
+
</span>
|
|
811
|
+
<div class="gname">${g.kind==="mentions" ? `<button class="secChev" title="${closed.has("mentions")?"展开来源群":"收起来源群"}">${closed.has("mentions")?"▸":"▾"}</button>` : ""}${esc(g.name)}${pinned?'<span class="pinTag" title="已置顶">📌</span>':""}${g.kind==="dm"?'<span class="dmTag">单聊</span>':""}${g.kind==="mentions"?'<span class="atTag">聚合</span>':""}</div>
|
|
417
812
|
<div class="gmeta">
|
|
418
813
|
<span><span class="dot ${g.complete===false?"bad":(g.newCount>0?"":"off")}"></span>${g.msgCount} 条</span>
|
|
419
814
|
${g.newCount>0 ? `<span class="newTag">+${g.newCount} 新</span>` : ""}
|
|
420
815
|
${g.kind==="group" ? `<span>${g.memberCount} 人</span>` : ""}
|
|
421
|
-
${g.kind==="mentions" ? `<span>${g.sourceCount}
|
|
816
|
+
${g.kind==="mentions" ? `<span>${g.sourceCount} 个群${g.since ? " · 自 " + esc(g.since.slice(5)) : ""}</span>` : ""}
|
|
422
817
|
<span>${esc((g.spanEnd||"").slice(5))}</span>
|
|
423
818
|
</div>
|
|
424
819
|
</div>`;
|
|
820
|
+
};
|
|
425
821
|
|
|
426
|
-
// @我
|
|
822
|
+
// @我 聚合:把来源群作为子级列在下面(未归档的也能点,点了自动归档)
|
|
823
|
+
const SHOW_SRC = 15;
|
|
427
824
|
const children = g => {
|
|
428
|
-
const srcs = g.sources || []
|
|
825
|
+
const srcs = (g.sources || []).slice().sort((a, b) =>
|
|
826
|
+
(b.archived ? 1 : 0) - (a.archived ? 1 : 0) || b.count - a.count);
|
|
429
827
|
if(!srcs.length) return "";
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
828
|
+
const opened = g.sourceOpenAll;
|
|
829
|
+
const list = opened ? srcs : srcs.slice(0, SHOW_SRC);
|
|
830
|
+
const rest = srcs.length - list.length;
|
|
831
|
+
const keyOf = s => s.short || ("cid:" + s.cid);
|
|
832
|
+
const html = list.map(s => `
|
|
833
|
+
<div class="gchild ${CUR && CUR.short===g.short && FILTER.group===keyOf(s) ? "active":""} ${s.archived ? "" : "unarchived"}"
|
|
834
|
+
data-at="${esc(s.short || "")}" data-cid="${esc(s.cid || "")}" data-name="${esc(s.name)}"
|
|
835
|
+
title="${esc(s.name)}(${s.count} 条 @我${s.archived ? "" : " · 未归档,点开自动归档"})">
|
|
836
|
+
<span class="nm">${esc(s.name)}${s.archived ? "" : '<span class="unTag">未归档</span>'}</span><span class="ct">${s.count}</span>
|
|
837
|
+
</div>`).join("");
|
|
838
|
+
const more = rest > 0
|
|
839
|
+
? `<div class="gchild gmoresrc" data-more="${esc(g.short)}">显示全部 ${srcs.length} 个群(还有 ${rest} 个)</div>`
|
|
840
|
+
: "";
|
|
841
|
+
return `<div class="gchildren">${html}${more}</div>`;
|
|
435
842
|
};
|
|
436
843
|
|
|
437
|
-
const
|
|
438
|
-
const
|
|
439
|
-
|
|
844
|
+
const orderIdx = new Map((GLAYOUT.order || []).map((s2,i) => [s2, i]));
|
|
845
|
+
const rank = g => {
|
|
846
|
+
const pinAt = GLAYOUT.pinned.indexOf(g.short);
|
|
847
|
+
if(pinAt >= 0) return -100000 + pinAt;
|
|
848
|
+
return orderIdx.has(g.short) ? orderIdx.get(g.short) : 200000;
|
|
849
|
+
};
|
|
850
|
+
const ats = GROUPS.filter(g => g.kind==="mentions" && hit(g)).sort((a,b)=>rank(a)-rank(b));
|
|
851
|
+
const grps = GROUPS.filter(g => g.kind==="group" && hit(g)).sort((a,b)=>rank(a)-rank(b));
|
|
852
|
+
const closed = closedSecs();
|
|
853
|
+
const sec = (key, label, n, unread) => `<div class="gsec ${closed.has(key)?"closed":""}" data-sec="${key}" title="展开 / 收起">
|
|
854
|
+
<span class="chev"></span>${label}${unread ? `<span class="secUnread">${unread > 99 ? "99+" : unread}</span>` : ""}<span class="secN">${n}</span></div>`;
|
|
855
|
+
const sum = list => list.reduce((a,g)=>a+g.msgCount,0);
|
|
440
856
|
let html = "";
|
|
441
|
-
|
|
442
|
-
if(
|
|
443
|
-
|
|
857
|
+
// 单聊不再单独列(统一走上面的「常用联系人」)
|
|
858
|
+
if(ats.length) html += ats.map(g => item(g) + (closed.has("mentions") ? "" : children(g))).join("");
|
|
859
|
+
const grpUnread = grps.reduce((a, g) => a + Number(g.newCount || 0), 0);
|
|
860
|
+
if(grps.length) html += sec("groups", "群聊", sum(grps), grpUnread) + (closed.has("groups") ? "" : grps.map(item).join(""));
|
|
444
861
|
$("#glist").innerHTML = html ||
|
|
445
862
|
`<div style="color:var(--muted);padding:12px;font-size:13px">没有匹配的会话</div>`;
|
|
863
|
+
$("#glist").querySelectorAll(".gsec[data-sec]").forEach(el => {
|
|
864
|
+
el.onclick = () => toggleSec(el.dataset.sec);
|
|
865
|
+
});
|
|
866
|
+
$("#glist").classList.toggle("picking", GPICK.size > 0);
|
|
446
867
|
$("#glist").querySelectorAll(".gitem").forEach(el => {
|
|
447
|
-
|
|
448
|
-
el.
|
|
449
|
-
|
|
450
|
-
|
|
868
|
+
const short = el.dataset.short;
|
|
869
|
+
el.onclick = () => {
|
|
870
|
+
if(GPICK.size){ togglePick(short); return; }
|
|
871
|
+
FILTER.group = "";
|
|
872
|
+
const gg = GROUPS.find(x => x.short === short);
|
|
873
|
+
if(gg) ensureSecOpen(gg.kind);
|
|
874
|
+
selectGroup(short);
|
|
875
|
+
};
|
|
876
|
+
el.oncontextmenu = e => { e.preventDefault(); openCtx(e, short); };
|
|
877
|
+
const chev = el.querySelector(".secChev");
|
|
878
|
+
if(chev) chev.onclick = e => { e.stopPropagation(); toggleSec("mentions"); };
|
|
879
|
+
|
|
880
|
+
// 置顶
|
|
881
|
+
el.querySelector(".gpin").onclick = async e => {
|
|
882
|
+
e.stopPropagation();
|
|
883
|
+
await togglePinGroup(short);
|
|
884
|
+
};
|
|
885
|
+
// 进入多选
|
|
886
|
+
el.querySelector(".gpick").onclick = e => {
|
|
451
887
|
e.stopPropagation();
|
|
452
|
-
|
|
453
|
-
openCtx({clientX: r.left, clientY: r.bottom + 4}, el.dataset.short);
|
|
888
|
+
togglePick(short);
|
|
454
889
|
};
|
|
890
|
+
// 更多
|
|
891
|
+
el.querySelector(".moreBtn").onclick = e => {
|
|
892
|
+
e.stopPropagation();
|
|
893
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
894
|
+
openCtx({clientX: r.left, clientY: r.bottom + 4}, short);
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
// 拖动排序(只允许同一分组内)
|
|
898
|
+
el.draggable = true;
|
|
899
|
+
el.addEventListener("dragstart", e => {
|
|
900
|
+
if(GPICK.size){ e.preventDefault(); return; }
|
|
901
|
+
GDRAG = { short, kind: el.dataset.kind };
|
|
902
|
+
el.classList.add("dragging");
|
|
903
|
+
e.dataTransfer.effectAllowed = "move";
|
|
904
|
+
try{ e.dataTransfer.setData("text/plain", short); }catch{}
|
|
905
|
+
});
|
|
906
|
+
el.addEventListener("dragend", () => {
|
|
907
|
+
el.classList.remove("dragging");
|
|
908
|
+
$("#glist").querySelectorAll(".gitem").forEach(x => x.classList.remove("dropBefore","dropAfter"));
|
|
909
|
+
GDRAG = null;
|
|
910
|
+
});
|
|
911
|
+
el.addEventListener("dragover", e => {
|
|
912
|
+
if(!GDRAG || GDRAG.kind !== el.dataset.kind || GDRAG.short === short) return;
|
|
913
|
+
e.preventDefault();
|
|
914
|
+
const r = el.getBoundingClientRect();
|
|
915
|
+
const after = (e.clientY - r.top) > r.height / 2;
|
|
916
|
+
el.classList.toggle("dropAfter", after);
|
|
917
|
+
el.classList.toggle("dropBefore", !after);
|
|
918
|
+
});
|
|
919
|
+
el.addEventListener("dragleave", () => el.classList.remove("dropBefore","dropAfter"));
|
|
920
|
+
el.addEventListener("drop", async e => {
|
|
921
|
+
e.preventDefault();
|
|
922
|
+
e.stopPropagation();
|
|
923
|
+
el.classList.remove("dropBefore","dropAfter");
|
|
924
|
+
if(!GDRAG || GDRAG.kind !== el.dataset.kind || GDRAG.short === short) return;
|
|
925
|
+
const from = GDRAG.short;
|
|
926
|
+
// 以当前可视顺序为基准重排
|
|
927
|
+
const keys = [...$("#glist").querySelectorAll(".gitem")].map(x => x.dataset.short).filter(k => k !== from);
|
|
928
|
+
const at = keys.indexOf(short);
|
|
929
|
+
const r = el.getBoundingClientRect();
|
|
930
|
+
const after = (e.clientY - r.top) > r.height / 2;
|
|
931
|
+
keys.splice(Math.max(0, after ? at + 1 : at), 0, from);
|
|
932
|
+
try{
|
|
933
|
+
await saveLayout({ keys });
|
|
934
|
+
await loadGroups(false);
|
|
935
|
+
}catch(err){ toast("排序失败:" + err.message, true); }
|
|
936
|
+
});
|
|
455
937
|
});
|
|
938
|
+
renderPickBar();
|
|
456
939
|
|
|
457
940
|
// 收起状态下也能看到当前会话
|
|
458
941
|
const rav = $("#railAv");
|
|
@@ -461,19 +944,80 @@ function renderGroups(){
|
|
|
461
944
|
rav.textContent = a.letter; rav.style.background = a.bg; rav.style.display = "flex"; }
|
|
462
945
|
else rav.style.display = "none";
|
|
463
946
|
}
|
|
947
|
+
renderContacts();
|
|
464
948
|
$("#glist").querySelectorAll(".gchild").forEach(el => {
|
|
465
|
-
|
|
949
|
+
if(el.dataset.more){
|
|
950
|
+
el.onclick = () => {
|
|
951
|
+
const at = GROUPS.find(x => x.kind === "mentions");
|
|
952
|
+
if(at){ at.sourceOpenAll = true; renderGroups(); }
|
|
953
|
+
};
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
el.onclick = () => {
|
|
957
|
+
if(el.dataset.at) openAtGroup(el.dataset.at);
|
|
958
|
+
else adoptAndOpenMention(el.dataset.cid, el.dataset.name || "");
|
|
959
|
+
};
|
|
466
960
|
});
|
|
467
961
|
}
|
|
468
962
|
|
|
469
963
|
let PENDING_GROUP = null;
|
|
470
964
|
|
|
965
|
+
/* @我 聚合里点了未归档的来源群:先归档(拉历史),再重新汇总并定位过去 */
|
|
966
|
+
async function adoptAndOpenMention(cid, name){
|
|
967
|
+
if(!cid) return;
|
|
968
|
+
toast(`正在归档「${name}」…`);
|
|
969
|
+
try{
|
|
970
|
+
const j = await api("/api/adopt", {
|
|
971
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
972
|
+
body: JSON.stringify({ name, cid, kind: "group" })
|
|
973
|
+
});
|
|
974
|
+
await loadGroups(false);
|
|
975
|
+
// 重新汇总,让这条来源变成已归档(能直接定位到归档群)
|
|
976
|
+
await api("/api/pull", { method:"POST", headers:{"Content-Type":"application/json"},
|
|
977
|
+
body: JSON.stringify({ shorts: ["@我的消息"] }) }).catch(()=>{});
|
|
978
|
+
await loadGroups(false);
|
|
979
|
+
// 强制重新拉一次聚合消息,让这条来源的 groupShort 映射生效,再定位过去
|
|
980
|
+
adoptAndOpenMention.lastShort = j.short;
|
|
981
|
+
PENDING_GROUP = j.short;
|
|
982
|
+
FILTER.group = "";
|
|
983
|
+
FILTER.range = ""; // 刚归档的群,@我 消息可能在很久以前
|
|
984
|
+
await selectGroup("@我的消息");
|
|
985
|
+
toast(`已归档「${name}」,共 ${j.total} 条消息`);
|
|
986
|
+
}catch(e){ toast("归档失败:" + e.message, true); }
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/* ---------------- 分组(@我 聚合 / 单聊 / 群聊)可收起 ---------------- */
|
|
990
|
+
function closedSecs(){
|
|
991
|
+
try{
|
|
992
|
+
const raw = JSON.parse(localStorage.getItem("omd.gsecClosed") || "[]");
|
|
993
|
+
return new Set(Array.isArray(raw) ? raw : []);
|
|
994
|
+
}catch{ return new Set(); }
|
|
995
|
+
}
|
|
996
|
+
function saveClosedSecs(set){
|
|
997
|
+
localStorage.setItem("omd.gsecClosed", JSON.stringify([...set]));
|
|
998
|
+
}
|
|
999
|
+
function toggleSec(key){
|
|
1000
|
+
const closed = closedSecs();
|
|
1001
|
+
if(closed.has(key)) closed.delete(key); else closed.add(key);
|
|
1002
|
+
saveClosedSecs(closed);
|
|
1003
|
+
renderGroups();
|
|
1004
|
+
}
|
|
1005
|
+
/** 被选中/定位的会话所在分组如果是收起的,就自动展开 */
|
|
1006
|
+
function ensureSecOpen(kind){
|
|
1007
|
+
const key = kind === "mentions" ? "mentions" : kind === "dm" ? "dms" : "groups";
|
|
1008
|
+
const closed = closedSecs();
|
|
1009
|
+
if(closed.delete(key)) saveClosedSecs(closed);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
471
1012
|
function openAtGroup(srcShort){
|
|
472
1013
|
const at = GROUPS.find(g => g.kind === "mentions");
|
|
1014
|
+
ensureSecOpen("mentions");
|
|
473
1015
|
if(!at) return;
|
|
474
1016
|
PENDING_GROUP = srcShort;
|
|
475
1017
|
if(CUR && CUR.short === at.short){
|
|
476
1018
|
FILTER.group = srcShort;
|
|
1019
|
+
FILTER.range = ""; // 从聚合点进某个来源群,别被「近 7 天」挡掉老消息
|
|
1020
|
+
resetRenderLimit();
|
|
477
1021
|
PENDING_GROUP = null;
|
|
478
1022
|
renderGroups();
|
|
479
1023
|
renderTab();
|
|
@@ -499,6 +1043,8 @@ function openCtx(e, short){
|
|
|
499
1043
|
m.querySelectorAll("[data-need-group]").forEach(el => {
|
|
500
1044
|
el.style.display = g ? (el.tagName === "BUTTON" ? "flex" : "block") : "none";
|
|
501
1045
|
});
|
|
1046
|
+
const resetItem = m.querySelector("#ctxResetMentions");
|
|
1047
|
+
if(resetItem) resetItem.style.display = g && g.kind === "mentions" ? "flex" : "none";
|
|
502
1048
|
m.classList.add("show");
|
|
503
1049
|
// 标出这次右键的是哪条会话
|
|
504
1050
|
document.querySelectorAll(".gitem.ctxTarget").forEach(el => el.classList.remove("ctxTarget"));
|
|
@@ -584,6 +1130,7 @@ async function ctxDelete(item){
|
|
|
584
1130
|
method:"POST", headers:{"Content-Type":"application/json"},
|
|
585
1131
|
body: JSON.stringify({short: g.short})
|
|
586
1132
|
});
|
|
1133
|
+
MSG_CACHE.delete(g.short);
|
|
587
1134
|
if(CUR && CUR.short === g.short){ CUR = null; MSGS = []; MEMBERS = null;
|
|
588
1135
|
$("#workspace").style.display = "none"; $("#empty").style.display = "flex"; }
|
|
589
1136
|
await loadGroups(false);
|
|
@@ -593,31 +1140,94 @@ async function ctxDelete(item){
|
|
|
593
1140
|
}
|
|
594
1141
|
|
|
595
1142
|
/* ---------------- 选群 & 渲染 ---------------- */
|
|
1143
|
+
/* 会话消息缓存:同一个会话再次打开先用缓存秒出,再后台刷新比对 */
|
|
1144
|
+
const MSG_CACHE = new Map(); // short -> { messages, cid, kind, sources, at }
|
|
1145
|
+
const MSG_CACHE_TTL = 10 * 60 * 1000;
|
|
1146
|
+
|
|
1147
|
+
function msgCacheGet(short){
|
|
1148
|
+
const c = MSG_CACHE.get(short);
|
|
1149
|
+
if(!c) return null;
|
|
1150
|
+
if(Date.now() - c.at > MSG_CACHE_TTL) { MSG_CACHE.delete(short); return null; }
|
|
1151
|
+
return c;
|
|
1152
|
+
}
|
|
1153
|
+
function msgCacheSet(short, pack){
|
|
1154
|
+
MSG_CACHE.set(short, { ...pack, at: Date.now() });
|
|
1155
|
+
}
|
|
596
1156
|
async function selectGroup(short, keepTab){
|
|
597
1157
|
const g = GROUPS.find(x=>x.short===short);
|
|
598
1158
|
if(!g) return;
|
|
599
1159
|
CUR = g;
|
|
600
1160
|
if(location.hash.slice(1) !== encodeURIComponent(short))
|
|
601
1161
|
history.replaceState(null, "", "#" + encodeURIComponent(short));
|
|
602
|
-
|
|
1162
|
+
resetRenderLimit();
|
|
1163
|
+
if(!keepTab){ FILTER = { kw:"", sender:"", from:"", to:"", range:"today", desc:true, newIds:new Set(), jump:true }; }
|
|
603
1164
|
else { FILTER.jump = true; }
|
|
1165
|
+
resetRenderLimit();
|
|
1166
|
+
PENDING_IMGS = [];
|
|
604
1167
|
renderGroups();
|
|
605
1168
|
$("#empty").style.display = "none";
|
|
606
1169
|
const ws = $("#workspace");
|
|
607
1170
|
ws.style.display = "flex";
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const j = await api("/api/messages?short=" + encodeURIComponent(short));
|
|
1171
|
+
|
|
1172
|
+
const applyPack = (j, isCache) => {
|
|
611
1173
|
MSGS = j.messages || [];
|
|
612
1174
|
MEMBERS = null;
|
|
613
1175
|
CUR.cid = j.cid;
|
|
614
1176
|
if(j.kind) CUR.kind = j.kind;
|
|
615
1177
|
CUR.msgSources = j.sources || [];
|
|
1178
|
+
};
|
|
1179
|
+
const autoRange = () => {
|
|
1180
|
+
if(keepTab || !MSGS.length) return;
|
|
1181
|
+
const rg = rangeBounds(FILTER.range);
|
|
1182
|
+
if(!rg) return;
|
|
1183
|
+
const has = MSGS.some(m => {
|
|
1184
|
+
const d = String(m.createTime || "").slice(0, 10);
|
|
1185
|
+
return d && d >= rg.from && (!rg.to || d <= rg.to);
|
|
1186
|
+
});
|
|
1187
|
+
if(!has) FILTER.range = "";
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
// ① 有缓存就立刻渲染,不再闪「加载中」
|
|
1191
|
+
const cached = msgCacheGet(short);
|
|
1192
|
+
if(cached){
|
|
1193
|
+
applyPack(cached, true);
|
|
1194
|
+
autoRange();
|
|
1195
|
+
renderWorkspace();
|
|
1196
|
+
}else{
|
|
1197
|
+
ws.innerHTML = `<div class="empty">加载中…</div>`;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
try{
|
|
1201
|
+
const j = await api("/api/messages?short=" + encodeURIComponent(short));
|
|
1202
|
+
const prev = cached && cached.messages ? cached.messages : null;
|
|
1203
|
+
const same = prev && prev.length === (j.messages || []).length
|
|
1204
|
+
&& (prev.length === 0 || String(prev[prev.length-1].messageId) === String((j.messages||[]).slice(-1)[0].messageId));
|
|
1205
|
+
msgCacheSet(short, { messages: j.messages || [], cid: j.cid, kind: j.kind, sources: j.sources || [] });
|
|
1206
|
+
applyPack(j, false);
|
|
1207
|
+
// 默认「今天」;这个会话/这个时间范围内一条都没有,就自动放开到全部时间,别一进来就空
|
|
1208
|
+
if(!keepTab && MSGS.length){
|
|
1209
|
+
const rg = rangeBounds(FILTER.range);
|
|
1210
|
+
if(rg){
|
|
1211
|
+
const has = MSGS.some(m => {
|
|
1212
|
+
const d = String(m.createTime || "").slice(0, 10);
|
|
1213
|
+
return d && d >= rg.from && (!rg.to || d <= rg.to);
|
|
1214
|
+
});
|
|
1215
|
+
if(!has) FILTER.range = "";
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
616
1218
|
if(PENDING_GROUP !== null){
|
|
617
1219
|
FILTER.group = PENDING_GROUP;
|
|
1220
|
+
FILTER.range = ""; // 从聚合点进某个来源群,消息可能是很久以前的
|
|
1221
|
+
resetRenderLimit();
|
|
618
1222
|
PENDING_GROUP = null;
|
|
619
1223
|
renderGroups();
|
|
620
|
-
|
|
1224
|
+
renderWorkspace();
|
|
1225
|
+
}else if(!cached || !same){
|
|
1226
|
+
autoRange();
|
|
1227
|
+
renderWorkspace();
|
|
1228
|
+
}else{
|
|
1229
|
+
// 缓存命中且服务端没变化:不重渲染,保持用户滚动位置
|
|
1230
|
+
}
|
|
621
1231
|
if(PENDING_FOCUS){
|
|
622
1232
|
const mid = PENDING_FOCUS;
|
|
623
1233
|
PENDING_FOCUS = null;
|
|
@@ -639,24 +1249,43 @@ function renderWorkspace(){
|
|
|
639
1249
|
const g = CUR;
|
|
640
1250
|
const ws = $("#workspace");
|
|
641
1251
|
const isAt = g.kind === "mentions";
|
|
1252
|
+
const isPerson = g.kind === "person";
|
|
1253
|
+
const isDmAll = g.kind === "dmAll";
|
|
642
1254
|
ws.innerHTML = `
|
|
643
1255
|
<div class="ghead">
|
|
644
1256
|
<div class="headline">
|
|
645
1257
|
<h2 title="${esc(g.name)}">${esc(g.name)}</h2>
|
|
646
|
-
${isAt
|
|
647
|
-
? `<span class="aggChip">${g.sourceCount || 0}
|
|
1258
|
+
${isAt || isPerson || isDmAll
|
|
1259
|
+
? `<span class="aggChip">${isAt ? `${g.sourceCount || 0} 个群汇总` : isPerson ? `${g.sourceCount || 0} 个群汇总` : `${g.sourceCount || 0} 个人私聊`}</span>`
|
|
648
1260
|
: `<span class="cid" title="点击复制 openConversationId" id="cidChip" style="cursor:copy">${esc(g.cid)}</span>`}
|
|
649
|
-
<span class="mini">${MSGS.length} 条${isAt ? " @我" : ""}${g.kind==="group" ? " · " + g.memberCount + " 人" : ""}</span>
|
|
1261
|
+
<span class="mini">${MSGS.length} 条${isAt ? " @我" : ""}${isPerson ? " 发言" : ""}${isDmAll ? " 别人发我的" : ""}${g.kind==="group" ? " · " + g.memberCount + " 人" : ""}</span>
|
|
650
1262
|
<span class="mini">${esc(MSGS.length ? MSGS[0].createTime.slice(5,16) : "")} ~ ${esc(MSGS.length ? MSGS[MSGS.length-1].createTime.slice(5,16) : "")}</span>
|
|
651
|
-
<span class="mini"
|
|
1263
|
+
<span class="mini">${isPerson ? "常用联系人" : isDmAll ? "私聊聚合" : "拉取 " + esc((g.lastPull || "-").slice(11) || "-")}</span>
|
|
652
1264
|
<span class="spacerHead"></span>
|
|
653
1265
|
<div class="actions">
|
|
654
|
-
|
|
1266
|
+
${isDmAll && CUR.unreadCount ? `<button id="btnDmReadAll" title="把这些人的未读一次清掉">全部标为已读(${CUR.unreadCount})</button>` : ""}
|
|
1267
|
+
<button id="btnSettings" title="设置:AI 模型 / 监控 / 进程 / 通用">⚙ 设置</button>
|
|
1268
|
+
<button id="btnAiSum" title="让 AI 总结当前范围内(${isAt ? "全部来源群" : "当前会话"})的消息">🧠 AI 总结</button>
|
|
1269
|
+
<button class="primary" id="btnPull">${isAt ? "重新汇总" : isPerson || isDmAll ? "刷新" : "拉取最新消息"}</button>
|
|
655
1270
|
</div>
|
|
656
1271
|
</div>
|
|
657
1272
|
</div>
|
|
658
1273
|
<div id="tabBody" style="flex:1;display:flex;flex-direction:column;min-height:0"></div>`;
|
|
659
|
-
$("#btnPull").onclick = () => pull([CUR.short], $("#btnPull"));
|
|
1274
|
+
$("#btnPull").onclick = () => (isPerson ? openPerson(g.openId) : isDmAll ? openDmAll() : pull([CUR.short], $("#btnPull")));
|
|
1275
|
+
$("#btnAiSum").onclick = () => aiSummarize($("#btnAiSum"));
|
|
1276
|
+
$("#btnSettings").onclick = () => openSettings();
|
|
1277
|
+
const ra = $("#btnDmReadAll");
|
|
1278
|
+
if(ra) ra.onclick = async () => {
|
|
1279
|
+
ra.disabled = true;
|
|
1280
|
+
const peersWithUnread = (CUR.sources || []).filter(p => p.unread > 0 && p.short);
|
|
1281
|
+
for(const p of peersWithUnread){
|
|
1282
|
+
await api("/api/seen", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1283
|
+
body: JSON.stringify({short: p.short})}).catch(()=>{});
|
|
1284
|
+
}
|
|
1285
|
+
await loadGroups(false);
|
|
1286
|
+
await openDmAll();
|
|
1287
|
+
toast("已把这些私聊标为已读");
|
|
1288
|
+
};
|
|
660
1289
|
if($("#cidChip")) $("#cidChip").onclick = () => {
|
|
661
1290
|
navigator.clipboard?.writeText(CUR.cid)
|
|
662
1291
|
.then(()=> toast("会话 ID 已复制:" + CUR.cid))
|
|
@@ -671,17 +1300,24 @@ function senders(){
|
|
|
671
1300
|
return [...set.entries()].sort((a,b)=>a[1].localeCompare(b[1],"zh"));
|
|
672
1301
|
}
|
|
673
1302
|
|
|
1303
|
+
const RENDER_PAGE = 10; // 首屏只渲染最近 10 条
|
|
1304
|
+
const RENDER_STEP = 20; // 每次「加载更早」再补 20 条
|
|
1305
|
+
let RENDER_LIMIT = RENDER_PAGE;
|
|
1306
|
+
function resetRenderLimit(){ RENDER_LIMIT = RENDER_PAGE; }
|
|
1307
|
+
|
|
674
1308
|
function renderTab(){
|
|
675
1309
|
const body = $("#tabBody");
|
|
676
1310
|
const opts = senders().map(([id,name]) => `<option value="${esc(id)}">${esc(name)}</option>`).join("");
|
|
677
1311
|
const isAt = CUR && CUR.kind === "mentions";
|
|
678
|
-
const
|
|
679
|
-
|
|
1312
|
+
const isAgg = CUR && (CUR.kind === "mentions" || CUR.kind === "person" || CUR.kind === "dmAll");
|
|
1313
|
+
const srcLabel = CUR && CUR.kind === "dmAll" ? "全部来源人" : "全部来源群";
|
|
1314
|
+
const srcOpts = isAgg ? (CUR.sources || []).map(s =>
|
|
1315
|
+
`<option value="${esc(s.short)}">${esc(s.name)}${s.unread ? ` · ${s.unread} 未读` : ""}</option>`).join("") : "";
|
|
680
1316
|
body.innerHTML = `
|
|
681
1317
|
<div class="toolbar">
|
|
682
1318
|
<input id="kw" placeholder="搜索内容 / 链接 / @人…" value="${esc(FILTER.kw)}">
|
|
683
1319
|
<select id="sender"><option value="">全部发送者</option>${opts}</select>
|
|
684
|
-
${
|
|
1320
|
+
${isAgg ? `<select id="gsrc"><option value="">${srcLabel}</option>${srcOpts}</select>` : ""}
|
|
685
1321
|
<select id="range">
|
|
686
1322
|
<option value="">全部时间</option>
|
|
687
1323
|
<option value="today">今天</option>
|
|
@@ -700,34 +1336,42 @@ function renderTab(){
|
|
|
700
1336
|
${isAt ? "" : `<button class="composerFab" id="btnCompose">✏️ 发消息</button>
|
|
701
1337
|
<div class="composer" id="composer">
|
|
702
1338
|
<div class="chtop">
|
|
703
|
-
<span>发到「${esc(CUR ? CUR.name : "")}
|
|
1339
|
+
<span>发到「${esc(CUR ? CUR.name : "")}」${CUR && CUR.kind === "person" ? "的单聊" : ""}</span>
|
|
704
1340
|
<span class="spacerL"></span>
|
|
705
1341
|
<span style="font-size:11px">⌘/Ctrl + Enter 发送</span>
|
|
706
1342
|
<button id="btnComposeClose" title="收起">×</button>
|
|
707
1343
|
</div>
|
|
708
|
-
<
|
|
1344
|
+
<div class="imgStrip" id="imgStrip"></div>
|
|
1345
|
+
<textarea id="sendBox" placeholder="输入消息内容…(可直接 ⌘V 粘贴截图,会挂在下面和文字一起发)"></textarea>
|
|
709
1346
|
<div class="cbar">
|
|
710
1347
|
<label title="开启后消息带钉钉 AI 发送角标"><input type="checkbox" id="aiTag"> 带 AI 角标</label>
|
|
711
1348
|
<span class="spacerL"></span>
|
|
712
1349
|
<span id="sendHint">以你的钉钉身份发送</span>
|
|
1350
|
+
<button class="aiBtn" id="btnAi" title="让 AI 按上下文写一条回复">✨ AI 帮我写</button>
|
|
713
1351
|
<button class="primary" id="btnSend">发送</button>
|
|
714
1352
|
</div>
|
|
1353
|
+
<div class="aiRow" id="aiRow">
|
|
1354
|
+
<input id="aiHint" placeholder="想表达什么?可留空,AI 会按上下文自己写">
|
|
1355
|
+
<button class="primary" id="aiGo">生成</button>
|
|
1356
|
+
<button class="aiCfg" id="aiCfg" title="AI 设置(接口 / 模型 / Key)">⚙</button>
|
|
1357
|
+
</div>
|
|
715
1358
|
</div>`}`;
|
|
716
1359
|
|
|
717
1360
|
$("#sender").value = FILTER.sender;
|
|
718
1361
|
if($("#gsrc")){
|
|
719
1362
|
$("#gsrc").value = FILTER.group || "";
|
|
720
|
-
$("#gsrc").onchange = e => { FILTER.group = e.target.value; renderMsgs(); };
|
|
1363
|
+
$("#gsrc").onchange = e => { FILTER.group = e.target.value; resetRenderLimit(); renderMsgs(); };
|
|
721
1364
|
}
|
|
722
|
-
$("#kw").oninput = e => { FILTER.kw = e.target.value; renderMsgs(); };
|
|
723
|
-
$("#sender").onchange = e => { FILTER.sender = e.target.value; renderMsgs(); };
|
|
1365
|
+
$("#kw").oninput = e => { FILTER.kw = e.target.value; resetRenderLimit(); renderMsgs(); };
|
|
1366
|
+
$("#sender").onchange = e => { FILTER.sender = e.target.value; resetRenderLimit(); renderMsgs(); };
|
|
724
1367
|
$("#range").value = FILTER.range || "";
|
|
725
|
-
$("#range").onchange = e => { FILTER.range = e.target.value; renderMsgs(); };
|
|
1368
|
+
$("#range").onchange = e => { FILTER.range = e.target.value; resetRenderLimit(); renderMsgs(); };
|
|
726
1369
|
$("#order").value = FILTER.desc ? "desc" : "asc";
|
|
727
1370
|
$("#order").onchange = e => {
|
|
728
1371
|
FILTER.desc = e.target.value === "desc";
|
|
729
1372
|
$("#jumpLatest").textContent = (FILTER.desc ? "↑" : "↓") + " 最新";
|
|
730
1373
|
FILTER.jump = true;
|
|
1374
|
+
resetRenderLimit();
|
|
731
1375
|
renderMsgs();
|
|
732
1376
|
};
|
|
733
1377
|
$("#jumpLatest").onclick = () => {
|
|
@@ -764,10 +1408,42 @@ function renderTab(){
|
|
|
764
1408
|
box.onkeydown = e => {
|
|
765
1409
|
if((e.metaKey || e.ctrlKey) && e.key === "Enter"){ e.preventDefault(); doSend(); }
|
|
766
1410
|
};
|
|
1411
|
+
renderPendingImgs();
|
|
1412
|
+
// 粘贴图片 / 拖图片进来 → 直接作为图片消息发出
|
|
1413
|
+
box.onpaste = e => {
|
|
1414
|
+
const files = [...((e.clipboardData && e.clipboardData.items) || [])]
|
|
1415
|
+
.filter(it => it.kind === "file" && /^image\//.test(it.type))
|
|
1416
|
+
.map(it => it.getAsFile())
|
|
1417
|
+
.filter(Boolean);
|
|
1418
|
+
if(!files.length) return;
|
|
1419
|
+
e.preventDefault();
|
|
1420
|
+
files.forEach(queueImageFile);
|
|
1421
|
+
};
|
|
1422
|
+
box.ondragover = e => {
|
|
1423
|
+
if(e.dataTransfer && [...(e.dataTransfer.types || [])].includes("Files")){ e.preventDefault(); }
|
|
1424
|
+
};
|
|
1425
|
+
box.ondrop = e => {
|
|
1426
|
+
const files = [...((e.dataTransfer && e.dataTransfer.files) || [])].filter(f => /^image\//.test(f.type));
|
|
1427
|
+
if(!files.length) return;
|
|
1428
|
+
e.preventDefault();
|
|
1429
|
+
files.forEach(queueImageFile);
|
|
1430
|
+
};
|
|
767
1431
|
const aiBox = $("#aiTag");
|
|
768
1432
|
aiBox.checked = localStorage.getItem("aiTag") === "1";
|
|
769
1433
|
aiBox.onchange = e => localStorage.setItem("aiTag", e.target.checked ? "1" : "0");
|
|
770
1434
|
$("#btnSend").onclick = doSend;
|
|
1435
|
+
|
|
1436
|
+
// ✨ AI 帮我写
|
|
1437
|
+
$("#btnAi").onclick = () => {
|
|
1438
|
+
const row = $("#aiRow");
|
|
1439
|
+
row.classList.toggle("show");
|
|
1440
|
+
if(row.classList.contains("show")) setTimeout(()=> $("#aiHint").focus(), 30);
|
|
1441
|
+
};
|
|
1442
|
+
$("#aiHint").onkeydown = e => {
|
|
1443
|
+
if(e.key === "Enter"){ e.preventDefault(); aiDraft(); }
|
|
1444
|
+
};
|
|
1445
|
+
$("#aiGo").onclick = aiDraft;
|
|
1446
|
+
$("#aiCfg").onclick = () => openAiModal();
|
|
771
1447
|
}
|
|
772
1448
|
|
|
773
1449
|
renderMsgs();
|
|
@@ -777,25 +1453,125 @@ function renderTab(){
|
|
|
777
1453
|
}
|
|
778
1454
|
}
|
|
779
1455
|
|
|
1456
|
+
/* 待发图片:先挂在这里,发送时和文字合成一条 markdown(图文混排) */
|
|
1457
|
+
let PENDING_IMGS = [];
|
|
1458
|
+
|
|
1459
|
+
function renderPendingImgs(){
|
|
1460
|
+
const strip = $("#imgStrip");
|
|
1461
|
+
if(!strip) return;
|
|
1462
|
+
strip.classList.toggle("show", PENDING_IMGS.length > 0);
|
|
1463
|
+
strip.innerHTML = PENDING_IMGS.map((p, i) => `
|
|
1464
|
+
<span class="thumb" title="${esc(p.name || "图片")}">
|
|
1465
|
+
<img src="${p.dataUrl}" alt="">
|
|
1466
|
+
<button data-i="${i}" title="移除">×</button>
|
|
1467
|
+
</span>`).join("");
|
|
1468
|
+
strip.querySelectorAll("button[data-i]").forEach(b => {
|
|
1469
|
+
b.onclick = e => {
|
|
1470
|
+
e.stopPropagation();
|
|
1471
|
+
PENDING_IMGS.splice(Number(b.dataset.i), 1);
|
|
1472
|
+
renderPendingImgs();
|
|
1473
|
+
};
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
async function queueImageFile(file){
|
|
1478
|
+
if(!CUR || !file) return;
|
|
1479
|
+
if(file.size > 20 * 1024 * 1024){ toast("图片太大(>20MB)", true); return; }
|
|
1480
|
+
const dataUrl = await new Promise(res => {
|
|
1481
|
+
const r = new FileReader();
|
|
1482
|
+
r.onload = () => res(String(r.result));
|
|
1483
|
+
r.readAsDataURL(file);
|
|
1484
|
+
});
|
|
1485
|
+
PENDING_IMGS.push({ dataUrl, name: file.name || "粘贴图片.png" });
|
|
1486
|
+
renderPendingImgs();
|
|
1487
|
+
toast(`已加入待发送图片(${PENDING_IMGS.length} 张),可继续写文字再一起发`);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
/* 只有图片、没有文字时用这个直接发 */
|
|
1491
|
+
async function sendImageFile(file){
|
|
1492
|
+
if(!CUR || !file) return;
|
|
1493
|
+
if(file.size > 20 * 1024 * 1024){ toast("图片太大(>20MB)", true); return; }
|
|
1494
|
+
const dataUrl = await new Promise(res => {
|
|
1495
|
+
const r = new FileReader();
|
|
1496
|
+
r.onload = () => res(String(r.result));
|
|
1497
|
+
r.readAsDataURL(file);
|
|
1498
|
+
});
|
|
1499
|
+
const hint = $("#sendHint");
|
|
1500
|
+
const old = hint ? hint.textContent : "";
|
|
1501
|
+
if(hint) hint.textContent = "图片发送中…";
|
|
1502
|
+
try{
|
|
1503
|
+
await api("/api/send-image", {
|
|
1504
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
1505
|
+
body: JSON.stringify({
|
|
1506
|
+
short: CUR.short, cid: CUR.cid || "", openId: CUR.openId || "",
|
|
1507
|
+
dataUrl, name: file.name || "粘贴图片.png",
|
|
1508
|
+
})
|
|
1509
|
+
});
|
|
1510
|
+
toast("图片已发出(钉钉里是文件附件形式)");
|
|
1511
|
+
setTimeout(() => { if(CUR) selectGroup(CUR.short, true); }, 1800);
|
|
1512
|
+
}catch(e){
|
|
1513
|
+
toast("图片发送失败:" + e.message, true);
|
|
1514
|
+
}finally{
|
|
1515
|
+
if(hint) hint.textContent = old;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
780
1519
|
async function doSend(){
|
|
781
1520
|
const box = $("#sendBox"), btn = $("#btnSend");
|
|
782
1521
|
if(!box || !CUR) return;
|
|
783
1522
|
const content = box.value.trim();
|
|
784
|
-
|
|
1523
|
+
const imgs = PENDING_IMGS.slice();
|
|
1524
|
+
if(!content && !imgs.length){ toast("先写点内容再发", true); box.focus(); return; }
|
|
1525
|
+
if(imgs.length){
|
|
1526
|
+
// 图文混排:文字 + 图片合成一条 markdown 消息
|
|
1527
|
+
btn.disabled = true;
|
|
1528
|
+
btn.innerHTML = `<span class="spin"></span>发送中`;
|
|
1529
|
+
try{
|
|
1530
|
+
const j = await api("/api/send-rich", {
|
|
1531
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
1532
|
+
body: JSON.stringify({
|
|
1533
|
+
short: CUR.short, cid: CUR.cid || "", openId: CUR.openId || "",
|
|
1534
|
+
text: content,
|
|
1535
|
+
images: imgs.map(x => x.dataUrl),
|
|
1536
|
+
names: imgs.map(x => x.name),
|
|
1537
|
+
})
|
|
1538
|
+
});
|
|
1539
|
+
PENDING_IMGS = [];
|
|
1540
|
+
renderPendingImgs();
|
|
1541
|
+
box.value = "";
|
|
1542
|
+
localStorage.removeItem("draft:" + CUR.short);
|
|
1543
|
+
window.__closeComposer && window.__closeComposer();
|
|
1544
|
+
toast(`已发送${content ? "图文消息" : "图片消息"}${j.images > 1 ? `(${j.images} 张)` : ""}`);
|
|
1545
|
+
setTimeout(() => { if(CUR) selectGroup(CUR.short, true); }, 1500);
|
|
1546
|
+
}catch(e){
|
|
1547
|
+
toast("发送失败:" + e.message, true);
|
|
1548
|
+
}finally{
|
|
1549
|
+
btn.disabled = false; btn.innerHTML = "发送";
|
|
1550
|
+
}
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
785
1553
|
const g = CUR;
|
|
1554
|
+
const isPerson = g.kind === "person";
|
|
786
1555
|
btn.disabled = true;
|
|
787
1556
|
btn.innerHTML = `<span class="spin"></span>发送中`;
|
|
788
1557
|
try{
|
|
789
|
-
const j = await api("/api/send", {
|
|
1558
|
+
const j = await api(isPerson ? "/api/contacts/send" : "/api/send", {
|
|
790
1559
|
method:"POST", headers:{"Content-Type":"application/json"},
|
|
791
|
-
body: JSON.stringify(
|
|
1560
|
+
body: JSON.stringify(isPerson
|
|
1561
|
+
? {openId: g.openId, content, aiTag: $("#aiTag").checked}
|
|
1562
|
+
: {short: g.short, content, aiTag: $("#aiTag").checked})
|
|
792
1563
|
});
|
|
793
1564
|
box.value = "";
|
|
794
1565
|
localStorage.removeItem("draft:" + g.short);
|
|
795
1566
|
window.__closeComposer && window.__closeComposer();
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
1567
|
+
if(isPerson){
|
|
1568
|
+
await openPerson(g.openId);
|
|
1569
|
+
toast(j.verified ? "已发送,并已回读确认" : "已发送到「" + g.name + "」的单聊");
|
|
1570
|
+
}else{
|
|
1571
|
+
await loadGroups(false);
|
|
1572
|
+
await selectGroup(g.short, true);
|
|
1573
|
+
toast(j.verified ? "已发送,并已在会话中回读确认" : "已发送(暂未回读到,稍后拉取最新核对)", !j.verified);
|
|
1574
|
+
}
|
|
799
1575
|
}catch(e){
|
|
800
1576
|
toast("发送失败:" + e.message, true);
|
|
801
1577
|
}finally{
|
|
@@ -803,6 +1579,491 @@ async function doSend(){
|
|
|
803
1579
|
}
|
|
804
1580
|
}
|
|
805
1581
|
|
|
1582
|
+
/* ---------------- AI 帮我写回复 ---------------- */
|
|
1583
|
+
let AI_CFG = null;
|
|
1584
|
+
|
|
1585
|
+
async function loadAiConfig(){
|
|
1586
|
+
try{ AI_CFG = await api("/api/ai/config"); }catch{ AI_CFG = null; }
|
|
1587
|
+
const el = $("#uAiState");
|
|
1588
|
+
if(el) el.textContent = aiStateText();
|
|
1589
|
+
return AI_CFG;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
function aiStateText(){
|
|
1593
|
+
if(!AI_CFG) return "AI 回复:读取中…";
|
|
1594
|
+
if(!AI_CFG.configured) return "AI 回复:未配置(点右边设置)";
|
|
1595
|
+
return `AI 回复:${AI_CFG.model} · 来源 ${AI_CFG.source}`;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
function aiContext(){
|
|
1599
|
+
const rows = MSGS.slice(-24).map(m => ({
|
|
1600
|
+
sender: m.sender || "",
|
|
1601
|
+
time: (m.createTime || "").slice(5, 16),
|
|
1602
|
+
text: String(m.text || "").slice(0, 500),
|
|
1603
|
+
}));
|
|
1604
|
+
return rows;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
async function aiDraft(){
|
|
1608
|
+
const box = $("#sendBox"), btn = $("#aiGo");
|
|
1609
|
+
if(!box || !CUR) return;
|
|
1610
|
+
if(!AI_CFG) await loadAiConfig();
|
|
1611
|
+
if(!AI_CFG || !AI_CFG.configured){ openAiModal(); return; }
|
|
1612
|
+
const hint = ($("#aiHint").value || "").trim() || (box.value || "").trim();
|
|
1613
|
+
const old = btn.innerHTML;
|
|
1614
|
+
btn.disabled = true; btn.innerHTML = `<span class="spin"></span>`;
|
|
1615
|
+
try{
|
|
1616
|
+
const j = await api("/api/ai/draft", {
|
|
1617
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
1618
|
+
body: JSON.stringify({
|
|
1619
|
+
target: CUR.name + (CUR.kind === "group" ? "(群聊)" : "(单聊)"),
|
|
1620
|
+
me: (PROFILE && PROFILE.userName) || "",
|
|
1621
|
+
hint,
|
|
1622
|
+
context: aiContext(),
|
|
1623
|
+
})
|
|
1624
|
+
});
|
|
1625
|
+
const text = String(j.text || "").trim();
|
|
1626
|
+
if(!text){ toast("AI 没写出内容,换个说法再试", true); return; }
|
|
1627
|
+
box.value = text;
|
|
1628
|
+
localStorage.setItem("draft:" + CUR.short, box.value);
|
|
1629
|
+
box.dispatchEvent(new Event("input"));
|
|
1630
|
+
setTimeout(()=> box.focus(), 20);
|
|
1631
|
+
toast(`AI 已写好(${j.model || "模型"}),可直接改或点发送`);
|
|
1632
|
+
closeAiModal();
|
|
1633
|
+
}catch(e){
|
|
1634
|
+
toast("AI 生成失败:" + e.message, true);
|
|
1635
|
+
}finally{
|
|
1636
|
+
btn.disabled = false; btn.innerHTML = old;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
let AI_SUM_TEXT = "";
|
|
1641
|
+
|
|
1642
|
+
async function aiSummarize(btn){
|
|
1643
|
+
if(!CUR) return;
|
|
1644
|
+
if(!AI_CFG) await loadAiConfig();
|
|
1645
|
+
if(!AI_CFG || !AI_CFG.configured){ openAiModal(); return; }
|
|
1646
|
+
const list = filteredMsgs();
|
|
1647
|
+
if(!list.length){ toast("当前范围没有消息可总结", true); return; }
|
|
1648
|
+
const cut = list.slice(-200);
|
|
1649
|
+
const old = btn ? btn.innerHTML : "";
|
|
1650
|
+
if(btn){ btn.disabled = true; btn.innerHTML = `<span class="spin"></span>总结中…`; }
|
|
1651
|
+
const rangeLabel = ($("#range") && $("#range").selectedOptions[0].textContent) || "全部时间";
|
|
1652
|
+
try{
|
|
1653
|
+
const j = await api("/api/ai/summary", {
|
|
1654
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
1655
|
+
body: JSON.stringify({
|
|
1656
|
+
target: CUR.name + (CUR.kind === "group" ? "(群聊)" : CUR.kind === "person" ? "(按人汇总)" : "(单聊)"),
|
|
1657
|
+
rangeLabel: `${rangeLabel}${cut.length < list.length ? `,最近 ${cut.length} 条` : ""}`,
|
|
1658
|
+
messages: cut.map(m => ({ sender: m.sender, time: m.createTime, text: String(m.text || "").slice(0, 400) })),
|
|
1659
|
+
})
|
|
1660
|
+
});
|
|
1661
|
+
AI_SUM_TEXT = String(j.text || "");
|
|
1662
|
+
$("#asMeta").textContent = `${CUR.name} · ${rangeLabel} · ${j.count} 条 · ${j.model}`;
|
|
1663
|
+
$("#asText").textContent = AI_SUM_TEXT;
|
|
1664
|
+
$("#aiSumModal").classList.add("show");
|
|
1665
|
+
}catch(e){
|
|
1666
|
+
toast("AI 总结失败:" + e.message, true);
|
|
1667
|
+
}finally{
|
|
1668
|
+
if(btn){ btn.disabled = false; btn.innerHTML = old; }
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
function closeAiSum(){ $("#aiSumModal").classList.remove("show"); }
|
|
1673
|
+
$("#asClose").onclick = closeAiSum;
|
|
1674
|
+
$("#asClose2").onclick = closeAiSum;
|
|
1675
|
+
$("#aiSumModal").onclick = e => { if(e.target.id === "aiSumModal") closeAiSum(); };
|
|
1676
|
+
$("#asCopy").onclick = () => {
|
|
1677
|
+
if(!AI_SUM_TEXT) return;
|
|
1678
|
+
navigator.clipboard?.writeText(AI_SUM_TEXT)
|
|
1679
|
+
.then(()=> toast("总结已复制"))
|
|
1680
|
+
.catch(()=> toast("复制失败,请手动选中", true));
|
|
1681
|
+
};
|
|
1682
|
+
$("#asAgain").onclick = () => { closeAiSum(); aiSummarize(null); };
|
|
1683
|
+
|
|
1684
|
+
/* ---------------- 设置中心 ---------------- */
|
|
1685
|
+
let ST_TAB = "ai";
|
|
1686
|
+
let ST_TMR = null;
|
|
1687
|
+
let ST_DATA = null;
|
|
1688
|
+
|
|
1689
|
+
function openSettings(tab){
|
|
1690
|
+
document.getElementById("settingsModal").classList.add("show");
|
|
1691
|
+
ST_TAB = tab || ST_TAB || "ai";
|
|
1692
|
+
document.querySelectorAll(".stTabs button").forEach(b => b.classList.toggle("on", b.dataset.tab === ST_TAB));
|
|
1693
|
+
refreshSettings();
|
|
1694
|
+
if(ST_TMR) clearInterval(ST_TMR);
|
|
1695
|
+
ST_TMR = setInterval(() => {
|
|
1696
|
+
if(document.getElementById("settingsModal").classList.contains("show")) renderStBody(true);
|
|
1697
|
+
else if(ST_TMR){ clearInterval(ST_TMR); ST_TMR = null; }
|
|
1698
|
+
}, 3000);
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
function closeSettings(){
|
|
1702
|
+
document.getElementById("settingsModal").classList.remove("show");
|
|
1703
|
+
if(ST_TMR){ clearInterval(ST_TMR); ST_TMR = null; }
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
async function refreshSettings(){
|
|
1707
|
+
try{
|
|
1708
|
+
ST_DATA = await api("/api/settings");
|
|
1709
|
+
}catch(e){
|
|
1710
|
+
ST_DATA = null;
|
|
1711
|
+
}
|
|
1712
|
+
renderStBody();
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
async function renderStBody(quiet){
|
|
1716
|
+
const body = document.getElementById("stBody");
|
|
1717
|
+
if(!body) return;
|
|
1718
|
+
if(ST_TAB === "ai") return renderStAi(body, quiet);
|
|
1719
|
+
if(ST_TAB === "monitor") return renderStMonitor(body, quiet);
|
|
1720
|
+
if(ST_TAB === "procs") return renderStProcs(body, quiet);
|
|
1721
|
+
return renderStGeneral(body, quiet);
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
function renderStAi(body, quiet){
|
|
1725
|
+
if(quiet) return;
|
|
1726
|
+
const ai = (ST_DATA && ST_DATA.ai) || AI_CFG || {};
|
|
1727
|
+
body.innerHTML = `
|
|
1728
|
+
<h4>AI 模型</h4>
|
|
1729
|
+
<div class="stHint">任意 OpenAI 兼容接口(<code>POST /chat/completions</code>)。留空则表示沿用环境变量或本机 pi 的配置。
|
|
1730
|
+
当前生效:<b>${esc(ai.configured ? `${ai.model}(来源 ${ai.source},Key ${ai.apiKeyMasked})` : "未配置")}</b></div>
|
|
1731
|
+
<label class="stL">接口地址</label>
|
|
1732
|
+
<input id="stAiBase" placeholder="https://api.deepseek.com" value="${esc(ai.source === "ai.json" ? ai.baseUrl || "" : "")}">
|
|
1733
|
+
<label class="stL">模型</label>
|
|
1734
|
+
<input id="stAiModel" placeholder="deepseek-chat" value="${esc(ai.source === "ai.json" ? ai.model || "" : "")}">
|
|
1735
|
+
<label class="stL">API Key(留空表示不修改)</label>
|
|
1736
|
+
<input id="stAiKey" placeholder="${esc(ai.apiKeyMasked || "sk-...")}">
|
|
1737
|
+
<label class="stL">额外人设 / 要求(可空)</label>
|
|
1738
|
+
<textarea id="stAiSys" style="min-height:56px;font:inherit;font-size:12.5px;border:1px solid var(--line);border-radius:8px;padding:6px 9px">${esc(ai.systemPrompt || "")}</textarea>
|
|
1739
|
+
<div class="stRow" style="margin-top:12px">
|
|
1740
|
+
<button class="primary" id="stAiSave">保存</button>
|
|
1741
|
+
<button id="stAiTest">测试连接</button>
|
|
1742
|
+
<button id="stAiClear">清空自定义</button>
|
|
1743
|
+
</div>
|
|
1744
|
+
<div id="stAiMsg" class="stHint"></div>`;
|
|
1745
|
+
document.getElementById("stAiSave").onclick = async () => {
|
|
1746
|
+
const baseUrl = document.getElementById("stAiBase").value.trim();
|
|
1747
|
+
const model = document.getElementById("stAiModel").value.trim();
|
|
1748
|
+
const apiKey = document.getElementById("stAiKey").value.trim();
|
|
1749
|
+
if(!baseUrl || !model || !apiKey){ toast("接口地址、模型、Key 都要填", true); return; }
|
|
1750
|
+
try{
|
|
1751
|
+
AI_CFG = await api("/api/ai/config", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1752
|
+
body: JSON.stringify({ baseUrl, model, apiKey, systemPrompt: document.getElementById("stAiSys").value.trim() })});
|
|
1753
|
+
toast(`已保存,当前模型 ${AI_CFG.model}`);
|
|
1754
|
+
await refreshSettings();
|
|
1755
|
+
const el = $("#uAiState"); if(el) el.textContent = aiStateText();
|
|
1756
|
+
}catch(e){ toast("保存失败:" + e.message, true); }
|
|
1757
|
+
};
|
|
1758
|
+
document.getElementById("stAiTest").onclick = async e => {
|
|
1759
|
+
const btn = e.currentTarget, old = btn.innerHTML;
|
|
1760
|
+
btn.disabled = true; btn.innerHTML = `<span class="spin"></span>测试中`;
|
|
1761
|
+
try{
|
|
1762
|
+
const j = await api("/api/ai/draft", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1763
|
+
body: JSON.stringify({ target:"测试", hint:"用一句话确认你能正常工作", context:[] })});
|
|
1764
|
+
document.getElementById("stAiMsg").textContent = `✓ 可用(${j.model}):${j.text.slice(0, 60)}`;
|
|
1765
|
+
}catch(err){
|
|
1766
|
+
document.getElementById("stAiMsg").textContent = `✗ ${err.message}`;
|
|
1767
|
+
}finally{ btn.disabled = false; btn.innerHTML = old; }
|
|
1768
|
+
};
|
|
1769
|
+
document.getElementById("stAiClear").onclick = async () => {
|
|
1770
|
+
try{
|
|
1771
|
+
await api("/api/ai/config", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({clear:true})});
|
|
1772
|
+
await loadAiConfig();
|
|
1773
|
+
await refreshSettings();
|
|
1774
|
+
toast("已清空自定义 AI 配置");
|
|
1775
|
+
}catch(e){ toast("清空失败:" + e.message, true); }
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
async function renderStMonitor(body, quiet){
|
|
1780
|
+
const l = (ST_DATA && ST_DATA.listen) || {};
|
|
1781
|
+
const sync = (ST_DATA && ST_DATA.sync) || {};
|
|
1782
|
+
if(!quiet){
|
|
1783
|
+
body.innerHTML = `
|
|
1784
|
+
<h4>实时监控(钉钉 Stream 长连接)</h4>
|
|
1785
|
+
<div class="stHint">群消息和单聊各一个常驻进程,事件直接写进归档,不占消息接口额度。下面这段是实时日志(每 3 秒刷新)。</div>
|
|
1786
|
+
<div id="stMonStatus"></div>
|
|
1787
|
+
<div class="stRow" style="margin:10px 0 14px">
|
|
1788
|
+
<button id="stMonRestart">重启监控</button>
|
|
1789
|
+
<button id="stMonToggle">${l.enabled ? "停止" : "启动"}</button>
|
|
1790
|
+
<button id="stMonSync">立即兜底同步</button>
|
|
1791
|
+
</div>
|
|
1792
|
+
<h4>兜底同步(查未读补漏)</h4>
|
|
1793
|
+
<div class="stRow" style="margin-top:6px">
|
|
1794
|
+
<label style="font-size:12.5px;display:flex;align-items:center;gap:6px">
|
|
1795
|
+
<input type="checkbox" id="stSyncOn" ${sync.enabled ? "checked" : ""}> 启用
|
|
1796
|
+
</label>
|
|
1797
|
+
每 <input type="number" id="stSyncInt" min="${sync.minIntervalSec || 20}" max="${sync.maxIntervalSec || 1800}" value="${sync.intervalSec || 60}" style="width:90px"> 秒
|
|
1798
|
+
<button id="stSyncSave">保存</button>
|
|
1799
|
+
</div>
|
|
1800
|
+
<div class="stHint" style="margin-top:6px">上次:${esc(sync.lastRunAt || "—")}${sync.lastAdded ? ` · 新增 ${sync.lastAdded} 条` : ""}${sync.lastError ? ` · <span class="bad">${esc(sync.lastError)}</span>` : ""}</div>
|
|
1801
|
+
<h4 style="margin-top:16px">实时日志 <span class="stHint" style="display:inline">(listen.log)</span></h4>
|
|
1802
|
+
<div class="logBox" id="stLog">加载中…</div>`;
|
|
1803
|
+
document.getElementById("stMonRestart").onclick = async () => {
|
|
1804
|
+
try{ await api("/api/listen", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({action:"restart"})});
|
|
1805
|
+
toast("监控已重启"); await refreshSettings(); }catch(e){ toast("重启失败:" + e.message, true); }
|
|
1806
|
+
};
|
|
1807
|
+
document.getElementById("stMonToggle").onclick = async e => {
|
|
1808
|
+
const stop = e.currentTarget.textContent === "停止";
|
|
1809
|
+
try{ await api("/api/listen", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({action: stop ? "stop" : "start"})});
|
|
1810
|
+
toast(stop ? "已停止监控" : "已启动监控"); await refreshSettings(); }catch(err){ toast("操作失败:" + err.message, true); }
|
|
1811
|
+
};
|
|
1812
|
+
document.getElementById("stMonSync").onclick = async e => {
|
|
1813
|
+
const btn = e.currentTarget; btn.disabled = true; const old = btn.innerHTML;
|
|
1814
|
+
btn.innerHTML = `<span class="spin"></span>同步中`;
|
|
1815
|
+
try{ const r = await api("/api/sync", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({once:true})});
|
|
1816
|
+
toast(`兜底同步完成,新增 ${r.added || 0} 条`); await refreshSettings(); }catch(err){ toast("同步失败:" + err.message, true); }
|
|
1817
|
+
finally{ btn.disabled = false; btn.innerHTML = old; }
|
|
1818
|
+
};
|
|
1819
|
+
document.getElementById("stSyncSave").onclick = async () => {
|
|
1820
|
+
try{
|
|
1821
|
+
await api("/api/settings", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1822
|
+
body: JSON.stringify({ syncEnabled: document.getElementById("stSyncOn").checked,
|
|
1823
|
+
syncIntervalSec: Number(document.getElementById("stSyncInt").value) })});
|
|
1824
|
+
toast("已保存兜底同步设置"); await refreshSettings();
|
|
1825
|
+
}catch(e){ toast("保存失败:" + e.message, true); }
|
|
1826
|
+
};
|
|
1827
|
+
quiet = true;
|
|
1828
|
+
}
|
|
1829
|
+
// 状态区 + 日志(高频刷新)
|
|
1830
|
+
const st = document.getElementById("stMonStatus");
|
|
1831
|
+
if(st && ST_DATA && ST_DATA.listen){
|
|
1832
|
+
const kinds = (ST_DATA.listen.kinds || []).map(k =>
|
|
1833
|
+
`<div class="stRow" style="margin:0 0 4px"><span class="${k.ready ? "ok" : "bad"}">${k.ready ? "●" : "○"}</span>
|
|
1834
|
+
${esc(k.label)} ${k.ready ? "已连接" : "重连中"} <span style="color:var(--muted)">pid ${k.pid || "-"} · 启动 ${esc(k.startedAt || "-")}${k.restarts ? ` · 重启 ${k.restarts} 次` : ""}</span></div>`
|
|
1835
|
+
).join("");
|
|
1836
|
+
st.innerHTML = `${kinds}
|
|
1837
|
+
<div class="stHint" style="margin:6px 0 0">累计事件 ${ST_DATA.listen.events || 0} · 写入归档 ${ST_DATA.listen.appended || 0} · 忽略 ${ST_DATA.listen.ignored || 0}
|
|
1838
|
+
${ST_DATA.listen.lastEventAt ? ` · 最后事件 ${esc(ST_DATA.listen.lastEventAt)}` : " · 还没有事件"}</div>
|
|
1839
|
+
${ST_DATA.listen.lastError ? `<div class="stHint bad">${esc(ST_DATA.listen.lastError)}</div>` : ""}`;
|
|
1840
|
+
}
|
|
1841
|
+
try{
|
|
1842
|
+
const lg = await api("/api/logs?name=listen&lines=60");
|
|
1843
|
+
const box = document.getElementById("stLog");
|
|
1844
|
+
if(box){
|
|
1845
|
+
box.textContent = (lg.lines || []).join("\n") || "(还没有日志)";
|
|
1846
|
+
box.scrollTop = box.scrollHeight;
|
|
1847
|
+
}
|
|
1848
|
+
}catch(e){
|
|
1849
|
+
const box = document.getElementById("stLog");
|
|
1850
|
+
if(box) box.textContent = "日志读取失败:" + e.message;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
async function renderStProcs(body, quiet){
|
|
1855
|
+
let p = null;
|
|
1856
|
+
try{ p = await api("/api/procs"); }catch(e){ body.innerHTML = `<div class="bad">读取失败:${esc(e.message)}</div>`; return; }
|
|
1857
|
+
const rows = [`<tr><td>${p.pid}</td><td>1</td><td>oh-my-dws 服务(本进程)</td><td class="ok">● 运行中</td><td>${Math.floor(p.uptime / 60)} 分钟</td></tr>`]
|
|
1858
|
+
.concat((p.children || []).map(c => `<tr><td>${c.pid}</td><td>${p.pid}</td><td>${esc(c.label)} 监听</td>
|
|
1859
|
+
<td class="${c.ready ? "ok" : "bad"}">${c.ready ? "● 已连接" : "○ 重连中"}</td><td>${esc(c.since || "")}</td></tr>`));
|
|
1860
|
+
body.innerHTML = `
|
|
1861
|
+
<h4>进程与服务</h4>
|
|
1862
|
+
<div class="stHint">这里是这个工具当前跑着的进程(服务 + 两个监听),以及运行环境。</div>
|
|
1863
|
+
<dl class="kv">
|
|
1864
|
+
<dt>版本</dt><dd>${esc(p.version)}</dd>
|
|
1865
|
+
<dt>Node</dt><dd>${esc(p.node)}</dd>
|
|
1866
|
+
<dt>运行时长</dt><dd>${Math.floor(p.uptime / 3600)} 小时 ${Math.floor((p.uptime % 3600) / 60)} 分钟</dd>
|
|
1867
|
+
<dt>内存占用</dt><dd>${p.rss} MB</dd>
|
|
1868
|
+
<dt>数据目录</dt><dd>${esc(p.dataDir)}</dd>
|
|
1869
|
+
</dl>
|
|
1870
|
+
<table class="proc">
|
|
1871
|
+
<thead><tr><th>PID</th><th>父 PID</th><th>说明</th><th>状态</th><th>启动时间</th></tr></thead>
|
|
1872
|
+
<tbody>${rows.join("")}</tbody>
|
|
1873
|
+
</table>
|
|
1874
|
+
<h4 style="margin-top:16px">服务日志(server.log)</h4>
|
|
1875
|
+
<div class="logBox" id="stLogSrv">加载中…</div>`;
|
|
1876
|
+
try{
|
|
1877
|
+
const lg = await api("/api/logs?name=server&lines=40");
|
|
1878
|
+
const box = document.getElementById("stLogSrv");
|
|
1879
|
+
box.textContent = (lg.lines || []).join("\n") || "(还没有日志)";
|
|
1880
|
+
box.scrollTop = box.scrollHeight;
|
|
1881
|
+
}catch(e){
|
|
1882
|
+
const box = document.getElementById("stLogSrv");
|
|
1883
|
+
if(box) box.textContent = "日志读取失败:" + e.message;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
function renderStGeneral(body, quiet){
|
|
1888
|
+
if(quiet) return;
|
|
1889
|
+
const prefs = (ST_DATA && ST_DATA.prefs) || {};
|
|
1890
|
+
body.innerHTML = `
|
|
1891
|
+
<h4>通用偏好</h4>
|
|
1892
|
+
<div class="stHint">这些是本地行为偏好。</div>
|
|
1893
|
+
<label class="stL">粘贴图片的发送方式</label>
|
|
1894
|
+
<div class="stRow">
|
|
1895
|
+
<label style="font-size:12.5px;display:flex;align-items:center;gap:6px">
|
|
1896
|
+
<input type="radio" name="stImgMode" value="inline" ${prefs.imageSendMode !== "file" ? "checked" : ""}> 内联图片(先传图床,钉钉里显示为图片)
|
|
1897
|
+
</label>
|
|
1898
|
+
<label style="font-size:12.5px;display:flex;align-items:center;gap:6px">
|
|
1899
|
+
<input type="radio" name="stImgMode" value="file" ${prefs.imageSendMode === "file" ? "checked" : ""}> 文件(不传图床,作为附件发送)
|
|
1900
|
+
</label>
|
|
1901
|
+
</div>
|
|
1902
|
+
<div class="stRow" style="margin-top:6px"><button class="primary" id="stGenSave">保存</button></div>
|
|
1903
|
+
<label class="stL">界面偏好(存在本浏览器)</label>
|
|
1904
|
+
<div class="stRow">
|
|
1905
|
+
<label style="font-size:12.5px;display:flex;align-items:center;gap:6px">
|
|
1906
|
+
<input type="checkbox" id="stSideCollapsed" ${localStorage.getItem("omd.sideCollapsed") !== "0" ? "checked" : ""}> 侧栏默认收起
|
|
1907
|
+
</label>
|
|
1908
|
+
<label style="font-size:12.5px;display:flex;align-items:center;gap:6px">
|
|
1909
|
+
<input type="checkbox" id="stContactsClosed" ${localStorage.getItem("omd.contactsClosed") === "1" ? "checked" : ""}> 常用联系人默认收起
|
|
1910
|
+
</label>
|
|
1911
|
+
</div>
|
|
1912
|
+
<div class="stHint" style="margin-top:10px">快捷键:<b>⌘/Ctrl + B</b> 收起/展开侧栏 · <b>⌘/Ctrl + Enter</b> 发消息 · <b>Esc</b> 关闭弹层</div>`;
|
|
1913
|
+
document.getElementById("stGenSave").onclick = async () => {
|
|
1914
|
+
const mode = [...document.querySelectorAll('input[name="stImgMode"]')].find(x => x.checked).value;
|
|
1915
|
+
localStorage.setItem("omd.sideCollapsed", document.getElementById("stSideCollapsed").checked ? "1" : "0");
|
|
1916
|
+
localStorage.setItem("omd.contactsClosed", document.getElementById("stContactsClosed").checked ? "1" : "0");
|
|
1917
|
+
setCollapsed(document.getElementById("stSideCollapsed").checked);
|
|
1918
|
+
try{
|
|
1919
|
+
ST_DATA = await api("/api/settings", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1920
|
+
body: JSON.stringify({ imageSendMode: mode })});
|
|
1921
|
+
toast("设置已保存"); await refreshSettings();
|
|
1922
|
+
}catch(e){ toast("保存失败:" + e.message, true); }
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
document.querySelectorAll(".stTabs button").forEach(b => {
|
|
1927
|
+
b.onclick = () => {
|
|
1928
|
+
ST_TAB = b.dataset.tab;
|
|
1929
|
+
document.querySelectorAll(".stTabs button").forEach(x => x.classList.toggle("on", x === b));
|
|
1930
|
+
ST_DATA = null;
|
|
1931
|
+
refreshSettings();
|
|
1932
|
+
};
|
|
1933
|
+
});
|
|
1934
|
+
document.getElementById("stClose").onclick = closeSettings;
|
|
1935
|
+
document.getElementById("stClose2").onclick = closeSettings;
|
|
1936
|
+
document.getElementById("settingsModal").onclick = e => { if(e.target.id === "settingsModal") closeSettings(); };
|
|
1937
|
+
|
|
1938
|
+
/* ---------------- 实时监听状态(账号面板里) ---------------- */
|
|
1939
|
+
let LISTEN_TMR = null;
|
|
1940
|
+
|
|
1941
|
+
function fmtListen(body){
|
|
1942
|
+
if(!body || !body.kinds) return "读取中…";
|
|
1943
|
+
const evt = `事件 ${body.events || 0} · 写入 ${body.appended || 0}`;
|
|
1944
|
+
const rows = (body.kinds || []).map(k =>
|
|
1945
|
+
`<div class="urow">${k.ready ? '<span class="ok">●</span>' : '<span class="bad">○</span>'}
|
|
1946
|
+
${esc(k.label)} ${k.ready ? "已连接" : "重连中"}
|
|
1947
|
+
<span style="margin-left:auto">pid ${k.pid || "-"}${k.restarts ? ` · 重启 ${k.restarts} 次` : ""}</span></div>`
|
|
1948
|
+
).join("");
|
|
1949
|
+
const last = body.lastEventAt ? `最后事件 ${body.lastEventAt}` : "还没收到事件(保持连接中)";
|
|
1950
|
+
const sync = body.sync || {};
|
|
1951
|
+
const syncLine = sync.enabled
|
|
1952
|
+
? `兜底同步:每 ${sync.intervalSec}s 查一次未读${sync.lastRunAt ? ` · 上次 ${sync.lastRunAt.slice(11)}` : ""}`
|
|
1953
|
+
: "兜底同步:已关闭";
|
|
1954
|
+
return `${rows}
|
|
1955
|
+
<div style="margin-top:4px">${esc(evt)} · ${esc(last)}</div>
|
|
1956
|
+
<div>${esc(syncLine)}${body.lastError ? ` · <span class="bad">${esc(body.lastError)}</span>` : ""}</div>`;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
async function refreshListenPanel(){
|
|
1960
|
+
const body = $("#uListenBody");
|
|
1961
|
+
if(!body) return;
|
|
1962
|
+
try{
|
|
1963
|
+
const j = await api("/api/listen");
|
|
1964
|
+
body.innerHTML = fmtListen(j);
|
|
1965
|
+
const t = $("#uListenToggle");
|
|
1966
|
+
if(t) t.textContent = j.enabled ? "停止" : "启动";
|
|
1967
|
+
}catch(e){
|
|
1968
|
+
body.innerHTML = `<span class="bad">读取失败:${esc(e.message)}</span>`;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
function openListenPoll(){
|
|
1973
|
+
closeListenPoll();
|
|
1974
|
+
refreshListenPanel();
|
|
1975
|
+
LISTEN_TMR = setInterval(() => {
|
|
1976
|
+
if($("#userPanel").classList.contains("show")) refreshListenPanel();
|
|
1977
|
+
else closeListenPoll();
|
|
1978
|
+
}, 5000);
|
|
1979
|
+
}
|
|
1980
|
+
function closeListenPoll(){ if(LISTEN_TMR){ clearInterval(LISTEN_TMR); LISTEN_TMR = null; } }
|
|
1981
|
+
|
|
1982
|
+
async function doListenRestart(e){
|
|
1983
|
+
const btn = e.currentTarget;
|
|
1984
|
+
const old = btn.textContent;
|
|
1985
|
+
btn.disabled = true; btn.textContent = "重启中…";
|
|
1986
|
+
try{
|
|
1987
|
+
await api("/api/listen", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
1988
|
+
body: JSON.stringify({action:"restart"})});
|
|
1989
|
+
toast("监听已重启");
|
|
1990
|
+
}catch(err){ toast("重启失败:" + err.message, true); }
|
|
1991
|
+
finally{ btn.disabled = false; btn.textContent = old; refreshListenPanel(); }
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
async function doListenToggle(e){
|
|
1995
|
+
const btn = e.currentTarget;
|
|
1996
|
+
const stop = btn.textContent === "停止";
|
|
1997
|
+
btn.disabled = true;
|
|
1998
|
+
try{
|
|
1999
|
+
await api("/api/listen", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2000
|
+
body: JSON.stringify({action: stop ? "stop" : "start"})});
|
|
2001
|
+
toast(stop ? "已停止监听" : "已启动监听");
|
|
2002
|
+
}catch(err){ toast("操作失败:" + err.message, true); }
|
|
2003
|
+
finally{ btn.disabled = false; refreshListenPanel(); }
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
function openAiModal(){
|
|
2007
|
+
$("#aiModal").classList.add("show");
|
|
2008
|
+
const c = AI_CFG || {};
|
|
2009
|
+
$("#aiBase").value = c.source === "ai.json" ? (c.baseUrl || "") : "";
|
|
2010
|
+
$("#aiModel").value = c.source === "ai.json" ? (c.model || "") : "";
|
|
2011
|
+
$("#aiKey").value = "";
|
|
2012
|
+
$("#aiSys").value = c.systemPrompt || "";
|
|
2013
|
+
$("#aiStatus").textContent = c.configured
|
|
2014
|
+
? `当前生效:${c.model}(来源 ${c.source},Key ${c.apiKeyMasked})`
|
|
2015
|
+
: "当前未配置,生成前先填下面的内容";
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
function closeAiModal(){ $("#aiModal").classList.remove("show"); }
|
|
2019
|
+
$("#aiClose").onclick = closeAiModal;
|
|
2020
|
+
|
|
2021
|
+
$("#aiSave").onclick = async () => {
|
|
2022
|
+
const baseUrl = $("#aiBase").value.trim();
|
|
2023
|
+
const model = $("#aiModel").value.trim();
|
|
2024
|
+
const apiKey = $("#aiKey").value.trim();
|
|
2025
|
+
if(!baseUrl || !model || !apiKey){ toast("接口地址、模型、Key 都要填", true); return; }
|
|
2026
|
+
try{
|
|
2027
|
+
AI_CFG = await api("/api/ai/config", {
|
|
2028
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
2029
|
+
body: JSON.stringify({ baseUrl, model, apiKey, systemPrompt: $("#aiSys").value.trim() })
|
|
2030
|
+
});
|
|
2031
|
+
const el = $("#uAiState");
|
|
2032
|
+
if(el) el.textContent = aiStateText();
|
|
2033
|
+
toast(AI_CFG.configured ? `已保存,当前模型 ${AI_CFG.model}` : "已保存,但仍不可用", !AI_CFG.configured);
|
|
2034
|
+
closeAiModal();
|
|
2035
|
+
}catch(e){ toast("保存失败:" + e.message, true); }
|
|
2036
|
+
};
|
|
2037
|
+
|
|
2038
|
+
$("#aiTest").onclick = async e => {
|
|
2039
|
+
const btn = e.currentTarget;
|
|
2040
|
+
const old = btn.innerHTML;
|
|
2041
|
+
btn.disabled = true; btn.innerHTML = `<span class="spin"></span>测试中`;
|
|
2042
|
+
try{
|
|
2043
|
+
const j = await api("/api/ai/draft", {
|
|
2044
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
2045
|
+
body: JSON.stringify({ target:"测试", hint:"用一句话确认你能正常工作", context:[] })
|
|
2046
|
+
});
|
|
2047
|
+
$("#aiStatus").textContent = `✓ 可用(${j.model}):${j.text.slice(0, 60)}`;
|
|
2048
|
+
}catch(err){
|
|
2049
|
+
$("#aiStatus").textContent = `✗ ${err.message}`;
|
|
2050
|
+
}finally{
|
|
2051
|
+
btn.disabled = false; btn.innerHTML = old;
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
|
|
2055
|
+
$("#aiReset").onclick = async () => {
|
|
2056
|
+
try{
|
|
2057
|
+
await api("/api/ai/config", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2058
|
+
body: JSON.stringify({ clear: true })});
|
|
2059
|
+
await loadAiConfig();
|
|
2060
|
+
openAiModal();
|
|
2061
|
+
toast("已清空自定义配置");
|
|
2062
|
+
}catch(e){ toast("清空失败:" + e.message, true); }
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
loadAiConfig();
|
|
2066
|
+
|
|
806
2067
|
const AV_COLORS = ["#4c6ef5","#12b886","#f59f00","#7048e8","#e8590c","#0ca678","#d6336c","#1c7ed6","#5f3dc4","#2b8a3e"];
|
|
807
2068
|
|
|
808
2069
|
function avatarOf(name, id){
|
|
@@ -813,6 +2074,29 @@ function avatarOf(name, id){
|
|
|
813
2074
|
return { letter: ch, bg: AV_COLORS[h % AV_COLORS.length] };
|
|
814
2075
|
}
|
|
815
2076
|
|
|
2077
|
+
/* 消息正文:自己发过的图片/文件(本地有副本)直接渲染出来 */
|
|
2078
|
+
function renderBody(m){
|
|
2079
|
+
const text = m.text || "";
|
|
2080
|
+
// markdown 图片: —— 我们自己贴图发出去的就是这种
|
|
2081
|
+
const mdImg = text.trim().match(/^!\[[^\]]*\]\((https?:\/\/[^)\s]+)\)$/);
|
|
2082
|
+
if(mdImg){
|
|
2083
|
+
return `<img class="msgimg" src="${esc(mdImg[1])}" alt="图片" loading="lazy">
|
|
2084
|
+
<div style="font-size:11.5px;color:var(--muted);margin-top:2px">图片消息</div>`;
|
|
2085
|
+
}
|
|
2086
|
+
const lf = m.localFile;
|
|
2087
|
+
if(lf){
|
|
2088
|
+
const isImg = /\.(png|jpe?g|gif|webp|bmp)$/i.test(lf.name || "");
|
|
2089
|
+
const ctx = { short: m.groupShort || (CUR && CUR.short), mid: m.messageId };
|
|
2090
|
+
if(isImg){
|
|
2091
|
+
return `<img class="msgimg" src="${esc(lf.url)}" alt="${esc(lf.name)}" loading="lazy" data-lf="1">
|
|
2092
|
+
<div style="font-size:11.5px;color:var(--muted);margin-top:2px">${esc(lf.name)} · 本地副本</div>`;
|
|
2093
|
+
}
|
|
2094
|
+
return `${linkify(text, ctx)}<div style="margin-top:6px"><a class="media" href="${esc(lf.url)}" download="${esc(lf.name)}" style="text-decoration:none">📎 下载 ${esc(lf.name)}</a></div>`;
|
|
2095
|
+
}
|
|
2096
|
+
return linkify(text, ctx0(m)) || '<span style="color:var(--muted)">(空消息)</span>';
|
|
2097
|
+
}
|
|
2098
|
+
function ctx0(m){ return { short: m.groupShort || (CUR && CUR.short), mid: m.messageId }; }
|
|
2099
|
+
|
|
816
2100
|
function quoteHtml(m){
|
|
817
2101
|
const q = m.quotedMessage;
|
|
818
2102
|
if(!q) return "";
|
|
@@ -873,6 +2157,25 @@ function rangeBounds(range){
|
|
|
873
2157
|
return { from: fmt(f), to: "" };
|
|
874
2158
|
}
|
|
875
2159
|
|
|
2160
|
+
/* 当前筛选下的消息(保持 MSGS 的原始顺序 = 从旧到新) */
|
|
2161
|
+
function filteredMsgs(){
|
|
2162
|
+
const kw = FILTER.kw.trim().toLowerCase();
|
|
2163
|
+
const rg = rangeBounds(FILTER.range);
|
|
2164
|
+
return MSGS.filter(m => {
|
|
2165
|
+
if(FILTER.sender && (m.senderId || m.sender) !== FILTER.sender) return false;
|
|
2166
|
+
if(FILTER.group){
|
|
2167
|
+
const key = m.groupShort || (m.groupCid ? "cid:" + m.groupCid : "");
|
|
2168
|
+
if(key !== FILTER.group) return false;
|
|
2169
|
+
}
|
|
2170
|
+
const d = (m.createTime || "").slice(0,10);
|
|
2171
|
+
if(FILTER.from && d < FILTER.from) return false;
|
|
2172
|
+
if(FILTER.to && d > FILTER.to) return false;
|
|
2173
|
+
if(rg && (d < rg.from || (rg.to && d > rg.to))) return false;
|
|
2174
|
+
if(kw && !(m.text || "").toLowerCase().includes(kw) && !(m.sender||"").toLowerCase().includes(kw)) return false;
|
|
2175
|
+
return true;
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
|
|
876
2179
|
function renderMsgs(){
|
|
877
2180
|
const box = $("#msgs");
|
|
878
2181
|
const kw = FILTER.kw.trim().toLowerCase();
|
|
@@ -891,7 +2194,10 @@ function renderMsgs(){
|
|
|
891
2194
|
|
|
892
2195
|
let list = MSGS.filter(m => {
|
|
893
2196
|
if(FILTER.sender && (m.senderId || m.sender) !== FILTER.sender) return false;
|
|
894
|
-
if(FILTER.group
|
|
2197
|
+
if(FILTER.group){
|
|
2198
|
+
const key = m.groupShort || (m.groupCid ? "cid:" + m.groupCid : "");
|
|
2199
|
+
if(key !== FILTER.group) return false;
|
|
2200
|
+
}
|
|
895
2201
|
const d = (m.createTime || "").slice(0,10);
|
|
896
2202
|
if(FILTER.from && d < FILTER.from) return false;
|
|
897
2203
|
if(FILTER.to && d > FILTER.to) return false;
|
|
@@ -901,45 +2207,107 @@ function renderMsgs(){
|
|
|
901
2207
|
return true;
|
|
902
2208
|
});
|
|
903
2209
|
if(FILTER.desc) list = list.slice().reverse();
|
|
904
|
-
$("#stat").textContent = `${list.length} / ${MSGS.length} 条`;
|
|
905
2210
|
|
|
906
|
-
|
|
2211
|
+
// 分页:只渲染最近 RENDER_LIMIT 条(倒序取头部,正序取尾部),其余点「加载更早」再补
|
|
2212
|
+
const total = list.length;
|
|
2213
|
+
const limited = FILTER.desc
|
|
2214
|
+
? list.slice(0, RENDER_LIMIT)
|
|
2215
|
+
: list.slice(Math.max(0, total - RENDER_LIMIT));
|
|
2216
|
+
const rest = total - limited.length;
|
|
2217
|
+
$("#stat").textContent = rest
|
|
2218
|
+
? `${limited.length}+${rest} / ${MSGS.length} 条`
|
|
2219
|
+
: `${total} / ${MSGS.length} 条`;
|
|
2220
|
+
const rangeLabel = $("#range") ? $("#range").selectedOptions[0].textContent : "";
|
|
2221
|
+
|
|
2222
|
+
if(!total){
|
|
907
2223
|
box.innerHTML = `<div class="empty" style="padding:40px 0">没有符合条件的消息</div>`;
|
|
908
2224
|
$("#jumpLatest")?.classList.remove("show");
|
|
909
2225
|
return;
|
|
910
2226
|
}
|
|
2227
|
+
// 序号索引(避免 MSGS.indexOf 的 O(n²))
|
|
2228
|
+
if(!renderMsgs._seq || renderMsgs._seqOf !== MSGS){
|
|
2229
|
+
const map = new Map();
|
|
2230
|
+
MSGS.forEach((m, i) => map.set(m, i + 1));
|
|
2231
|
+
renderMsgs._seq = map;
|
|
2232
|
+
renderMsgs._seqOf = MSGS;
|
|
2233
|
+
}
|
|
2234
|
+
const seqOf = renderMsgs._seq;
|
|
911
2235
|
let lastDate = "";
|
|
912
|
-
|
|
2236
|
+
const bodyHtml = limited.map((m, i) => {
|
|
913
2237
|
const d = (m.createTime||"").slice(0,10);
|
|
914
2238
|
let sep = "";
|
|
915
2239
|
if(d !== lastDate){ lastDate = d; sep = `<div class="dateSep">${esc(d)}</div>`; }
|
|
916
2240
|
const isNew = FILTER.newIds.has(m.messageId);
|
|
917
2241
|
const c = m.groupName ? colorFor(m.groupShort) : null;
|
|
918
|
-
const
|
|
2242
|
+
const isDmAgg = CUR && CUR.kind === "dmAll";
|
|
2243
|
+
const canJump = CUR && ((CUR.kind === "mentions" && (m.groupShort || m.groupCid))
|
|
2244
|
+
|| (isDmAgg && m.groupShort));
|
|
919
2245
|
const av = avatarOf(m.sender, m.senderId);
|
|
920
2246
|
const q = quoteHtml(m);
|
|
2247
|
+
if(m.recalled){
|
|
2248
|
+
return sep + `
|
|
2249
|
+
<div class="msg recalled" data-mid="${esc(m.messageId||"")}">
|
|
2250
|
+
${avatarHtml(m.sender, m.senderId, "av msgAv", "")}
|
|
2251
|
+
<div class="mbody">
|
|
2252
|
+
<div class="meta">
|
|
2253
|
+
<span class="seq">#${seqOf.get(m) || ""}</span>
|
|
2254
|
+
<span class="who">${fresh?'<span class="unreadDot" title="未读"></span>':""}${esc(m.sender)}</span>
|
|
2255
|
+
<span>${esc((m.createTime||"").slice(11))}</span>
|
|
2256
|
+
${fresh?'<span class="freshTag">未读</span>':""}
|
|
2257
|
+
</div>
|
|
2258
|
+
<div class="recalledText"><span class="recalledTag">已撤回</span>
|
|
2259
|
+
${m.recalledBy ? esc(m.recalledBy + " 撤回了一条消息") : "这条消息已被撤回"}${m.recalledAt ? ` · ${esc(String(m.recalledAt).slice(11, 16))}` : ""}</div>
|
|
2260
|
+
</div>
|
|
2261
|
+
</div>`;
|
|
2262
|
+
}
|
|
2263
|
+
const fresh = Boolean(m.fresh);
|
|
921
2264
|
return sep + `
|
|
922
|
-
<div class="msg ${isNew?"new":""} ${c?"byGroup":""}" data-mid="${esc(m.messageId||"")}" ${c?`style="border-left-color:${c.bd}"`: ""}>
|
|
923
|
-
|
|
2265
|
+
<div class="msg ${isNew?"new":""} ${fresh?"unread":""} ${c?"byGroup":""}" data-mid="${esc(m.messageId||"")}" ${c?`style="border-left-color:${c.bd}"`: ""}>
|
|
2266
|
+
${avatarHtml(m.sender, m.senderId, "av", "").replace('class="av', `class="av msgAv`)}
|
|
924
2267
|
<div class="mbody">
|
|
925
2268
|
<div class="meta">
|
|
926
|
-
<span class="seq">#${
|
|
927
|
-
${m.groupName ? `<span class="gTag" style="background:${c.bg};color:${c.fg};border-color:${c.bd}">📍 ${esc(m.groupName)}</span>` : ""}
|
|
928
|
-
<span class="who">${esc(m.sender)}</span>
|
|
2269
|
+
<span class="seq">#${seqOf.get(m) || ""}</span>
|
|
2270
|
+
${m.groupName && !isDmAgg ? `<span class="gTag" style="background:${c.bg};color:${c.fg};border-color:${c.bd}">📍 ${esc(m.groupName)}</span>` : ""}
|
|
2271
|
+
<span class="who" title="${esc(m.senderId || "")}">${fresh?'<span class="unreadDot" title="未读"></span>':""}${esc(m.sender)}</span>
|
|
929
2272
|
<span>${esc((m.createTime||"").slice(11))}</span>
|
|
930
|
-
<span class="
|
|
2273
|
+
${fresh?'<span class="freshTag">未读</span>':""}
|
|
2274
|
+
${isDmAgg ? "" : `<span class="id">${esc(m.senderId||"")}</span>`}
|
|
931
2275
|
</div>
|
|
932
2276
|
${q}
|
|
933
|
-
<div class="body">${
|
|
2277
|
+
<div class="body">${renderBody(m)}</div>
|
|
934
2278
|
${canJump ? `<div class="jumpbtns">
|
|
935
|
-
<button data-arc="${esc(m.groupShort)}" data-
|
|
936
|
-
|
|
937
|
-
<button data-
|
|
2279
|
+
<button data-arc="${esc(m.groupShort)}" data-acid="${esc(m.groupCid||"")}" data-aname="${esc(m.groupName||"")}" data-mid2="${esc(m.messageId||"")}"
|
|
2280
|
+
title="${isDmAgg ? "跳到这个单聊里定位这条消息" : m.groupShort ? "在左侧该群的归档里定位这条消息" : "这个群还没归档,点一下先归档再定位"}">🗄 ${isDmAgg ? "到单聊定位" : m.groupShort ? "归档定位" : "归档并定位"}</button>
|
|
2281
|
+
<button data-dt="${esc(m.groupShort)}" data-dcid="${esc(m.groupCid||"")}" data-dname="${esc(m.groupName||"")}" data-mid2="${esc(m.messageId||"")}"
|
|
2282
|
+
data-dtext="${esc(m.text||"")}" data-dtime="${esc(m.createTime||"")}" data-dsender="${esc(m.sender||"")}"
|
|
2283
|
+
title="唤起钉钉并复制群名/消息,便于在钉钉里搜索定位">💬 打开钉钉</button>
|
|
2284
|
+
<button data-cp="${esc(m.groupShort)}" data-dcid="${esc(m.groupCid||"")}" data-dname="${esc(m.groupName||"")}" data-mid2="${esc(m.messageId||"")}"
|
|
2285
|
+
data-dtext="${esc(m.text||"")}" data-dtime="${esc(m.createTime||"")}" data-dsender="${esc(m.sender||"")}"
|
|
2286
|
+
title="只复制群名+消息,不动钉钉">📋 复制定位信息</button>
|
|
938
2287
|
</div>` : ""}
|
|
939
2288
|
</div>
|
|
940
2289
|
</div>`;
|
|
941
2290
|
}).join("");
|
|
942
2291
|
|
|
2292
|
+
const moreLabel = `加载更早的 ${Math.min(RENDER_STEP, rest)} 条(还有 ${rest} 条)`;
|
|
2293
|
+
const moreHtml = rest ? `<button class="loadMore" id="loadMore">${moreLabel}</button>` : "";
|
|
2294
|
+
const noteHtml = rest ? `<div class="loadNote">只显示了最近 ${limited.length} 条${FILTER.range ? "(时间范围:" + rangeLabel + ")" : ""},更多点下面的按钮</div>` : "";
|
|
2295
|
+
box.innerHTML = FILTER.desc
|
|
2296
|
+
? bodyHtml + noteHtml + moreHtml
|
|
2297
|
+
: moreHtml + noteHtml + bodyHtml;
|
|
2298
|
+
|
|
2299
|
+
const moreBtn = $("#loadMore");
|
|
2300
|
+
if(moreBtn){
|
|
2301
|
+
moreBtn.onclick = () => {
|
|
2302
|
+
const before = box.scrollHeight;
|
|
2303
|
+
const keepFromTop = box.scrollTop;
|
|
2304
|
+
RENDER_LIMIT += RENDER_STEP;
|
|
2305
|
+
renderMsgs();
|
|
2306
|
+
// 正序(最早在前)时新内容加在顶部,补偿滚动位置
|
|
2307
|
+
if(!FILTER.desc) box.scrollTop = box.scrollHeight - before + keepFromTop;
|
|
2308
|
+
};
|
|
2309
|
+
}
|
|
2310
|
+
|
|
943
2311
|
// 默认位置:正序时滚到最底部(最新一条),倒序时滚到顶部
|
|
944
2312
|
const jumpBtn = $("#jumpLatest"); const atLatest = () => FILTER.desc
|
|
945
2313
|
? box.scrollTop < 40
|
|
@@ -951,9 +2319,65 @@ function renderMsgs(){
|
|
|
951
2319
|
if(jumpBtn) jumpBtn.classList.remove("show");
|
|
952
2320
|
}
|
|
953
2321
|
|
|
2322
|
+
// 私聊聚合里点人名跳到对应单聊
|
|
2323
|
+
if(CUR && CUR.kind === "dmAll"){
|
|
2324
|
+
box.querySelectorAll(".msg .who").forEach(el => {
|
|
2325
|
+
el.style.cursor = "pointer";
|
|
2326
|
+
el.title = (el.title ? el.title + " · " : "") + "点击打开这个单聊";
|
|
2327
|
+
el.onclick = e => {
|
|
2328
|
+
e.stopPropagation();
|
|
2329
|
+
const wrap = el.closest(".msg");
|
|
2330
|
+
const m = wrap && MSGS.find(x => String(x.messageId || "") === String(wrap.dataset.mid || ""));
|
|
2331
|
+
if(!m || !m.groupShort) return;
|
|
2332
|
+
FILTER.group = "";
|
|
2333
|
+
ensureSecOpen("dm");
|
|
2334
|
+
selectGroup(m.groupShort);
|
|
2335
|
+
};
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// 点头像:给这个人设头像(全局,一次设置到处生效)
|
|
2340
|
+
box.querySelectorAll(".msgAv").forEach(el => {
|
|
2341
|
+
el.style.cursor = "pointer";
|
|
2342
|
+
el.onclick = e => {
|
|
2343
|
+
e.stopPropagation();
|
|
2344
|
+
const wrap = el.closest(".msg");
|
|
2345
|
+
const m = wrap && MSGS.find(x => String(x.messageId || "") === String(wrap.dataset.mid || ""));
|
|
2346
|
+
if(!m) return;
|
|
2347
|
+
setAvatarFor(String(m.senderId || ""), m.sender || "");
|
|
2348
|
+
};
|
|
2349
|
+
});
|
|
2350
|
+
|
|
2351
|
+
// 右键消息:自己发的可以撤回
|
|
2352
|
+
box.querySelectorAll(".msg").forEach(el => {
|
|
2353
|
+
el.oncontextmenu = e => {
|
|
2354
|
+
const mid = el.dataset.mid;
|
|
2355
|
+
const m = MSGS.find(x => String(x.messageId || "") === String(mid || ""));
|
|
2356
|
+
if(!m) return;
|
|
2357
|
+
const mine = PROFILE && PROFILE.openId && String(m.senderId || "") === PROFILE.openId;
|
|
2358
|
+
if(!mine) return; // 别人的消息不弹,避免误操作
|
|
2359
|
+
e.preventDefault();
|
|
2360
|
+
openMsgCtx(e, m);
|
|
2361
|
+
};
|
|
2362
|
+
});
|
|
2363
|
+
|
|
954
2364
|
// @我 聚合里的两个跳转按钮
|
|
955
2365
|
box.querySelectorAll("[data-arc]").forEach(b => {
|
|
956
|
-
b.onclick = () =>
|
|
2366
|
+
b.onclick = async () => {
|
|
2367
|
+
if(b.dataset.arc){ goArchiveFocus(b.dataset.arc, b.dataset.mid2); return; }
|
|
2368
|
+
// 未归档:先归档这个群,再定位
|
|
2369
|
+
if(!b.dataset.acid) return;
|
|
2370
|
+
b.disabled = true;
|
|
2371
|
+
const old = b.textContent;
|
|
2372
|
+
b.textContent = "归档中…";
|
|
2373
|
+
try{
|
|
2374
|
+
await adoptAndOpenMention(b.dataset.acid, b.dataset.aname || "");
|
|
2375
|
+
FILTER.kw = ""; FILTER.sender = "";
|
|
2376
|
+
const short = adoptAndOpenMention.lastShort;
|
|
2377
|
+
if(short) goArchiveFocus(short, b.dataset.mid2);
|
|
2378
|
+
}catch(e){ toast("归档失败:" + e.message, true); }
|
|
2379
|
+
finally{ b.disabled = false; b.textContent = old; }
|
|
2380
|
+
};
|
|
957
2381
|
});
|
|
958
2382
|
box.querySelectorAll(".quote").forEach(el => {
|
|
959
2383
|
el.onclick = () => {
|
|
@@ -968,7 +2392,11 @@ function renderMsgs(){
|
|
|
968
2392
|
try{
|
|
969
2393
|
const j = await api("/api/open-dingtalk", {
|
|
970
2394
|
method:"POST", headers:{"Content-Type":"application/json"},
|
|
971
|
-
body: JSON.stringify({
|
|
2395
|
+
body: JSON.stringify({
|
|
2396
|
+
short: b.dataset.cp, messageId: b.dataset.mid2, copyOnly: true,
|
|
2397
|
+
cid: b.dataset.dcid, name: b.dataset.dname,
|
|
2398
|
+
text: b.dataset.dtext, time: b.dataset.dtime, sender: b.dataset.dsender,
|
|
2399
|
+
})
|
|
972
2400
|
});
|
|
973
2401
|
toast(j.copied ? "已复制定位信息(群名/时间/内容/会话ID)" : "复制失败", !j.copied);
|
|
974
2402
|
}catch(e){ toast("失败:" + e.message, true); }
|
|
@@ -983,7 +2411,11 @@ function renderMsgs(){
|
|
|
983
2411
|
try{
|
|
984
2412
|
const j = await api("/api/open-dingtalk", {
|
|
985
2413
|
method:"POST", headers:{"Content-Type":"application/json"},
|
|
986
|
-
body: JSON.stringify({
|
|
2414
|
+
body: JSON.stringify({
|
|
2415
|
+
short: b.dataset.dt, messageId: b.dataset.mid2,
|
|
2416
|
+
cid: b.dataset.dcid, name: b.dataset.dname,
|
|
2417
|
+
text: b.dataset.dtext, time: b.dataset.dtime, sender: b.dataset.dsender,
|
|
2418
|
+
})
|
|
987
2419
|
});
|
|
988
2420
|
if(!j.opened){ toast("没唤起钉钉:" + (j.error || "未知原因"), true); return; }
|
|
989
2421
|
toast(j.copied
|
|
@@ -1001,7 +2433,7 @@ function goArchiveFocus(short, messageId){
|
|
|
1001
2433
|
if(!short) return;
|
|
1002
2434
|
PENDING_FOCUS = messageId || null;
|
|
1003
2435
|
if(CUR && CUR.short === short){
|
|
1004
|
-
FILTER.kw = ""; FILTER.sender = ""; FILTER.group = ""; FILTER.range = "";
|
|
2436
|
+
FILTER.kw = ""; FILTER.sender = ""; FILTER.group = ""; FILTER.range = "today"; resetRenderLimit();
|
|
1005
2437
|
renderTab();
|
|
1006
2438
|
const mid = PENDING_FOCUS; PENDING_FOCUS = null;
|
|
1007
2439
|
focusMessage(mid);
|
|
@@ -1166,6 +2598,20 @@ $("#ctxMembersItem").onclick = () => {
|
|
|
1166
2598
|
closeCtx();
|
|
1167
2599
|
if(short) openMembers(short);
|
|
1168
2600
|
};
|
|
2601
|
+
$("#ctxResetMentions").onclick = async e => {
|
|
2602
|
+
const btn = e.currentTarget;
|
|
2603
|
+
closeCtx();
|
|
2604
|
+
if(!confirm("@我 聚合会先清空,然后只从今天开始重新累积(更早的 @我 不再汇总)。继续?")) return;
|
|
2605
|
+
btn.disabled = true;
|
|
2606
|
+
try{
|
|
2607
|
+
const j = await api("/api/mentions/reset", {method:"POST", headers:{"Content-Type":"application/json"}, body:"{}"});
|
|
2608
|
+
await loadGroups(false);
|
|
2609
|
+
if(CUR && CUR.kind === "mentions") await selectGroup(CUR.short, true);
|
|
2610
|
+
toast(`已清空重来:自 ${j.since} 起共 ${j.total} 条 @我`);
|
|
2611
|
+
}catch(err){ toast("清空失败:" + err.message, true); }
|
|
2612
|
+
finally{ btn.disabled = false; }
|
|
2613
|
+
};
|
|
2614
|
+
|
|
1169
2615
|
$("#ctxSearchItem").onclick = () => { closeCtx(); toggleSearch(true); };
|
|
1170
2616
|
$("#ctxPullAllItem").onclick = e => ctxPullAll(e.currentTarget);
|
|
1171
2617
|
$("#ctxPullItem").onclick = e => ctxPull(e.currentTarget);
|
|
@@ -1186,11 +2632,13 @@ document.addEventListener("scroll", closeCtx, true);
|
|
|
1186
2632
|
document.addEventListener("keydown", e => {
|
|
1187
2633
|
if(e.key === "Escape"){
|
|
1188
2634
|
closeCtx(); closeLightbox(); window.__closeComposer && window.__closeComposer();
|
|
2635
|
+
if($("#contactModal").classList.contains("show")) closeContactModal();
|
|
2636
|
+
if(document.getElementById("settingsModal").classList.contains("show")) closeSettings();
|
|
1189
2637
|
if($("#gsearchWrap").classList.contains("show") && !$("#gsearch").value) toggleSearch(false);
|
|
1190
2638
|
}
|
|
1191
2639
|
});
|
|
1192
2640
|
window.addEventListener("resize", closeCtx);
|
|
1193
|
-
$("#
|
|
2641
|
+
$("#sideScroll").addEventListener("scroll", closeCtx);
|
|
1194
2642
|
|
|
1195
2643
|
/* 手动归档会话 */
|
|
1196
2644
|
$("#btnManualAdopt").onclick = async e => {
|
|
@@ -1214,6 +2662,488 @@ $("#btnManualAdopt").onclick = async e => {
|
|
|
1214
2662
|
finally { btn.disabled = false; btn.innerHTML = html; }
|
|
1215
2663
|
};
|
|
1216
2664
|
|
|
2665
|
+
/* ---------------- 常用联系人 ---------------- */
|
|
2666
|
+
let CONTACTS = [];
|
|
2667
|
+
|
|
2668
|
+
async function loadContacts(){
|
|
2669
|
+
try{
|
|
2670
|
+
const j = await api("/api/contacts");
|
|
2671
|
+
CONTACTS = j.contacts || [];
|
|
2672
|
+
}catch(e){ CONTACTS = []; }
|
|
2673
|
+
renderContacts();
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
/* ---------------- 全局头像库(openId → 图片) ---------------- */
|
|
2677
|
+
let AVATARS = {};
|
|
2678
|
+
|
|
2679
|
+
async function loadAvatars(){
|
|
2680
|
+
try{
|
|
2681
|
+
const j = await api("/api/avatars");
|
|
2682
|
+
AVATARS = j.avatars || {};
|
|
2683
|
+
}catch{ AVATARS = {}; }
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/** 渲染头像:有图就用图,没有就首字彩色圆 */
|
|
2687
|
+
function avatarHtml(name, openId, cls, extraStyle){
|
|
2688
|
+
const key = String(openId || "").trim();
|
|
2689
|
+
const url = key ? AVATARS[key] : "";
|
|
2690
|
+
const a = avatarOf(name, key || name);
|
|
2691
|
+
const c = cls || "av";
|
|
2692
|
+
const st = extraStyle || "";
|
|
2693
|
+
if(url) return `<div class="${c} hasImg" style="${st}" title="${esc(name || "")}(点击换头像)"><img src="${esc(url)}" alt=""></div>`;
|
|
2694
|
+
return `<div class="${c}" style="background:${a.bg};${st}" title="${esc(name || "")}(点击设头像)">${esc(a.letter)}</div>`;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
async function setAvatarFor(openId, name){
|
|
2698
|
+
if(!openId){ toast("这条消息没有人员 openDingTalkId,无法设头像", true); return; }
|
|
2699
|
+
AVATAR_OPENID = openId;
|
|
2700
|
+
const pv = document.getElementById("amPreview");
|
|
2701
|
+
const url = AVATARS[openId];
|
|
2702
|
+
if(pv) pv.innerHTML = url ? `<img src="${esc(url)}" alt="" style="width:100%;height:100%;object-fit:cover">` : "预览";
|
|
2703
|
+
const u = document.getElementById("amUrl"); if(u) u.value = "";
|
|
2704
|
+
document.getElementById("avatarModal").classList.add("show");
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
/* 未读:私聊看 dm 归档的 newCount,群聊/聚合同理 */
|
|
2708
|
+
function groupOfCid(cid){
|
|
2709
|
+
return cid ? GROUPS.find(x => x.cid === cid) : null;
|
|
2710
|
+
}
|
|
2711
|
+
function contactUnread(c){
|
|
2712
|
+
const g = groupOfCid(c.cid);
|
|
2713
|
+
return g ? Number(g.newCount || 0) : 0;
|
|
2714
|
+
}
|
|
2715
|
+
function totalUnread(){
|
|
2716
|
+
let n = 0;
|
|
2717
|
+
for(const c of CONTACTS) n += contactUnread(c);
|
|
2718
|
+
for(const g of GROUPS){
|
|
2719
|
+
if(g.kind === "group" || g.kind === "mentions") n += Number(g.newCount || 0);
|
|
2720
|
+
}
|
|
2721
|
+
return n;
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
function renderContacts(){
|
|
2725
|
+
const box = $("#contactsBox"), list = $("#contactsList");
|
|
2726
|
+
if(!box || !list) return;
|
|
2727
|
+
box.classList.toggle("closed", localStorage.getItem("omd.contactsClosed") === "1");
|
|
2728
|
+
const cUnread = CONTACTS.reduce((a, c) => a + contactUnread(c), 0);
|
|
2729
|
+
$("#contactsCount").innerHTML = `${CONTACTS.length || ""}${cUnread ? `<span class="cUnread" title="${cUnread} 条未读私聊">${cUnread > 99 ? "99+" : cUnread}</span>` : ""}`;
|
|
2730
|
+
const railU = $("#railUnread");
|
|
2731
|
+
if(railU){
|
|
2732
|
+
const n = totalUnread();
|
|
2733
|
+
railU.style.display = n ? "block" : "none";
|
|
2734
|
+
railU.textContent = n > 99 ? "99+" : String(n);
|
|
2735
|
+
}
|
|
2736
|
+
if(!CONTACTS.length){
|
|
2737
|
+
list.innerHTML = `<div class="cEmpty">还没有常用联系人,点右上 + 从「单聊」里挑</div>`;
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
list.innerHTML = CONTACTS.map(c => {
|
|
2741
|
+
const key = c.cid || ("open:" + c.openId);
|
|
2742
|
+
const a = avatarOf(c.name, key);
|
|
2743
|
+
const gurl = c.avatar || (c.openId && AVATARS[c.openId]) || (c.cid && AVATARS[c.cid]) || "";
|
|
2744
|
+
const av = gurl
|
|
2745
|
+
? `<span class="cav hasImg"><img src="${esc(gurl)}" alt=""></span>`
|
|
2746
|
+
: `<span class="cav" style="background:${a.bg}">${esc(a.letter)}</span>`;
|
|
2747
|
+
const active = (CUR && CUR.kind === "person" && CUR.openId === c.openId)
|
|
2748
|
+
|| (CUR && c.cid && CUR.cid === c.cid);
|
|
2749
|
+
const time = (c.lastTime || "").slice(5, 16);
|
|
2750
|
+
const prev = c.preview || (c.hasDm ? "" : (c.cid ? "还没有归档这个单聊,点开即拉取" : "只有 openDingTalkId,没有会话历史"));
|
|
2751
|
+
const tip = [c.name, c.hasDm ? `${c.msgCount} 条 · 已归档` : "未归档", c.lastTime ? "最近 " + c.lastTime : ""].filter(Boolean).join(" · ");
|
|
2752
|
+
return `<div class="cItem ${active?"active":""} ${c.pinned?"pinned":""}" data-key="${esc(key)}" title="${esc(tip)}">
|
|
2753
|
+
${c.avatar ? av : av.replace('<span class="cav"', '<span class="cav" title="点击设置头像"')}
|
|
2754
|
+
<div class="cmain">
|
|
2755
|
+
<div class="crow"><span class="cnm">${esc(c.name)}${c.pinned?'<span class="cpinTag" title="已置顶">📌</span>':""}</span>
|
|
2756
|
+
${contactUnread(c) ? `<span class="cunread" title="${contactUnread(c)} 条未读私聊">${contactUnread(c) > 99 ? "99+" : contactUnread(c)}</span>` : ""}
|
|
2757
|
+
<span class="ctime">${esc(time)}</span></div>
|
|
2758
|
+
<div class="cprev ${c.preview ? "" : "empty"}">${esc(prev)}</div>
|
|
2759
|
+
</div>
|
|
2760
|
+
<span class="cacts">
|
|
2761
|
+
<button class="ava" title="设置头像">🖼</button>
|
|
2762
|
+
<button class="pin" title="${c.pinned?"取消置顶":"置顶到最前"}">${c.pinned?"📌":"⇧"}</button>
|
|
2763
|
+
<button class="del" title="从常用联系人移除">×</button>
|
|
2764
|
+
</span>
|
|
2765
|
+
</div>`;
|
|
2766
|
+
}).join("");
|
|
2767
|
+
clearTimeout(renderContacts._t);
|
|
2768
|
+
if(CONTACTS.some(c => c.previewPending)){
|
|
2769
|
+
renderContacts._t = setTimeout(()=> loadContacts(), 3500);
|
|
2770
|
+
}
|
|
2771
|
+
list.querySelectorAll(".cItem").forEach(el => {
|
|
2772
|
+
const key = el.dataset.key;
|
|
2773
|
+
el.onclick = e => { if(e.target.closest(".cacts")) return; openContact(key); };
|
|
2774
|
+
el.draggable = true;
|
|
2775
|
+
el.addEventListener("dragstart", e => {
|
|
2776
|
+
DRAG_KEY = key;
|
|
2777
|
+
el.classList.add("dragging");
|
|
2778
|
+
e.dataTransfer.effectAllowed = "move";
|
|
2779
|
+
try{ e.dataTransfer.setData("text/plain", key); }catch{}
|
|
2780
|
+
});
|
|
2781
|
+
el.addEventListener("dragend", () => {
|
|
2782
|
+
el.classList.remove("dragging");
|
|
2783
|
+
list.querySelectorAll(".cItem").forEach(x => x.classList.remove("dropBefore","dropAfter"));
|
|
2784
|
+
DRAG_KEY = "";
|
|
2785
|
+
});
|
|
2786
|
+
el.addEventListener("dragover", e => {
|
|
2787
|
+
if(!DRAG_KEY || DRAG_KEY === key) return;
|
|
2788
|
+
e.preventDefault();
|
|
2789
|
+
const r = el.getBoundingClientRect();
|
|
2790
|
+
const after = (e.clientY - r.top) > r.height / 2;
|
|
2791
|
+
el.classList.toggle("dropAfter", after);
|
|
2792
|
+
el.classList.toggle("dropBefore", !after);
|
|
2793
|
+
});
|
|
2794
|
+
el.addEventListener("dragleave", () => el.classList.remove("dropBefore","dropAfter"));
|
|
2795
|
+
el.addEventListener("drop", async e => {
|
|
2796
|
+
e.preventDefault();
|
|
2797
|
+
e.stopPropagation();
|
|
2798
|
+
const from = DRAG_KEY;
|
|
2799
|
+
const r = el.getBoundingClientRect();
|
|
2800
|
+
const after = (e.clientY - r.top) > r.height / 2;
|
|
2801
|
+
el.classList.remove("dropBefore","dropAfter");
|
|
2802
|
+
if(!from || from === key) return;
|
|
2803
|
+
const keys = [...list.querySelectorAll(".cItem")].map(x => x.dataset.key).filter(k => k !== from);
|
|
2804
|
+
const at = keys.indexOf(key);
|
|
2805
|
+
keys.splice(after ? at + 1 : at, 0, from);
|
|
2806
|
+
try{
|
|
2807
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2808
|
+
body: JSON.stringify({action:"reorder", keys})});
|
|
2809
|
+
await loadContacts();
|
|
2810
|
+
}catch(err){ toast("排序失败:" + err.message, true); }
|
|
2811
|
+
});
|
|
2812
|
+
el.querySelector("button.ava").onclick = e => { e.stopPropagation(); pickAvatar(key); };
|
|
2813
|
+
// 点头像圈 / 把图片拖进条目 = 设置头像
|
|
2814
|
+
el.querySelector(".cav").addEventListener("click", e => { e.stopPropagation(); pickAvatar(key); });
|
|
2815
|
+
el.addEventListener("dragover", e => {
|
|
2816
|
+
if(e.dataTransfer && [...(e.dataTransfer.types || [])].includes("Files")){
|
|
2817
|
+
e.preventDefault();
|
|
2818
|
+
el.classList.add("dropBefore");
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
el.addEventListener("dragleave", () => el.classList.remove("dropBefore"));
|
|
2822
|
+
el.addEventListener("drop", async e => {
|
|
2823
|
+
const f = e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files[0];
|
|
2824
|
+
if(!f) return;
|
|
2825
|
+
e.preventDefault();
|
|
2826
|
+
e.stopPropagation();
|
|
2827
|
+
el.classList.remove("dropBefore");
|
|
2828
|
+
await uploadAvatarFile(key, f);
|
|
2829
|
+
});
|
|
2830
|
+
el.querySelector("button.pin").onclick = async e => {
|
|
2831
|
+
e.stopPropagation();
|
|
2832
|
+
const c = CONTACTS.find(x => (x.cid || ("open:" + x.openId)) === key);
|
|
2833
|
+
if(!c) return;
|
|
2834
|
+
try{
|
|
2835
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2836
|
+
body: JSON.stringify({action:"pin", cid:c.cid||"", openId:c.openId||"", pinned: !c.pinned})});
|
|
2837
|
+
await loadContacts();
|
|
2838
|
+
toast(c.pinned ? "已取消置顶" : `已置顶「${c.name}」`);
|
|
2839
|
+
}catch(err){ toast("操作失败:" + err.message, true); }
|
|
2840
|
+
};
|
|
2841
|
+
el.querySelector("button.del").onclick = async e => {
|
|
2842
|
+
e.stopPropagation();
|
|
2843
|
+
const c = CONTACTS.find(x => (x.cid || ("open:" + x.openId)) === key);
|
|
2844
|
+
if(!confirm(`从常用联系人里移除「${c ? c.name : key}」?\n只删这条常用,不动归档消息。`)) return;
|
|
2845
|
+
try{
|
|
2846
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2847
|
+
body: JSON.stringify({action:"remove", cid: (c && c.cid) || "", openId: (c && c.openId) || ""})});
|
|
2848
|
+
await loadContacts();
|
|
2849
|
+
toast("已移出常用联系人");
|
|
2850
|
+
}catch(err){ toast("移除失败:" + err.message, true); }
|
|
2851
|
+
};
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
let DRAG_KEY = "";
|
|
2856
|
+
|
|
2857
|
+
/* 给联系人设头像:本地图片 / 图片链接 / 直接把图片拖到条目上 */
|
|
2858
|
+
let AVATAR_KEY = "";
|
|
2859
|
+
let AVATAR_OPENID = "";
|
|
2860
|
+
|
|
2861
|
+
function avatarTarget(key){
|
|
2862
|
+
const c = CONTACTS.find(x => (x.cid || ("open:" + x.openId)) === key);
|
|
2863
|
+
if(!c) return null;
|
|
2864
|
+
return { c, payload: { cid: c.cid || "", openId: c.openId || "" } };
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
async function uploadAvatarFile(key, file){
|
|
2868
|
+
const t = avatarTarget(key);
|
|
2869
|
+
if((!t && !AVATAR_OPENID) || !file) return;
|
|
2870
|
+
if(!/^image\//.test(file.type)){ toast("只支持图片文件", true); return; }
|
|
2871
|
+
if(file.size > 3 * 1024 * 1024){ toast("图片超过 3MB,先压缩一下", true); return; }
|
|
2872
|
+
const dataUrl = await new Promise(res => {
|
|
2873
|
+
const r = new FileReader();
|
|
2874
|
+
r.onload = () => res(String(r.result));
|
|
2875
|
+
r.readAsDataURL(file);
|
|
2876
|
+
});
|
|
2877
|
+
try{
|
|
2878
|
+
if(t){
|
|
2879
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2880
|
+
body: JSON.stringify({action:"avatar", ...t.payload, dataUrl})});
|
|
2881
|
+
}
|
|
2882
|
+
if(AVATAR_OPENID){
|
|
2883
|
+
await api("/api/avatars", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2884
|
+
body: JSON.stringify({openId: AVATAR_OPENID, name: (t && t.c && t.c.name) || "", dataUrl})});
|
|
2885
|
+
await loadAvatars();
|
|
2886
|
+
}
|
|
2887
|
+
if(t) await loadContacts();
|
|
2888
|
+
if(CUR) selectGroup(CUR.short, true);
|
|
2889
|
+
toast("头像已更新");
|
|
2890
|
+
}catch(e){ toast("设置头像失败:" + e.message, true); }
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
function pickAvatar(key){
|
|
2894
|
+
const t = avatarTarget(key);
|
|
2895
|
+
if(!t){ toast("先添加这个联系人", true); return; }
|
|
2896
|
+
AVATAR_KEY = key;
|
|
2897
|
+
AVATAR_OPENID = (t.c && t.c.openId) || "";
|
|
2898
|
+
const pv = $("#amPreview");
|
|
2899
|
+
pv.innerHTML = t.c.avatar ? `<img src="${esc(t.c.avatar)}" alt="" style="width:100%;height:100%;object-fit:cover">` : "预览";
|
|
2900
|
+
$("#amUrl").value = "";
|
|
2901
|
+
$("#avatarModal").classList.add("show");
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
function closeAvatarModal(){ $("#avatarModal").classList.remove("show"); }
|
|
2905
|
+
$("#amClose").onclick = closeAvatarModal;
|
|
2906
|
+
$("#amCancel").onclick = closeAvatarModal;
|
|
2907
|
+
$("#avatarModal").onclick = e => { if(e.target.id === "avatarModal") closeAvatarModal(); };
|
|
2908
|
+
|
|
2909
|
+
$("#amFile").onclick = () => {
|
|
2910
|
+
const pick = document.createElement("input");
|
|
2911
|
+
pick.type = "file";
|
|
2912
|
+
pick.accept = "image/png,image/jpeg,image/webp,image/gif";
|
|
2913
|
+
pick.onchange = async () => {
|
|
2914
|
+
const f = pick.files && pick.files[0];
|
|
2915
|
+
if(!f) return;
|
|
2916
|
+
await uploadAvatarFile(AVATAR_KEY, f);
|
|
2917
|
+
closeAvatarModal();
|
|
2918
|
+
};
|
|
2919
|
+
pick.click();
|
|
2920
|
+
};
|
|
2921
|
+
|
|
2922
|
+
$("#amClear").onclick = async () => {
|
|
2923
|
+
const t = avatarTarget(AVATAR_KEY);
|
|
2924
|
+
if(!t && !AVATAR_OPENID) return;
|
|
2925
|
+
try{
|
|
2926
|
+
if(t){
|
|
2927
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2928
|
+
body: JSON.stringify({action:"avatar", ...t.payload, clear:true})});
|
|
2929
|
+
}
|
|
2930
|
+
if(AVATAR_OPENID){
|
|
2931
|
+
await api("/api/avatars", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2932
|
+
body: JSON.stringify({openId: AVATAR_OPENID, clear:true})});
|
|
2933
|
+
await loadAvatars();
|
|
2934
|
+
}
|
|
2935
|
+
if(t) await loadContacts();
|
|
2936
|
+
closeAvatarModal();
|
|
2937
|
+
if(CUR) selectGroup(CUR.short, true);
|
|
2938
|
+
toast("已清除头像");
|
|
2939
|
+
}catch(e){ toast("清除失败:" + e.message, true); }
|
|
2940
|
+
};
|
|
2941
|
+
|
|
2942
|
+
$("#amUrlOk").onclick = async () => {
|
|
2943
|
+
const url = $("#amUrl").value.trim();
|
|
2944
|
+
const t = avatarTarget(AVATAR_KEY);
|
|
2945
|
+
if(!t && !AVATAR_OPENID) return;
|
|
2946
|
+
if(!/^https?:\/\//i.test(url)){ toast("请填 http(s) 开头的图片链接", true); return; }
|
|
2947
|
+
try{
|
|
2948
|
+
if(t){
|
|
2949
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2950
|
+
body: JSON.stringify({action:"avatar-url", ...t.payload, url})});
|
|
2951
|
+
}
|
|
2952
|
+
if(AVATAR_OPENID){
|
|
2953
|
+
await api("/api/avatars", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
2954
|
+
body: JSON.stringify({openId: AVATAR_OPENID, name: (t && t.c && t.c.name) || "", url})});
|
|
2955
|
+
await loadAvatars();
|
|
2956
|
+
}
|
|
2957
|
+
if(t) await loadContacts();
|
|
2958
|
+
closeAvatarModal();
|
|
2959
|
+
if(CUR) selectGroup(CUR.short, true);
|
|
2960
|
+
toast("头像已更新");
|
|
2961
|
+
}catch(e){ toast("设置头像失败:" + e.message, true); }
|
|
2962
|
+
};
|
|
2963
|
+
|
|
2964
|
+
$("#amPreview").onclick = () => $("#amFile").click();
|
|
2965
|
+
|
|
2966
|
+
/* 点常用联系人:有单聊会话就打开(没归档的先归档),只有 openId 的走跨群时间线 */
|
|
2967
|
+
async function openContact(key){
|
|
2968
|
+
const c = CONTACTS.find(x => (x.cid || ("open:" + x.openId)) === key);
|
|
2969
|
+
if(!c) return;
|
|
2970
|
+
if(c.cid){
|
|
2971
|
+
const g = GROUPS.find(x => x.cid === c.cid);
|
|
2972
|
+
if(g){ FILTER.group = ""; ensureSecOpen("dm"); selectGroup(g.short); return; }
|
|
2973
|
+
toast(`正在归档「${c.name}」的单聊…`);
|
|
2974
|
+
try{
|
|
2975
|
+
const j = await api("/api/adopt", {
|
|
2976
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
2977
|
+
body: JSON.stringify({name: c.name, cid: c.cid, kind: "dm"})
|
|
2978
|
+
});
|
|
2979
|
+
await loadGroups(false);
|
|
2980
|
+
await loadContacts();
|
|
2981
|
+
FILTER.group = ""; ensureSecOpen("dm");
|
|
2982
|
+
selectGroup(j.short);
|
|
2983
|
+
}catch(e){ toast("归档失败:" + e.message, true); }
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
openPerson(c.openId);
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
/* 某人的跨群时间线 */
|
|
2990
|
+
async function openPerson(openId){
|
|
2991
|
+
if(!openId) return;
|
|
2992
|
+
const c = CONTACTS.find(x => x.openId === openId);
|
|
2993
|
+
CUR = { short: "person:" + openId, kind: "person", openId,
|
|
2994
|
+
name: c ? c.name : openId, cid: "", sources: [], sourceCount: 0 };
|
|
2995
|
+
MSGS = []; MEMBERS = null;
|
|
2996
|
+
FILTER = { kw:"", sender:"", group:"", range:"today", from:"", to:"", desc:true, newIds:new Set(), jump:true };
|
|
2997
|
+
PENDING_GROUP = null;
|
|
2998
|
+
renderGroups(); renderContacts();
|
|
2999
|
+
$("#empty").style.display = "none";
|
|
3000
|
+
const ws = $("#workspace");
|
|
3001
|
+
ws.style.display = "flex";
|
|
3002
|
+
ws.innerHTML = `<div class="empty">加载中…</div>`;
|
|
3003
|
+
try{
|
|
3004
|
+
const j = await api("/api/contacts/messages?openId=" + encodeURIComponent(openId));
|
|
3005
|
+
MSGS = j.messages || [];
|
|
3006
|
+
CUR.name = (c && c.name) || j.name || openId;
|
|
3007
|
+
CUR.sources = (j.groups || []).map(g => ({short: g.short, name: g.name, count: g.count}));
|
|
3008
|
+
CUR.sourceCount = CUR.sources.length;
|
|
3009
|
+
renderWorkspace();
|
|
3010
|
+
renderContacts();
|
|
3011
|
+
}catch(e){ toast("读取失败:" + e.message, true); }
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
$("#contactsToggle").onclick = () => {
|
|
3015
|
+
const box = $("#contactsBox");
|
|
3016
|
+
const closed = !box.classList.contains("closed");
|
|
3017
|
+
box.classList.toggle("closed", closed);
|
|
3018
|
+
localStorage.setItem("omd.contactsClosed", closed ? "1" : "0");
|
|
3019
|
+
};
|
|
3020
|
+
|
|
3021
|
+
/* 添加弹窗 */
|
|
3022
|
+
function openContactModal(){
|
|
3023
|
+
$("#contactModal").classList.add("show");
|
|
3024
|
+
$("#cmQuery").value = ""; $("#cmName").value = ""; $("#cmOpenId").value = "";
|
|
3025
|
+
loadCandidates("");
|
|
3026
|
+
setTimeout(()=> $("#cmQuery").focus(), 30);
|
|
3027
|
+
}
|
|
3028
|
+
function closeContactModal(){ $("#contactModal").classList.remove("show"); }
|
|
3029
|
+
$("#contactsTitle").onclick = () => openDmAll();
|
|
3030
|
+
$("#contactsAdd").onclick = openContactModal;
|
|
3031
|
+
|
|
3032
|
+
/** 私聊聚合:所有私聊消息一条时间线 */
|
|
3033
|
+
async function openDmAll(){
|
|
3034
|
+
CUR = { short: "@私聊", kind: "dmAll", name: "私聊消息", cid: "", sources: [], sourceCount: 0 };
|
|
3035
|
+
MSGS = []; MEMBERS = null;
|
|
3036
|
+
FILTER = { kw:"", sender:"", group:"", range:"today", from:"", to:"", desc:true, newIds:new Set(), jump:true };
|
|
3037
|
+
PENDING_GROUP = null;
|
|
3038
|
+
resetRenderLimit();
|
|
3039
|
+
renderGroups(); renderContacts();
|
|
3040
|
+
$("#empty").style.display = "none";
|
|
3041
|
+
const ws = $("#workspace");
|
|
3042
|
+
ws.style.display = "flex";
|
|
3043
|
+
ws.innerHTML = `<div class="empty">加载中…</div>`;
|
|
3044
|
+
try{
|
|
3045
|
+
const j = await api("/api/dm-messages");
|
|
3046
|
+
MSGS = j.messages || [];
|
|
3047
|
+
CUR.sources = (j.peers || []).map(p => ({ short: p.short, name: p.name, count: p.count, unread: p.unread || 0, openId: p.openId }));
|
|
3048
|
+
CUR.sourceCount = j.peerCount || CUR.sources.length;
|
|
3049
|
+
CUR.unreadCount = j.unread || 0;
|
|
3050
|
+
CUR.msgCount = j.count || MSGS.length;
|
|
3051
|
+
// 时间范围默认今天;今天没有就放开
|
|
3052
|
+
const rg = rangeBounds(FILTER.range);
|
|
3053
|
+
if(rg && MSGS.length){
|
|
3054
|
+
const has = MSGS.some(m => { const d = String(m.createTime||"").slice(0,10); return d && d >= rg.from && (!rg.to || d <= rg.to); });
|
|
3055
|
+
if(!has) FILTER.range = "";
|
|
3056
|
+
}
|
|
3057
|
+
renderWorkspace();
|
|
3058
|
+
renderContacts();
|
|
3059
|
+
}catch(e){ toast("读取失败:" + e.message, true); }
|
|
3060
|
+
}
|
|
3061
|
+
$("#cmClose").onclick = closeContactModal;
|
|
3062
|
+
$("#cmCancel").onclick = closeContactModal;
|
|
3063
|
+
$("#contactModal").onclick = e => { if(e.target.id === "contactModal") closeContactModal(); };
|
|
3064
|
+
|
|
3065
|
+
let CM_TIMER = null;
|
|
3066
|
+
$("#cmQuery").oninput = e => {
|
|
3067
|
+
clearTimeout(CM_TIMER);
|
|
3068
|
+
const q = e.target.value.trim();
|
|
3069
|
+
CM_TIMER = setTimeout(()=> loadCandidates(q), 220);
|
|
3070
|
+
};
|
|
3071
|
+
|
|
3072
|
+
let CM_POLL = null;
|
|
3073
|
+
|
|
3074
|
+
async function loadCandidates(q){
|
|
3075
|
+
const box = $("#cmList"), hint = $("#cmHint");
|
|
3076
|
+
clearTimeout(CM_POLL);
|
|
3077
|
+
box.innerHTML = `<div style="padding:8px 2px">加载中…</div>`;
|
|
3078
|
+
let j;
|
|
3079
|
+
try{
|
|
3080
|
+
j = await api("/api/contacts/candidates?q=" + encodeURIComponent(q || ""));
|
|
3081
|
+
}catch(e){
|
|
3082
|
+
box.innerHTML = `<div style="padding:8px 2px;color:#9c4b45">加载失败:${esc(e.message)}</div>`;
|
|
3083
|
+
return;
|
|
3084
|
+
}
|
|
3085
|
+
const rows = j.candidates || [];
|
|
3086
|
+
const cache = j.dmCache || {};
|
|
3087
|
+
const stamp = cache.updatedAt ? new Date(cache.updatedAt).toLocaleString("zh-CN", {hour12:false}) : "";
|
|
3088
|
+
hint.textContent = cache.refreshing
|
|
3089
|
+
? "正在读取钉钉单聊列表(第一次要 1~2 分钟,好了会自动刷新)…"
|
|
3090
|
+
: cache.error
|
|
3091
|
+
? `钉钉单聊列表读取失败:${cache.error}(下面是本地已归档的单聊)`
|
|
3092
|
+
: stamp ? `钉钉单聊列表更新于 ${stamp} · ${cache.count} 个单聊` : "";
|
|
3093
|
+
if(!rows.length){
|
|
3094
|
+
box.innerHTML = `<div style="padding:8px 2px">${cache.refreshing ? "稍等,正在抓取你的单聊列表…" : "没有匹配的单聊(也可以在下面手动填 openConversationId)"}</div>`;
|
|
3095
|
+
}else{
|
|
3096
|
+
box.innerHTML = rows.map(c => {
|
|
3097
|
+
const a = avatarOf(c.name, c.cid || c.openId);
|
|
3098
|
+
return `<div class="cand">
|
|
3099
|
+
<span class="cav" style="width:26px;height:26px;border-radius:50%;flex:0 0 26px;display:flex;align-items:center;justify-content:center;color:#fff;font-size:12px;font-weight:600;background:${a.bg}">${esc(a.letter)}</span>
|
|
3100
|
+
<div class="info">
|
|
3101
|
+
<div class="n">${esc(c.name)} ${c.archived ? '<span class="badge">已归档</span>' : '<span class="badge gray">单聊</span>'} ${c.saved ? '<span class="badge">已添加</span>' : ""}</div>
|
|
3102
|
+
<div class="m">${esc(c.cid || c.openId || "")}</div>
|
|
3103
|
+
<div class="m" style="font-family:inherit">${c.archived ? c.msgCount + " 条消息" : "未归档"}${c.lastTime ? " · 最近 " + esc(c.lastTime) : ""}</div>
|
|
3104
|
+
</div>
|
|
3105
|
+
<button ${c.saved ? "disabled" : ""} data-cid="${esc(c.cid || "")}" data-oid="${esc(c.openId || "")}" data-name="${esc(c.name)}">${c.saved ? "已添加" : "添加"}</button>
|
|
3106
|
+
</div>`;
|
|
3107
|
+
}).join("");
|
|
3108
|
+
box.querySelectorAll("button[data-cid]").forEach(b => {
|
|
3109
|
+
b.onclick = () => addContact({ cid: b.dataset.cid, openId: b.dataset.oid, name: b.dataset.name }, b);
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
if(cache.refreshing) CM_POLL = setTimeout(()=> {
|
|
3113
|
+
if($("#contactModal").classList.contains("show")) loadCandidates(q);
|
|
3114
|
+
}, 6000);
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
async function addContact({ cid = "", openId = "", name = "" }, btn){
|
|
3118
|
+
if(!cid && !openId){ toast("需要单聊会话 ID 或 openDingTalkId", true); return; }
|
|
3119
|
+
if(btn){ btn.disabled = true; btn.innerHTML = `<span class="spin"></span>`; }
|
|
3120
|
+
try{
|
|
3121
|
+
await api("/api/contacts", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
3122
|
+
body: JSON.stringify({action:"add", cid, openId, name})});
|
|
3123
|
+
await loadContacts();
|
|
3124
|
+
toast(`已添加常用联系人:${name || cid || openId}`);
|
|
3125
|
+
$("#cmName").value = ""; $("#cmCid").value = ""; $("#cmOpenId").value = "";
|
|
3126
|
+
if($("#contactModal").classList.contains("show")) loadCandidates($("#cmQuery").value.trim());
|
|
3127
|
+
}catch(e){
|
|
3128
|
+
toast("添加失败:" + e.message, true);
|
|
3129
|
+
if(btn){ btn.disabled = false; btn.textContent = "添加"; }
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
$("#cmReload").onclick = async () => {
|
|
3134
|
+
$("#cmHint").textContent = "正在重新读取钉钉单聊列表…";
|
|
3135
|
+
try{ await api("/api/contacts/candidates?refresh=1"); }catch{}
|
|
3136
|
+
loadCandidates($("#cmQuery").value.trim());
|
|
3137
|
+
};
|
|
3138
|
+
|
|
3139
|
+
$("#cmAddBtn").onclick = () => {
|
|
3140
|
+
const name = $("#cmName").value.trim();
|
|
3141
|
+
const cid = $("#cmCid").value.trim();
|
|
3142
|
+
const openId = $("#cmOpenId").value.trim();
|
|
3143
|
+
if(!cid && !openId){ toast("至少填单聊会话 ID 或 openDingTalkId 之一", true); $("#cmCid").focus(); return; }
|
|
3144
|
+
addContact({ cid, openId, name }, $("#cmAddBtn"));
|
|
3145
|
+
};
|
|
3146
|
+
|
|
1217
3147
|
/* ---------------- 侧栏:调宽 / 收起 ---------------- */
|
|
1218
3148
|
const ASIDE = $("#aside"), LAYOUT = $("#layout");
|
|
1219
3149
|
const SIDE_MIN = 200, SIDE_DEF = 310;
|
|
@@ -1328,7 +3258,24 @@ function renderUserPanel(){
|
|
|
1328
3258
|
<button id="uLogout" ${p.authenticated ? "" : "disabled"} title="dws auth logout:清除本机登录态">退出登录</button>
|
|
1329
3259
|
<button class="primary" id="uLogin">${p.authenticated ? "重新登录" : "登录 dws"}</button>
|
|
1330
3260
|
</div>
|
|
1331
|
-
${p.error ? `<div class="uerr">${esc(p.error)}</div>` : ""}
|
|
3261
|
+
${p.error ? `<div class="uerr">${esc(p.error)}</div>` : ""}
|
|
3262
|
+
<div class="ulisten">
|
|
3263
|
+
<div class="uhead"><b>实时监听</b><span class="spacerL"></span>
|
|
3264
|
+
<button id="uListenToggle" title="启动 / 停止长连接监听">…</button>
|
|
3265
|
+
<button id="uListenRestart" title="重启监听进程(连不上时点它)">重启</button>
|
|
3266
|
+
</div>
|
|
3267
|
+
<div id="uListenBody">读取中…</div>
|
|
3268
|
+
</div>
|
|
3269
|
+
<div class="uai">
|
|
3270
|
+
<div class="uaiRow">
|
|
3271
|
+
<span class="uaiState" id="uAiState">${esc(aiStateText())}</span>
|
|
3272
|
+
<button id="uAiBtn" title="打开设置">⚙ 设置</button>
|
|
3273
|
+
</div>
|
|
3274
|
+
</div>`;
|
|
3275
|
+
$("#uAiBtn").onclick = () => { $("#userPanel").classList.remove("show"); closeListenPoll(); openSettings("ai"); };
|
|
3276
|
+
const lr = $("#uListenRestart"); if(lr) lr.onclick = doListenRestart;
|
|
3277
|
+
const lt = $("#uListenToggle"); if(lt) lt.onclick = doListenToggle;
|
|
3278
|
+
openListenPoll();
|
|
1332
3279
|
$("#uRefresh").onclick = () => loadProfile(true);
|
|
1333
3280
|
$("#uLogin").onclick = doLogin;
|
|
1334
3281
|
$("#uLogout").onclick = doLogout;
|
|
@@ -1388,6 +3335,7 @@ $("#userChip").onclick = e => {
|
|
|
1388
3335
|
const show = !el.classList.contains("show");
|
|
1389
3336
|
el.classList.toggle("show", show);
|
|
1390
3337
|
if(show){ renderUserPanel(); loadProfile(false); }
|
|
3338
|
+
else { closeListenPoll(); }
|
|
1391
3339
|
};
|
|
1392
3340
|
document.addEventListener("click", e => {
|
|
1393
3341
|
const el = $("#userPanel");
|
|
@@ -1396,7 +3344,121 @@ document.addEventListener("click", e => {
|
|
|
1396
3344
|
el.classList.remove("show");
|
|
1397
3345
|
});
|
|
1398
3346
|
|
|
3347
|
+
/* ---------------- 自动刷新(收到新消息时列表自己更新) ---------------- */
|
|
3348
|
+
let REV_LAST = null;
|
|
3349
|
+
let REV_TMR = null;
|
|
3350
|
+
|
|
3351
|
+
async function pollRevision(){
|
|
3352
|
+
try{
|
|
3353
|
+
const j = await api("/api/ping");
|
|
3354
|
+
if(REV_LAST === null){ REV_LAST = j.rev; return; }
|
|
3355
|
+
if(j.rev === REV_LAST) return;
|
|
3356
|
+
REV_LAST = j.rev;
|
|
3357
|
+
await refreshFromServer();
|
|
3358
|
+
}catch{
|
|
3359
|
+
/* 服务重启中,下一轮再试 */
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
/** 有新消息:刷新左右两栏;正在看的会话给出「有新消息」提示而不是直接跳 */
|
|
3364
|
+
async function refreshFromServer(){
|
|
3365
|
+
const before = new Map(GROUPS.map(g => [g.short, Number(g.newCount || 0)]));
|
|
3366
|
+
const curShort = CUR ? CUR.short : null;
|
|
3367
|
+
await loadGroups(false);
|
|
3368
|
+
await loadContacts();
|
|
3369
|
+
if(!curShort) return;
|
|
3370
|
+
const g = GROUPS.find(x => x.short === curShort);
|
|
3371
|
+
if(!g) return;
|
|
3372
|
+
const delta = Number(g.newCount || 0) - (before.get(curShort) || 0);
|
|
3373
|
+
if(delta > 0 && CUR && CUR.short === curShort){
|
|
3374
|
+
showNewPill(delta);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
/* ---------------- 消息右键(撤回 / 复制) ---------------- */
|
|
3379
|
+
let MSG_CTX = null;
|
|
3380
|
+
|
|
3381
|
+
function openMsgCtx(e, m){
|
|
3382
|
+
MSG_CTX = m;
|
|
3383
|
+
const menu = document.getElementById("msgCtx");
|
|
3384
|
+
const title = document.getElementById("msgCtxTitle");
|
|
3385
|
+
title.textContent = `我:${String(m.text || "").replace(/\s+/g, " ").slice(0, 30) || "(空消息)"}`;
|
|
3386
|
+
menu.classList.add("show");
|
|
3387
|
+
const w = menu.offsetWidth || 200, h = menu.offsetHeight || 90;
|
|
3388
|
+
const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight;
|
|
3389
|
+
menu.style.left = Math.max(8, Math.min(e.clientX, vw - w - 8)) + "px";
|
|
3390
|
+
menu.style.top = Math.max(8, Math.min(e.clientY, vh - h - 8)) + "px";
|
|
3391
|
+
}
|
|
3392
|
+
|
|
3393
|
+
function closeMsgCtx(){
|
|
3394
|
+
const menu = document.getElementById("msgCtx");
|
|
3395
|
+
if(menu) menu.classList.remove("show");
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
document.getElementById("msgCtxRecall").onclick = async e => {
|
|
3399
|
+
const m = MSG_CTX;
|
|
3400
|
+
closeMsgCtx();
|
|
3401
|
+
if(!m) return;
|
|
3402
|
+
if(!confirm("撤回这条消息?\n钉钉里所有人都会看到「某某撤回了一条消息」。")) return;
|
|
3403
|
+
const btn = e.currentTarget;
|
|
3404
|
+
btn.disabled = true;
|
|
3405
|
+
try{
|
|
3406
|
+
await api("/api/recall", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
3407
|
+
body: JSON.stringify({short: CUR ? CUR.short : "", messageId: m.messageId})});
|
|
3408
|
+
toast("已撤回");
|
|
3409
|
+
if(CUR) setTimeout(()=> selectGroup(CUR.short, true), 1200);
|
|
3410
|
+
}catch(err){
|
|
3411
|
+
toast("撤回失败:" + err.message, true);
|
|
3412
|
+
}finally{ btn.disabled = false; }
|
|
3413
|
+
};
|
|
3414
|
+
|
|
3415
|
+
document.getElementById("msgCtxCopy").onclick = () => {
|
|
3416
|
+
const m = MSG_CTX;
|
|
3417
|
+
closeMsgCtx();
|
|
3418
|
+
if(!m) return;
|
|
3419
|
+
navigator.clipboard?.writeText(String(m.text || ""))
|
|
3420
|
+
.then(()=> toast("消息内容已复制"))
|
|
3421
|
+
.catch(()=> toast("复制失败", true));
|
|
3422
|
+
};
|
|
3423
|
+
|
|
3424
|
+
document.addEventListener("click", e => {
|
|
3425
|
+
const menu = document.getElementById("msgCtx");
|
|
3426
|
+
if(menu && menu.classList.contains("show") && !menu.contains(e.target)) closeMsgCtx();
|
|
3427
|
+
});
|
|
3428
|
+
document.addEventListener("scroll", closeMsgCtx, true);
|
|
3429
|
+
|
|
3430
|
+
function showNewPill(n){
|
|
3431
|
+
let el = document.getElementById("newPill");
|
|
3432
|
+
if(!el){
|
|
3433
|
+
el = document.createElement("button");
|
|
3434
|
+
el.id = "newPill";
|
|
3435
|
+
el.className = "newPill";
|
|
3436
|
+
el.onclick = async () => {
|
|
3437
|
+
el.remove();
|
|
3438
|
+
if(CUR) await selectGroup(CUR.short, true);
|
|
3439
|
+
};
|
|
3440
|
+
$("#workspace").appendChild(el);
|
|
3441
|
+
}
|
|
3442
|
+
el.textContent = `↓ 有 ${n} 条新消息,点击刷新`;
|
|
3443
|
+
el.classList.add("show");
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
function startPolling(){
|
|
3447
|
+
if(REV_TMR) clearInterval(REV_TMR);
|
|
3448
|
+
REV_TMR = setInterval(pollRevision, 5000);
|
|
3449
|
+
pollRevision();
|
|
3450
|
+
}
|
|
3451
|
+
document.addEventListener("visibilitychange", () => {
|
|
3452
|
+
if(!document.hidden) pollRevision();
|
|
3453
|
+
});
|
|
3454
|
+
|
|
1399
3455
|
loadProfile(false);
|
|
3456
|
+
loadAvatars();
|
|
3457
|
+
loadContacts();
|
|
3458
|
+
loadLayout().then(()=> {
|
|
3459
|
+
loadGroups(false).then(()=> startPolling()).catch(()=> startPolling());
|
|
3460
|
+
});
|
|
3461
|
+
|
|
1400
3462
|
|
|
1401
3463
|
loadGroups(false).then(()=>{
|
|
1402
3464
|
if(!GROUPS.length) return;
|