@guokit-dev/im-react 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -10
- package/dist/index.cjs +2467 -283
- package/dist/index.mjs +2448 -264
- package/dist/style.css +291 -0
- package/dist/types/core/groupAvatarCache.d.ts +37 -0
- package/dist/types/core/imStore.d.ts +6 -1
- package/dist/types/core/index.d.ts +3 -1
- package/dist/types/core/pinyinIndex.d.ts +15 -0
- package/dist/types/core/strings.d.ts +6 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/ui/contacts/AddFriendDialog.d.ts +2 -0
- package/dist/types/ui/contacts/ContactsPage.d.ts +9 -0
- package/dist/types/ui/contacts/FriendGroups.d.ts +6 -0
- package/dist/types/ui/contacts/FriendSettings.d.ts +4 -0
- package/dist/types/ui/contacts/NewFriendsPage.d.ts +2 -0
- package/dist/types/ui/contacts/UserCard.d.ts +8 -0
- package/dist/types/ui/contacts/index.d.ts +5 -0
- package/dist/types/ui/contacts/routes.d.ts +4 -0
- package/dist/types/ui/contacts/shared.d.ts +33 -0
- package/dist/types/ui/group/GroupChats.d.ts +2 -0
- package/dist/types/ui/group/GroupInfo.d.ts +9 -0
- package/dist/types/ui/group/GroupMembers.d.ts +11 -0
- package/dist/types/ui/group/GroupNotice.d.ts +8 -0
- package/dist/types/ui/group/SelectFriends.d.ts +8 -0
- package/dist/types/ui/group/routes.d.ts +4 -0
- package/dist/types/ui/group/shared.d.ts +47 -0
- package/dist/types/ui/hooks.d.ts +3 -1
- package/dist/types/ui/navigator.d.ts +38 -0
- package/dist/types/ui/privacy/PrivacyPage.d.ts +7 -0
- package/dist/types/ui/privacy/routes.d.ts +4 -0
- package/dist/types/ui/widgets/GroupAvatar.d.ts +21 -0
- package/dist/types/ui/widgets/Icon.d.ts +11 -0
- package/dist/types/ui/widgets/IndexedList.d.ts +14 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -24,12 +24,18 @@ __export(index_exports, {
|
|
|
24
24
|
GuokitImUi: () => GuokitImUi,
|
|
25
25
|
ImAvatar: () => Avatar,
|
|
26
26
|
ImChat: () => ImChat,
|
|
27
|
+
ImContacts: () => ImContacts,
|
|
27
28
|
ImConversationList: () => ImConversationList,
|
|
29
|
+
ImGroupAvatar: () => ImGroupAvatar,
|
|
30
|
+
ImGroupInfo: () => ImGroupInfo,
|
|
31
|
+
ImPrivacy: () => ImPrivacy,
|
|
28
32
|
ImUnreadBadge: () => ImUnreadBadge,
|
|
33
|
+
ImUserCard: () => ImUserCard,
|
|
29
34
|
ImWorkspace: () => ImWorkspace,
|
|
30
35
|
defaultStrings: () => defaultStrings,
|
|
31
36
|
useConnection: () => useConnection,
|
|
32
37
|
useConversations: () => useConversations,
|
|
38
|
+
useFriends: () => useFriends,
|
|
33
39
|
useIm: () => useIm,
|
|
34
40
|
useImNavigator: () => useImNavigator,
|
|
35
41
|
useTotalUnread: () => useTotalUnread
|
|
@@ -37,7 +43,7 @@ __export(index_exports, {
|
|
|
37
43
|
module.exports = __toCommonJS(index_exports);
|
|
38
44
|
|
|
39
45
|
// src/ui/context.tsx
|
|
40
|
-
var
|
|
46
|
+
var import_react35 = require("react");
|
|
41
47
|
|
|
42
48
|
// src/core/strings.ts
|
|
43
49
|
var defaultStrings = {
|
|
@@ -238,6 +244,9 @@ var defaultStrings = {
|
|
|
238
244
|
// B 期:选择好友
|
|
239
245
|
selectFriendsTitle: "选择好友",
|
|
240
246
|
doneWithCount: "完成({n})",
|
|
247
|
+
selectedCount: "已选 {n} 人 · 最多 {max} 人",
|
|
248
|
+
notFriendYet: "还不是好友",
|
|
249
|
+
add: "添加",
|
|
241
250
|
searchFriends: "搜索好友",
|
|
242
251
|
alreadyInGroup: "已在群里",
|
|
243
252
|
inviteToGroup: "邀请进群",
|
|
@@ -330,14 +339,31 @@ var routePlacement = {
|
|
|
330
339
|
chat: "main",
|
|
331
340
|
report: "dialog",
|
|
332
341
|
imageViewer: "overlay",
|
|
333
|
-
videoPlayer: "overlay"
|
|
342
|
+
videoPlayer: "overlay",
|
|
343
|
+
contacts: "list",
|
|
344
|
+
contactProfile: "main",
|
|
345
|
+
newFriends: "main",
|
|
346
|
+
groupChats: "main",
|
|
347
|
+
privacy: "main",
|
|
348
|
+
blocklist: "main",
|
|
349
|
+
userCard: "drawer",
|
|
350
|
+
friendSettings: "drawer",
|
|
351
|
+
friendGroups: "drawer",
|
|
352
|
+
groupInfo: "drawer",
|
|
353
|
+
groupMembers: "drawer",
|
|
354
|
+
groupNotice: "drawer",
|
|
355
|
+
addFriend: "dialog",
|
|
356
|
+
selectFriends: "dialog"
|
|
334
357
|
};
|
|
335
358
|
var initialNav = { list: { name: "conversations" }, main: null, drawer: [], dialog: [], overlay: [] };
|
|
336
359
|
function navReducer(s, a) {
|
|
337
360
|
switch (a.type) {
|
|
338
361
|
case "open": {
|
|
339
|
-
const p = routePlacement[a.route.name];
|
|
340
|
-
if (p === "list")
|
|
362
|
+
const p = a.as ?? routePlacement[a.route.name];
|
|
363
|
+
if (p === "list") {
|
|
364
|
+
const leave = a.route.name !== s.list.name || s.main?.name === "privacy" || s.main?.name === "blocklist";
|
|
365
|
+
return { ...s, list: a.route, main: leave ? null : s.main, drawer: [], dialog: [] };
|
|
366
|
+
}
|
|
341
367
|
if (p === "main") return { ...s, main: a.route, drawer: [], dialog: [] };
|
|
342
368
|
if (p === "drawer") return { ...s, drawer: [...s.drawer, a.route] };
|
|
343
369
|
if (p === "dialog") return { ...s, dialog: [...s.dialog, a.route] };
|
|
@@ -362,7 +388,9 @@ function useNavState(workspace, onMainOrList) {
|
|
|
362
388
|
const open = (0, import_react.useCallback)((route) => {
|
|
363
389
|
const p = routePlacement[route.name];
|
|
364
390
|
if (!workspace && (p === "main" || p === "list")) {
|
|
365
|
-
|
|
391
|
+
if (route.name === "contactProfile") dispatch({ type: "open", route: { name: "userCard", userId: route.userId } });
|
|
392
|
+
else if (p === "main" && route.name !== "chat") dispatch({ type: "open", route, as: "drawer" });
|
|
393
|
+
else onMainOrList?.(route);
|
|
366
394
|
return;
|
|
367
395
|
}
|
|
368
396
|
dispatch({ type: "open", route });
|
|
@@ -401,11 +429,11 @@ function themeVars(t) {
|
|
|
401
429
|
}
|
|
402
430
|
|
|
403
431
|
// src/ui/layout/Layers.tsx
|
|
404
|
-
var
|
|
432
|
+
var import_react34 = require("react");
|
|
405
433
|
|
|
406
434
|
// src/ui/chat/ChatPage.tsx
|
|
407
|
-
var
|
|
408
|
-
var
|
|
435
|
+
var import_react13 = require("react");
|
|
436
|
+
var import_im3 = require("@guokit-dev/im");
|
|
409
437
|
|
|
410
438
|
// src/core/externalStore.ts
|
|
411
439
|
var ListenerSet = class {
|
|
@@ -1089,6 +1117,126 @@ function useFeedback() {
|
|
|
1089
1117
|
return v;
|
|
1090
1118
|
}
|
|
1091
1119
|
|
|
1120
|
+
// src/ui/contacts/shared.ts
|
|
1121
|
+
var import_react4 = require("react");
|
|
1122
|
+
var import_im = require("@guokit-dev/im");
|
|
1123
|
+
function friendDisplayName(f) {
|
|
1124
|
+
return f.remark !== "" ? f.remark : f.nickname !== "" ? f.nickname : f.userId;
|
|
1125
|
+
}
|
|
1126
|
+
function errorText(e, fallback) {
|
|
1127
|
+
return e instanceof import_im.ImApiError && e.message ? e.message : fallback;
|
|
1128
|
+
}
|
|
1129
|
+
function ymd(ms) {
|
|
1130
|
+
const d = new Date(ms);
|
|
1131
|
+
return `${d.getFullYear()}/${String(d.getMonth() + 1).padStart(2, "0")}/${String(d.getDate()).padStart(2, "0")}`;
|
|
1132
|
+
}
|
|
1133
|
+
function safe(f, fallback) {
|
|
1134
|
+
try {
|
|
1135
|
+
return f();
|
|
1136
|
+
} catch {
|
|
1137
|
+
return fallback;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
var hints = /* @__PURE__ */ new WeakMap();
|
|
1141
|
+
function rememberUser(im, userId, hint) {
|
|
1142
|
+
let m = hints.get(im);
|
|
1143
|
+
if (!m) hints.set(im, m = /* @__PURE__ */ new Map());
|
|
1144
|
+
const old = m.get(userId);
|
|
1145
|
+
m.set(userId, { nickname: hint.nickname || old?.nickname || "", avatarUrl: hint.avatarUrl || old?.avatarUrl || "" });
|
|
1146
|
+
}
|
|
1147
|
+
function userHint(im, userId) {
|
|
1148
|
+
const h = hints.get(im)?.get(userId);
|
|
1149
|
+
if (h) return h;
|
|
1150
|
+
const p = safe(() => im.conversationWith(userId), null)?.peer;
|
|
1151
|
+
return { nickname: p?.nickname ?? "", avatarUrl: p?.avatarUrl ?? "" };
|
|
1152
|
+
}
|
|
1153
|
+
function openUserCard(ctx, userId, hint, route = "userCard") {
|
|
1154
|
+
if (userId === ctx.im.currentUserId) return;
|
|
1155
|
+
if (hint) rememberUser(ctx.im, userId, hint);
|
|
1156
|
+
if (ctx.callbacks.onAvatarTap) {
|
|
1157
|
+
ctx.callbacks.onAvatarTap(userId);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
ctx.nav.open({ name: route, userId });
|
|
1161
|
+
}
|
|
1162
|
+
var buses = /* @__PURE__ */ new WeakMap();
|
|
1163
|
+
function listeners(im, ch) {
|
|
1164
|
+
let m = buses.get(im);
|
|
1165
|
+
if (!m) buses.set(im, m = /* @__PURE__ */ new Map());
|
|
1166
|
+
let s = m.get(ch);
|
|
1167
|
+
if (!s) m.set(ch, s = /* @__PURE__ */ new Set());
|
|
1168
|
+
return s;
|
|
1169
|
+
}
|
|
1170
|
+
function notifyContacts(im, ch) {
|
|
1171
|
+
for (const f of [...listeners(im, ch)]) f();
|
|
1172
|
+
}
|
|
1173
|
+
function onContacts(im, ch, f) {
|
|
1174
|
+
const s = listeners(im, ch);
|
|
1175
|
+
s.add(f);
|
|
1176
|
+
return () => {
|
|
1177
|
+
s.delete(f);
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
function sortGroups(g) {
|
|
1181
|
+
return [...g].sort((a, b) => a.sort - b.sort || a.id - b.id);
|
|
1182
|
+
}
|
|
1183
|
+
function useFriendGroups(im) {
|
|
1184
|
+
const [groups, setGroups] = (0, import_react4.useState)(null);
|
|
1185
|
+
const load = (0, import_react4.useCallback)(async () => {
|
|
1186
|
+
try {
|
|
1187
|
+
const g = await im.friendGroups();
|
|
1188
|
+
setGroups(sortGroups(g));
|
|
1189
|
+
} catch {
|
|
1190
|
+
setGroups((old) => old ?? []);
|
|
1191
|
+
}
|
|
1192
|
+
}, [im]);
|
|
1193
|
+
(0, import_react4.useEffect)(() => {
|
|
1194
|
+
if (im.currentUserId === null) {
|
|
1195
|
+
setGroups([]);
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
void load();
|
|
1199
|
+
const off1 = im.on("friendGroupsChanged", () => {
|
|
1200
|
+
void load();
|
|
1201
|
+
});
|
|
1202
|
+
const off2 = onContacts(im, "groups", () => {
|
|
1203
|
+
void load();
|
|
1204
|
+
});
|
|
1205
|
+
return () => {
|
|
1206
|
+
off1();
|
|
1207
|
+
off2();
|
|
1208
|
+
};
|
|
1209
|
+
}, [im, load]);
|
|
1210
|
+
return [groups, load];
|
|
1211
|
+
}
|
|
1212
|
+
function usePendingCount(im) {
|
|
1213
|
+
const [n, setN] = (0, import_react4.useState)(0);
|
|
1214
|
+
(0, import_react4.useEffect)(() => {
|
|
1215
|
+
if (im.currentUserId === null) return;
|
|
1216
|
+
let alive = true;
|
|
1217
|
+
const load = async () => {
|
|
1218
|
+
try {
|
|
1219
|
+
const r = await im.friendRequests("in", { limit: 50 });
|
|
1220
|
+
if (alive) setN(r.items.filter((x) => x.status === "pending").length);
|
|
1221
|
+
} catch {
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
void load();
|
|
1225
|
+
const off1 = im.on("friendRequest", () => {
|
|
1226
|
+
void load();
|
|
1227
|
+
});
|
|
1228
|
+
const off2 = onContacts(im, "pending", () => {
|
|
1229
|
+
void load();
|
|
1230
|
+
});
|
|
1231
|
+
return () => {
|
|
1232
|
+
alive = false;
|
|
1233
|
+
off1();
|
|
1234
|
+
off2();
|
|
1235
|
+
};
|
|
1236
|
+
}, [im]);
|
|
1237
|
+
return n;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1092
1240
|
// src/ui/widgets/Icon.tsx
|
|
1093
1241
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1094
1242
|
var PATHS = {
|
|
@@ -1171,7 +1319,36 @@ var PATHS = {
|
|
|
1171
1319
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 8a6 6 0 0 0-9.3-5" }),
|
|
1172
1320
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6.3 6.3A6 6 0 0 0 6 8c0 7-3 9-3 9h14" }),
|
|
1173
1321
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M3 3l18 18" })
|
|
1174
|
-
] })
|
|
1322
|
+
] }),
|
|
1323
|
+
add: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5v14M5 12h14" }),
|
|
1324
|
+
userPlus: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1325
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "9", cy: "8", r: "3.5" }),
|
|
1326
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M2.5 20a6.5 6.5 0 0 1 13 0" }),
|
|
1327
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M19 8v6M16 11h6" })
|
|
1328
|
+
] }),
|
|
1329
|
+
chatPlus: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1330
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 5h16v11H9l-5 4z" }),
|
|
1331
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 8v5M9.5 10.5h5" })
|
|
1332
|
+
] }),
|
|
1333
|
+
contacts: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1334
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "9", cy: "8", r: "3.5" }),
|
|
1335
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M2.5 20a6.5 6.5 0 0 1 13 0" }),
|
|
1336
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M16 4.5a3.5 3.5 0 0 1 0 7" }),
|
|
1337
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 14a6 6 0 0 1 3.5 6" })
|
|
1338
|
+
] }),
|
|
1339
|
+
shield: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6z" }),
|
|
1340
|
+
search: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1341
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "11", cy: "11", r: "7" }),
|
|
1342
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M20 20l-4-4" })
|
|
1343
|
+
] }),
|
|
1344
|
+
edit: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 20h4L19 9l-4-4L4 16z" }),
|
|
1345
|
+
grip: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 8h14M5 12h14M5 16h14" }),
|
|
1346
|
+
minus: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1347
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "9.5" }),
|
|
1348
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8 12h8" })
|
|
1349
|
+
] }),
|
|
1350
|
+
chevron: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M9 5l7 7-7 7" }),
|
|
1351
|
+
minusLine: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 12h14" })
|
|
1175
1352
|
};
|
|
1176
1353
|
function Icon({ name, size = 20 }) {
|
|
1177
1354
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -1193,15 +1370,15 @@ function Icon({ name, size = 20 }) {
|
|
|
1193
1370
|
}
|
|
1194
1371
|
|
|
1195
1372
|
// src/ui/widgets/Page.tsx
|
|
1196
|
-
var
|
|
1373
|
+
var import_react6 = require("react");
|
|
1197
1374
|
|
|
1198
1375
|
// src/ui/layout/frame.ts
|
|
1199
|
-
var
|
|
1376
|
+
var import_react5 = require("react");
|
|
1200
1377
|
var noop = () => {
|
|
1201
1378
|
};
|
|
1202
|
-
var FrameContext = (0,
|
|
1379
|
+
var FrameContext = (0, import_react5.createContext)({ kind: "standalone", canBack: false, back: noop, close: noop });
|
|
1203
1380
|
function useFrame() {
|
|
1204
|
-
return (0,
|
|
1381
|
+
return (0, import_react5.useContext)(FrameContext);
|
|
1205
1382
|
}
|
|
1206
1383
|
|
|
1207
1384
|
// src/ui/widgets/Page.tsx
|
|
@@ -1209,7 +1386,7 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
|
1209
1386
|
function Page({ title, actions, banner, footer, children, className, scroll = true }) {
|
|
1210
1387
|
const f = useFrame();
|
|
1211
1388
|
const s = useImUi().strings;
|
|
1212
|
-
const titleId = (0,
|
|
1389
|
+
const titleId = (0, import_react6.useId)();
|
|
1213
1390
|
const dialog = f.kind === "dialog";
|
|
1214
1391
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1215
1392
|
"section",
|
|
@@ -1236,7 +1413,7 @@ function Page({ title, actions, banner, footer, children, className, scroll = tr
|
|
|
1236
1413
|
}
|
|
1237
1414
|
|
|
1238
1415
|
// src/ui/chat/Composer.tsx
|
|
1239
|
-
var
|
|
1416
|
+
var import_react9 = require("react");
|
|
1240
1417
|
|
|
1241
1418
|
// src/core/mention.ts
|
|
1242
1419
|
var mentionToken = (m) => `@${m.name} `;
|
|
@@ -1306,7 +1483,7 @@ _MentionEditing.maxAt = 20;
|
|
|
1306
1483
|
var MentionEditing = _MentionEditing;
|
|
1307
1484
|
|
|
1308
1485
|
// src/ui/widgets/Avatar.tsx
|
|
1309
|
-
var
|
|
1486
|
+
var import_react7 = require("react");
|
|
1310
1487
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1311
1488
|
var PALETTE = ["#0F766E", "#B45309", "#7C3AED", "#BE185D", "#4D7C0F", "#0369A1", "#9A3412", "#475569"];
|
|
1312
1489
|
function avatarColor(id) {
|
|
@@ -1320,7 +1497,7 @@ function avatarInitial(name, id) {
|
|
|
1320
1497
|
return String.fromCodePoint(s.codePointAt(0)).toUpperCase();
|
|
1321
1498
|
}
|
|
1322
1499
|
function Avatar({ id, name, url, size, group, onClick }) {
|
|
1323
|
-
const [broken, setBroken] = (0,
|
|
1500
|
+
const [broken, setBroken] = (0, import_react7.useState)(null);
|
|
1324
1501
|
const label = name || id;
|
|
1325
1502
|
const style = size ? { ["--gkim-av"]: `${size}px` } : void 0;
|
|
1326
1503
|
const cls = `gkim-avatar${group ? " gkim-avatar--group" : ""}`;
|
|
@@ -1332,21 +1509,28 @@ function Avatar({ id, name, url, size, group, onClick }) {
|
|
|
1332
1509
|
}
|
|
1333
1510
|
|
|
1334
1511
|
// src/ui/widgets/Menu.tsx
|
|
1335
|
-
var
|
|
1512
|
+
var import_react8 = require("react");
|
|
1336
1513
|
var import_react_dom = require("react-dom");
|
|
1337
1514
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1338
1515
|
function Menu({ entries, x, y, onClose, label }) {
|
|
1339
|
-
const ref = (0,
|
|
1340
|
-
const [pos, setPos] = (0,
|
|
1341
|
-
const [sub, setSub] = (0,
|
|
1342
|
-
(0,
|
|
1516
|
+
const ref = (0, import_react8.useRef)(null);
|
|
1517
|
+
const [pos, setPos] = (0, import_react8.useState)({ left: x, top: y });
|
|
1518
|
+
const [sub, setSub] = (0, import_react8.useState)(null);
|
|
1519
|
+
const [subLeft, setSubLeft] = (0, import_react8.useState)(false);
|
|
1520
|
+
(0, import_react8.useLayoutEffect)(() => {
|
|
1343
1521
|
const el = ref.current;
|
|
1344
1522
|
if (!el) return;
|
|
1345
1523
|
const r = el.getBoundingClientRect();
|
|
1346
1524
|
const vw = window.innerWidth, vh = window.innerHeight;
|
|
1347
1525
|
setPos({ left: x + r.width > vw - 8 ? Math.max(8, x - r.width) : x, top: y + r.height > vh - 8 ? Math.max(8, y - r.height) : y });
|
|
1348
1526
|
}, [x, y]);
|
|
1349
|
-
(0,
|
|
1527
|
+
(0, import_react8.useLayoutEffect)(() => {
|
|
1528
|
+
const el = ref.current?.querySelector(".gkim-menu--sub");
|
|
1529
|
+
if (!el || !ref.current) return setSubLeft(false);
|
|
1530
|
+
const r = ref.current.getBoundingClientRect();
|
|
1531
|
+
setSubLeft(r.right + el.offsetWidth + 12 > window.innerWidth);
|
|
1532
|
+
}, [sub, pos]);
|
|
1533
|
+
(0, import_react8.useEffect)(() => {
|
|
1350
1534
|
const prev = document.activeElement;
|
|
1351
1535
|
ref.current?.querySelector('[role="menuitem"]:not([disabled])')?.focus();
|
|
1352
1536
|
const down = (e) => {
|
|
@@ -1416,7 +1600,7 @@ function Menu({ entries, x, y, onClose, label }) {
|
|
|
1416
1600
|
it.icon,
|
|
1417
1601
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: it.label }),
|
|
1418
1602
|
it.children && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "gkim-menu__arrow", children: "›" }),
|
|
1419
|
-
it.children && sub === i && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className:
|
|
1603
|
+
it.children && sub === i && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `gkim-menu gkim-menu--sub${subLeft ? " gkim-menu--sub-left" : ""}`, role: "menu", children: it.children.map((c, j) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1420
1604
|
"span",
|
|
1421
1605
|
{
|
|
1422
1606
|
role: "menuitem",
|
|
@@ -1448,9 +1632,9 @@ function Menu({ entries, x, y, onClose, label }) {
|
|
|
1448
1632
|
return (0, import_react_dom.createPortal)(menu, host);
|
|
1449
1633
|
}
|
|
1450
1634
|
function useContextMenu() {
|
|
1451
|
-
const [at, setAt] = (0,
|
|
1452
|
-
const timer = (0,
|
|
1453
|
-
const start = (0,
|
|
1635
|
+
const [at, setAt] = (0, import_react8.useState)(null);
|
|
1636
|
+
const timer = (0, import_react8.useRef)(void 0);
|
|
1637
|
+
const start = (0, import_react8.useRef)(null);
|
|
1454
1638
|
const bind = {
|
|
1455
1639
|
onContextMenu: (e) => {
|
|
1456
1640
|
e.preventDefault();
|
|
@@ -1475,7 +1659,7 @@ function useContextMenu() {
|
|
|
1475
1659
|
start.current = null;
|
|
1476
1660
|
}
|
|
1477
1661
|
};
|
|
1478
|
-
const close = (0,
|
|
1662
|
+
const close = (0, import_react8.useCallback)(() => setAt(null), []);
|
|
1479
1663
|
return { at, open: setAt, close, bind };
|
|
1480
1664
|
}
|
|
1481
1665
|
|
|
@@ -1557,25 +1741,25 @@ var EMOJIS = [
|
|
|
1557
1741
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1558
1742
|
var MAX_ROWS_PX = 6 * 21 + 8;
|
|
1559
1743
|
var seq = 0;
|
|
1560
|
-
var Composer = (0,
|
|
1744
|
+
var Composer = (0, import_react9.forwardRef)(function Composer2(p, ref) {
|
|
1561
1745
|
const { im, strings: s, moreItems } = useImUi();
|
|
1562
1746
|
const { toast } = useFeedback();
|
|
1563
|
-
const [text, setText] = (0,
|
|
1564
|
-
const [tray, setTray] = (0,
|
|
1565
|
-
const [emoji, setEmoji] = (0,
|
|
1566
|
-
const [more, setMore] = (0,
|
|
1567
|
-
const [mention, setMention] = (0,
|
|
1568
|
-
const [busy, setBusy] = (0,
|
|
1569
|
-
const closeMore = (0,
|
|
1570
|
-
const ta = (0,
|
|
1571
|
-
const media = (0,
|
|
1572
|
-
const anyFile = (0,
|
|
1573
|
-
const mentions = (0,
|
|
1747
|
+
const [text, setText] = (0, import_react9.useState)("");
|
|
1748
|
+
const [tray, setTray] = (0, import_react9.useState)([]);
|
|
1749
|
+
const [emoji, setEmoji] = (0, import_react9.useState)(false);
|
|
1750
|
+
const [more, setMore] = (0, import_react9.useState)(null);
|
|
1751
|
+
const [mention, setMention] = (0, import_react9.useState)(null);
|
|
1752
|
+
const [busy, setBusy] = (0, import_react9.useState)(false);
|
|
1753
|
+
const closeMore = (0, import_react9.useCallback)(() => setMore(null), []);
|
|
1754
|
+
const ta = (0, import_react9.useRef)(null);
|
|
1755
|
+
const media = (0, import_react9.useRef)(null);
|
|
1756
|
+
const anyFile = (0, import_react9.useRef)(null);
|
|
1757
|
+
const mentions = (0, import_react9.useMemo)(() => new MentionEditing(), []);
|
|
1574
1758
|
const f = p.features;
|
|
1575
1759
|
const canImage = true;
|
|
1576
1760
|
const canVideo = (f?.videoMaxMb ?? 0) > 0;
|
|
1577
1761
|
const canFile = (f?.fileMaxMb ?? 0) > 0;
|
|
1578
|
-
(0,
|
|
1762
|
+
(0, import_react9.useLayoutEffect)(() => {
|
|
1579
1763
|
const el = ta.current;
|
|
1580
1764
|
if (!el) return;
|
|
1581
1765
|
el.style.height = "auto";
|
|
@@ -1596,15 +1780,15 @@ var Composer = (0, import_react8.forwardRef)(function Composer2(p, ref) {
|
|
|
1596
1780
|
}
|
|
1597
1781
|
if (ok.length) setTray((t) => [...t, ...ok]);
|
|
1598
1782
|
};
|
|
1599
|
-
(0,
|
|
1600
|
-
const thumbs = (0,
|
|
1601
|
-
(0,
|
|
1783
|
+
(0, import_react9.useImperativeHandle)(ref, () => ({ addFiles }));
|
|
1784
|
+
const thumbs = (0, import_react9.useMemo)(() => /* @__PURE__ */ new Map(), []);
|
|
1785
|
+
(0, import_react9.useEffect)(() => {
|
|
1602
1786
|
for (const [id, url] of thumbs) if (!tray.some((a) => a.id === id)) {
|
|
1603
1787
|
URL.revokeObjectURL(url);
|
|
1604
1788
|
thumbs.delete(id);
|
|
1605
1789
|
}
|
|
1606
1790
|
}, [tray, thumbs]);
|
|
1607
|
-
(0,
|
|
1791
|
+
(0, import_react9.useEffect)(() => () => {
|
|
1608
1792
|
for (const url of thumbs.values()) URL.revokeObjectURL(url);
|
|
1609
1793
|
}, [thumbs]);
|
|
1610
1794
|
const thumb = (a) => {
|
|
@@ -1615,7 +1799,7 @@ var Composer = (0, import_react8.forwardRef)(function Composer2(p, ref) {
|
|
|
1615
1799
|
}
|
|
1616
1800
|
return u;
|
|
1617
1801
|
};
|
|
1618
|
-
const candidates = (0,
|
|
1802
|
+
const candidates = (0, import_react9.useMemo)(() => {
|
|
1619
1803
|
if (!mention || !p.members) return [];
|
|
1620
1804
|
const q = mention.q.toLowerCase();
|
|
1621
1805
|
const me = im.currentUserId;
|
|
@@ -1863,19 +2047,19 @@ var Composer = (0, import_react8.forwardRef)(function Composer2(p, ref) {
|
|
|
1863
2047
|
});
|
|
1864
2048
|
|
|
1865
2049
|
// src/ui/chat/MessageList.tsx
|
|
1866
|
-
var
|
|
2050
|
+
var import_react12 = require("react");
|
|
1867
2051
|
|
|
1868
2052
|
// src/ui/chat/MessageRow.tsx
|
|
1869
|
-
var
|
|
2053
|
+
var import_react11 = require("react");
|
|
1870
2054
|
|
|
1871
2055
|
// src/ui/chat/bubbles.tsx
|
|
1872
|
-
var
|
|
1873
|
-
var
|
|
2056
|
+
var import_react10 = require("react");
|
|
2057
|
+
var import_im2 = require("@guokit-dev/im");
|
|
1874
2058
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1875
2059
|
function useAsyncUrl(load) {
|
|
1876
|
-
const [url, setUrl] = (0,
|
|
2060
|
+
const [url, setUrl] = (0, import_react10.useState)(null);
|
|
1877
2061
|
const enabled = load !== null;
|
|
1878
|
-
(0,
|
|
2062
|
+
(0, import_react10.useEffect)(() => {
|
|
1879
2063
|
if (!load) return;
|
|
1880
2064
|
let alive = true;
|
|
1881
2065
|
Promise.resolve().then(load).then((u) => {
|
|
@@ -1937,7 +2121,7 @@ function ImageBubble({ message: m, localUrl, progress, onImageClick }) {
|
|
|
1937
2121
|
const { im, strings: s } = useImUi();
|
|
1938
2122
|
const sent = m.status === "sent";
|
|
1939
2123
|
const remote = useAsyncUrl(sent && !localUrl ? () => im.imageUrl(m) : null);
|
|
1940
|
-
const [broken, setBroken] = (0,
|
|
2124
|
+
const [broken, setBroken] = (0, import_react10.useState)(false);
|
|
1941
2125
|
const src = localUrl ?? remote;
|
|
1942
2126
|
const size = fit(m.content.width, m.content.height);
|
|
1943
2127
|
const img = src && !broken ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src, alt: s.image, onError: () => setBroken(true) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "gkim-media__ph", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "image" }) });
|
|
@@ -2067,7 +2251,7 @@ function MessageContent(props) {
|
|
|
2067
2251
|
case "voice":
|
|
2068
2252
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VoiceBubble, { ...props });
|
|
2069
2253
|
case "custom": {
|
|
2070
|
-
const card = (0,
|
|
2254
|
+
const card = (0, import_im2.messageCard)(m);
|
|
2071
2255
|
if (card) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CardBubble, { message: m, card });
|
|
2072
2256
|
const desc = m.content.desc;
|
|
2073
2257
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextBubble, { message: m, text: typeof desc === "string" && desc ? desc : s.unsupported });
|
|
@@ -2082,7 +2266,7 @@ var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
|
2082
2266
|
function CenterTip({ text }) {
|
|
2083
2267
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "gkim-tip", children: text });
|
|
2084
2268
|
}
|
|
2085
|
-
var MessageRow = (0,
|
|
2269
|
+
var MessageRow = (0, import_react11.memo)(function MessageRow2(p) {
|
|
2086
2270
|
const { strings: s } = useImUi();
|
|
2087
2271
|
const { toast } = useFeedback();
|
|
2088
2272
|
const m = p.message;
|
|
@@ -2104,7 +2288,7 @@ var MessageRow = (0, import_react10.memo)(function MessageRow2(p) {
|
|
|
2104
2288
|
}
|
|
2105
2289
|
);
|
|
2106
2290
|
}
|
|
2107
|
-
const press = (0,
|
|
2291
|
+
const press = (0, import_react11.useRef)(null);
|
|
2108
2292
|
const touchStart = (e) => {
|
|
2109
2293
|
if (!p.onMenu) return;
|
|
2110
2294
|
const t = e.touches[0];
|
|
@@ -2174,17 +2358,17 @@ var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
|
2174
2358
|
var FIVE_MIN = 5 * 6e4;
|
|
2175
2359
|
function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
2176
2360
|
const { im, strings: s } = useImUi();
|
|
2177
|
-
const ref = (0,
|
|
2361
|
+
const ref = (0, import_react12.useRef)(null);
|
|
2178
2362
|
const me = im.currentUserId;
|
|
2179
2363
|
const nearTop = (el) => el.scrollHeight - el.clientHeight + el.scrollTop < 200;
|
|
2180
|
-
const check = (0,
|
|
2364
|
+
const check = (0, import_react12.useCallback)(() => {
|
|
2181
2365
|
const el = ref.current;
|
|
2182
2366
|
if (el && snap.hasMore && !snap.loadingMore && nearTop(el)) ctl.loadMore();
|
|
2183
2367
|
}, [ctl, snap.hasMore, snap.loadingMore]);
|
|
2184
|
-
(0,
|
|
2368
|
+
(0, import_react12.useLayoutEffect)(() => {
|
|
2185
2369
|
check();
|
|
2186
2370
|
}, [check, snap.messages]);
|
|
2187
|
-
(0,
|
|
2371
|
+
(0, import_react12.useEffect)(() => {
|
|
2188
2372
|
scrollRef.current = () => {
|
|
2189
2373
|
if (ref.current) ref.current.scrollTop = 0;
|
|
2190
2374
|
};
|
|
@@ -2192,7 +2376,7 @@ function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
|
2192
2376
|
scrollRef.current = null;
|
|
2193
2377
|
};
|
|
2194
2378
|
}, [scrollRef]);
|
|
2195
|
-
(0,
|
|
2379
|
+
(0, import_react12.useEffect)(() => ctl.onNewMessage((m) => {
|
|
2196
2380
|
const el = ref.current;
|
|
2197
2381
|
if (el && (m.isSelf || el.scrollTop > -120)) el.scrollTop = 0;
|
|
2198
2382
|
}), [ctl]);
|
|
@@ -2208,7 +2392,7 @@ function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
|
2208
2392
|
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CenterTip, { text: tipText(m, s, { nameOf, me, isGroup }) }, m.clientMsgId));
|
|
2209
2393
|
continue;
|
|
2210
2394
|
}
|
|
2211
|
-
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2395
|
+
items.push(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react12.Fragment, { children: renderRow(m) }, m.clientMsgId));
|
|
2212
2396
|
}
|
|
2213
2397
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "gkim-msglist", ref, onScroll: check, role: "log", "aria-live": "polite", "aria-relevant": "additions", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "gkim-msglist__inner", children: [
|
|
2214
2398
|
snap.loadingMore && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }),
|
|
@@ -2254,8 +2438,8 @@ function ImChat(props) {
|
|
|
2254
2438
|
const key = "conversation" in target ? `c${target.conversation.id}` : "group" in target ? `g${target.group}` : `p${target.peer}`;
|
|
2255
2439
|
const isGroup = "group" in target || "conversation" in target && target.conversation.group !== null;
|
|
2256
2440
|
const groupId = "group" in target ? target.group : "conversation" in target ? target.conversation.group?.groupId ?? null : null;
|
|
2257
|
-
const [ctl, setCtl] = (0,
|
|
2258
|
-
(0,
|
|
2441
|
+
const [ctl, setCtl] = (0, import_react13.useState)(null);
|
|
2442
|
+
(0, import_react13.useEffect)(() => {
|
|
2259
2443
|
const c = new ChatController(im, target);
|
|
2260
2444
|
setCtl(c);
|
|
2261
2445
|
void c.start();
|
|
@@ -2266,9 +2450,9 @@ function ImChat(props) {
|
|
|
2266
2450
|
c.dispose();
|
|
2267
2451
|
};
|
|
2268
2452
|
}, [im, key]);
|
|
2269
|
-
const snap = (0,
|
|
2270
|
-
const [members, setMembers] = (0,
|
|
2271
|
-
(0,
|
|
2453
|
+
const snap = (0, import_react13.useSyncExternalStore)(ctl?.subscribe ?? noSub, ctl?.getSnapshot ?? (() => EMPTY_SNAP));
|
|
2454
|
+
const [members, setMembers] = (0, import_react13.useState)(null);
|
|
2455
|
+
(0, import_react13.useEffect)(() => {
|
|
2272
2456
|
if (!groupId) return;
|
|
2273
2457
|
const m = new MemberCache(im, groupId);
|
|
2274
2458
|
setMembers(m);
|
|
@@ -2278,32 +2462,32 @@ function ImChat(props) {
|
|
|
2278
2462
|
setMembers(null);
|
|
2279
2463
|
};
|
|
2280
2464
|
}, [im, groupId]);
|
|
2281
|
-
const memberMap = (0,
|
|
2282
|
-
const memberList = (0,
|
|
2283
|
-
const urls = (0,
|
|
2284
|
-
(0,
|
|
2465
|
+
const memberMap = (0, import_react13.useSyncExternalStore)(members?.subscribe ?? noSub, members?.getSnapshot ?? (() => EMPTY_MEMBERS));
|
|
2466
|
+
const memberList = (0, import_react13.useMemo)(() => [...memberMap.values()], [memberMap]);
|
|
2467
|
+
const urls = (0, import_react13.useMemo)(() => new ObjectUrlRegistry(), []);
|
|
2468
|
+
(0, import_react13.useEffect)(() => () => urls.releaseAll(), [urls]);
|
|
2285
2469
|
urls.sync(snap.localFiles);
|
|
2286
2470
|
const conv = snap.conversation;
|
|
2287
2471
|
const myId = im.currentUserId;
|
|
2288
|
-
const nameOf = (0,
|
|
2472
|
+
const nameOf = (0, import_react13.useCallback)((id) => {
|
|
2289
2473
|
const mm = memberMap.get(id);
|
|
2290
2474
|
if (mm && mm.nickname) return mm.nickname;
|
|
2291
2475
|
if (id === myId) return me.nickname || id;
|
|
2292
2476
|
if (conv?.peer && conv.peer.userId === id) return conversationTitle(conv, s);
|
|
2293
2477
|
return id;
|
|
2294
2478
|
}, [memberMap, myId, me.nickname, conv, s]);
|
|
2295
|
-
const avatarOf = (0,
|
|
2479
|
+
const avatarOf = (0, import_react13.useCallback)((id) => {
|
|
2296
2480
|
const mm = memberMap.get(id);
|
|
2297
2481
|
if (mm?.avatarUrl) return mm.avatarUrl;
|
|
2298
2482
|
if (id === myId) return me.avatarUrl ?? "";
|
|
2299
2483
|
return conv?.peer && conv.peer.userId === id ? conv.peer.avatarUrl : "";
|
|
2300
2484
|
}, [memberMap, myId, me.avatarUrl, conv]);
|
|
2301
|
-
const audio = (0,
|
|
2302
|
-
const [playing, setPlaying] = (0,
|
|
2303
|
-
(0,
|
|
2485
|
+
const audio = (0, import_react13.useRef)(null);
|
|
2486
|
+
const [playing, setPlaying] = (0, import_react13.useState)(null);
|
|
2487
|
+
(0, import_react13.useEffect)(() => () => {
|
|
2304
2488
|
audio.current?.pause();
|
|
2305
2489
|
}, []);
|
|
2306
|
-
const onVoice = (0,
|
|
2490
|
+
const onVoice = (0, import_react13.useCallback)(async (m) => {
|
|
2307
2491
|
const a = audio.current ?? (audio.current = new Audio());
|
|
2308
2492
|
a.onended = () => setPlaying(null);
|
|
2309
2493
|
if (playing === m.clientMsgId) {
|
|
@@ -2318,22 +2502,29 @@ function ImChat(props) {
|
|
|
2318
2502
|
setPlaying(m.clientMsgId);
|
|
2319
2503
|
a.play().catch(() => setPlaying(null));
|
|
2320
2504
|
}, [im, playing]);
|
|
2321
|
-
const onImage = (0,
|
|
2505
|
+
const onImage = (0, import_react13.useCallback)((m) => {
|
|
2322
2506
|
const images = snap.messages.filter((x) => x.type === "image" && x.status === "sent");
|
|
2323
2507
|
const index = images.findIndex((x) => x.clientMsgId === m.clientMsgId);
|
|
2324
2508
|
if (index >= 0) nav.open({ name: "imageViewer", images, index });
|
|
2325
2509
|
}, [snap.messages, nav]);
|
|
2326
|
-
const onVideo = (0,
|
|
2510
|
+
const onVideo = (0, import_react13.useCallback)((m) => {
|
|
2327
2511
|
audio.current?.pause();
|
|
2328
2512
|
setPlaying(null);
|
|
2329
2513
|
nav.open({ name: "videoPlayer", message: m });
|
|
2330
2514
|
}, [nav]);
|
|
2331
|
-
const onResend = (0,
|
|
2515
|
+
const onResend = (0, import_react13.useCallback)((m) => {
|
|
2332
2516
|
ctl?.resend(m).catch(() => toast(s.sendRejected));
|
|
2333
2517
|
}, [ctl, toast, s]);
|
|
2334
|
-
const
|
|
2335
|
-
const
|
|
2336
|
-
|
|
2518
|
+
const hostAvatar = callbacks.onAvatarTap;
|
|
2519
|
+
const onAvatar = (0, import_react13.useCallback)((userId) => {
|
|
2520
|
+
if (hostAvatar) hostAvatar(userId);
|
|
2521
|
+
else {
|
|
2522
|
+
rememberUser(im, userId, { nickname: nameOf(userId), avatarUrl: avatarOf(userId) });
|
|
2523
|
+
nav.open({ name: "userCard", userId });
|
|
2524
|
+
}
|
|
2525
|
+
}, [hostAvatar, nav, im, nameOf, avatarOf]);
|
|
2526
|
+
const scrollToLatest = (0, import_react13.useRef)(null);
|
|
2527
|
+
const send = (0, import_react13.useCallback)(async (text, at) => {
|
|
2337
2528
|
if (!ctl) return;
|
|
2338
2529
|
try {
|
|
2339
2530
|
const m = await ctl.sendText(text, at);
|
|
@@ -2343,7 +2534,7 @@ function ImChat(props) {
|
|
|
2343
2534
|
toast(s.operationFailed);
|
|
2344
2535
|
}
|
|
2345
2536
|
}, [ctl, toast, s]);
|
|
2346
|
-
const sendFile = (0,
|
|
2537
|
+
const sendFile = (0, import_react13.useCallback)(async (a) => {
|
|
2347
2538
|
if (!ctl) return;
|
|
2348
2539
|
try {
|
|
2349
2540
|
let m;
|
|
@@ -2358,9 +2549,9 @@ function ImChat(props) {
|
|
|
2358
2549
|
toast(e instanceof RangeError ? e.message : s.operationFailed);
|
|
2359
2550
|
}
|
|
2360
2551
|
}, [ctl, toast, s]);
|
|
2361
|
-
const composer = (0,
|
|
2362
|
-
const [dragging, setDragging] = (0,
|
|
2363
|
-
const depth = (0,
|
|
2552
|
+
const composer = (0, import_react13.useRef)(null);
|
|
2553
|
+
const [dragging, setDragging] = (0, import_react13.useState)(false);
|
|
2554
|
+
const depth = (0, import_react13.useRef)(0);
|
|
2364
2555
|
const hasFiles = (e) => Array.from(e.dataTransfer.types).includes("Files");
|
|
2365
2556
|
const dropProps = snap.quit ? {} : {
|
|
2366
2557
|
onDragEnter: (e) => {
|
|
@@ -2386,11 +2577,11 @@ function ImChat(props) {
|
|
|
2386
2577
|
composer.current?.addFiles(Array.from(e.dataTransfer.files));
|
|
2387
2578
|
}
|
|
2388
2579
|
};
|
|
2389
|
-
const [menu, setMenu] = (0,
|
|
2390
|
-
const closeMenu = (0,
|
|
2580
|
+
const [menu, setMenu] = (0, import_react13.useState)(null);
|
|
2581
|
+
const closeMenu = (0, import_react13.useCallback)(() => setMenu(null), []);
|
|
2391
2582
|
const { menuItems } = useImUi();
|
|
2392
2583
|
const recallMinutes = snap.features?.recallMinutes ?? 0;
|
|
2393
|
-
const entriesFor = (0,
|
|
2584
|
+
const entriesFor = (0, import_react13.useCallback)((m) => {
|
|
2394
2585
|
const out = [];
|
|
2395
2586
|
if (m.type === "text") {
|
|
2396
2587
|
out.push({ label: s.copy, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "copy", size: 16 }), onSelect: () => {
|
|
@@ -2399,7 +2590,7 @@ function ImChat(props) {
|
|
|
2399
2590
|
}
|
|
2400
2591
|
if (m.isSelf && m.id !== null && m.status === "sent" && recallMinutes > 0 && Date.now() - m.createdAt < recallMinutes * 6e4) {
|
|
2401
2592
|
out.push({ label: s.recall, icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "recall", size: 16 }), onSelect: () => {
|
|
2402
|
-
ctl?.recall(m).catch((e) => toast(e instanceof
|
|
2593
|
+
ctl?.recall(m).catch((e) => toast(e instanceof import_im3.ImApiError && e.message ? e.message : s.operationFailed));
|
|
2403
2594
|
} });
|
|
2404
2595
|
}
|
|
2405
2596
|
if (!m.isSelf && m.id !== null) {
|
|
@@ -2410,7 +2601,7 @@ function ImChat(props) {
|
|
|
2410
2601
|
for (const it of menuItems?.(m) ?? []) out.push({ label: it.label, icon: it.icon, onSelect: () => it.onClick(m) });
|
|
2411
2602
|
return out;
|
|
2412
2603
|
}, [s, toast, recallMinutes, ctl, nav, menuItems]);
|
|
2413
|
-
const onMenu = (0,
|
|
2604
|
+
const onMenu = (0, import_react13.useCallback)((m, x, y) => {
|
|
2414
2605
|
if (entriesFor(m).length) setMenu({ m, x, y });
|
|
2415
2606
|
}, [entriesFor]);
|
|
2416
2607
|
const hoverBar = (m) => {
|
|
@@ -2465,7 +2656,16 @@ function ImChat(props) {
|
|
|
2465
2656
|
}
|
|
2466
2657
|
if (!title) title = s.groupChat;
|
|
2467
2658
|
const groupInfo = callbacks.onGroupInfoTap;
|
|
2468
|
-
const actions = isGroup && groupId
|
|
2659
|
+
const actions = isGroup && groupId ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2660
|
+
"button",
|
|
2661
|
+
{
|
|
2662
|
+
type: "button",
|
|
2663
|
+
className: "gkim-iconbtn",
|
|
2664
|
+
"aria-label": s.groupInfoTitle,
|
|
2665
|
+
onClick: () => groupInfo ? groupInfo(groupId) : nav.open({ name: "groupInfo", groupId }),
|
|
2666
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Icon, { name: "more" })
|
|
2667
|
+
}
|
|
2668
|
+
) : null;
|
|
2469
2669
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2470
2670
|
Page,
|
|
2471
2671
|
{
|
|
@@ -2507,11 +2707,11 @@ function ImChat(props) {
|
|
|
2507
2707
|
}
|
|
2508
2708
|
|
|
2509
2709
|
// src/ui/conversation/ConversationList.tsx
|
|
2510
|
-
var
|
|
2511
|
-
var
|
|
2710
|
+
var import_react16 = require("react");
|
|
2711
|
+
var import_im4 = require("@guokit-dev/im");
|
|
2512
2712
|
|
|
2513
2713
|
// src/ui/hooks.ts
|
|
2514
|
-
var
|
|
2714
|
+
var import_react14 = require("react");
|
|
2515
2715
|
|
|
2516
2716
|
// src/core/imStore.ts
|
|
2517
2717
|
var EMPTY = Object.freeze([]);
|
|
@@ -2551,9 +2751,9 @@ function createConversationsStore(im) {
|
|
|
2551
2751
|
const v = getSnapshot();
|
|
2552
2752
|
if (v === last) return;
|
|
2553
2753
|
last = v;
|
|
2554
|
-
|
|
2754
|
+
listeners2.notify();
|
|
2555
2755
|
};
|
|
2556
|
-
const
|
|
2756
|
+
const listeners2 = new ListenerSet(
|
|
2557
2757
|
() => {
|
|
2558
2758
|
offs = [
|
|
2559
2759
|
im.on("conversations", (list) => {
|
|
@@ -2581,19 +2781,19 @@ function createConversationsStore(im) {
|
|
|
2581
2781
|
offs = [];
|
|
2582
2782
|
}
|
|
2583
2783
|
);
|
|
2584
|
-
return { subscribe: (fn) =>
|
|
2784
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot };
|
|
2585
2785
|
}
|
|
2586
2786
|
function valueStore(im, event, read) {
|
|
2587
2787
|
let off = null;
|
|
2588
2788
|
let last;
|
|
2589
|
-
const
|
|
2789
|
+
const listeners2 = new ListenerSet(
|
|
2590
2790
|
() => {
|
|
2591
2791
|
last = read();
|
|
2592
2792
|
off = im.on(event, () => {
|
|
2593
2793
|
const v = read();
|
|
2594
2794
|
if (v === last) return;
|
|
2595
2795
|
last = v;
|
|
2596
|
-
|
|
2796
|
+
listeners2.notify();
|
|
2597
2797
|
});
|
|
2598
2798
|
},
|
|
2599
2799
|
() => {
|
|
@@ -2601,12 +2801,58 @@ function valueStore(im, event, read) {
|
|
|
2601
2801
|
off = null;
|
|
2602
2802
|
}
|
|
2603
2803
|
);
|
|
2604
|
-
return { subscribe: (fn) =>
|
|
2804
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot: read };
|
|
2805
|
+
}
|
|
2806
|
+
var NO_FRIENDS = Object.freeze([]);
|
|
2807
|
+
function friendsStore(im) {
|
|
2808
|
+
const s = storesOf(im);
|
|
2809
|
+
return s.friends ?? (s.friends = createFriendsStore(im));
|
|
2810
|
+
}
|
|
2811
|
+
function createFriendsStore(im) {
|
|
2812
|
+
let snap = NO_FRIENDS;
|
|
2813
|
+
let owner = null;
|
|
2814
|
+
let offs = [];
|
|
2815
|
+
const getSnapshot = () => {
|
|
2816
|
+
const me = im.currentUserId;
|
|
2817
|
+
if (me === null) {
|
|
2818
|
+
snap = NO_FRIENDS;
|
|
2819
|
+
owner = null;
|
|
2820
|
+
return NO_FRIENDS;
|
|
2821
|
+
}
|
|
2822
|
+
return me === owner ? snap : NO_FRIENDS;
|
|
2823
|
+
};
|
|
2824
|
+
const listeners2 = new ListenerSet(
|
|
2825
|
+
() => {
|
|
2826
|
+
offs = [
|
|
2827
|
+
im.on("friendsChanged", (list) => {
|
|
2828
|
+
const me2 = im.currentUserId;
|
|
2829
|
+
if (me2 === null) return;
|
|
2830
|
+
snap = list;
|
|
2831
|
+
owner = me2;
|
|
2832
|
+
listeners2.notify();
|
|
2833
|
+
}),
|
|
2834
|
+
im.on("connection", () => listeners2.notify())
|
|
2835
|
+
];
|
|
2836
|
+
const me = im.currentUserId;
|
|
2837
|
+
if (me !== null) {
|
|
2838
|
+
try {
|
|
2839
|
+
snap = im.friends();
|
|
2840
|
+
owner = me;
|
|
2841
|
+
} catch {
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
},
|
|
2845
|
+
() => {
|
|
2846
|
+
offs.forEach((f) => f());
|
|
2847
|
+
offs = [];
|
|
2848
|
+
}
|
|
2849
|
+
);
|
|
2850
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot };
|
|
2605
2851
|
}
|
|
2606
2852
|
|
|
2607
2853
|
// src/ui/hooks.ts
|
|
2608
2854
|
function useStore(s) {
|
|
2609
|
-
return (0,
|
|
2855
|
+
return (0, import_react14.useSyncExternalStore)(s.subscribe, s.getSnapshot, s.getSnapshot);
|
|
2610
2856
|
}
|
|
2611
2857
|
function useConversations() {
|
|
2612
2858
|
return useStore(conversationsStore(useIm()));
|
|
@@ -2617,26 +2863,191 @@ function useTotalUnread() {
|
|
|
2617
2863
|
function useConnection() {
|
|
2618
2864
|
return useStore(connectionStore(useIm()));
|
|
2619
2865
|
}
|
|
2866
|
+
function useFriends() {
|
|
2867
|
+
return useStore(friendsStore(useIm()));
|
|
2868
|
+
}
|
|
2620
2869
|
|
|
2621
|
-
// src/ui/widgets/
|
|
2870
|
+
// src/ui/widgets/GroupAvatar.tsx
|
|
2871
|
+
var import_react15 = require("react");
|
|
2872
|
+
|
|
2873
|
+
// src/core/groupAvatarCache.ts
|
|
2874
|
+
var _GroupAvatarCache = class _GroupAvatarCache {
|
|
2875
|
+
constructor(fetch, subscribeChanges, now = Date.now) {
|
|
2876
|
+
this.fetch = fetch;
|
|
2877
|
+
this.now = now;
|
|
2878
|
+
this.members = /* @__PURE__ */ new Map();
|
|
2879
|
+
this.stale = /* @__PURE__ */ new Set();
|
|
2880
|
+
this.failedAt = /* @__PURE__ */ new Map();
|
|
2881
|
+
this.wanted = /* @__PURE__ */ new Map();
|
|
2882
|
+
this.queue = [];
|
|
2883
|
+
this.inflight = /* @__PURE__ */ new Set();
|
|
2884
|
+
this.gen = /* @__PURE__ */ new Map();
|
|
2885
|
+
this.listeners = new ListenerSet();
|
|
2886
|
+
this.subscribe = (fn) => this.listeners.add(fn);
|
|
2887
|
+
/** 已拉到的前 9 名成员;没拉过或在拉为 undefined。没变化时引用不变。 */
|
|
2888
|
+
this.membersOf = (groupId) => this.members.get(groupId.toLowerCase());
|
|
2889
|
+
this.off = subscribeChanges((c) => this.onChange(c));
|
|
2890
|
+
}
|
|
2891
|
+
static of(im) {
|
|
2892
|
+
let c = _GroupAvatarCache.byIm.get(im);
|
|
2893
|
+
if (!c) {
|
|
2894
|
+
c = new _GroupAvatarCache(
|
|
2895
|
+
async (id) => (await im.groupMembers(id, { limit: 9 })).items,
|
|
2896
|
+
(fn) => im.on("groupChanged", fn)
|
|
2897
|
+
);
|
|
2898
|
+
_GroupAvatarCache.byIm.set(im, c);
|
|
2899
|
+
}
|
|
2900
|
+
return c;
|
|
2901
|
+
}
|
|
2902
|
+
/** 测试用:给某个实例换上自带的缓存。 */
|
|
2903
|
+
static set(im, cache3) {
|
|
2904
|
+
_GroupAvatarCache.byIm.set(im, cache3);
|
|
2905
|
+
}
|
|
2906
|
+
attach(groupId) {
|
|
2907
|
+
const k = groupId.toLowerCase();
|
|
2908
|
+
this.wanted.set(k, (this.wanted.get(k) ?? 0) + 1);
|
|
2909
|
+
this.enqueue(k);
|
|
2910
|
+
}
|
|
2911
|
+
detach(groupId) {
|
|
2912
|
+
const k = groupId.toLowerCase();
|
|
2913
|
+
const n = (this.wanted.get(k) ?? 0) - 1;
|
|
2914
|
+
if (n > 0) this.wanted.set(k, n);
|
|
2915
|
+
else {
|
|
2916
|
+
this.wanted.delete(k);
|
|
2917
|
+
this.queue = this.queue.filter((x) => x !== k);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
dispose() {
|
|
2921
|
+
this.off();
|
|
2922
|
+
this.listeners.clear();
|
|
2923
|
+
}
|
|
2924
|
+
enqueue(k) {
|
|
2925
|
+
if (this.members.has(k) && !this.stale.has(k) || this.inflight.has(k) || this.queue.includes(k)) return;
|
|
2926
|
+
const failed = this.failedAt.get(k);
|
|
2927
|
+
if (failed !== void 0 && this.now() - failed < _GroupAvatarCache.retryAfterMs) return;
|
|
2928
|
+
this.queue.push(k);
|
|
2929
|
+
this.pump();
|
|
2930
|
+
}
|
|
2931
|
+
pump() {
|
|
2932
|
+
while (this.inflight.size < _GroupAvatarCache.maxConcurrent && this.queue.length) {
|
|
2933
|
+
const k = this.queue.shift();
|
|
2934
|
+
if (!this.wanted.has(k)) continue;
|
|
2935
|
+
this.inflight.add(k);
|
|
2936
|
+
const g = this.gen.get(k) ?? 0;
|
|
2937
|
+
this.fetch(k).then(
|
|
2938
|
+
(items) => {
|
|
2939
|
+
if ((this.gen.get(k) ?? 0) !== g) return;
|
|
2940
|
+
this.members.set(k, items);
|
|
2941
|
+
this.stale.delete(k);
|
|
2942
|
+
this.failedAt.delete(k);
|
|
2943
|
+
this.listeners.notify();
|
|
2944
|
+
},
|
|
2945
|
+
() => {
|
|
2946
|
+
if ((this.gen.get(k) ?? 0) !== g) return;
|
|
2947
|
+
this.failedAt.set(k, this.now());
|
|
2948
|
+
}
|
|
2949
|
+
).finally(() => {
|
|
2950
|
+
this.inflight.delete(k);
|
|
2951
|
+
if ((this.gen.get(k) ?? 0) !== g && this.wanted.has(k)) this.enqueue(k);
|
|
2952
|
+
this.pump();
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
onChange(c) {
|
|
2957
|
+
const fields = c.message.content?.fields;
|
|
2958
|
+
const avatarChanged = c.action === "update" && !!fields && typeof fields === "object" && "avatar_url" in fields;
|
|
2959
|
+
if (!_GroupAvatarCache.memberActions.has(c.action) && !avatarChanged) return;
|
|
2960
|
+
const k = c.groupId.toLowerCase();
|
|
2961
|
+
this.gen.set(k, (this.gen.get(k) ?? 0) + 1);
|
|
2962
|
+
this.failedAt.delete(k);
|
|
2963
|
+
if (!this.wanted.has(k)) {
|
|
2964
|
+
this.members.delete(k);
|
|
2965
|
+
this.stale.delete(k);
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
if (this.members.has(k)) this.stale.add(k);
|
|
2969
|
+
if (!this.inflight.has(k)) this.enqueue(k);
|
|
2970
|
+
}
|
|
2971
|
+
};
|
|
2972
|
+
_GroupAvatarCache.maxConcurrent = 3;
|
|
2973
|
+
_GroupAvatarCache.retryAfterMs = 6e4;
|
|
2974
|
+
_GroupAvatarCache.memberActions = /* @__PURE__ */ new Set(["create", "join", "quit", "kick", "dismiss"]);
|
|
2975
|
+
_GroupAvatarCache.byIm = /* @__PURE__ */ new WeakMap();
|
|
2976
|
+
var GroupAvatarCache = _GroupAvatarCache;
|
|
2977
|
+
|
|
2978
|
+
// src/ui/widgets/GroupAvatar.tsx
|
|
2622
2979
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2980
|
+
function GroupGrid({ members, label, size }) {
|
|
2981
|
+
const list = members.slice(0, 9);
|
|
2982
|
+
const cols = list.length <= 4 ? 2 : 3;
|
|
2983
|
+
const style = { ["--gkim-grid-cols"]: String(cols) };
|
|
2984
|
+
if (size) style["--gkim-av"] = `${size}px`;
|
|
2985
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2986
|
+
"span",
|
|
2987
|
+
{
|
|
2988
|
+
className: "gkim-avatar gkim-avatar--group gkim-groupgrid",
|
|
2989
|
+
role: "img",
|
|
2990
|
+
"aria-label": label,
|
|
2991
|
+
style,
|
|
2992
|
+
"data-cols": cols,
|
|
2993
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "gkim-groupgrid__tiles", children: list.map((m) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "gkim-groupgrid__tile", children: [
|
|
2994
|
+
m.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("img", { src: m.avatarUrl, alt: "", onError: (e) => {
|
|
2995
|
+
e.currentTarget.style.display = "none";
|
|
2996
|
+
} }) : null,
|
|
2997
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: { background: avatarColor(m.userId) }, children: avatarInitial(m.nickname, m.userId) })
|
|
2998
|
+
] }, m.userId)) })
|
|
2999
|
+
}
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
function ImGroupAvatar({ groupId, name = "", url = "", size }) {
|
|
3003
|
+
const im = useIm();
|
|
3004
|
+
const cache3 = GroupAvatarCache.of(im);
|
|
3005
|
+
const ref = (0, import_react15.useRef)(null);
|
|
3006
|
+
const [visible, setVisible] = (0, import_react15.useState)(false);
|
|
3007
|
+
const want = !url && !!groupId;
|
|
3008
|
+
(0, import_react15.useEffect)(() => {
|
|
3009
|
+
if (!want || visible) return;
|
|
3010
|
+
const el = ref.current;
|
|
3011
|
+
if (!el || typeof IntersectionObserver === "undefined") {
|
|
3012
|
+
setVisible(true);
|
|
3013
|
+
return;
|
|
3014
|
+
}
|
|
3015
|
+
const io = new IntersectionObserver((es) => {
|
|
3016
|
+
if (es.some((e) => e.isIntersecting)) setVisible(true);
|
|
3017
|
+
});
|
|
3018
|
+
io.observe(el);
|
|
3019
|
+
return () => io.disconnect();
|
|
3020
|
+
}, [want, visible]);
|
|
3021
|
+
(0, import_react15.useEffect)(() => {
|
|
3022
|
+
if (!want || !visible) return;
|
|
3023
|
+
cache3.attach(groupId);
|
|
3024
|
+
return () => cache3.detach(groupId);
|
|
3025
|
+
}, [cache3, groupId, want, visible]);
|
|
3026
|
+
const members = (0, import_react15.useSyncExternalStore)(cache3.subscribe, () => want ? cache3.membersOf(groupId) : void 0, () => void 0);
|
|
3027
|
+
const label = name || groupId;
|
|
3028
|
+
if (want && members?.length) return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(GroupGrid, { members, label, size });
|
|
3029
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { ref, className: "gkim-groupavatar-slot", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Avatar, { id: groupId, name, url: url || void 0, size, group: true }) });
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
// src/ui/widgets/UnreadBadge.tsx
|
|
3033
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2623
3034
|
function Badge({ count = 0, dot = false, muted = false }) {
|
|
2624
|
-
if (dot) return /* @__PURE__ */ (0,
|
|
3035
|
+
if (dot) return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-badge gkim-badge--dot", "aria-hidden": "true" });
|
|
2625
3036
|
if (count <= 0) return null;
|
|
2626
|
-
return /* @__PURE__ */ (0,
|
|
3037
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: `gkim-badge${muted ? " gkim-badge--muted" : ""}`, children: count > 99 ? "99+" : count });
|
|
2627
3038
|
}
|
|
2628
3039
|
function ImUnreadBadge({ children }) {
|
|
2629
3040
|
const n = useTotalUnread();
|
|
2630
|
-
return /* @__PURE__ */ (0,
|
|
3041
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "gkim-badge-anchor", children: [
|
|
2631
3042
|
children,
|
|
2632
|
-
/* @__PURE__ */ (0,
|
|
3043
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Badge, { count: n })
|
|
2633
3044
|
] });
|
|
2634
3045
|
}
|
|
2635
3046
|
|
|
2636
3047
|
// src/ui/conversation/ConversationList.tsx
|
|
2637
|
-
var
|
|
2638
|
-
function
|
|
2639
|
-
return e instanceof
|
|
3048
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3049
|
+
function errorText2(e, fallback) {
|
|
3050
|
+
return e instanceof import_im4.ImApiError && e.message ? e.message : fallback;
|
|
2640
3051
|
}
|
|
2641
3052
|
function Row({ c, selected, onOpen }) {
|
|
2642
3053
|
const { im, strings: s } = useImUi();
|
|
@@ -2649,7 +3060,7 @@ function Row({ c, selected, onOpen }) {
|
|
|
2649
3060
|
try {
|
|
2650
3061
|
await f();
|
|
2651
3062
|
} catch (e) {
|
|
2652
|
-
toast(
|
|
3063
|
+
toast(errorText2(e, s.operationFailed));
|
|
2653
3064
|
}
|
|
2654
3065
|
};
|
|
2655
3066
|
const entries = [
|
|
@@ -2663,8 +3074,8 @@ function Row({ c, selected, onOpen }) {
|
|
|
2663
3074
|
}
|
|
2664
3075
|
}
|
|
2665
3076
|
];
|
|
2666
|
-
return /* @__PURE__ */ (0,
|
|
2667
|
-
/* @__PURE__ */ (0,
|
|
3077
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("li", { className: `gkim-conv${c.pinned ? " gkim-conv--pinned" : ""}${selected ? " gkim-conv--selected" : ""}`, children: [
|
|
3078
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2668
3079
|
"button",
|
|
2669
3080
|
{
|
|
2670
3081
|
type: "button",
|
|
@@ -2674,36 +3085,27 @@ function Row({ c, selected, onOpen }) {
|
|
|
2674
3085
|
"aria-label": c.unread > 0 ? `${title},${c.unread} 条未读` : title,
|
|
2675
3086
|
...menu.bind,
|
|
2676
3087
|
children: [
|
|
2677
|
-
/* @__PURE__ */ (0,
|
|
2678
|
-
/* @__PURE__ */ (0,
|
|
2679
|
-
|
|
2680
|
-
{
|
|
2681
|
-
id: g?.groupId ?? c.peer?.userId ?? "",
|
|
2682
|
-
name: title,
|
|
2683
|
-
url: g?.avatarUrl ?? c.peer?.avatarUrl,
|
|
2684
|
-
group: !!g,
|
|
2685
|
-
size: void 0
|
|
2686
|
-
}
|
|
2687
|
-
),
|
|
2688
|
-
c.unread > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "gkim-conv__badge", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Badge, { count: c.unread, dot: c.muted }) })
|
|
3088
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "gkim-conv__avatar", children: [
|
|
3089
|
+
g ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Avatar, { id: c.peer?.userId ?? "", name: title, url: c.peer?.avatarUrl }),
|
|
3090
|
+
c.unread > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "gkim-conv__badge", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Badge, { count: c.unread, dot: c.muted }) })
|
|
2689
3091
|
] }),
|
|
2690
|
-
/* @__PURE__ */ (0,
|
|
2691
|
-
/* @__PURE__ */ (0,
|
|
2692
|
-
/* @__PURE__ */ (0,
|
|
2693
|
-
/* @__PURE__ */ (0,
|
|
3092
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "gkim-conv__body", children: [
|
|
3093
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "gkim-conv__line", children: [
|
|
3094
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "gkim-conv__title", children: title }),
|
|
3095
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "gkim-conv__time", children: formatConversationTime(c.lastMsgAt, s) })
|
|
2694
3096
|
] }),
|
|
2695
|
-
/* @__PURE__ */ (0,
|
|
2696
|
-
/* @__PURE__ */ (0,
|
|
2697
|
-
sum.atMe && /* @__PURE__ */ (0,
|
|
3097
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "gkim-conv__line", children: [
|
|
3098
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "gkim-conv__preview", children: [
|
|
3099
|
+
sum.atMe && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "gkim-conv__at", children: sum.atMe }),
|
|
2698
3100
|
sum.text
|
|
2699
3101
|
] }),
|
|
2700
|
-
c.muted && /* @__PURE__ */ (0,
|
|
3102
|
+
c.muted && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "gkim-conv__muted", "aria-label": s.mute, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "mute", size: 14 }) })
|
|
2701
3103
|
] })
|
|
2702
3104
|
] })
|
|
2703
3105
|
]
|
|
2704
3106
|
}
|
|
2705
3107
|
),
|
|
2706
|
-
menu.at && /* @__PURE__ */ (0,
|
|
3108
|
+
menu.at && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Menu, { entries, x: menu.at.x, y: menu.at.y, onClose: menu.close, label: title })
|
|
2707
3109
|
] });
|
|
2708
3110
|
}
|
|
2709
3111
|
function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, selectedId }) {
|
|
@@ -2713,8 +3115,8 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2713
3115
|
const conn = useConnection();
|
|
2714
3116
|
const nav = useNavContext();
|
|
2715
3117
|
const frame = useFrame();
|
|
2716
|
-
const [busy, setBusy] = (0,
|
|
2717
|
-
|
|
3118
|
+
const [busy, setBusy] = (0, import_react16.useState)(false);
|
|
3119
|
+
const add = useContextMenu();
|
|
2718
3120
|
void showSearch;
|
|
2719
3121
|
const mainChat = nav.state.main?.name === "chat" ? nav.state.main.target : null;
|
|
2720
3122
|
const selected = selectedId !== void 0 ? selectedId : mainChat?.conversation?.id ?? null;
|
|
@@ -2725,14 +3127,14 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2725
3127
|
try {
|
|
2726
3128
|
await im.markAllRead();
|
|
2727
3129
|
} catch (e) {
|
|
2728
|
-
toast(
|
|
3130
|
+
toast(errorText2(e, s.operationFailed));
|
|
2729
3131
|
} finally {
|
|
2730
3132
|
setBusy(false);
|
|
2731
3133
|
}
|
|
2732
3134
|
};
|
|
2733
3135
|
const markAllBtn = (
|
|
2734
3136
|
// 总未读不含免打扰会话,按各会话判断,免打扰的也能一键清掉。
|
|
2735
|
-
/* @__PURE__ */ (0,
|
|
3137
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2736
3138
|
"button",
|
|
2737
3139
|
{
|
|
2738
3140
|
type: "button",
|
|
@@ -2741,37 +3143,65 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2741
3143
|
title: s.markAllRead,
|
|
2742
3144
|
disabled: !anyUnread || busy,
|
|
2743
3145
|
onClick: markAll,
|
|
2744
|
-
children: /* @__PURE__ */ (0,
|
|
3146
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "checkAll" })
|
|
2745
3147
|
}
|
|
2746
3148
|
)
|
|
2747
3149
|
);
|
|
2748
|
-
const
|
|
2749
|
-
|
|
3150
|
+
const addEntries = [
|
|
3151
|
+
{ label: s.startGroupChat, icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "chatPlus", size: 18 }), onSelect: () => nav.open({ name: "selectFriends" }) },
|
|
3152
|
+
{ label: s.addFriend, icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "userPlus", size: 18 }), onSelect: () => nav.open({ name: "addFriend" }) }
|
|
3153
|
+
];
|
|
3154
|
+
const addBtn = showAddMenu ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3155
|
+
"button",
|
|
3156
|
+
{
|
|
3157
|
+
type: "button",
|
|
3158
|
+
className: "gkim-iconbtn",
|
|
3159
|
+
"aria-label": s.startGroupChat + " / " + s.addFriend,
|
|
3160
|
+
"aria-haspopup": "menu",
|
|
3161
|
+
"aria-expanded": !!add.at,
|
|
3162
|
+
onClick: (e) => {
|
|
3163
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
3164
|
+
add.open({ x: r.left, y: r.bottom + 4 });
|
|
3165
|
+
},
|
|
3166
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "add" })
|
|
3167
|
+
}
|
|
3168
|
+
) : null;
|
|
3169
|
+
const addMenu = add.at && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Menu, { entries: addEntries, x: add.at.x, y: add.at.y, onClose: add.close });
|
|
3170
|
+
const banner = conn === "disconnected" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "gkim-banner gkim-banner--danger", role: "status", children: s.disconnected }) : null;
|
|
3171
|
+
const list = convs.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "gkim-empty gkim-grow", children: s.emptyConversations }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("ul", { className: "gkim-conv-list", "aria-label": s.conversationsTitle, children: convs.map((c) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Row, { c, selected: c.id === selected, onOpen: () => open(c) }, c.id)) });
|
|
2750
3172
|
if (frame.kind === "list") {
|
|
2751
|
-
return /* @__PURE__ */ (0,
|
|
2752
|
-
/* @__PURE__ */ (0,
|
|
2753
|
-
/* @__PURE__ */ (0,
|
|
2754
|
-
/* @__PURE__ */ (0,
|
|
2755
|
-
markAllBtn
|
|
3173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "gkim-listpane", children: [
|
|
3174
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "gkim-listpane__head", children: [
|
|
3175
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h2", { className: "gkim-sr-only", children: s.conversationsTitle }),
|
|
3176
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "gkim-grow" }),
|
|
3177
|
+
markAllBtn,
|
|
3178
|
+
addBtn
|
|
2756
3179
|
] }),
|
|
2757
3180
|
banner,
|
|
2758
|
-
list
|
|
3181
|
+
list,
|
|
3182
|
+
addMenu
|
|
2759
3183
|
] });
|
|
2760
3184
|
}
|
|
2761
|
-
return /* @__PURE__ */ (0,
|
|
3185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Page, { title: s.conversationsTitle, actions: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
3186
|
+
markAllBtn,
|
|
3187
|
+
addBtn
|
|
3188
|
+
] }), banner, children: [
|
|
3189
|
+
list,
|
|
3190
|
+
addMenu
|
|
3191
|
+
] });
|
|
2762
3192
|
}
|
|
2763
3193
|
|
|
2764
3194
|
// src/ui/menu/Report.tsx
|
|
2765
|
-
var
|
|
2766
|
-
var
|
|
2767
|
-
var
|
|
3195
|
+
var import_react17 = require("react");
|
|
3196
|
+
var import_im5 = require("@guokit-dev/im");
|
|
3197
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2768
3198
|
function ReportDialog({ target, title, messageIds }) {
|
|
2769
3199
|
const { im, strings: s } = useImUi();
|
|
2770
3200
|
const { toast } = useFeedback();
|
|
2771
3201
|
const frame = useFrame();
|
|
2772
|
-
const [reason, setReason] = (0,
|
|
2773
|
-
const [block, setBlock] = (0,
|
|
2774
|
-
const [busy, setBusy] = (0,
|
|
3202
|
+
const [reason, setReason] = (0, import_react17.useState)(null);
|
|
3203
|
+
const [block, setBlock] = (0, import_react17.useState)(false);
|
|
3204
|
+
const [busy, setBusy] = (0, import_react17.useState)(false);
|
|
2775
3205
|
const submit = async () => {
|
|
2776
3206
|
if (!reason) return;
|
|
2777
3207
|
setBusy(true);
|
|
@@ -2780,31 +3210,31 @@ function ReportDialog({ target, title, messageIds }) {
|
|
|
2780
3210
|
const r = await im.report(typeof target === "string" ? target : target.groupId, reason, { messageIds: messageIds?.length ? messageIds : void 0, block });
|
|
2781
3211
|
tip = r.duplicated ? s.reportDuplicated : s.reported;
|
|
2782
3212
|
} catch (e) {
|
|
2783
|
-
tip = e instanceof
|
|
3213
|
+
tip = e instanceof import_im5.ImApiError && e.message ? e.message : s.operationFailed;
|
|
2784
3214
|
}
|
|
2785
3215
|
toast(tip);
|
|
2786
3216
|
frame.close();
|
|
2787
3217
|
};
|
|
2788
|
-
return /* @__PURE__ */ (0,
|
|
3218
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2789
3219
|
Page,
|
|
2790
3220
|
{
|
|
2791
3221
|
title,
|
|
2792
3222
|
className: "gkim-report",
|
|
2793
|
-
footer: /* @__PURE__ */ (0,
|
|
2794
|
-
/* @__PURE__ */ (0,
|
|
2795
|
-
/* @__PURE__ */ (0,
|
|
3223
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
3224
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-btn", onClick: frame.close, children: s.cancel }),
|
|
3225
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--primary", disabled: !reason || busy, onClick: submit, children: s.submit })
|
|
2796
3226
|
] }),
|
|
2797
3227
|
children: [
|
|
2798
|
-
/* @__PURE__ */ (0,
|
|
2799
|
-
/* @__PURE__ */ (0,
|
|
2800
|
-
|
|
2801
|
-
/* @__PURE__ */ (0,
|
|
2802
|
-
/* @__PURE__ */ (0,
|
|
3228
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("fieldset", { className: "gkim-report__reasons", children: [
|
|
3229
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("legend", { className: "gkim-sr-only", children: title }),
|
|
3230
|
+
import_im5.reportReasons.map((r) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: `gkim-choice${reason === r ? " gkim-choice--on" : ""}`, children: [
|
|
3231
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { type: "radio", name: "gkim-report-reason", value: r, checked: reason === r, disabled: busy, onChange: () => setReason(r) }),
|
|
3232
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: s.reportReasons[r] ?? r })
|
|
2803
3233
|
] }, r))
|
|
2804
3234
|
] }),
|
|
2805
|
-
/* @__PURE__ */ (0,
|
|
2806
|
-
/* @__PURE__ */ (0,
|
|
2807
|
-
/* @__PURE__ */ (0,
|
|
3235
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: "gkim-check", children: [
|
|
3236
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { type: "checkbox", checked: block, disabled: busy, onChange: (e) => setBlock(e.target.checked) }),
|
|
3237
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: s.alsoBlock })
|
|
2808
3238
|
] })
|
|
2809
3239
|
]
|
|
2810
3240
|
}
|
|
@@ -2812,18 +3242,18 @@ function ReportDialog({ target, title, messageIds }) {
|
|
|
2812
3242
|
}
|
|
2813
3243
|
|
|
2814
3244
|
// src/ui/viewer/ImageViewer.tsx
|
|
2815
|
-
var
|
|
2816
|
-
var
|
|
3245
|
+
var import_react18 = require("react");
|
|
3246
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2817
3247
|
var MIN = 1;
|
|
2818
3248
|
var MAX = 4;
|
|
2819
3249
|
function ImageViewer({ images, index }) {
|
|
2820
3250
|
const { im, strings: s } = useImUi();
|
|
2821
3251
|
const frame = useFrame();
|
|
2822
|
-
const [i, setI] = (0,
|
|
2823
|
-
const [scale, setScale] = (0,
|
|
2824
|
-
const [urls, setUrls] = (0,
|
|
3252
|
+
const [i, setI] = (0, import_react18.useState)(index);
|
|
3253
|
+
const [scale, setScale] = (0, import_react18.useState)(1);
|
|
3254
|
+
const [urls, setUrls] = (0, import_react18.useState)({});
|
|
2825
3255
|
const m = images[i];
|
|
2826
|
-
(0,
|
|
3256
|
+
(0, import_react18.useEffect)(() => {
|
|
2827
3257
|
if (!m || m.clientMsgId in urls) return;
|
|
2828
3258
|
let alive = true;
|
|
2829
3259
|
im.imageUrl(m).then((u) => {
|
|
@@ -2850,33 +3280,33 @@ function ImageViewer({ images, index }) {
|
|
|
2850
3280
|
};
|
|
2851
3281
|
const onWheel = (e) => zoom(e.deltaY < 0 ? 0.25 : -0.25);
|
|
2852
3282
|
const url = m ? urls[m.clientMsgId] : null;
|
|
2853
|
-
return /* @__PURE__ */ (0,
|
|
2854
|
-
/* @__PURE__ */ (0,
|
|
2855
|
-
/* @__PURE__ */ (0,
|
|
2856
|
-
/* @__PURE__ */ (0,
|
|
2857
|
-
/* @__PURE__ */ (0,
|
|
2858
|
-
url && /* @__PURE__ */ (0,
|
|
2859
|
-
/* @__PURE__ */ (0,
|
|
3283
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "gkim-viewer", onKeyDown: onKey, children: [
|
|
3284
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "gkim-viewer__bar", children: [
|
|
3285
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "gkim-viewer__count", children: fill(s.imageIndex, { n: i + 1, total: images.length }) }),
|
|
3286
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomOut, disabled: scale <= MIN, onClick: () => zoom(-0.5), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "zoomOut" }) }),
|
|
3287
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomIn, disabled: scale >= MAX, onClick: () => zoom(0.5), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "zoomIn" }) }),
|
|
3288
|
+
url && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { className: "gkim-viewer__btn", href: url, target: "_blank", rel: "noopener", "aria-label": s.openOriginal, title: s.openOriginal, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "external" }) }),
|
|
3289
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "close" }) })
|
|
2860
3290
|
] }),
|
|
2861
|
-
/* @__PURE__ */ (0,
|
|
3291
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "gkim-viewer__stage", onWheel, onClick: (e) => {
|
|
2862
3292
|
if (e.target === e.currentTarget) frame.close();
|
|
2863
3293
|
}, children: [
|
|
2864
|
-
url ? /* @__PURE__ */ (0,
|
|
2865
|
-
i > 0 && /* @__PURE__ */ (0,
|
|
2866
|
-
i < images.length - 1 && /* @__PURE__ */ (0,
|
|
3294
|
+
url ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("img", { src: url, alt: s.image, style: { transform: `scale(${scale})` }, onDoubleClick: () => setScale((v) => v > 1 ? 1 : 2), draggable: false }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }),
|
|
3295
|
+
i > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--prev", "aria-label": s.prevImage, onClick: () => go(-1), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "back", size: 28 }) }),
|
|
3296
|
+
i < images.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--next", "aria-label": s.nextImage, onClick: () => go(1), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Icon, { name: "back", size: 28 }) })
|
|
2867
3297
|
] })
|
|
2868
3298
|
] });
|
|
2869
3299
|
}
|
|
2870
3300
|
|
|
2871
3301
|
// src/ui/viewer/VideoPlayer.tsx
|
|
2872
|
-
var
|
|
2873
|
-
var
|
|
3302
|
+
var import_react19 = require("react");
|
|
3303
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2874
3304
|
function VideoPlayer({ message }) {
|
|
2875
3305
|
const { im, strings: s } = useImUi();
|
|
2876
3306
|
const frame = useFrame();
|
|
2877
|
-
const [url, setUrl] = (0,
|
|
2878
|
-
const [failed, setFailed] = (0,
|
|
2879
|
-
(0,
|
|
3307
|
+
const [url, setUrl] = (0, import_react19.useState)(null);
|
|
3308
|
+
const [failed, setFailed] = (0, import_react19.useState)(false);
|
|
3309
|
+
(0, import_react19.useEffect)(() => {
|
|
2880
3310
|
let alive = true;
|
|
2881
3311
|
im.videoUrl(message).then((u) => {
|
|
2882
3312
|
if (alive) {
|
|
@@ -2888,90 +3318,1796 @@ function VideoPlayer({ message }) {
|
|
|
2888
3318
|
alive = false;
|
|
2889
3319
|
};
|
|
2890
3320
|
}, [im, message]);
|
|
2891
|
-
return /* @__PURE__ */ (0,
|
|
2892
|
-
/* @__PURE__ */ (0,
|
|
2893
|
-
/* @__PURE__ */ (0,
|
|
2894
|
-
/* @__PURE__ */ (0,
|
|
3321
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "gkim-viewer", children: [
|
|
3322
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "gkim-viewer__bar", children: [
|
|
3323
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "gkim-viewer__count" }),
|
|
3324
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Icon, { name: "close" }) })
|
|
2895
3325
|
] }),
|
|
2896
|
-
/* @__PURE__ */ (0,
|
|
3326
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "gkim-viewer__stage", onClick: (e) => {
|
|
2897
3327
|
if (e.target === e.currentTarget) frame.close();
|
|
2898
|
-
}, children: url ? /* @__PURE__ */ (0,
|
|
3328
|
+
}, children: url ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("video", { src: url, controls: true, autoPlay: true, playsInline: true }) : failed ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: s.operationFailed }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) })
|
|
2899
3329
|
] });
|
|
2900
3330
|
}
|
|
2901
3331
|
|
|
2902
|
-
// src/ui/
|
|
2903
|
-
var
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
3332
|
+
// src/ui/contacts/AddFriendDialog.tsx
|
|
3333
|
+
var import_react20 = require("react");
|
|
3334
|
+
var import_im6 = require("@guokit-dev/im");
|
|
3335
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
3336
|
+
function ImAddFriend() {
|
|
3337
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3338
|
+
const nav = useNavContext();
|
|
3339
|
+
const frame = useFrame();
|
|
3340
|
+
const [q, setQ] = (0, import_react20.useState)("");
|
|
3341
|
+
const [busy, setBusy] = (0, import_react20.useState)(false);
|
|
3342
|
+
const [result, setResult] = (0, import_react20.useState)(void 0);
|
|
3343
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
3344
|
+
const search = async () => {
|
|
3345
|
+
const text = q.trim();
|
|
3346
|
+
if (!text || busy) return;
|
|
3347
|
+
setBusy(true);
|
|
3348
|
+
setError(null);
|
|
3349
|
+
try {
|
|
3350
|
+
setResult({ r: await im.searchUser(text), q: text });
|
|
3351
|
+
} catch (e) {
|
|
3352
|
+
setError(e instanceof import_im6.ImApiError && e.code === "IM_RATE_LIMITED" ? s.rateLimited : errorText(e, s.operationFailed));
|
|
3353
|
+
} finally {
|
|
3354
|
+
setBusy(false);
|
|
2913
3355
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
3356
|
+
};
|
|
3357
|
+
const view = (r) => {
|
|
3358
|
+
if (frame.kind === "dialog" || frame.kind === "page") nav.back();
|
|
3359
|
+
openUserCard({ im, callbacks, nav }, r.userId, { nickname: r.nickname, avatarUrl: r.avatarUrl });
|
|
3360
|
+
};
|
|
3361
|
+
let body = null;
|
|
3362
|
+
if (error) {
|
|
3363
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "gkim-addfriend__error", role: "alert", children: error });
|
|
3364
|
+
} else if (result && result.r === null) {
|
|
3365
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "gkim-addfriend__none", children: [
|
|
3366
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "gkim-addfriend__none-title", children: s.userNotFound }),
|
|
3367
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "gkim-addfriend__tip", children: s.userNotFoundTip })
|
|
3368
|
+
] });
|
|
3369
|
+
} else if (result?.r?.isSelf) {
|
|
3370
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-addfriend__none", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "gkim-addfriend__none-title", children: s.searchSelf }) });
|
|
3371
|
+
} else if (result?.r) {
|
|
3372
|
+
const r = result.r;
|
|
3373
|
+
const name = r.nickname || r.userId;
|
|
3374
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "gkim-addfriend__card", children: [
|
|
3375
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Avatar, { id: r.userId, name, url: r.avatarUrl, size: 48 }),
|
|
3376
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "gkim-addfriend__card-body", children: [
|
|
3377
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-addfriend__card-name", children: name }),
|
|
3378
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "gkim-addfriend__card-sub", children: fill(r.matchedBy === "search_key" ? s.matchedBySearchKey : s.matchedByUserId, { q: result.q }) })
|
|
3379
|
+
] }),
|
|
3380
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => view(r), children: s.view })
|
|
3381
|
+
] });
|
|
2922
3382
|
}
|
|
3383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Page, { title: s.addFriend, className: "gkim-addfriend", children: [
|
|
3384
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("form", { className: "gkim-addfriend__bar", onSubmit: (e) => {
|
|
3385
|
+
e.preventDefault();
|
|
3386
|
+
void search();
|
|
3387
|
+
}, children: [
|
|
3388
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3389
|
+
"input",
|
|
3390
|
+
{
|
|
3391
|
+
className: "gkim-input",
|
|
3392
|
+
type: "search",
|
|
3393
|
+
value: q,
|
|
3394
|
+
"data-autofocus": true,
|
|
3395
|
+
placeholder: s.addFriendHint,
|
|
3396
|
+
"aria-label": s.addFriendHint,
|
|
3397
|
+
onChange: (e) => setQ(e.target.value)
|
|
3398
|
+
}
|
|
3399
|
+
),
|
|
3400
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "submit", className: "gkim-btn gkim-btn--primary", disabled: busy || !q.trim(), children: s.search })
|
|
3401
|
+
] }),
|
|
3402
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "gkim-addfriend__tip", children: s.addFriendTip }),
|
|
3403
|
+
!busy && body
|
|
3404
|
+
] });
|
|
2923
3405
|
}
|
|
2924
3406
|
|
|
2925
|
-
// src/ui/
|
|
2926
|
-
var
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
3407
|
+
// src/ui/contacts/ContactsPage.tsx
|
|
3408
|
+
var import_react22 = require("react");
|
|
3409
|
+
|
|
3410
|
+
// src/core/pinyinIndex.ts
|
|
3411
|
+
var indexLetters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#"];
|
|
3412
|
+
var BOUND_LETTERS = "ABCDEFGHJKLMNOPQRSTWXYZ";
|
|
3413
|
+
var BOUNDS = "阿八嚓哒妸发旮哈讥咔垃妈拏噢妑七呥仨他屲夕丫帀";
|
|
3414
|
+
var HAN = /[㐀-䶿一-鿿豈-]/;
|
|
3415
|
+
var collator = null;
|
|
3416
|
+
function coll() {
|
|
3417
|
+
return collator ?? (collator = new Intl.Collator("zh-Hans-CN-u-co-pinyin", { sensitivity: "base", numeric: true }));
|
|
2934
3418
|
}
|
|
2935
|
-
function
|
|
2936
|
-
|
|
3419
|
+
function indexLetterOf(name) {
|
|
3420
|
+
const s = name.trim();
|
|
3421
|
+
if (!s) return "#";
|
|
3422
|
+
const ch = String.fromCodePoint(s.codePointAt(0));
|
|
3423
|
+
const c = ch.toUpperCase();
|
|
3424
|
+
if (c >= "A" && c <= "Z" && c.length === 1) return c;
|
|
3425
|
+
if (!HAN.test(ch)) return "#";
|
|
3426
|
+
const cl = coll();
|
|
3427
|
+
if (cl.compare(ch, BOUNDS[0]) < 0) return "#";
|
|
3428
|
+
let lo = 0, hi = BOUNDS.length - 1;
|
|
3429
|
+
while (lo < hi) {
|
|
3430
|
+
const mid = lo + hi + 1 >> 1;
|
|
3431
|
+
if (cl.compare(BOUNDS[mid], ch) <= 0) lo = mid;
|
|
3432
|
+
else hi = mid - 1;
|
|
3433
|
+
}
|
|
3434
|
+
return BOUND_LETTERS[lo];
|
|
2937
3435
|
}
|
|
2938
|
-
function
|
|
2939
|
-
const
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
3436
|
+
function indexSections(items, nameOf, idOf) {
|
|
3437
|
+
const by = /* @__PURE__ */ new Map();
|
|
3438
|
+
for (const it of items) {
|
|
3439
|
+
const name = nameOf(it);
|
|
3440
|
+
const l = indexLetterOf(name);
|
|
3441
|
+
let list = by.get(l);
|
|
3442
|
+
if (!list) by.set(l, list = []);
|
|
3443
|
+
list.push({ it, name, id: idOf(it) });
|
|
3444
|
+
}
|
|
3445
|
+
const cl = coll();
|
|
3446
|
+
const out = [];
|
|
3447
|
+
for (const letter of indexLetters) {
|
|
3448
|
+
const list = by.get(letter);
|
|
3449
|
+
if (!list) continue;
|
|
3450
|
+
list.sort((a, b) => cl.compare(a.name, b.name) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
3451
|
+
out.push({ letter, items: list.map((x) => x.it) });
|
|
3452
|
+
}
|
|
3453
|
+
return out;
|
|
2945
3454
|
}
|
|
2946
|
-
|
|
3455
|
+
|
|
3456
|
+
// src/ui/widgets/IndexedList.tsx
|
|
3457
|
+
var import_react21 = require("react");
|
|
3458
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
3459
|
+
var TOP = "↑";
|
|
3460
|
+
var BAR = [TOP, ...indexLetters];
|
|
3461
|
+
function IndexedList({ sections, renderItem, keyOf, header, footer, className }) {
|
|
3462
|
+
const s = useImUi().strings;
|
|
3463
|
+
const scroller = (0, import_react21.useRef)(null);
|
|
3464
|
+
const [touching, setTouching] = (0, import_react21.useState)(null);
|
|
3465
|
+
const present = new Set(sections.map((x) => x.letter));
|
|
3466
|
+
const jump = (letter) => {
|
|
3467
|
+
const box = scroller.current;
|
|
3468
|
+
if (!box) return;
|
|
3469
|
+
if (letter === TOP || !sections.length) {
|
|
3470
|
+
box.scrollTop = 0;
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const want = indexLetters.indexOf(letter);
|
|
3474
|
+
const target = sections.find((x) => indexLetters.indexOf(x.letter) >= want) ?? sections[sections.length - 1];
|
|
3475
|
+
const el = box.querySelector(`[data-letter="${target.letter}"]`);
|
|
3476
|
+
if (el) box.scrollTop = el.offsetTop;
|
|
3477
|
+
};
|
|
3478
|
+
const touch = (e) => {
|
|
3479
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
3480
|
+
const i = Math.min(BAR.length - 1, Math.max(0, Math.floor((e.clientY - r.top) / r.height * BAR.length)));
|
|
3481
|
+
const l = BAR[i];
|
|
3482
|
+
if (l === touching) return;
|
|
3483
|
+
setTouching(l);
|
|
3484
|
+
jump(l);
|
|
3485
|
+
};
|
|
3486
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: `gkim-indexed${className ? " " + className : ""}`, children: [
|
|
3487
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "gkim-indexed__scroll", ref: scroller, children: [
|
|
3488
|
+
header,
|
|
3489
|
+
sections.map((sec) => /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("section", { "aria-label": sec.letter, children: [
|
|
3490
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("h3", { className: "gkim-indexed__head", "data-letter": sec.letter, children: sec.letter }),
|
|
3491
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("ul", { className: "gkim-indexed__list", children: sec.items.map((it) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("li", { children: renderItem(it) }, keyOf(it))) })
|
|
3492
|
+
] }, sec.letter)),
|
|
3493
|
+
footer
|
|
3494
|
+
] }),
|
|
3495
|
+
sections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3496
|
+
"div",
|
|
3497
|
+
{
|
|
3498
|
+
className: "gkim-indexbar",
|
|
3499
|
+
role: "toolbar",
|
|
3500
|
+
"aria-label": s.indexBar,
|
|
3501
|
+
onPointerDown: (e) => {
|
|
3502
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
3503
|
+
touch(e);
|
|
3504
|
+
},
|
|
3505
|
+
onPointerMove: (e) => {
|
|
3506
|
+
if (touching) touch(e);
|
|
3507
|
+
},
|
|
3508
|
+
onPointerUp: () => setTouching(null),
|
|
3509
|
+
onPointerCancel: () => setTouching(null),
|
|
3510
|
+
children: BAR.map((l) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3511
|
+
"button",
|
|
3512
|
+
{
|
|
3513
|
+
type: "button",
|
|
3514
|
+
tabIndex: -1,
|
|
3515
|
+
"aria-label": l,
|
|
3516
|
+
className: `gkim-indexbar__l${present.has(l) ? " gkim-indexbar__l--on" : ""}`,
|
|
3517
|
+
onKeyDown: (e) => {
|
|
3518
|
+
if (e.key === "Enter") jump(l);
|
|
3519
|
+
},
|
|
3520
|
+
children: l
|
|
3521
|
+
},
|
|
3522
|
+
l
|
|
3523
|
+
))
|
|
3524
|
+
}
|
|
3525
|
+
),
|
|
3526
|
+
touching && touching !== TOP && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "gkim-indexbubble", "aria-hidden": "true", children: touching })
|
|
3527
|
+
] });
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
// src/ui/contacts/ContactsPage.tsx
|
|
3531
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3532
|
+
function Entry({ label, tone, badge = 0, onClick }) {
|
|
3533
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("button", { type: "button", className: "gkim-contacts__entry", onClick, children: [
|
|
3534
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: `gkim-contacts__entry-icon gkim-contacts__entry-icon--${tone}`, "aria-hidden": "true", children: label.slice(0, 1) }),
|
|
3535
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "gkim-contacts__entry-label", children: label }),
|
|
3536
|
+
badge > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Badge, { count: badge })
|
|
3537
|
+
] });
|
|
3538
|
+
}
|
|
3539
|
+
function ImContacts({ onSelect }) {
|
|
3540
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3541
|
+
const nav = useNavContext();
|
|
3542
|
+
const frame = useFrame();
|
|
3543
|
+
const friends = useFriends();
|
|
3544
|
+
const [groups] = useFriendGroups(im);
|
|
3545
|
+
const pending = usePendingCount(im);
|
|
3546
|
+
const [query, setQuery] = (0, import_react22.useState)("");
|
|
3547
|
+
const [group, setGroup] = (0, import_react22.useState)(null);
|
|
3548
|
+
const curGroup = group !== null && groups?.some((g) => g.id === group) ? group : null;
|
|
3549
|
+
const q = query.trim().toLowerCase();
|
|
3550
|
+
const visible = (0, import_react22.useMemo)(() => friends.filter((f) => (curGroup === null || f.groupIds.includes(curGroup)) && (q === "" || f.remark.toLowerCase().includes(q) || f.nickname.toLowerCase().includes(q))), [friends, curGroup, q]);
|
|
3551
|
+
const sections = (0, import_react22.useMemo)(() => indexSections(visible, friendDisplayName, (f) => f.userId), [visible]);
|
|
3552
|
+
const counts = (0, import_react22.useMemo)(() => {
|
|
3553
|
+
const m = /* @__PURE__ */ new Map();
|
|
3554
|
+
for (const f of friends) for (const id of f.groupIds) m.set(id, (m.get(id) ?? 0) + 1);
|
|
3555
|
+
return m;
|
|
3556
|
+
}, [friends]);
|
|
3557
|
+
const selected = nav.state.main?.name === "contactProfile" ? nav.state.main.userId : null;
|
|
3558
|
+
const inWide = frame.kind === "list";
|
|
3559
|
+
const select = (f) => {
|
|
3560
|
+
if (onSelect) {
|
|
3561
|
+
onSelect(f.userId);
|
|
3562
|
+
return;
|
|
3563
|
+
}
|
|
3564
|
+
openUserCard({ im, callbacks, nav }, f.userId, void 0, inWide ? "contactProfile" : "userCard");
|
|
3565
|
+
};
|
|
3566
|
+
const addBtn = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3567
|
+
"button",
|
|
3568
|
+
{
|
|
3569
|
+
type: "button",
|
|
3570
|
+
className: "gkim-iconbtn",
|
|
3571
|
+
"aria-label": s.addFriend,
|
|
3572
|
+
title: s.addFriend,
|
|
3573
|
+
onClick: () => nav.open({ name: "addFriend" }),
|
|
3574
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Icon, { name: "userPlus" })
|
|
3575
|
+
}
|
|
3576
|
+
);
|
|
3577
|
+
const search = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("label", { className: "gkim-contacts__search", children: [
|
|
3578
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Icon, { name: "search", size: 18 }),
|
|
3579
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3580
|
+
"input",
|
|
3581
|
+
{
|
|
3582
|
+
type: "search",
|
|
3583
|
+
value: query,
|
|
3584
|
+
placeholder: s.contactsSearchHint,
|
|
3585
|
+
"aria-label": s.contactsSearchHint,
|
|
3586
|
+
onChange: (e) => setQuery(e.target.value)
|
|
3587
|
+
}
|
|
3588
|
+
)
|
|
3589
|
+
] });
|
|
3590
|
+
const header = /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
3591
|
+
!inWide && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "gkim-contacts__searchbar", children: search }),
|
|
3592
|
+
q === "" && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
3593
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "gkim-contacts__entries", children: [
|
|
3594
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Entry, { label: s.newFriends, tone: "new", badge: pending, onClick: () => nav.open({ name: "newFriends" }) }),
|
|
3595
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Entry, { label: s.groupChats, tone: "group", onClick: () => nav.open({ name: "groupChats" }) }),
|
|
3596
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Entry, { label: s.blocklist, tone: "block", onClick: () => nav.open({ name: "blocklist" }) })
|
|
3597
|
+
] }),
|
|
3598
|
+
groups && groups.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "gkim-contacts__chips", role: "group", "aria-label": s.friendGroupsTitle, children: [
|
|
3599
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("button", { type: "button", className: "gkim-chip", "aria-pressed": curGroup === null, onClick: () => setGroup(null), children: [
|
|
3600
|
+
s.allFriends,
|
|
3601
|
+
" ",
|
|
3602
|
+
friends.length
|
|
3603
|
+
] }),
|
|
3604
|
+
groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("button", { type: "button", className: "gkim-chip", "aria-pressed": curGroup === g.id, onClick: () => setGroup(g.id), children: [
|
|
3605
|
+
g.name,
|
|
3606
|
+
" ",
|
|
3607
|
+
counts.get(g.id) ?? 0
|
|
3608
|
+
] }, g.id))
|
|
3609
|
+
] })
|
|
3610
|
+
] })
|
|
3611
|
+
] });
|
|
3612
|
+
const list = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3613
|
+
IndexedList,
|
|
3614
|
+
{
|
|
3615
|
+
className: "gkim-contacts",
|
|
3616
|
+
sections,
|
|
3617
|
+
keyOf: (f) => f.userId,
|
|
3618
|
+
header,
|
|
3619
|
+
footer: visible.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "gkim-empty gkim-contacts__empty", children: s.emptyContacts }) : null,
|
|
3620
|
+
renderItem: (f) => {
|
|
3621
|
+
const name = friendDisplayName(f);
|
|
3622
|
+
const on = f.userId === selected;
|
|
3623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
3624
|
+
"button",
|
|
3625
|
+
{
|
|
3626
|
+
type: "button",
|
|
3627
|
+
className: `gkim-friend${on ? " gkim-friend--selected" : ""}`,
|
|
3628
|
+
"aria-current": on || void 0,
|
|
3629
|
+
onClick: () => select(f),
|
|
3630
|
+
children: [
|
|
3631
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Avatar, { id: f.userId, name, url: f.avatarUrl }),
|
|
3632
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "gkim-friend__name", children: name }),
|
|
3633
|
+
f.remark !== "" && f.nickname !== "" && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "gkim-friend__sub", children: [
|
|
3634
|
+
"(",
|
|
3635
|
+
f.nickname,
|
|
3636
|
+
")"
|
|
3637
|
+
] })
|
|
3638
|
+
]
|
|
3639
|
+
}
|
|
3640
|
+
);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
);
|
|
3644
|
+
if (inWide) {
|
|
3645
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "gkim-listpane", children: [
|
|
3646
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "gkim-listpane__head", children: [
|
|
3647
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("h2", { className: "gkim-sr-only", children: s.contactsTitle }),
|
|
3648
|
+
search,
|
|
3649
|
+
addBtn
|
|
3650
|
+
] }),
|
|
3651
|
+
list
|
|
3652
|
+
] });
|
|
3653
|
+
}
|
|
3654
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Page, { title: s.contactsTitle, actions: addBtn, scroll: false, children: list });
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
// src/ui/contacts/FriendGroups.tsx
|
|
3658
|
+
var import_react23 = require("react");
|
|
3659
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3660
|
+
var GROUP_NAME_MAX = 20;
|
|
3661
|
+
function FriendGroups() {
|
|
3662
|
+
const { im, strings: s } = useImUi();
|
|
3663
|
+
const frame = useFrame();
|
|
3664
|
+
const { toast, confirm } = useFeedback();
|
|
3665
|
+
const friends = useFriends();
|
|
3666
|
+
const [groups] = useFriendGroups(im);
|
|
3667
|
+
const [local, setLocal] = (0, import_react23.useState)(null);
|
|
3668
|
+
(0, import_react23.useEffect)(() => setLocal(null), [groups]);
|
|
3669
|
+
const list = local ?? groups ?? [];
|
|
3670
|
+
const dragFrom = (0, import_react23.useRef)(null);
|
|
3671
|
+
const [dragging, setDragging] = (0, import_react23.useState)(null);
|
|
3672
|
+
const [prompt, setPrompt] = (0, import_react23.useState)(null);
|
|
3673
|
+
const [name, setName] = (0, import_react23.useState)("");
|
|
3674
|
+
const counts = (0, import_react23.useMemo)(() => {
|
|
3675
|
+
const m = /* @__PURE__ */ new Map();
|
|
3676
|
+
for (const f of friends) for (const id of f.groupIds) m.set(id, (m.get(id) ?? 0) + 1);
|
|
3677
|
+
return m;
|
|
3678
|
+
}, [friends]);
|
|
3679
|
+
const guard = async (f) => {
|
|
3680
|
+
try {
|
|
3681
|
+
await f();
|
|
3682
|
+
} catch (e) {
|
|
3683
|
+
toast(errorText(e, s.operationFailed));
|
|
3684
|
+
}
|
|
3685
|
+
notifyContacts(im, "groups");
|
|
3686
|
+
};
|
|
3687
|
+
const move = (from, to) => {
|
|
3688
|
+
const next = [...list];
|
|
3689
|
+
next.splice(to, 0, next.splice(from, 1)[0]);
|
|
3690
|
+
return next;
|
|
3691
|
+
};
|
|
3692
|
+
const commit = (next) => {
|
|
3693
|
+
setLocal(next);
|
|
3694
|
+
return guard(async () => {
|
|
3695
|
+
for (let i = 0; i < next.length; i++) {
|
|
3696
|
+
if (next[i].sort !== i) await im.updateFriendGroup(next[i].id, { sort: i });
|
|
3697
|
+
}
|
|
3698
|
+
});
|
|
3699
|
+
};
|
|
3700
|
+
const remove = async (g) => {
|
|
3701
|
+
if (!await confirm({ content: fill(s.deleteFriendGroupConfirm, { name: g.name }), ok: s.deleteFriendGroup, danger: true })) return;
|
|
3702
|
+
await guard(() => im.deleteFriendGroup(g.id));
|
|
3703
|
+
};
|
|
3704
|
+
const openPrompt = (p) => {
|
|
3705
|
+
setPrompt(p);
|
|
3706
|
+
setName(p.kind === "rename" ? p.group.name : "");
|
|
3707
|
+
};
|
|
3708
|
+
const submitPrompt = async () => {
|
|
3709
|
+
const n = name.trim();
|
|
3710
|
+
const p = prompt;
|
|
3711
|
+
if (!p || !n) return;
|
|
3712
|
+
setPrompt(null);
|
|
3713
|
+
if (p.kind === "new") await guard(() => im.createFriendGroup(n));
|
|
3714
|
+
else if (n !== p.group.name) await guard(() => im.updateFriendGroup(p.group.id, { name: n }));
|
|
3715
|
+
};
|
|
3716
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
3717
|
+
Page,
|
|
3718
|
+
{
|
|
3719
|
+
title: s.friendGroupsTitle,
|
|
3720
|
+
className: "gkim-friendgroups",
|
|
3721
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", onClick: frame.back, children: s.done }),
|
|
3722
|
+
children: [
|
|
3723
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "gkim-form__tip gkim-friendgroups__tip", children: s.friendGroupsTip }),
|
|
3724
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("ul", { className: "gkim-friendgroups__list", children: [
|
|
3725
|
+
list.map((g, i) => /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
3726
|
+
"li",
|
|
3727
|
+
{
|
|
3728
|
+
className: `gkim-friendgroup${dragging === i ? " gkim-friendgroup--dragging" : ""}`,
|
|
3729
|
+
draggable: true,
|
|
3730
|
+
onDragStart: (e) => {
|
|
3731
|
+
dragFrom.current = i;
|
|
3732
|
+
setDragging(i);
|
|
3733
|
+
e.dataTransfer?.setData("text/plain", String(g.id));
|
|
3734
|
+
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
|
|
3735
|
+
},
|
|
3736
|
+
onDragOver: (e) => {
|
|
3737
|
+
e.preventDefault();
|
|
3738
|
+
const from = dragFrom.current;
|
|
3739
|
+
if (from === null || from === i) return;
|
|
3740
|
+
setLocal(move(from, i));
|
|
3741
|
+
dragFrom.current = i;
|
|
3742
|
+
setDragging(i);
|
|
3743
|
+
},
|
|
3744
|
+
onDrop: (e) => e.preventDefault(),
|
|
3745
|
+
onDragEnd: () => {
|
|
3746
|
+
const was = dragFrom.current;
|
|
3747
|
+
dragFrom.current = null;
|
|
3748
|
+
setDragging(null);
|
|
3749
|
+
if (was !== null && local) void commit(local);
|
|
3750
|
+
},
|
|
3751
|
+
children: [
|
|
3752
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "gkim-friendgroup__del", "aria-label": `${s.deleteFriendGroup} ${g.name}`, onClick: () => remove(g), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Icon, { name: "minus", size: 22 }) }),
|
|
3753
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "gkim-friendgroup__name", children: g.name }),
|
|
3754
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "gkim-friendgroup__count", children: fill(s.peopleCount, { n: counts.get(g.id) ?? 0 }) }),
|
|
3755
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "gkim-iconbtn", "aria-label": `${s.rename} ${g.name}`, onClick: () => openPrompt({ kind: "rename", group: g }), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Icon, { name: "edit", size: 18 }) }),
|
|
3756
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3757
|
+
"button",
|
|
3758
|
+
{
|
|
3759
|
+
type: "button",
|
|
3760
|
+
className: "gkim-iconbtn gkim-friendgroup__grip",
|
|
3761
|
+
"aria-label": `${s.dragToSort} ${g.name}`,
|
|
3762
|
+
onKeyDown: (e) => {
|
|
3763
|
+
const to = e.key === "ArrowUp" ? i - 1 : e.key === "ArrowDown" ? i + 1 : -1;
|
|
3764
|
+
if (to < 0 || to >= list.length) return;
|
|
3765
|
+
e.preventDefault();
|
|
3766
|
+
void commit(move(i, to));
|
|
3767
|
+
},
|
|
3768
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Icon, { name: "grip", size: 18 })
|
|
3769
|
+
}
|
|
3770
|
+
)
|
|
3771
|
+
]
|
|
3772
|
+
},
|
|
3773
|
+
g.id
|
|
3774
|
+
)),
|
|
3775
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("button", { type: "button", className: "gkim-friendgroups__new", onClick: () => openPrompt({ kind: "new" }), children: [
|
|
3776
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Icon, { name: "add", size: 18 }),
|
|
3777
|
+
s.newFriendGroup
|
|
3778
|
+
] }) })
|
|
3779
|
+
] }),
|
|
3780
|
+
prompt && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
3781
|
+
"form",
|
|
3782
|
+
{
|
|
3783
|
+
className: "gkim-friendgroups__prompt",
|
|
3784
|
+
onSubmit: (e) => {
|
|
3785
|
+
e.preventDefault();
|
|
3786
|
+
void submitPrompt();
|
|
3787
|
+
},
|
|
3788
|
+
onKeyDown: (e) => {
|
|
3789
|
+
if (e.key === "Escape") {
|
|
3790
|
+
e.stopPropagation();
|
|
3791
|
+
setPrompt(null);
|
|
3792
|
+
}
|
|
3793
|
+
},
|
|
3794
|
+
children: [
|
|
3795
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("h3", { className: "gkim-friendgroups__prompt-title", children: prompt.kind === "new" ? s.newFriendGroup : `${s.rename}「${prompt.group.name}」` }),
|
|
3796
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3797
|
+
"input",
|
|
3798
|
+
{
|
|
3799
|
+
className: "gkim-input",
|
|
3800
|
+
autoFocus: true,
|
|
3801
|
+
value: name,
|
|
3802
|
+
maxLength: GROUP_NAME_MAX,
|
|
3803
|
+
placeholder: s.friendGroupName,
|
|
3804
|
+
"aria-label": s.friendGroupName,
|
|
3805
|
+
onChange: (e) => setName(e.target.value)
|
|
3806
|
+
}
|
|
3807
|
+
),
|
|
3808
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "gkim-friendgroups__prompt-actions", children: [
|
|
3809
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => setPrompt(null), children: s.cancel }),
|
|
3810
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "submit", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: !name.trim(), children: s.confirm })
|
|
3811
|
+
] })
|
|
3812
|
+
]
|
|
3813
|
+
}
|
|
3814
|
+
)
|
|
3815
|
+
]
|
|
3816
|
+
}
|
|
3817
|
+
);
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
// src/ui/contacts/FriendSettings.tsx
|
|
3821
|
+
var import_react24 = require("react");
|
|
3822
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
3823
|
+
var REMARK_MAX = 32;
|
|
3824
|
+
var GROUP_NAME_MAX2 = 20;
|
|
3825
|
+
function FriendSettings({ userId }) {
|
|
3826
|
+
const { im, strings: s } = useImUi();
|
|
3827
|
+
const friends = useFriends();
|
|
3828
|
+
const friend = friends.find((f) => f.userId === userId) ?? safe(() => im.friend(userId), null);
|
|
3829
|
+
if (!friend) return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Page, { title: s.remarkAndGroups });
|
|
3830
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Form, { friend });
|
|
3831
|
+
}
|
|
3832
|
+
function Form({ friend: f }) {
|
|
3833
|
+
const { im, strings: s } = useImUi();
|
|
3834
|
+
const nav = useNavContext();
|
|
3835
|
+
const frame = useFrame();
|
|
3836
|
+
const { toast } = useFeedback();
|
|
3837
|
+
const [groups] = useFriendGroups(im);
|
|
3838
|
+
const [remark, setRemark] = (0, import_react24.useState)(f.remark);
|
|
3839
|
+
const [picked, setPicked] = (0, import_react24.useState)(() => new Set(f.groupIds));
|
|
3840
|
+
const [draft, setDraft] = (0, import_react24.useState)(null);
|
|
3841
|
+
const [busy, setBusy] = (0, import_react24.useState)(false);
|
|
3842
|
+
const toggle = (id) => setPicked((old) => {
|
|
3843
|
+
const n = new Set(old);
|
|
3844
|
+
if (n.has(id)) n.delete(id);
|
|
3845
|
+
else n.add(id);
|
|
3846
|
+
return n;
|
|
3847
|
+
});
|
|
3848
|
+
const createGroup = async () => {
|
|
3849
|
+
const name = draft?.trim();
|
|
3850
|
+
if (!name) {
|
|
3851
|
+
setDraft(null);
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
try {
|
|
3855
|
+
const g = await im.createFriendGroup(name);
|
|
3856
|
+
setPicked((old) => new Set(old).add(g.id));
|
|
3857
|
+
setDraft(null);
|
|
3858
|
+
notifyContacts(im, "groups");
|
|
3859
|
+
} catch (e) {
|
|
3860
|
+
toast(errorText(e, s.operationFailed));
|
|
3861
|
+
}
|
|
3862
|
+
};
|
|
3863
|
+
const save = async () => {
|
|
3864
|
+
const r = remark.trim();
|
|
3865
|
+
const order = (groups ?? []).filter((g) => picked.has(g.id)).map((g) => g.id);
|
|
3866
|
+
const before = (groups ?? []).filter((g) => f.groupIds.includes(g.id)).map((g) => g.id);
|
|
3867
|
+
const groupsChanged = order.join(",") !== before.join(",");
|
|
3868
|
+
if (r === f.remark && !groupsChanged) {
|
|
3869
|
+
frame.back();
|
|
3870
|
+
return;
|
|
3871
|
+
}
|
|
3872
|
+
setBusy(true);
|
|
3873
|
+
try {
|
|
3874
|
+
await im.setFriend(f.userId, { remark: r === f.remark ? void 0 : r, groupIds: groupsChanged ? order : void 0 });
|
|
3875
|
+
frame.back();
|
|
3876
|
+
} catch (e) {
|
|
3877
|
+
setBusy(false);
|
|
3878
|
+
toast(errorText(e, s.operationFailed));
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
3882
|
+
Page,
|
|
3883
|
+
{
|
|
3884
|
+
title: s.remarkAndGroups,
|
|
3885
|
+
className: "gkim-friendsettings",
|
|
3886
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: busy || groups === null, onClick: save, children: s.done }),
|
|
3887
|
+
children: [
|
|
3888
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("label", { className: "gkim-form__label", htmlFor: `gkim-remark-${f.userId}`, children: s.remark }),
|
|
3889
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "gkim-friendsettings__remark", children: [
|
|
3890
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3891
|
+
"input",
|
|
3892
|
+
{
|
|
3893
|
+
id: `gkim-remark-${f.userId}`,
|
|
3894
|
+
className: "gkim-input",
|
|
3895
|
+
value: remark,
|
|
3896
|
+
maxLength: REMARK_MAX,
|
|
3897
|
+
onChange: (e) => setRemark(e.target.value)
|
|
3898
|
+
}
|
|
3899
|
+
),
|
|
3900
|
+
remark !== "" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", className: "gkim-friendsettings__clear", "aria-label": s.clearRemark, onClick: () => setRemark(""), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Icon, { name: "close", size: 14 }) })
|
|
3901
|
+
] }),
|
|
3902
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "gkim-form__tip", children: fill(s.remarkTip, { name: f.nickname || f.userId }) }),
|
|
3903
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "gkim-form__labelrow", children: [
|
|
3904
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "gkim-form__label", children: s.friendGroupsMulti }),
|
|
3905
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("button", { type: "button", className: "gkim-linkbtn gkim-friendsettings__manage", onClick: () => nav.open({ name: "friendGroups" }), children: [
|
|
3906
|
+
s.manageFriendGroups,
|
|
3907
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Icon, { name: "chevron", size: 14 })
|
|
3908
|
+
] })
|
|
3909
|
+
] }),
|
|
3910
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "gkim-friendsettings__chips", role: "group", "aria-label": s.friendGroupsMulti, children: [
|
|
3911
|
+
(groups ?? []).map((g) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("button", { type: "button", className: "gkim-chip gkim-chip--check", "aria-pressed": picked.has(g.id), onClick: () => toggle(g.id), children: [
|
|
3912
|
+
picked.has(g.id) && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Icon, { name: "check", size: 14 }),
|
|
3913
|
+
g.name
|
|
3914
|
+
] }, g.id)),
|
|
3915
|
+
draft === null ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("button", { type: "button", className: "gkim-chip gkim-chip--dashed", disabled: groups === null, onClick: () => setDraft(""), children: [
|
|
3916
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Icon, { name: "add", size: 14 }),
|
|
3917
|
+
s.newFriendGroup
|
|
3918
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("form", { className: "gkim-chip gkim-chip--input", onSubmit: (e) => {
|
|
3919
|
+
e.preventDefault();
|
|
3920
|
+
void createGroup();
|
|
3921
|
+
}, children: [
|
|
3922
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3923
|
+
"input",
|
|
3924
|
+
{
|
|
3925
|
+
autoFocus: true,
|
|
3926
|
+
value: draft,
|
|
3927
|
+
maxLength: GROUP_NAME_MAX2,
|
|
3928
|
+
placeholder: s.friendGroupName,
|
|
3929
|
+
"aria-label": s.friendGroupName,
|
|
3930
|
+
onChange: (e) => setDraft(e.target.value),
|
|
3931
|
+
onKeyDown: (e) => {
|
|
3932
|
+
if (e.key === "Escape") {
|
|
3933
|
+
e.stopPropagation();
|
|
3934
|
+
setDraft(null);
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
),
|
|
3939
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "submit", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: !draft.trim(), children: s.add })
|
|
3940
|
+
] })
|
|
3941
|
+
] })
|
|
3942
|
+
]
|
|
3943
|
+
}
|
|
3944
|
+
);
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
// src/ui/contacts/NewFriendsPage.tsx
|
|
3948
|
+
var import_react25 = require("react");
|
|
3949
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
3950
|
+
function RequestList({ box, hidden }) {
|
|
3951
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3952
|
+
const nav = useNavContext();
|
|
3953
|
+
const { toast } = useFeedback();
|
|
3954
|
+
const [items, setItems] = (0, import_react25.useState)(null);
|
|
3955
|
+
const [busy, setBusy] = (0, import_react25.useState)(/* @__PURE__ */ new Set());
|
|
3956
|
+
const cursor = (0, import_react25.useRef)(null);
|
|
3957
|
+
const loading = (0, import_react25.useRef)(false);
|
|
3958
|
+
const fetch = (0, import_react25.useCallback)(async (reset) => {
|
|
3959
|
+
if (loading.current || !reset && !cursor.current) return;
|
|
3960
|
+
loading.current = true;
|
|
3961
|
+
try {
|
|
3962
|
+
const r = await im.friendRequests(box, { cursor: reset ? null : cursor.current });
|
|
3963
|
+
cursor.current = r.nextCursor;
|
|
3964
|
+
setItems((old) => reset || !old ? r.items : [...old, ...r.items]);
|
|
3965
|
+
} catch (e) {
|
|
3966
|
+
setItems((old) => old ?? []);
|
|
3967
|
+
toast(errorText(e, s.operationFailed));
|
|
3968
|
+
} finally {
|
|
3969
|
+
loading.current = false;
|
|
3970
|
+
}
|
|
3971
|
+
}, [im, box, toast, s]);
|
|
3972
|
+
(0, import_react25.useEffect)(() => {
|
|
3973
|
+
if (im.currentUserId === null) {
|
|
3974
|
+
setItems([]);
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
void fetch(true);
|
|
3978
|
+
return box === "in" ? im.on("friendRequest", () => {
|
|
3979
|
+
void fetch(true);
|
|
3980
|
+
}) : void 0;
|
|
3981
|
+
}, [im, box, fetch]);
|
|
3982
|
+
const handle = async (r, accept) => {
|
|
3983
|
+
setBusy((x) => new Set(x).add(r.requestId));
|
|
3984
|
+
try {
|
|
3985
|
+
if (accept) await im.acceptFriend(r.requestId);
|
|
3986
|
+
else await im.rejectFriend(r.requestId);
|
|
3987
|
+
const status = accept ? "accepted" : "rejected";
|
|
3988
|
+
setItems((old) => old?.map((x) => x.requestId === r.requestId ? { ...x, status, updatedAt: Date.now() } : x) ?? null);
|
|
3989
|
+
notifyContacts(im, "pending");
|
|
3990
|
+
} catch (e) {
|
|
3991
|
+
toast(errorText(e, s.operationFailed));
|
|
3992
|
+
} finally {
|
|
3993
|
+
setBusy((x) => {
|
|
3994
|
+
const n = new Set(x);
|
|
3995
|
+
n.delete(r.requestId);
|
|
3996
|
+
return n;
|
|
3997
|
+
});
|
|
3998
|
+
}
|
|
3999
|
+
};
|
|
4000
|
+
const statusText = (st) => st === "pending" ? s.requestPending : st === "accepted" ? s.requestAccepted : st === "rejected" ? s.requestRejected : s.requestExpired;
|
|
4001
|
+
const tip = /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("p", { className: "gkim-requests__tip", children: s.requestsTip });
|
|
4002
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
4003
|
+
"div",
|
|
4004
|
+
{
|
|
4005
|
+
className: "gkim-requests",
|
|
4006
|
+
role: "tabpanel",
|
|
4007
|
+
hidden,
|
|
4008
|
+
"aria-label": box === "in" ? s.requestsIn : s.requestsOut,
|
|
4009
|
+
onScroll: (e) => {
|
|
4010
|
+
const el = e.currentTarget;
|
|
4011
|
+
if (el.scrollHeight - el.scrollTop - el.clientHeight < 200) void fetch(false);
|
|
4012
|
+
},
|
|
4013
|
+
children: [
|
|
4014
|
+
items === null ? null : items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "gkim-empty gkim-requests__empty", children: s.emptyRequests }) : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("ul", { className: "gkim-requests__list", children: items.map((r) => {
|
|
4015
|
+
const name = r.nickname || r.userId;
|
|
4016
|
+
const b = busy.has(r.requestId);
|
|
4017
|
+
const open = () => openUserCard({ im, callbacks, nav }, r.userId, { nickname: r.nickname, avatarUrl: r.avatarUrl });
|
|
4018
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("li", { className: "gkim-request", children: [
|
|
4019
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("button", { type: "button", className: "gkim-request__main", onClick: open, children: [
|
|
4020
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Avatar, { id: r.userId, name, url: r.avatarUrl, size: 44 }),
|
|
4021
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("span", { className: "gkim-request__body", children: [
|
|
4022
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "gkim-request__name", children: name }),
|
|
4023
|
+
r.message !== "" && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "gkim-request__msg", children: r.message })
|
|
4024
|
+
] })
|
|
4025
|
+
] }),
|
|
4026
|
+
r.status === "pending" && box === "in" ? /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("span", { className: "gkim-request__actions", children: [
|
|
4027
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm", disabled: b, onClick: () => handle(r, false), children: s.reject }),
|
|
4028
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: b, onClick: () => handle(r, true), children: s.accept })
|
|
4029
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "gkim-request__status", children: statusText(r.status) })
|
|
4030
|
+
] }, r.requestId);
|
|
4031
|
+
}) }),
|
|
4032
|
+
items !== null && tip
|
|
4033
|
+
]
|
|
4034
|
+
}
|
|
4035
|
+
);
|
|
4036
|
+
}
|
|
4037
|
+
function ImNewFriends() {
|
|
4038
|
+
const { strings: s } = useImUi();
|
|
4039
|
+
const nav = useNavContext();
|
|
4040
|
+
const [tab, setTab] = (0, import_react25.useState)("in");
|
|
4041
|
+
const tabBtn = (b, label) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", role: "tab", "aria-selected": tab === b, className: "gkim-tabs__tab", onClick: () => setTab(b), children: label });
|
|
4042
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
4043
|
+
Page,
|
|
4044
|
+
{
|
|
4045
|
+
title: s.newFriends,
|
|
4046
|
+
className: "gkim-newfriends",
|
|
4047
|
+
scroll: false,
|
|
4048
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => nav.open({ name: "addFriend" }), children: s.addFriend }),
|
|
4049
|
+
children: [
|
|
4050
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "gkim-tabs", role: "tablist", children: [
|
|
4051
|
+
tabBtn("in", s.requestsIn),
|
|
4052
|
+
tabBtn("out", s.requestsOut)
|
|
4053
|
+
] }),
|
|
4054
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(RequestList, { box: "in", hidden: tab !== "in" }),
|
|
4055
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(RequestList, { box: "out", hidden: tab !== "out" })
|
|
4056
|
+
]
|
|
4057
|
+
}
|
|
4058
|
+
);
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
// src/ui/contacts/UserCard.tsx
|
|
4062
|
+
var import_react26 = require("react");
|
|
4063
|
+
var import_im7 = require("@guokit-dev/im");
|
|
4064
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
4065
|
+
var MESSAGE_MAX = 50;
|
|
4066
|
+
function ImUserCard({ userId }) {
|
|
4067
|
+
const { im, me, strings: s } = useImUi();
|
|
4068
|
+
const nav = useNavContext();
|
|
4069
|
+
const frame = useFrame();
|
|
4070
|
+
const { toast, confirm } = useFeedback();
|
|
4071
|
+
const friends = useFriends();
|
|
4072
|
+
useConversations();
|
|
4073
|
+
const [groups] = useFriendGroups(im);
|
|
4074
|
+
const menu = useContextMenu();
|
|
4075
|
+
const [message, setMessage] = (0, import_react26.useState)(() => me.nickname ? fill(s.friendRequestDefault, { name: me.nickname }) : "");
|
|
4076
|
+
const [busy, setBusy] = (0, import_react26.useState)(false);
|
|
4077
|
+
const [result, setResult] = (0, import_react26.useState)(null);
|
|
4078
|
+
const friend = friends.find((f) => f.userId === userId) ?? safe(() => im.friend(userId), null);
|
|
4079
|
+
const isSelf = im.currentUserId === userId;
|
|
4080
|
+
const hint = userHint(im, userId);
|
|
4081
|
+
const nickname = friend?.nickname || hint.nickname;
|
|
4082
|
+
const title = friend ? friendDisplayName(friend) : hint.nickname || userId;
|
|
4083
|
+
const avatarUrl = friend?.avatarUrl || hint.avatarUrl;
|
|
4084
|
+
const main = frame.kind === "main";
|
|
4085
|
+
const run = async (f) => {
|
|
4086
|
+
try {
|
|
4087
|
+
await f();
|
|
4088
|
+
return true;
|
|
4089
|
+
} catch (e) {
|
|
4090
|
+
toast(errorText(e, s.operationFailed));
|
|
4091
|
+
return false;
|
|
4092
|
+
}
|
|
4093
|
+
};
|
|
4094
|
+
const entries = [
|
|
4095
|
+
{
|
|
4096
|
+
label: s.blockUser,
|
|
4097
|
+
onSelect: async () => {
|
|
4098
|
+
if (await confirm({ title: s.blockUser, content: s.blockConfirm, danger: true })) void run(() => im.block(userId));
|
|
4099
|
+
}
|
|
4100
|
+
},
|
|
4101
|
+
{ label: s.report, onSelect: () => nav.open({ name: "report", target: userId, title: s.report }) },
|
|
4102
|
+
...friend ? [{
|
|
4103
|
+
label: s.deleteFriend,
|
|
4104
|
+
danger: true,
|
|
4105
|
+
onSelect: async () => {
|
|
4106
|
+
const ok = await confirm({ content: fill(s.deleteFriendConfirm, { name: friendDisplayName(friend) }), ok: s.deleteFriend, danger: true });
|
|
4107
|
+
if (ok && await run(() => im.deleteFriend(userId))) frame.back();
|
|
4108
|
+
}
|
|
4109
|
+
}] : []
|
|
4110
|
+
];
|
|
4111
|
+
const moreBtn = isSelf ? null : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4112
|
+
"button",
|
|
4113
|
+
{
|
|
4114
|
+
type: "button",
|
|
4115
|
+
className: "gkim-iconbtn",
|
|
4116
|
+
"aria-label": s.more,
|
|
4117
|
+
title: s.more,
|
|
4118
|
+
"aria-haspopup": "menu",
|
|
4119
|
+
"aria-expanded": !!menu.at,
|
|
4120
|
+
onClick: (e) => {
|
|
4121
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
4122
|
+
menu.open({ x: r.left, y: r.bottom + 4 });
|
|
4123
|
+
},
|
|
4124
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Icon, { name: "more" })
|
|
4125
|
+
}
|
|
4126
|
+
);
|
|
4127
|
+
const add = async () => {
|
|
4128
|
+
setBusy(true);
|
|
4129
|
+
setResult(null);
|
|
4130
|
+
try {
|
|
4131
|
+
const r = await im.addFriend(userId, message.trim());
|
|
4132
|
+
setResult({ text: r.status === "friend" ? s.becameFriends : s.requestSent, error: false });
|
|
4133
|
+
} catch (e) {
|
|
4134
|
+
const code = e instanceof import_im7.ImApiError ? e.code : "";
|
|
4135
|
+
const text = code === "IM_FRIEND_ADD_DENIED" ? s.addDenied : code === "IM_BLOCKED" ? s.addBlocked : code === "IM_RATE_LIMITED" ? s.rateLimited : errorText(e, s.operationFailed);
|
|
4136
|
+
setResult({ text, error: true });
|
|
4137
|
+
} finally {
|
|
4138
|
+
setBusy(false);
|
|
4139
|
+
}
|
|
4140
|
+
};
|
|
4141
|
+
const stranger = !friend && !isSelf;
|
|
4142
|
+
const head = /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: `gkim-usercard__head${stranger ? " gkim-usercard__head--center" : ""}`, children: [
|
|
4143
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Avatar, { id: userId, name: title, url: avatarUrl, size: stranger ? 72 : 64 }),
|
|
4144
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "gkim-usercard__who", children: [
|
|
4145
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "gkim-usercard__name", children: title }),
|
|
4146
|
+
friend && friend.remark !== "" && nickname !== "" && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "gkim-usercard__sub", children: fill(s.nicknameLabel, { name: nickname }) }),
|
|
4147
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "gkim-usercard__sub", children: fill(s.accountLabel, { id: userId }) }),
|
|
4148
|
+
stranger && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "gkim-usercard__tag", children: s.notFriendYet })
|
|
4149
|
+
] }),
|
|
4150
|
+
main && moreBtn
|
|
4151
|
+
] });
|
|
4152
|
+
let body = null;
|
|
4153
|
+
if (friend) {
|
|
4154
|
+
const names = (groups ?? []).filter((g) => friend.groupIds.includes(g.id)).map((g) => g.name);
|
|
4155
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
|
|
4156
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "gkim-usercard__rows", children: [
|
|
4157
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("button", { type: "button", className: "gkim-usercard__row", onClick: () => nav.open({ name: "friendSettings", userId }), children: [
|
|
4158
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "gkim-usercard__label", children: s.remarkAndGroups }),
|
|
4159
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "gkim-usercard__value", children: names.join("、") }),
|
|
4160
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Icon, { name: "chevron", size: 16 })
|
|
4161
|
+
] }),
|
|
4162
|
+
friend.createdAt > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "gkim-usercard__row", children: [
|
|
4163
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "gkim-usercard__label", children: s.friendSince }),
|
|
4164
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "gkim-usercard__value", children: ymd(friend.createdAt) })
|
|
4165
|
+
] })
|
|
4166
|
+
] }),
|
|
4167
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--primary gkim-usercard__chat", onClick: () => {
|
|
4168
|
+
nav.open({ name: "chat", target: { peer: userId } });
|
|
4169
|
+
if (!nav.workspace) nav.close();
|
|
4170
|
+
}, children: s.sendMessage })
|
|
4171
|
+
] });
|
|
4172
|
+
} else if (stranger) {
|
|
4173
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("form", { className: "gkim-usercard__request", onSubmit: (e) => {
|
|
4174
|
+
e.preventDefault();
|
|
4175
|
+
void add();
|
|
4176
|
+
}, children: [
|
|
4177
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("label", { className: "gkim-usercard__request-title", htmlFor: `gkim-req-${userId}`, children: s.friendRequestTitle }),
|
|
4178
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
4179
|
+
"textarea",
|
|
4180
|
+
{
|
|
4181
|
+
id: `gkim-req-${userId}`,
|
|
4182
|
+
className: "gkim-input gkim-usercard__message",
|
|
4183
|
+
rows: 3,
|
|
4184
|
+
maxLength: MESSAGE_MAX,
|
|
4185
|
+
value: message,
|
|
4186
|
+
onChange: (e) => setMessage(e.target.value)
|
|
4187
|
+
}
|
|
4188
|
+
),
|
|
4189
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "gkim-usercard__count", children: [
|
|
4190
|
+
message.length,
|
|
4191
|
+
" / ",
|
|
4192
|
+
MESSAGE_MAX
|
|
4193
|
+
] }),
|
|
4194
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("button", { type: "submit", className: "gkim-btn gkim-btn--primary gkim-usercard__send", disabled: busy, children: s.sendRequest }),
|
|
4195
|
+
result && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { className: `gkim-usercard__result${result.error ? " gkim-usercard__result--error" : ""}`, role: result.error ? "alert" : "status", children: result.text })
|
|
4196
|
+
] });
|
|
4197
|
+
}
|
|
4198
|
+
const menuEl = menu.at && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Menu, { entries, x: menu.at.x, y: menu.at.y, onClose: menu.close, label: title });
|
|
4199
|
+
if (main) {
|
|
4200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("section", { className: "gkim-usercard gkim-usercard--main", "aria-label": s.userCardTitle, children: [
|
|
4201
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "gkim-usercard__card", children: [
|
|
4202
|
+
head,
|
|
4203
|
+
body
|
|
4204
|
+
] }),
|
|
4205
|
+
menuEl
|
|
4206
|
+
] });
|
|
4207
|
+
}
|
|
4208
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Page, { title: s.userCardTitle, className: "gkim-usercard", actions: moreBtn, children: [
|
|
4209
|
+
head,
|
|
4210
|
+
body,
|
|
4211
|
+
menuEl
|
|
4212
|
+
] });
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
// src/ui/contacts/routes.tsx
|
|
4216
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
4217
|
+
function renderContactsRoute(route) {
|
|
4218
|
+
switch (route.name) {
|
|
4219
|
+
case "contacts":
|
|
4220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImContacts, {});
|
|
4221
|
+
case "contactProfile":
|
|
4222
|
+
case "userCard":
|
|
4223
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImUserCard, { userId: route.userId }, route.userId);
|
|
4224
|
+
case "newFriends":
|
|
4225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImNewFriends, {});
|
|
4226
|
+
case "friendSettings":
|
|
4227
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(FriendSettings, { userId: route.userId }, route.userId);
|
|
4228
|
+
case "friendGroups":
|
|
4229
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(FriendGroups, {});
|
|
4230
|
+
case "addFriend":
|
|
4231
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImAddFriend, {});
|
|
4232
|
+
default:
|
|
4233
|
+
return void 0;
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4237
|
+
// src/ui/group/GroupChats.tsx
|
|
4238
|
+
var import_react27 = require("react");
|
|
4239
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
4240
|
+
function GroupChatsPage() {
|
|
4241
|
+
const { strings: s } = useImUi();
|
|
4242
|
+
const nav = useNavContext();
|
|
4243
|
+
const convs = useConversations();
|
|
4244
|
+
const groups = (0, import_react27.useMemo)(() => convs.filter((c) => c.group !== null && !c.group.quit).sort((a, b) => b.lastMsgAt - a.lastMsgAt), [convs]);
|
|
4245
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Page, { title: s.groupChats, className: "gkim-gchats", children: groups.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "gkim-empty gkim-grow", children: s.emptyGroupChats }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("ul", { className: "gkim-gchats__list", "aria-label": s.groupChats, children: groups.map((c) => {
|
|
4246
|
+
const g = c.group;
|
|
4247
|
+
const title = conversationTitle(c, s);
|
|
4248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("button", { type: "button", className: "gkim-gchats__row", onClick: () => {
|
|
4249
|
+
nav.open({ name: "chat", target: { conversation: c } });
|
|
4250
|
+
if (!nav.workspace) nav.close();
|
|
4251
|
+
}, children: [
|
|
4252
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl, size: 40 }),
|
|
4253
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "gkim-gchats__title", children: g.memberCount > 0 ? `${title}(${g.memberCount})` : title })
|
|
4254
|
+
] }) }, c.id);
|
|
4255
|
+
}) }) });
|
|
4256
|
+
}
|
|
4257
|
+
|
|
4258
|
+
// src/ui/group/GroupInfo.tsx
|
|
4259
|
+
var import_react29 = require("react");
|
|
4260
|
+
|
|
4261
|
+
// src/ui/group/shared.tsx
|
|
4262
|
+
var import_react28 = require("react");
|
|
4263
|
+
var import_im8 = require("@guokit-dev/im");
|
|
4264
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
4265
|
+
var noSub2 = () => () => {
|
|
4266
|
+
};
|
|
4267
|
+
var EMPTY_MEMBERS2 = /* @__PURE__ */ new Map();
|
|
4268
|
+
function sameId(a, b) {
|
|
4269
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
4270
|
+
}
|
|
4271
|
+
function errorText3(e, s) {
|
|
4272
|
+
return e instanceof import_im8.ImApiError && e.message ? e.message : s.operationFailed;
|
|
4273
|
+
}
|
|
4274
|
+
function memberName(m) {
|
|
4275
|
+
return m.nickname !== "" ? m.nickname : m.userId;
|
|
4276
|
+
}
|
|
4277
|
+
function roleName(role, s) {
|
|
4278
|
+
return role === 2 ? s.roleOwner : role === 1 ? s.roleAdmin : s.roleMember;
|
|
4279
|
+
}
|
|
4280
|
+
function remainingText(ms, s) {
|
|
4281
|
+
const m = Math.max(1, Math.ceil(ms / 6e4));
|
|
4282
|
+
if (m < 60) return fill(s.durationMinutes, { n: m });
|
|
4283
|
+
const h = Math.ceil(m / 60);
|
|
4284
|
+
if (h < 24) return fill(s.durationHours, { n: h });
|
|
4285
|
+
return fill(s.durationDays, { n: Math.ceil(h / 24) });
|
|
4286
|
+
}
|
|
4287
|
+
var two2 = (n) => String(n).padStart(2, "0");
|
|
4288
|
+
function ymd2(ms, withTime = false) {
|
|
4289
|
+
const d = new Date(ms);
|
|
4290
|
+
const day = `${d.getFullYear()}/${two2(d.getMonth() + 1)}/${two2(d.getDate())}`;
|
|
4291
|
+
return withTime ? `${day} ${two2(d.getHours())}:${two2(d.getMinutes())}` : day;
|
|
4292
|
+
}
|
|
4293
|
+
function useGroup(groupId) {
|
|
4294
|
+
const im = useIm();
|
|
4295
|
+
const [group, setGroup] = (0, import_react28.useState)(null);
|
|
4296
|
+
const [error, setError] = (0, import_react28.useState)(null);
|
|
4297
|
+
const reload = (0, import_react28.useCallback)(async () => {
|
|
4298
|
+
try {
|
|
4299
|
+
const g = await im.group(groupId);
|
|
4300
|
+
setGroup(g);
|
|
4301
|
+
setError(null);
|
|
4302
|
+
} catch (e) {
|
|
4303
|
+
setError(e);
|
|
4304
|
+
}
|
|
4305
|
+
}, [im, groupId]);
|
|
4306
|
+
(0, import_react28.useEffect)(() => {
|
|
4307
|
+
void reload();
|
|
4308
|
+
return im.on("groupChanged", (c) => {
|
|
4309
|
+
if (sameId(c.groupId, groupId)) void reload();
|
|
4310
|
+
});
|
|
4311
|
+
}, [im, groupId, reload]);
|
|
4312
|
+
return { group, error, reload, setGroup };
|
|
4313
|
+
}
|
|
4314
|
+
function useMembers(groupId) {
|
|
4315
|
+
const im = useIm();
|
|
4316
|
+
const [cache3, setCache] = (0, import_react28.useState)(null);
|
|
4317
|
+
(0, import_react28.useEffect)(() => {
|
|
4318
|
+
if (groupId === null) return;
|
|
4319
|
+
const m = new MemberCache(im, groupId);
|
|
4320
|
+
setCache(m);
|
|
4321
|
+
m.start();
|
|
4322
|
+
return () => {
|
|
4323
|
+
m.dispose();
|
|
4324
|
+
setCache(null);
|
|
4325
|
+
};
|
|
4326
|
+
}, [im, groupId]);
|
|
4327
|
+
const map = (0, import_react28.useSyncExternalStore)(cache3?.subscribe ?? noSub2, cache3?.getSnapshot ?? (() => EMPTY_MEMBERS2));
|
|
4328
|
+
const members = (0, import_react28.useMemo)(() => [...map.values()], [map]);
|
|
4329
|
+
return { cache: cache3, map, members };
|
|
4330
|
+
}
|
|
4331
|
+
function useGroupConversation(groupId) {
|
|
4332
|
+
const convs = useConversations();
|
|
4333
|
+
return convs.find((c) => c.group !== null && sameId(c.group.groupId, groupId)) ?? null;
|
|
4334
|
+
}
|
|
4335
|
+
function Switch({ label, checked, onChange, disabled }) {
|
|
4336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
4337
|
+
"button",
|
|
4338
|
+
{
|
|
4339
|
+
type: "button",
|
|
4340
|
+
role: "switch",
|
|
4341
|
+
"aria-checked": checked,
|
|
4342
|
+
"aria-label": label,
|
|
4343
|
+
disabled,
|
|
4344
|
+
className: `gkim-gswitch${checked ? " gkim-gswitch--on" : ""}`,
|
|
4345
|
+
onClick: () => onChange(!checked),
|
|
4346
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "gkim-gswitch__knob" })
|
|
4347
|
+
}
|
|
4348
|
+
);
|
|
4349
|
+
}
|
|
4350
|
+
function SettingRow({ title, value, sub, trailing, onClick }) {
|
|
4351
|
+
const inner = /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
4352
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("span", { className: "gkim-gset__text", children: [
|
|
4353
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "gkim-gset__title", children: title }),
|
|
4354
|
+
sub && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "gkim-gset__sub", children: sub })
|
|
4355
|
+
] }),
|
|
4356
|
+
value !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "gkim-gset__value", children: value }),
|
|
4357
|
+
trailing,
|
|
4358
|
+
onClick && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "gkim-gset__chev", "aria-hidden": "true", children: "›" })
|
|
4359
|
+
] });
|
|
4360
|
+
return onClick ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("button", { type: "button", className: "gkim-gset gkim-gset--btn", onClick, children: inner }) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "gkim-gset", children: inner });
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4363
|
+
// src/ui/group/GroupInfo.tsx
|
|
4364
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
4365
|
+
var CELLS = 9;
|
|
4366
|
+
function ImGroupInfo({ groupId }) {
|
|
4367
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
4368
|
+
const { toast, confirm } = useFeedback();
|
|
4369
|
+
const nav = useNavContext();
|
|
4370
|
+
const frame = useFrame();
|
|
4371
|
+
const { group: g, error } = useGroup(groupId);
|
|
4372
|
+
const { members } = useMembers(groupId);
|
|
4373
|
+
const conv = useGroupConversation(groupId);
|
|
4374
|
+
const [naming, setNaming] = (0, import_react29.useState)(null);
|
|
4375
|
+
const cancelName = (0, import_react29.useRef)(false);
|
|
4376
|
+
const run = async (f) => {
|
|
4377
|
+
try {
|
|
4378
|
+
await f();
|
|
4379
|
+
return true;
|
|
4380
|
+
} catch (e) {
|
|
4381
|
+
toast(errorText3(e, s));
|
|
4382
|
+
return false;
|
|
4383
|
+
}
|
|
4384
|
+
};
|
|
4385
|
+
if (!g) {
|
|
4386
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Page, { title: s.groupInfoTitle, className: "gkim-ginfo", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "gkim-empty gkim-grow", children: error ? errorText3(error, s) : "" }) });
|
|
4387
|
+
}
|
|
4388
|
+
const active = !g.quit && !g.dismissed;
|
|
4389
|
+
const isAdmin = active && g.role >= 1;
|
|
4390
|
+
const isOwner = active && g.role === 2;
|
|
4391
|
+
const canInvite = active && (!g.inviteAdminOnly || isAdmin);
|
|
4392
|
+
const buttons = (canInvite ? 1 : 0) + (isAdmin ? 1 : 0);
|
|
4393
|
+
const shown = members.slice(0, CELLS - buttons);
|
|
4394
|
+
const title = g.name !== "" ? g.name : s.groupChat;
|
|
4395
|
+
const adminCount = members.filter((m) => m.role === 1).length;
|
|
4396
|
+
const openMembers = () => nav.open({ name: "groupMembers", groupId });
|
|
4397
|
+
const saveName = async () => {
|
|
4398
|
+
const name = (naming ?? "").trim();
|
|
4399
|
+
setNaming(null);
|
|
4400
|
+
if (!name || name === g.name) return;
|
|
4401
|
+
await run(() => im.updateGroup(g.groupId, { name }));
|
|
4402
|
+
};
|
|
4403
|
+
const nameKey = (e) => {
|
|
4404
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) {
|
|
4405
|
+
e.preventDefault();
|
|
4406
|
+
e.currentTarget.blur();
|
|
4407
|
+
} else if (e.key === "Escape") {
|
|
4408
|
+
e.stopPropagation();
|
|
4409
|
+
cancelName.current = true;
|
|
4410
|
+
setNaming(null);
|
|
4411
|
+
}
|
|
4412
|
+
};
|
|
4413
|
+
const nameBlur = () => {
|
|
4414
|
+
if (cancelName.current) {
|
|
4415
|
+
cancelName.current = false;
|
|
4416
|
+
return;
|
|
4417
|
+
}
|
|
4418
|
+
void saveName();
|
|
4419
|
+
};
|
|
4420
|
+
const clear = async () => {
|
|
4421
|
+
if (!conv) return;
|
|
4422
|
+
if (await confirm({ content: s.clearHistoryConfirm, ok: s.clearHistory, danger: true })) await run(() => im.clearConversation(conv.id));
|
|
4423
|
+
};
|
|
4424
|
+
const quit = async () => {
|
|
4425
|
+
if (g.role === 2) {
|
|
4426
|
+
toast(s.ownerQuitTip);
|
|
4427
|
+
return;
|
|
4428
|
+
}
|
|
4429
|
+
if (!await confirm({ title: s.quitGroup, content: s.quitGroupConfirm, ok: s.quitGroup, danger: true })) return;
|
|
4430
|
+
if (await run(() => im.quitGroup(g.groupId))) frame.close();
|
|
4431
|
+
};
|
|
4432
|
+
const dismiss = async () => {
|
|
4433
|
+
if (!await confirm({ title: s.dismissGroup, content: s.dismissGroupConfirm, ok: s.dismissGroup, danger: true })) return;
|
|
4434
|
+
if (await run(() => im.dismissGroup(g.groupId))) frame.close();
|
|
4435
|
+
};
|
|
4436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(Page, { title: s.groupInfoTitle, className: "gkim-ginfo", children: [
|
|
4437
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-ginfo__head", children: [
|
|
4438
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl, size: 56 }),
|
|
4439
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-ginfo__headtext", children: [
|
|
4440
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "gkim-ginfo__name", children: title }),
|
|
4441
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "gkim-ginfo__meta", children: fill(s.groupIdAndCount, { id: g.groupId, n: g.memberCount }) })
|
|
4442
|
+
] })
|
|
4443
|
+
] }),
|
|
4444
|
+
active && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gsection", children: [
|
|
4445
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("ul", { className: "gkim-ginfo__grid", "aria-label": s.groupMembersTitle, children: [
|
|
4446
|
+
shown.map((m) => {
|
|
4447
|
+
const name = memberName(m);
|
|
4448
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("button", { type: "button", className: "gkim-ginfo__cell", onClick: () => openUserCard({ im, callbacks, nav }, m.userId, m), children: [
|
|
4449
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("span", { className: "gkim-ginfo__cellav", children: [
|
|
4450
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Avatar, { id: m.userId, name, url: m.avatarUrl || void 0, size: 48 }),
|
|
4451
|
+
m.role > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__role", children: m.role === 2 ? s.roleOwner : s.roleAdmin })
|
|
4452
|
+
] }),
|
|
4453
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__celllabel", children: name })
|
|
4454
|
+
] }) }, m.userId);
|
|
4455
|
+
}),
|
|
4456
|
+
canInvite && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("button", { type: "button", className: "gkim-ginfo__cell", onClick: () => nav.open({ name: "selectFriends", groupId }), children: [
|
|
4457
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__dashed", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Icon, { name: "add" }) }),
|
|
4458
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__celllabel", children: s.inviteMember })
|
|
4459
|
+
] }) }),
|
|
4460
|
+
isAdmin && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("button", { type: "button", className: "gkim-ginfo__cell", onClick: openMembers, children: [
|
|
4461
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__dashed", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Icon, { name: "minusLine" }) }),
|
|
4462
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-ginfo__celllabel", children: s.removeMember })
|
|
4463
|
+
] }) })
|
|
4464
|
+
] }),
|
|
4465
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("button", { type: "button", className: "gkim-ginfo__all", onClick: openMembers, children: [
|
|
4466
|
+
fill(s.viewAllMembers, { n: g.memberCount }),
|
|
4467
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { "aria-hidden": "true", children: " ›" })
|
|
4468
|
+
] })
|
|
4469
|
+
] }),
|
|
4470
|
+
active && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gsection", children: [
|
|
4471
|
+
naming !== null ? /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gset", children: [
|
|
4472
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "gkim-gset__title", children: s.groupNameLabel }),
|
|
4473
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
4474
|
+
"input",
|
|
4475
|
+
{
|
|
4476
|
+
className: "gkim-ginfo__nameinput",
|
|
4477
|
+
"aria-label": s.groupNameLabel,
|
|
4478
|
+
autoFocus: true,
|
|
4479
|
+
maxLength: 64,
|
|
4480
|
+
value: naming,
|
|
4481
|
+
onChange: (e) => setNaming(e.target.value),
|
|
4482
|
+
onKeyDown: nameKey,
|
|
4483
|
+
onBlur: nameBlur
|
|
4484
|
+
}
|
|
4485
|
+
)
|
|
4486
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SettingRow, { title: s.groupNameLabel, value: title, onClick: isAdmin ? () => setNaming(g.name) : void 0 }),
|
|
4487
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
4488
|
+
SettingRow,
|
|
4489
|
+
{
|
|
4490
|
+
title: s.groupNotice,
|
|
4491
|
+
value: g.notice === "" ? s.notSet : g.notice,
|
|
4492
|
+
onClick: () => nav.open({ name: "groupNotice", groupId })
|
|
4493
|
+
}
|
|
4494
|
+
)
|
|
4495
|
+
] }),
|
|
4496
|
+
active && conv && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gsection", children: [
|
|
4497
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SettingRow, { title: s.mute, trailing: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Switch, { label: s.mute, checked: conv.muted, onChange: (v) => run(() => im.setMuted(conv.id, v)) }) }),
|
|
4498
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SettingRow, { title: s.pinChat, trailing: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Switch, { label: s.pinChat, checked: conv.pinned, onChange: (v) => run(() => im.setPinned(conv.id, v)) }) })
|
|
4499
|
+
] }),
|
|
4500
|
+
isAdmin && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gsection", children: [
|
|
4501
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("h3", { className: "gkim-gsection__head", children: s.groupManage }),
|
|
4502
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
4503
|
+
SettingRow,
|
|
4504
|
+
{
|
|
4505
|
+
title: s.muteAll,
|
|
4506
|
+
sub: s.muteAllTip,
|
|
4507
|
+
trailing: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Switch, { label: s.muteAll, checked: g.muteAll, onChange: (v) => run(() => im.updateGroup(g.groupId, { muteAll: v })) })
|
|
4508
|
+
}
|
|
4509
|
+
),
|
|
4510
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
4511
|
+
SettingRow,
|
|
4512
|
+
{
|
|
4513
|
+
title: s.inviteAdminOnly,
|
|
4514
|
+
trailing: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Switch, { label: s.inviteAdminOnly, checked: g.inviteAdminOnly, onChange: (v) => run(() => im.updateGroup(g.groupId, { inviteAdminOnly: v })) })
|
|
4515
|
+
}
|
|
4516
|
+
),
|
|
4517
|
+
isOwner && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SettingRow, { title: s.groupAdmins, value: fill(s.peopleCount, { n: adminCount }), onClick: openMembers }),
|
|
4518
|
+
isOwner && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SettingRow, { title: s.transferOwner, onClick: openMembers })
|
|
4519
|
+
] }),
|
|
4520
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "gkim-gsection gkim-ginfo__danger", children: [
|
|
4521
|
+
conv && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: clear, children: s.clearHistory }),
|
|
4522
|
+
active && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: quit, children: s.quitGroup }),
|
|
4523
|
+
isOwner && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: dismiss, children: s.dismissGroup })
|
|
4524
|
+
] }),
|
|
4525
|
+
isOwner && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("p", { className: "gkim-ginfo__tip", children: s.ownerQuitTip })
|
|
4526
|
+
] });
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
// src/ui/group/GroupMembers.tsx
|
|
4530
|
+
var import_react30 = require("react");
|
|
4531
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
4532
|
+
function GroupMembersPage({ groupId, now = Date.now }) {
|
|
4533
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
4534
|
+
const { toast, confirm } = useFeedback();
|
|
4535
|
+
const nav = useNavContext();
|
|
4536
|
+
const { group, reload } = useGroup(groupId);
|
|
4537
|
+
const { cache: cache3, members } = useMembers(groupId);
|
|
4538
|
+
const [query, setQuery] = (0, import_react30.useState)("");
|
|
4539
|
+
const [menu, setMenu] = (0, import_react30.useState)(null);
|
|
4540
|
+
const closeMenu = (0, import_react30.useCallback)(() => setMenu(null), []);
|
|
4541
|
+
const t = now();
|
|
4542
|
+
const muted = (m) => m.muteUntil !== null && m.muteUntil > t;
|
|
4543
|
+
const q = query.trim().toLowerCase();
|
|
4544
|
+
const list = q ? members.filter((m) => m.nickname.toLowerCase().includes(q) || m.userId.toLowerCase().includes(q)) : members;
|
|
4545
|
+
const count = group?.memberCount || members.length;
|
|
4546
|
+
const me = im.currentUserId;
|
|
4547
|
+
const myRole = group && !group.quit && !group.dismissed ? group.role : 0;
|
|
4548
|
+
const run = async (f) => {
|
|
4549
|
+
try {
|
|
4550
|
+
await f();
|
|
4551
|
+
} catch (e) {
|
|
4552
|
+
toast(errorText3(e, s));
|
|
4553
|
+
}
|
|
4554
|
+
await cache3?.reload();
|
|
4555
|
+
await reload();
|
|
4556
|
+
};
|
|
4557
|
+
const entriesOf = (m) => {
|
|
4558
|
+
const name = memberName(m);
|
|
4559
|
+
const isOwner = myRole === 2;
|
|
4560
|
+
const canManage = isOwner || myRole === 1 && m.role === 0;
|
|
4561
|
+
const role = roleName(m.role, s);
|
|
4562
|
+
const out = [
|
|
4563
|
+
{ label: `${name} · ${m.joinedAt ? fill(s.joinedAt, { role, date: ymd2(m.joinedAt) }) : role}`, disabled: true, onSelect: () => {
|
|
4564
|
+
} },
|
|
4565
|
+
{ label: s.viewProfile, onSelect: () => openUserCard({ im, callbacks, nav }, m.userId, m) }
|
|
4566
|
+
];
|
|
4567
|
+
if (isOwner) {
|
|
4568
|
+
out.push({ label: m.role === 1 ? s.unsetAdmin : s.setAdmin, onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { role: m.role === 1 ? 0 : 1 })) });
|
|
4569
|
+
}
|
|
4570
|
+
if (canManage) {
|
|
4571
|
+
if (muted(m)) {
|
|
4572
|
+
out.push({ label: s.unmuteMember, onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { muteMinutes: 0 })) });
|
|
4573
|
+
} else {
|
|
4574
|
+
out.push({
|
|
4575
|
+
label: s.muteMember,
|
|
4576
|
+
onSelect: () => {
|
|
4577
|
+
},
|
|
4578
|
+
children: Object.entries(s.muteDurations).map(([sec, label]) => ({
|
|
4579
|
+
label,
|
|
4580
|
+
onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { muteMinutes: Math.round(Number(sec) / 60) }))
|
|
4581
|
+
}))
|
|
4582
|
+
});
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
if (isOwner) {
|
|
4586
|
+
out.push({
|
|
4587
|
+
label: s.transferTo,
|
|
4588
|
+
onSelect: async () => {
|
|
4589
|
+
if (await confirm({ title: s.transferOwner, content: fill(s.transferConfirm, { name }), danger: true })) await run(() => im.transferGroup(groupId, m.userId));
|
|
4590
|
+
}
|
|
4591
|
+
});
|
|
4592
|
+
}
|
|
4593
|
+
if (canManage) {
|
|
4594
|
+
out.push({
|
|
4595
|
+
label: s.kickMember,
|
|
4596
|
+
danger: true,
|
|
4597
|
+
onSelect: async () => {
|
|
4598
|
+
if (await confirm({ content: fill(s.kickConfirm, { name }), ok: s.kickMember, danger: true })) await run(() => im.removeGroupMember(groupId, m.userId));
|
|
4599
|
+
}
|
|
4600
|
+
});
|
|
4601
|
+
}
|
|
4602
|
+
return out;
|
|
4603
|
+
};
|
|
4604
|
+
const openMenu = (m, el) => {
|
|
4605
|
+
const r = el.getBoundingClientRect();
|
|
4606
|
+
setMenu({ m, at: { x: r.right, y: r.bottom + 4 } });
|
|
4607
|
+
};
|
|
4608
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(Page, { title: count > 0 ? `${s.groupMembersTitle}(${count})` : s.groupMembersTitle, className: "gkim-gmembers", children: [
|
|
4609
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "gkim-gsearch", children: [
|
|
4610
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Icon, { name: "search", size: 16 }),
|
|
4611
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("input", { type: "search", placeholder: s.searchMembers, "aria-label": s.searchMembers, value: query, onChange: (e) => setQuery(e.target.value) })
|
|
4612
|
+
] }),
|
|
4613
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("ul", { className: "gkim-gmembers__list", "aria-label": s.groupMembersTitle, children: list.map((m) => {
|
|
4614
|
+
const name = memberName(m);
|
|
4615
|
+
const self = m.userId === me;
|
|
4616
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
4617
|
+
"li",
|
|
4618
|
+
{
|
|
4619
|
+
className: `gkim-gmember${menu?.m.userId === m.userId ? " gkim-gmember--active" : ""}`,
|
|
4620
|
+
onClick: self ? void 0 : (e) => openMenu(m, e.currentTarget.querySelector(".gkim-gmember__more") ?? e.currentTarget),
|
|
4621
|
+
children: [
|
|
4622
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Avatar, { id: m.userId, name, url: m.avatarUrl || void 0, size: 40 }),
|
|
4623
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "gkim-gmember__name", children: name }),
|
|
4624
|
+
m.role === 2 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "gkim-gtag gkim-gtag--owner", children: s.roleOwner }),
|
|
4625
|
+
m.role === 1 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "gkim-gtag gkim-gtag--admin", children: s.roleAdmin }),
|
|
4626
|
+
muted(m) && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "gkim-gtag gkim-gtag--muted", children: fill(s.mutedRemaining, { time: remainingText(m.muteUntil - t, s) }) }),
|
|
4627
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "gkim-grow" }),
|
|
4628
|
+
!self && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
4629
|
+
"button",
|
|
4630
|
+
{
|
|
4631
|
+
type: "button",
|
|
4632
|
+
className: "gkim-iconbtn gkim-gmember__more",
|
|
4633
|
+
"aria-label": `${s.more} ${name}`,
|
|
4634
|
+
"aria-haspopup": "menu",
|
|
4635
|
+
onClick: (e) => {
|
|
4636
|
+
e.stopPropagation();
|
|
4637
|
+
openMenu(m, e.currentTarget);
|
|
4638
|
+
},
|
|
4639
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Icon, { name: "more" })
|
|
4640
|
+
}
|
|
4641
|
+
)
|
|
4642
|
+
]
|
|
4643
|
+
},
|
|
4644
|
+
m.userId
|
|
4645
|
+
);
|
|
4646
|
+
}) }),
|
|
4647
|
+
menu && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Menu, { entries: entriesOf(menu.m), x: menu.at.x, y: menu.at.y, onClose: closeMenu, label: memberName(menu.m) })
|
|
4648
|
+
] });
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
// src/ui/group/GroupNotice.tsx
|
|
4652
|
+
var import_react31 = require("react");
|
|
4653
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
4654
|
+
var MAX2 = 1e3;
|
|
4655
|
+
function GroupNoticePage({ groupId }) {
|
|
4656
|
+
const { im, strings: s } = useImUi();
|
|
4657
|
+
const { toast } = useFeedback();
|
|
4658
|
+
const { group: g, error, setGroup } = useGroup(groupId);
|
|
4659
|
+
const { map } = useMembers(groupId);
|
|
4660
|
+
const [text, setText] = (0, import_react31.useState)(null);
|
|
4661
|
+
const [busy, setBusy] = (0, import_react31.useState)(false);
|
|
4662
|
+
if (!g) {
|
|
4663
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Page, { title: s.groupNotice, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "gkim-empty gkim-grow", children: error ? errorText3(error, s) : "" }) });
|
|
4664
|
+
}
|
|
4665
|
+
const canEdit = g.role >= 1 && !g.quit && !g.dismissed;
|
|
4666
|
+
if (text !== null) {
|
|
4667
|
+
const publish = async () => {
|
|
4668
|
+
setBusy(true);
|
|
4669
|
+
try {
|
|
4670
|
+
setGroup(await im.updateGroup(g.groupId, { notice: text.trim() }));
|
|
4671
|
+
setText(null);
|
|
4672
|
+
} catch (e) {
|
|
4673
|
+
toast(errorText3(e, s));
|
|
4674
|
+
} finally {
|
|
4675
|
+
setBusy(false);
|
|
4676
|
+
}
|
|
4677
|
+
};
|
|
4678
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
|
|
4679
|
+
Page,
|
|
4680
|
+
{
|
|
4681
|
+
title: s.groupNotice,
|
|
4682
|
+
className: "gkim-gnotice gkim-gnotice--edit",
|
|
4683
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
|
|
4684
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("button", { type: "button", className: "gkim-gnotice__link", disabled: busy, onClick: () => setText(null), children: s.cancel }),
|
|
4685
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--primary gkim-gnotice__publish", disabled: busy || text.trim() === g.notice, onClick: publish, children: s.publish })
|
|
4686
|
+
] }),
|
|
4687
|
+
children: [
|
|
4688
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
4689
|
+
"textarea",
|
|
4690
|
+
{
|
|
4691
|
+
className: "gkim-gnotice__field",
|
|
4692
|
+
"aria-label": s.groupNotice,
|
|
4693
|
+
placeholder: s.noticeHint,
|
|
4694
|
+
maxLength: MAX2,
|
|
4695
|
+
autoFocus: true,
|
|
4696
|
+
value: text,
|
|
4697
|
+
onChange: (e) => setText(e.target.value),
|
|
4698
|
+
onKeyDown: (e) => {
|
|
4699
|
+
if (e.key === "Escape") {
|
|
4700
|
+
e.stopPropagation();
|
|
4701
|
+
if (!busy) setText(null);
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
),
|
|
4706
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "gkim-gnotice__foot", children: [
|
|
4707
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { children: s.noticePublishTip }),
|
|
4708
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("span", { children: [
|
|
4709
|
+
text.length,
|
|
4710
|
+
" / ",
|
|
4711
|
+
MAX2
|
|
4712
|
+
] })
|
|
4713
|
+
] })
|
|
4714
|
+
]
|
|
4715
|
+
}
|
|
4716
|
+
);
|
|
4717
|
+
}
|
|
4718
|
+
const by = g.noticeBy;
|
|
4719
|
+
const isSystem = by === "@system";
|
|
4720
|
+
const m = isSystem ? void 0 : map.get(by);
|
|
4721
|
+
const name = isSystem ? s.system : m?.nickname || by;
|
|
4722
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
|
|
4723
|
+
Page,
|
|
4724
|
+
{
|
|
4725
|
+
title: s.groupNotice,
|
|
4726
|
+
className: "gkim-gnotice",
|
|
4727
|
+
actions: canEdit && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("button", { type: "button", className: "gkim-gnotice__link", onClick: () => setText(g.notice), children: s.editNotice }),
|
|
4728
|
+
children: [
|
|
4729
|
+
g.notice === "" ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "gkim-empty gkim-gnotice__empty", children: s.emptyNotice }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
|
|
4730
|
+
by !== "" && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "gkim-gnotice__by", children: [
|
|
4731
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Avatar, { id: by, name, url: m?.avatarUrl || void 0, size: 36 }),
|
|
4732
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { children: [
|
|
4733
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "gkim-gnotice__name", children: name }),
|
|
4734
|
+
g.noticeAt !== null && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "gkim-gnotice__time", children: fill(s.noticePublishedAt, { date: ymd2(g.noticeAt, true) }) })
|
|
4735
|
+
] })
|
|
4736
|
+
] }),
|
|
4737
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "gkim-gnotice__text", children: g.notice })
|
|
4738
|
+
] }),
|
|
4739
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { className: "gkim-gnotice__tip", children: s.noticeEditTip })
|
|
4740
|
+
]
|
|
4741
|
+
}
|
|
4742
|
+
);
|
|
4743
|
+
}
|
|
4744
|
+
|
|
4745
|
+
// src/ui/group/SelectFriends.tsx
|
|
4746
|
+
var import_react32 = require("react");
|
|
4747
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
4748
|
+
var MAX3 = 50;
|
|
4749
|
+
var friendName = (f) => f.remark || f.nickname || f.userId;
|
|
4750
|
+
function SelectFriendsDialog({ groupId }) {
|
|
4751
|
+
const { im, me, strings: s } = useImUi();
|
|
4752
|
+
const { toast } = useFeedback();
|
|
4753
|
+
const nav = useNavContext();
|
|
4754
|
+
const frame = useFrame();
|
|
4755
|
+
const friends = useFriends();
|
|
4756
|
+
const invite = groupId !== void 0;
|
|
4757
|
+
const { map } = useMembers(groupId ?? null);
|
|
4758
|
+
const existing = (0, import_react32.useMemo)(() => new Set(invite ? [...map.keys()].map((k) => k.toLowerCase()) : []), [map, invite]);
|
|
4759
|
+
const [picked, setPicked] = (0, import_react32.useState)([]);
|
|
4760
|
+
const [query, setQuery] = (0, import_react32.useState)("");
|
|
4761
|
+
const [busy, setBusy] = (0, import_react32.useState)(false);
|
|
4762
|
+
const inGroup = (f) => existing.has(f.userId.toLowerCase());
|
|
4763
|
+
const isPicked = (f) => picked.some((p) => p.userId === f.userId);
|
|
4764
|
+
const toggle = (f) => {
|
|
4765
|
+
if (inGroup(f)) return;
|
|
4766
|
+
setPicked((list) => list.some((p) => p.userId === f.userId) ? list.filter((p) => p.userId !== f.userId) : list.length < MAX3 ? [...list, f] : list);
|
|
4767
|
+
};
|
|
4768
|
+
const q = query.trim().toLowerCase();
|
|
4769
|
+
const sections = (0, import_react32.useMemo)(() => {
|
|
4770
|
+
const visible = q ? friends.filter((f) => f.remark.toLowerCase().includes(q) || f.nickname.toLowerCase().includes(q)) : friends;
|
|
4771
|
+
return indexSections(visible, friendName, (f) => f.userId);
|
|
4772
|
+
}, [friends, q]);
|
|
4773
|
+
const defaultName = () => {
|
|
4774
|
+
const parts = [...me.nickname ? [me.nickname] : [], ...picked.slice(0, 2).map((f) => f.nickname || f.userId)];
|
|
4775
|
+
return Array.from(parts.join(s.groupNameSeparator)).slice(0, 64).join("");
|
|
4776
|
+
};
|
|
4777
|
+
const done = async () => {
|
|
4778
|
+
const ids = picked.map((f) => f.userId);
|
|
4779
|
+
setBusy(true);
|
|
4780
|
+
try {
|
|
4781
|
+
if (groupId !== void 0) {
|
|
4782
|
+
const r = await im.addGroupMembers(groupId, ids);
|
|
4783
|
+
if (r.skipped.length) toast(fill(s.skippedMembers, { n: r.skipped.length }));
|
|
4784
|
+
frame.close();
|
|
4785
|
+
} else {
|
|
4786
|
+
const r = await im.createGroup({ name: defaultName(), members: ids });
|
|
4787
|
+
if (r.skipped.length) toast(fill(s.skippedMembers, { n: r.skipped.length }));
|
|
4788
|
+
frame.close();
|
|
4789
|
+
nav.open({ name: "chat", target: { group: r.group.groupId } });
|
|
4790
|
+
}
|
|
4791
|
+
} catch (e) {
|
|
4792
|
+
setBusy(false);
|
|
4793
|
+
toast(errorText3(e, s));
|
|
4794
|
+
}
|
|
4795
|
+
};
|
|
4796
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
4797
|
+
Page,
|
|
4798
|
+
{
|
|
4799
|
+
title: invite ? s.inviteToGroup : s.startGroupChat,
|
|
4800
|
+
className: "gkim-selfriends",
|
|
4801
|
+
scroll: false,
|
|
4802
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
|
|
4803
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: "gkim-btn", onClick: frame.close, children: s.cancel }),
|
|
4804
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: "gkim-btn gkim-btn--primary", disabled: !picked.length || busy, onClick: done, children: picked.length ? fill(s.doneWithCount, { n: picked.length }) : s.done })
|
|
4805
|
+
] }),
|
|
4806
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "gkim-selfriends__panes", children: [
|
|
4807
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "gkim-selfriends__left", children: [
|
|
4808
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "gkim-gsearch", children: [
|
|
4809
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Icon, { name: "search", size: 16 }),
|
|
4810
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("input", { type: "search", placeholder: s.searchFriends, "aria-label": s.searchFriends, value: query, onChange: (e) => setQuery(e.target.value) })
|
|
4811
|
+
] }),
|
|
4812
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
4813
|
+
IndexedList,
|
|
4814
|
+
{
|
|
4815
|
+
sections,
|
|
4816
|
+
keyOf: (f) => f.userId,
|
|
4817
|
+
renderItem: (f) => {
|
|
4818
|
+
const disabled = inGroup(f);
|
|
4819
|
+
const name = friendName(f);
|
|
4820
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("label", { className: `gkim-selfriends__row${disabled ? " gkim-selfriends__row--off" : ""}`, children: [
|
|
4821
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("input", { type: "checkbox", checked: disabled || isPicked(f), disabled, onChange: () => toggle(f), "aria-label": name }),
|
|
4822
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Avatar, { id: f.userId, name, url: f.avatarUrl || void 0, size: 36 }),
|
|
4823
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "gkim-selfriends__name", children: name }),
|
|
4824
|
+
disabled && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "gkim-selfriends__in", children: s.alreadyInGroup })
|
|
4825
|
+
] });
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
)
|
|
4829
|
+
] }),
|
|
4830
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "gkim-selfriends__right", children: [
|
|
4831
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "gkim-selfriends__count", children: fill(s.selectedCount, { n: picked.length, max: MAX3 }) }),
|
|
4832
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("ul", { className: "gkim-selfriends__picked", "aria-label": s.selectFriendsTitle, children: picked.map((f) => {
|
|
4833
|
+
const name = friendName(f);
|
|
4834
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("li", { className: "gkim-selfriends__chip", children: [
|
|
4835
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Avatar, { id: f.userId, name, url: f.avatarUrl || void 0, size: 32 }),
|
|
4836
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "gkim-selfriends__name", children: name }),
|
|
4837
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: "gkim-iconbtn gkim-selfriends__x", "aria-label": `${s.removeMember} ${name}`, onClick: () => toggle(f), children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Icon, { name: "close", size: 16 }) })
|
|
4838
|
+
] }, f.userId);
|
|
4839
|
+
}) })
|
|
4840
|
+
] })
|
|
4841
|
+
] })
|
|
4842
|
+
}
|
|
4843
|
+
);
|
|
4844
|
+
}
|
|
4845
|
+
|
|
4846
|
+
// src/ui/group/routes.tsx
|
|
4847
|
+
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
4848
|
+
function renderGroupRoute(route) {
|
|
4849
|
+
switch (route.name) {
|
|
4850
|
+
case "groupChats":
|
|
4851
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(GroupChatsPage, {});
|
|
4852
|
+
case "groupInfo":
|
|
4853
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ImGroupInfo, { groupId: route.groupId }, route.groupId);
|
|
4854
|
+
case "groupMembers":
|
|
4855
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(GroupMembersPage, { groupId: route.groupId }, route.groupId);
|
|
4856
|
+
case "groupNotice":
|
|
4857
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(GroupNoticePage, { groupId: route.groupId }, route.groupId);
|
|
4858
|
+
case "selectFriends":
|
|
4859
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(SelectFriendsDialog, { groupId: route.groupId });
|
|
4860
|
+
default:
|
|
4861
|
+
return void 0;
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
|
|
4865
|
+
// src/ui/privacy/PrivacyPage.tsx
|
|
4866
|
+
var import_react33 = require("react");
|
|
4867
|
+
var import_im9 = require("@guokit-dev/im");
|
|
4868
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
4869
|
+
var PAGE = 50;
|
|
4870
|
+
function errorText4(e, fallback) {
|
|
4871
|
+
return e instanceof import_im9.ImApiError && e.message ? e.message : fallback;
|
|
4872
|
+
}
|
|
4873
|
+
function ymd3(ms) {
|
|
4874
|
+
const d = new Date(ms);
|
|
4875
|
+
return `${d.getFullYear()}/${String(d.getMonth() + 1).padStart(2, "0")}/${String(d.getDate()).padStart(2, "0")}`;
|
|
4876
|
+
}
|
|
4877
|
+
function Blocklist({ onCount }) {
|
|
4878
|
+
const { im, strings: s } = useImUi();
|
|
4879
|
+
const { toast } = useFeedback();
|
|
4880
|
+
const [items, setItems] = (0, import_react33.useState)(null);
|
|
4881
|
+
const [hasMore, setHasMore] = (0, import_react33.useState)(false);
|
|
4882
|
+
const [busy, setBusy] = (0, import_react33.useState)(/* @__PURE__ */ new Set());
|
|
4883
|
+
const loading = (0, import_react33.useRef)(false);
|
|
4884
|
+
const fetchMore = (0, import_react33.useCallback)(async (reset = false) => {
|
|
4885
|
+
if (loading.current) return;
|
|
4886
|
+
loading.current = true;
|
|
4887
|
+
try {
|
|
4888
|
+
const r = await im.blocks({ offset: reset ? 0 : items?.length ?? 0, limit: PAGE });
|
|
4889
|
+
setItems((old) => reset || !old ? r.items : [...old, ...r.items]);
|
|
4890
|
+
setHasMore(r.hasMore);
|
|
4891
|
+
} catch (e) {
|
|
4892
|
+
setItems((old) => old ?? []);
|
|
4893
|
+
toast(errorText4(e, s.operationFailed));
|
|
4894
|
+
} finally {
|
|
4895
|
+
loading.current = false;
|
|
4896
|
+
}
|
|
4897
|
+
}, [im, items, toast, s]);
|
|
4898
|
+
(0, import_react33.useEffect)(() => {
|
|
4899
|
+
fetchMore(true);
|
|
4900
|
+
}, [im]);
|
|
4901
|
+
(0, import_react33.useEffect)(() => {
|
|
4902
|
+
if (items) onCount?.(hasMore ? `${items.length}+` : String(items.length));
|
|
4903
|
+
}, [items, hasMore, onCount]);
|
|
4904
|
+
const unblock = async (b) => {
|
|
4905
|
+
setBusy((x) => new Set(x).add(b.userId));
|
|
4906
|
+
try {
|
|
4907
|
+
await im.unblock(b.userId);
|
|
4908
|
+
setItems((old) => old?.filter((x) => x.userId !== b.userId) ?? null);
|
|
4909
|
+
} catch (e) {
|
|
4910
|
+
toast(errorText4(e, s.operationFailed));
|
|
4911
|
+
} finally {
|
|
4912
|
+
setBusy((x) => {
|
|
4913
|
+
const n = new Set(x);
|
|
4914
|
+
n.delete(b.userId);
|
|
4915
|
+
return n;
|
|
4916
|
+
});
|
|
4917
|
+
}
|
|
4918
|
+
};
|
|
4919
|
+
if (!items) return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "gkim-loading", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) });
|
|
4920
|
+
if (!items.length) return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "gkim-empty gkim-privacy__empty", children: s.emptyBlocklist });
|
|
4921
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
|
|
4922
|
+
"ul",
|
|
4923
|
+
{
|
|
4924
|
+
className: "gkim-blocklist",
|
|
4925
|
+
"aria-label": s.blocklist,
|
|
4926
|
+
onScroll: (e) => {
|
|
4927
|
+
const el = e.currentTarget;
|
|
4928
|
+
if (hasMore && el.scrollHeight - el.scrollTop - el.clientHeight < 200) fetchMore();
|
|
4929
|
+
},
|
|
4930
|
+
children: [
|
|
4931
|
+
items.map((b) => {
|
|
4932
|
+
const name = b.nickname || fill(s.unknownUser, { id: b.userId });
|
|
4933
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("li", { className: "gkim-blocklist__row", children: [
|
|
4934
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Avatar, { id: b.userId, name, url: b.avatarUrl || void 0 }),
|
|
4935
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("span", { className: "gkim-blocklist__body", children: [
|
|
4936
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-blocklist__name", children: name }),
|
|
4937
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-blocklist__date", children: fill(s.blockedAt, { date: ymd3(b.createdAt) }) })
|
|
4938
|
+
] }),
|
|
4939
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
4940
|
+
"button",
|
|
4941
|
+
{
|
|
4942
|
+
type: "button",
|
|
4943
|
+
className: "gkim-btn gkim-btn--sm",
|
|
4944
|
+
disabled: busy.has(b.userId),
|
|
4945
|
+
"aria-label": `${s.unblock} ${name}`,
|
|
4946
|
+
onClick: () => unblock(b),
|
|
4947
|
+
children: s.unblock
|
|
4948
|
+
}
|
|
4949
|
+
)
|
|
4950
|
+
] }, b.userId);
|
|
4951
|
+
}),
|
|
4952
|
+
hasMore && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("li", { className: "gkim-blocklist__more", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("button", { type: "button", className: "gkim-linkbtn", onClick: () => fetchMore(), children: "…" }) })
|
|
4953
|
+
]
|
|
4954
|
+
}
|
|
4955
|
+
);
|
|
4956
|
+
}
|
|
4957
|
+
function ImPrivacy() {
|
|
4958
|
+
const { im, strings: s } = useImUi();
|
|
4959
|
+
const { toast } = useFeedback();
|
|
4960
|
+
const frame = useFrame();
|
|
4961
|
+
const nav = useNavContext();
|
|
4962
|
+
const [policy, setPolicy] = (0, import_react33.useState)(null);
|
|
4963
|
+
const [count, setCount] = (0, import_react33.useState)(null);
|
|
4964
|
+
const inline = frame.kind === "main";
|
|
4965
|
+
(0, import_react33.useEffect)(() => {
|
|
4966
|
+
let live = true;
|
|
4967
|
+
im.features().then((f) => {
|
|
4968
|
+
if (live) setPolicy(f.addPolicy);
|
|
4969
|
+
}, () => {
|
|
4970
|
+
if (live) setPolicy((p) => p ?? 0);
|
|
4971
|
+
});
|
|
4972
|
+
if (!inline) im.blocks({ limit: 100 }).then((r) => {
|
|
4973
|
+
if (live) setCount(r.hasMore ? `${r.items.length}+` : String(r.items.length));
|
|
4974
|
+
}, () => {
|
|
4975
|
+
});
|
|
4976
|
+
return () => {
|
|
4977
|
+
live = false;
|
|
4978
|
+
};
|
|
4979
|
+
}, [im, inline]);
|
|
4980
|
+
const choose = async (p) => {
|
|
4981
|
+
const old = policy;
|
|
4982
|
+
if (p === old) return;
|
|
4983
|
+
setPolicy(p);
|
|
4984
|
+
try {
|
|
4985
|
+
await im.setFriendAddPolicy(p);
|
|
4986
|
+
} catch (e) {
|
|
4987
|
+
setPolicy(old);
|
|
4988
|
+
toast(errorText4(e, s.operationFailed));
|
|
4989
|
+
}
|
|
4990
|
+
};
|
|
4991
|
+
const onCount = (0, import_react33.useCallback)((t) => setCount(t), []);
|
|
4992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Page, { title: s.privacyTitle, className: "gkim-privacy", children: [
|
|
4993
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("section", { className: "gkim-privacy__card", "aria-labelledby": "gkim-privacy-policy", children: [
|
|
4994
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("h3", { id: "gkim-privacy-policy", className: "gkim-privacy__h", children: s.addMeWhen }),
|
|
4995
|
+
policy === null ? /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "gkim-loading", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) }) : /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { role: "radiogroup", "aria-labelledby": "gkim-privacy-policy", className: "gkim-privacy__options", children: s.addPolicyTitles.map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("label", { className: `gkim-privacy__opt${policy === i ? " gkim-privacy__opt--on" : ""}`, children: [
|
|
4996
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("input", { type: "radio", name: "gkim-add-policy", checked: policy === i, onChange: () => choose(i) }),
|
|
4997
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("span", { className: "gkim-privacy__opt-text", children: [
|
|
4998
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-privacy__opt-title", children: t }),
|
|
4999
|
+
s.addPolicyTips[i] && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-privacy__opt-tip", children: s.addPolicyTips[i] })
|
|
5000
|
+
] })
|
|
5001
|
+
] }, i)) })
|
|
5002
|
+
] }),
|
|
5003
|
+
inline ? /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("section", { className: "gkim-privacy__card", "aria-labelledby": "gkim-privacy-block", children: [
|
|
5004
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("h3", { id: "gkim-privacy-block", className: "gkim-privacy__h", children: [
|
|
5005
|
+
s.blocklist,
|
|
5006
|
+
count !== null && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-privacy__count", children: count })
|
|
5007
|
+
] }),
|
|
5008
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("p", { className: "gkim-privacy__tip", children: s.blocklistTip }),
|
|
5009
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Blocklist, { onCount })
|
|
5010
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("section", { className: "gkim-privacy__card gkim-privacy__card--row", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("button", { type: "button", className: "gkim-row", onClick: () => nav.open({ name: "blocklist" }), children: [
|
|
5011
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-grow", children: s.blocklist }),
|
|
5012
|
+
count !== null && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("span", { className: "gkim-row__value", children: fill(s.peopleCount, { n: count }) }),
|
|
5013
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Icon, { name: "chevron", size: 16 })
|
|
5014
|
+
] }) })
|
|
5015
|
+
] });
|
|
5016
|
+
}
|
|
5017
|
+
function BlocklistPage() {
|
|
5018
|
+
const s = useImUi().strings;
|
|
5019
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Page, { title: s.blocklist, className: "gkim-privacy", children: [
|
|
5020
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("p", { className: "gkim-privacy__tip gkim-privacy__tip--page", children: s.blocklistTip }),
|
|
5021
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Blocklist, {})
|
|
5022
|
+
] });
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
// src/ui/privacy/routes.tsx
|
|
5026
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
5027
|
+
function renderPrivacyRoute(route) {
|
|
5028
|
+
switch (route.name) {
|
|
5029
|
+
case "privacy":
|
|
5030
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(ImPrivacy, {});
|
|
5031
|
+
case "blocklist":
|
|
5032
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BlocklistPage, {});
|
|
5033
|
+
default:
|
|
5034
|
+
return void 0;
|
|
5035
|
+
}
|
|
5036
|
+
}
|
|
5037
|
+
|
|
5038
|
+
// src/ui/routes.tsx
|
|
5039
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
5040
|
+
function renderRoute(route) {
|
|
5041
|
+
switch (route.name) {
|
|
5042
|
+
case "conversations":
|
|
5043
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ImConversationList, {});
|
|
5044
|
+
case "chat": {
|
|
5045
|
+
const t = route.target;
|
|
5046
|
+
if (t.conversation) return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ImChat, { conversation: t.conversation }, `c${t.conversation.id}`);
|
|
5047
|
+
if (t.group) return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ImChat, { group: t.group }, `g${t.group}`);
|
|
5048
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ImChat, { peer: t.peer }, `p${t.peer}`);
|
|
5049
|
+
}
|
|
5050
|
+
case "report":
|
|
5051
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ReportDialog, { target: route.target, title: route.title, messageIds: route.messageIds });
|
|
5052
|
+
case "imageViewer":
|
|
5053
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ImageViewer, { images: route.images, index: route.index });
|
|
5054
|
+
case "videoPlayer":
|
|
5055
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(VideoPlayer, { message: route.message });
|
|
5056
|
+
default:
|
|
5057
|
+
return renderContactsRoute(route) ?? renderGroupRoute(route) ?? renderPrivacyRoute(route) ?? null;
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
// src/ui/layout/Layers.tsx
|
|
5062
|
+
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
5063
|
+
function escToBack(back) {
|
|
5064
|
+
return (e) => {
|
|
5065
|
+
if (e.key === "Escape") {
|
|
5066
|
+
e.stopPropagation();
|
|
5067
|
+
back();
|
|
5068
|
+
}
|
|
5069
|
+
};
|
|
5070
|
+
}
|
|
5071
|
+
function FrameBox({ frame, children }) {
|
|
5072
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(FrameContext.Provider, { value: frame, children });
|
|
5073
|
+
}
|
|
5074
|
+
function DrawerLayer({ stack, back, close }) {
|
|
5075
|
+
const ref = useFocusTrap(stack.length > 0);
|
|
5076
|
+
if (!stack.length) return null;
|
|
5077
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "gkim-drawer-layer", children: [
|
|
5078
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "gkim-scrim", onClick: close }),
|
|
5079
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("aside", { className: "gkim-drawer", ref, tabIndex: -1, onKeyDown: escToBack(back), children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "gkim-stack-item", hidden: i !== stack.length - 1, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(FrameBox, { frame: { kind: "drawer", canBack: i > 0, back, close }, children: renderRoute(r) }) }, i)) })
|
|
5080
|
+
] });
|
|
5081
|
+
}
|
|
5082
|
+
function DialogBox({ children, back }) {
|
|
2947
5083
|
const ref = useFocusTrap();
|
|
2948
|
-
return /* @__PURE__ */ (0,
|
|
2949
|
-
/* @__PURE__ */ (0,
|
|
2950
|
-
/* @__PURE__ */ (0,
|
|
5084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "gkim-dialog-layer", onKeyDown: escToBack(back), children: [
|
|
5085
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "gkim-scrim", onClick: back }),
|
|
5086
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "gkim-dialog", ref, tabIndex: -1, children })
|
|
2951
5087
|
] });
|
|
2952
5088
|
}
|
|
2953
5089
|
function DialogLayer({ stack, back }) {
|
|
2954
|
-
return /* @__PURE__ */ (0,
|
|
5090
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_jsx_runtime35.Fragment, { children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DialogBox, { back, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2955
5091
|
}
|
|
2956
5092
|
function OverlayBox({ children, back }) {
|
|
2957
5093
|
const ref = useFocusTrap();
|
|
2958
|
-
return /* @__PURE__ */ (0,
|
|
5094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "gkim-overlay", ref, tabIndex: -1, onKeyDown: escToBack(back), children });
|
|
2959
5095
|
}
|
|
2960
5096
|
function OverlayLayer({ stack, back }) {
|
|
2961
|
-
return /* @__PURE__ */ (0,
|
|
5097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_jsx_runtime35.Fragment, { children: stack.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(OverlayBox, { back, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2962
5098
|
}
|
|
2963
5099
|
function LayerHost() {
|
|
2964
5100
|
const { state: st, back, close } = useNavContext();
|
|
2965
|
-
return (0,
|
|
2966
|
-
/* @__PURE__ */ (0,
|
|
2967
|
-
/* @__PURE__ */ (0,
|
|
2968
|
-
/* @__PURE__ */ (0,
|
|
5101
|
+
return (0, import_react34.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
|
5102
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DrawerLayer, { stack: st.drawer, back, close }),
|
|
5103
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DialogLayer, { stack: st.dialog, back }),
|
|
5104
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
2969
5105
|
] }), [st, back, close]);
|
|
2970
5106
|
}
|
|
2971
5107
|
|
|
2972
5108
|
// src/ui/context.tsx
|
|
2973
|
-
var
|
|
2974
|
-
var UiContext = (0,
|
|
5109
|
+
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
5110
|
+
var UiContext = (0, import_react35.createContext)(null);
|
|
2975
5111
|
var EMPTY2 = {};
|
|
2976
5112
|
var NO_ITEMS = [];
|
|
2977
5113
|
function chatTargetOf(t) {
|
|
@@ -2982,9 +5118,9 @@ function chatTargetOf(t) {
|
|
|
2982
5118
|
}
|
|
2983
5119
|
function GuokitImUi(props) {
|
|
2984
5120
|
const { im, me, theme, strings, callbacks, messageRenderers, moreItems, menuItems, className, style, children } = props;
|
|
2985
|
-
const merged = (0,
|
|
5121
|
+
const merged = (0, import_react35.useMemo)(() => mergeStrings(strings), [strings]);
|
|
2986
5122
|
const cb = callbacks ?? EMPTY2;
|
|
2987
|
-
const value = (0,
|
|
5123
|
+
const value = (0, import_react35.useMemo)(() => ({
|
|
2988
5124
|
im,
|
|
2989
5125
|
me: me ?? EMPTY2,
|
|
2990
5126
|
strings: merged,
|
|
@@ -2993,20 +5129,20 @@ function GuokitImUi(props) {
|
|
|
2993
5129
|
moreItems: moreItems ?? NO_ITEMS,
|
|
2994
5130
|
menuItems
|
|
2995
5131
|
}), [im, me, merged, cb, messageRenderers, moreItems, menuItems]);
|
|
2996
|
-
const cbRef = (0,
|
|
5132
|
+
const cbRef = (0, import_react35.useRef)(cb);
|
|
2997
5133
|
cbRef.current = cb;
|
|
2998
|
-
(0,
|
|
2999
|
-
const onMainOrList = (0,
|
|
5134
|
+
(0, import_react35.useEffect)(() => im.on("kickedOut", () => cbRef.current.onKickedOut?.()), [im]);
|
|
5135
|
+
const onMainOrList = (0, import_react35.useCallback)((r) => {
|
|
3000
5136
|
if (r.name === "chat") cbRef.current.onOpenConversation?.(chatTargetOf(r.target));
|
|
3001
5137
|
}, []);
|
|
3002
5138
|
const nav = useNavState(false, onMainOrList);
|
|
3003
|
-
return /* @__PURE__ */ (0,
|
|
5139
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(UiContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(NavContext.Provider, { value: nav, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: className ? `gkim-root ${className}` : "gkim-root", style: { ...themeVars(theme), ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(FeedbackProvider, { labels: { ok: merged.confirm, cancel: merged.cancel }, children: [
|
|
3004
5140
|
children,
|
|
3005
|
-
/* @__PURE__ */ (0,
|
|
5141
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(LayerHost, {})
|
|
3006
5142
|
] }) }) }) });
|
|
3007
5143
|
}
|
|
3008
5144
|
function useImUi() {
|
|
3009
|
-
const v = (0,
|
|
5145
|
+
const v = (0, import_react35.useContext)(UiContext);
|
|
3010
5146
|
if (!v) throw new Error("没有找到 GuokitImUi:IM 组件要放在 GuokitImUi 下面。");
|
|
3011
5147
|
return v;
|
|
3012
5148
|
}
|
|
@@ -3015,14 +5151,14 @@ function useIm() {
|
|
|
3015
5151
|
}
|
|
3016
5152
|
|
|
3017
5153
|
// src/ui/layout/ImWorkspace.tsx
|
|
3018
|
-
var
|
|
5154
|
+
var import_react37 = require("react");
|
|
3019
5155
|
|
|
3020
5156
|
// src/ui/layout/useWide.ts
|
|
3021
|
-
var
|
|
5157
|
+
var import_react36 = require("react");
|
|
3022
5158
|
var WIDE_MIN = 768;
|
|
3023
5159
|
function useWide(ref) {
|
|
3024
|
-
const [wide, setWide] = (0,
|
|
3025
|
-
(0,
|
|
5160
|
+
const [wide, setWide] = (0, import_react36.useState)(true);
|
|
5161
|
+
(0, import_react36.useLayoutEffect)(() => {
|
|
3026
5162
|
const el = ref.current;
|
|
3027
5163
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
3028
5164
|
const ro = new ResizeObserver((entries) => {
|
|
@@ -3036,33 +5172,78 @@ function useWide(ref) {
|
|
|
3036
5172
|
}
|
|
3037
5173
|
|
|
3038
5174
|
// src/ui/layout/ImWorkspace.tsx
|
|
3039
|
-
var
|
|
3040
|
-
function
|
|
3041
|
-
|
|
5175
|
+
var import_jsx_runtime37 = require("react/jsx-runtime");
|
|
5176
|
+
function currentTab(st) {
|
|
5177
|
+
if (st.main?.name === "privacy" || st.main?.name === "blocklist") return "privacy";
|
|
5178
|
+
return st.list.name === "contacts" ? "contacts" : "messages";
|
|
5179
|
+
}
|
|
5180
|
+
function useTabs(nav) {
|
|
5181
|
+
const { strings: s } = useImUi();
|
|
3042
5182
|
const unread = useTotalUnread();
|
|
5183
|
+
const cur = currentTab(nav.state);
|
|
5184
|
+
const go = (t) => {
|
|
5185
|
+
if (t === "messages") nav.open({ name: "conversations" });
|
|
5186
|
+
else if (t === "contacts") nav.open({ name: "contacts" });
|
|
5187
|
+
else nav.open({ name: "privacy" });
|
|
5188
|
+
};
|
|
5189
|
+
return [
|
|
5190
|
+
{ key: "messages", label: s.navMessages, icon: "message", badge: unread },
|
|
5191
|
+
{ key: "contacts", label: s.contactsTitle, icon: "contacts", badge: 0 },
|
|
5192
|
+
{ key: "privacy", label: s.privacyTitle, icon: "shield", badge: 0 }
|
|
5193
|
+
].map((t) => ({ ...t, current: t.key === cur, onClick: () => go(t.key) }));
|
|
5194
|
+
}
|
|
5195
|
+
function Rail({ nav }) {
|
|
5196
|
+
const { im, me } = useImUi();
|
|
5197
|
+
const tabs = useTabs(nav);
|
|
3043
5198
|
const uid = im.currentUserId ?? "";
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
5199
|
+
const item = (t) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
|
|
5200
|
+
"button",
|
|
5201
|
+
{
|
|
5202
|
+
type: "button",
|
|
5203
|
+
className: "gkim-rail__item",
|
|
5204
|
+
"aria-label": t.label,
|
|
5205
|
+
title: t.label,
|
|
5206
|
+
"aria-current": t.current ? "page" : void 0,
|
|
5207
|
+
onClick: t.onClick,
|
|
5208
|
+
children: [
|
|
5209
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Icon, { name: t.icon, size: 22 }),
|
|
5210
|
+
t.badge > 0 && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Badge, { count: t.badge })
|
|
5211
|
+
]
|
|
5212
|
+
},
|
|
5213
|
+
t.key
|
|
5214
|
+
);
|
|
5215
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("nav", { className: "gkim-rail", "aria-label": "IM", children: [
|
|
5216
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Avatar, { id: uid, name: me.nickname ?? "", url: me.avatarUrl, size: 36 }),
|
|
5217
|
+
item(tabs[0]),
|
|
5218
|
+
item(tabs[1]),
|
|
5219
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "gkim-grow" }),
|
|
5220
|
+
item(tabs[2])
|
|
3050
5221
|
] });
|
|
3051
5222
|
}
|
|
5223
|
+
function TabBar({ nav }) {
|
|
5224
|
+
const tabs = useTabs(nav);
|
|
5225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "gkim-tabbar", role: "tablist", "aria-label": "IM", children: tabs.map((t) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("button", { type: "button", role: "tab", "aria-selected": t.current, className: "gkim-tabbar__item", onClick: t.onClick, children: [
|
|
5226
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("span", { className: "gkim-tabbar__icon", children: [
|
|
5227
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Icon, { name: t.icon, size: 22 }),
|
|
5228
|
+
t.badge > 0 && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Badge, { count: t.badge })
|
|
5229
|
+
] }),
|
|
5230
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { children: t.label })
|
|
5231
|
+
] }, t.key)) });
|
|
5232
|
+
}
|
|
3052
5233
|
function Wide({ nav }) {
|
|
3053
5234
|
const { state: st, back, close } = nav;
|
|
3054
5235
|
const { strings: s } = useImUi();
|
|
3055
5236
|
const noop2 = () => {
|
|
3056
5237
|
};
|
|
3057
|
-
return /* @__PURE__ */ (0,
|
|
3058
|
-
/* @__PURE__ */ (0,
|
|
3059
|
-
/* @__PURE__ */ (0,
|
|
3060
|
-
/* @__PURE__ */ (0,
|
|
3061
|
-
st.main ? /* @__PURE__ */ (0,
|
|
3062
|
-
/* @__PURE__ */ (0,
|
|
5238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_jsx_runtime37.Fragment, { children: [
|
|
5239
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Rail, { nav }),
|
|
5240
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: `gkim-listcol${st.main?.name === "privacy" || st.main?.name === "blocklist" ? " gkim-listcol--hidden" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(FrameContext.Provider, { value: { kind: "list", canBack: false, back: noop2, close: noop2 }, children: renderRoute(st.list) }) }),
|
|
5241
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "gkim-main", children: [
|
|
5242
|
+
st.main ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(FrameContext.Provider, { value: { kind: "main", canBack: false, back, close }, children: renderRoute(st.main) }) : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "gkim-empty gkim-main__empty", children: s.selectConversation }),
|
|
5243
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(DrawerLayer, { stack: st.drawer, back, close })
|
|
3063
5244
|
] }),
|
|
3064
|
-
/* @__PURE__ */ (0,
|
|
3065
|
-
/* @__PURE__ */ (0,
|
|
5245
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(DialogLayer, { stack: st.dialog, back }),
|
|
5246
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
3066
5247
|
] });
|
|
3067
5248
|
}
|
|
3068
5249
|
function Narrow({ nav }) {
|
|
@@ -3073,23 +5254,26 @@ function Narrow({ nav }) {
|
|
|
3073
5254
|
...st.drawer.map((route, i) => ({ key: `d${i}`, route })),
|
|
3074
5255
|
...st.dialog.map((route, i) => ({ key: `g${i}`, route }))
|
|
3075
5256
|
];
|
|
3076
|
-
return /* @__PURE__ */ (0,
|
|
3077
|
-
pages.map((p, i) => /* @__PURE__ */ (0,
|
|
3078
|
-
|
|
5257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_jsx_runtime37.Fragment, { children: [
|
|
5258
|
+
pages.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "gkim-stack-item gkim-narrow-page", hidden: i !== pages.length - 1, children: [
|
|
5259
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(FrameContext.Provider, { value: { kind: "page", canBack: i > 0, back, close: back }, children: renderRoute(p.route) }),
|
|
5260
|
+
i === 0 && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(TabBar, { nav })
|
|
5261
|
+
] }, p.key)),
|
|
5262
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(OverlayLayer, { stack: st.overlay, back })
|
|
3079
5263
|
] });
|
|
3080
5264
|
}
|
|
3081
5265
|
function ImWorkspace({ className }) {
|
|
3082
|
-
const ref = (0,
|
|
5266
|
+
const ref = (0, import_react37.useRef)(null);
|
|
3083
5267
|
const wide = useWide(ref);
|
|
3084
5268
|
const { callbacks } = useImUi();
|
|
3085
5269
|
const nav = useNavState(true);
|
|
3086
|
-
const onNavigate = (0,
|
|
5270
|
+
const onNavigate = (0, import_react37.useRef)(callbacks.onNavigate);
|
|
3087
5271
|
onNavigate.current = callbacks.onNavigate;
|
|
3088
|
-
const last = (0,
|
|
3089
|
-
(0,
|
|
5272
|
+
const last = (0, import_react37.useRef)(nav.state);
|
|
5273
|
+
(0, import_react37.useEffect)(() => {
|
|
3090
5274
|
if (last.current === nav.state) return;
|
|
3091
5275
|
last.current = nav.state;
|
|
3092
5276
|
onNavigate.current?.(topRoute(nav.state));
|
|
3093
5277
|
}, [nav.state]);
|
|
3094
|
-
return /* @__PURE__ */ (0,
|
|
5278
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(NavContext.Provider, { value: nav, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { ref, className: `gkim-workspace gkim-workspace--${wide ? "wide" : "narrow"}${className ? " " + className : ""}`, children: wide ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Wide, { nav }) : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Narrow, { nav }) }) });
|
|
3095
5279
|
}
|