@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.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
// src/ui/context.tsx
|
|
4
|
-
import { createContext as createContext4, useCallback as
|
|
4
|
+
import { createContext as createContext4, useCallback as useCallback12, useContext as useContext4, useEffect as useEffect15, useMemo as useMemo11, useRef as useRef14 } from "react";
|
|
5
5
|
|
|
6
6
|
// src/core/strings.ts
|
|
7
7
|
var defaultStrings = {
|
|
@@ -202,6 +202,9 @@ var defaultStrings = {
|
|
|
202
202
|
// B 期:选择好友
|
|
203
203
|
selectFriendsTitle: "选择好友",
|
|
204
204
|
doneWithCount: "完成({n})",
|
|
205
|
+
selectedCount: "已选 {n} 人 · 最多 {max} 人",
|
|
206
|
+
notFriendYet: "还不是好友",
|
|
207
|
+
add: "添加",
|
|
205
208
|
searchFriends: "搜索好友",
|
|
206
209
|
alreadyInGroup: "已在群里",
|
|
207
210
|
inviteToGroup: "邀请进群",
|
|
@@ -294,14 +297,31 @@ var routePlacement = {
|
|
|
294
297
|
chat: "main",
|
|
295
298
|
report: "dialog",
|
|
296
299
|
imageViewer: "overlay",
|
|
297
|
-
videoPlayer: "overlay"
|
|
300
|
+
videoPlayer: "overlay",
|
|
301
|
+
contacts: "list",
|
|
302
|
+
contactProfile: "main",
|
|
303
|
+
newFriends: "main",
|
|
304
|
+
groupChats: "main",
|
|
305
|
+
privacy: "main",
|
|
306
|
+
blocklist: "main",
|
|
307
|
+
userCard: "drawer",
|
|
308
|
+
friendSettings: "drawer",
|
|
309
|
+
friendGroups: "drawer",
|
|
310
|
+
groupInfo: "drawer",
|
|
311
|
+
groupMembers: "drawer",
|
|
312
|
+
groupNotice: "drawer",
|
|
313
|
+
addFriend: "dialog",
|
|
314
|
+
selectFriends: "dialog"
|
|
298
315
|
};
|
|
299
316
|
var initialNav = { list: { name: "conversations" }, main: null, drawer: [], dialog: [], overlay: [] };
|
|
300
317
|
function navReducer(s, a) {
|
|
301
318
|
switch (a.type) {
|
|
302
319
|
case "open": {
|
|
303
|
-
const p = routePlacement[a.route.name];
|
|
304
|
-
if (p === "list")
|
|
320
|
+
const p = a.as ?? routePlacement[a.route.name];
|
|
321
|
+
if (p === "list") {
|
|
322
|
+
const leave = a.route.name !== s.list.name || s.main?.name === "privacy" || s.main?.name === "blocklist";
|
|
323
|
+
return { ...s, list: a.route, main: leave ? null : s.main, drawer: [], dialog: [] };
|
|
324
|
+
}
|
|
305
325
|
if (p === "main") return { ...s, main: a.route, drawer: [], dialog: [] };
|
|
306
326
|
if (p === "drawer") return { ...s, drawer: [...s.drawer, a.route] };
|
|
307
327
|
if (p === "dialog") return { ...s, dialog: [...s.dialog, a.route] };
|
|
@@ -326,7 +346,9 @@ function useNavState(workspace, onMainOrList) {
|
|
|
326
346
|
const open = useCallback((route) => {
|
|
327
347
|
const p = routePlacement[route.name];
|
|
328
348
|
if (!workspace && (p === "main" || p === "list")) {
|
|
329
|
-
|
|
349
|
+
if (route.name === "contactProfile") dispatch({ type: "open", route: { name: "userCard", userId: route.userId } });
|
|
350
|
+
else if (p === "main" && route.name !== "chat") dispatch({ type: "open", route, as: "drawer" });
|
|
351
|
+
else onMainOrList?.(route);
|
|
330
352
|
return;
|
|
331
353
|
}
|
|
332
354
|
dispatch({ type: "open", route });
|
|
@@ -365,11 +387,11 @@ function themeVars(t) {
|
|
|
365
387
|
}
|
|
366
388
|
|
|
367
389
|
// src/ui/layout/Layers.tsx
|
|
368
|
-
import { useMemo as
|
|
390
|
+
import { useMemo as useMemo10 } from "react";
|
|
369
391
|
|
|
370
392
|
// src/ui/chat/ChatPage.tsx
|
|
371
|
-
import { useCallback as
|
|
372
|
-
import { ImApiError } from "@guokit-dev/im";
|
|
393
|
+
import { useCallback as useCallback7, useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7, useState as useState7, useSyncExternalStore } from "react";
|
|
394
|
+
import { ImApiError as ImApiError2 } from "@guokit-dev/im";
|
|
373
395
|
|
|
374
396
|
// src/core/externalStore.ts
|
|
375
397
|
var ListenerSet = class {
|
|
@@ -1053,6 +1075,126 @@ function useFeedback() {
|
|
|
1053
1075
|
return v;
|
|
1054
1076
|
}
|
|
1055
1077
|
|
|
1078
|
+
// src/ui/contacts/shared.ts
|
|
1079
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useState as useState2 } from "react";
|
|
1080
|
+
import { ImApiError } from "@guokit-dev/im";
|
|
1081
|
+
function friendDisplayName(f) {
|
|
1082
|
+
return f.remark !== "" ? f.remark : f.nickname !== "" ? f.nickname : f.userId;
|
|
1083
|
+
}
|
|
1084
|
+
function errorText(e, fallback) {
|
|
1085
|
+
return e instanceof ImApiError && e.message ? e.message : fallback;
|
|
1086
|
+
}
|
|
1087
|
+
function ymd(ms) {
|
|
1088
|
+
const d = new Date(ms);
|
|
1089
|
+
return `${d.getFullYear()}/${String(d.getMonth() + 1).padStart(2, "0")}/${String(d.getDate()).padStart(2, "0")}`;
|
|
1090
|
+
}
|
|
1091
|
+
function safe(f, fallback) {
|
|
1092
|
+
try {
|
|
1093
|
+
return f();
|
|
1094
|
+
} catch {
|
|
1095
|
+
return fallback;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
var hints = /* @__PURE__ */ new WeakMap();
|
|
1099
|
+
function rememberUser(im, userId, hint) {
|
|
1100
|
+
let m = hints.get(im);
|
|
1101
|
+
if (!m) hints.set(im, m = /* @__PURE__ */ new Map());
|
|
1102
|
+
const old = m.get(userId);
|
|
1103
|
+
m.set(userId, { nickname: hint.nickname || old?.nickname || "", avatarUrl: hint.avatarUrl || old?.avatarUrl || "" });
|
|
1104
|
+
}
|
|
1105
|
+
function userHint(im, userId) {
|
|
1106
|
+
const h = hints.get(im)?.get(userId);
|
|
1107
|
+
if (h) return h;
|
|
1108
|
+
const p = safe(() => im.conversationWith(userId), null)?.peer;
|
|
1109
|
+
return { nickname: p?.nickname ?? "", avatarUrl: p?.avatarUrl ?? "" };
|
|
1110
|
+
}
|
|
1111
|
+
function openUserCard(ctx, userId, hint, route = "userCard") {
|
|
1112
|
+
if (userId === ctx.im.currentUserId) return;
|
|
1113
|
+
if (hint) rememberUser(ctx.im, userId, hint);
|
|
1114
|
+
if (ctx.callbacks.onAvatarTap) {
|
|
1115
|
+
ctx.callbacks.onAvatarTap(userId);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
ctx.nav.open({ name: route, userId });
|
|
1119
|
+
}
|
|
1120
|
+
var buses = /* @__PURE__ */ new WeakMap();
|
|
1121
|
+
function listeners(im, ch) {
|
|
1122
|
+
let m = buses.get(im);
|
|
1123
|
+
if (!m) buses.set(im, m = /* @__PURE__ */ new Map());
|
|
1124
|
+
let s = m.get(ch);
|
|
1125
|
+
if (!s) m.set(ch, s = /* @__PURE__ */ new Set());
|
|
1126
|
+
return s;
|
|
1127
|
+
}
|
|
1128
|
+
function notifyContacts(im, ch) {
|
|
1129
|
+
for (const f of [...listeners(im, ch)]) f();
|
|
1130
|
+
}
|
|
1131
|
+
function onContacts(im, ch, f) {
|
|
1132
|
+
const s = listeners(im, ch);
|
|
1133
|
+
s.add(f);
|
|
1134
|
+
return () => {
|
|
1135
|
+
s.delete(f);
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function sortGroups(g) {
|
|
1139
|
+
return [...g].sort((a, b) => a.sort - b.sort || a.id - b.id);
|
|
1140
|
+
}
|
|
1141
|
+
function useFriendGroups(im) {
|
|
1142
|
+
const [groups, setGroups] = useState2(null);
|
|
1143
|
+
const load = useCallback3(async () => {
|
|
1144
|
+
try {
|
|
1145
|
+
const g = await im.friendGroups();
|
|
1146
|
+
setGroups(sortGroups(g));
|
|
1147
|
+
} catch {
|
|
1148
|
+
setGroups((old) => old ?? []);
|
|
1149
|
+
}
|
|
1150
|
+
}, [im]);
|
|
1151
|
+
useEffect2(() => {
|
|
1152
|
+
if (im.currentUserId === null) {
|
|
1153
|
+
setGroups([]);
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
void load();
|
|
1157
|
+
const off1 = im.on("friendGroupsChanged", () => {
|
|
1158
|
+
void load();
|
|
1159
|
+
});
|
|
1160
|
+
const off2 = onContacts(im, "groups", () => {
|
|
1161
|
+
void load();
|
|
1162
|
+
});
|
|
1163
|
+
return () => {
|
|
1164
|
+
off1();
|
|
1165
|
+
off2();
|
|
1166
|
+
};
|
|
1167
|
+
}, [im, load]);
|
|
1168
|
+
return [groups, load];
|
|
1169
|
+
}
|
|
1170
|
+
function usePendingCount(im) {
|
|
1171
|
+
const [n, setN] = useState2(0);
|
|
1172
|
+
useEffect2(() => {
|
|
1173
|
+
if (im.currentUserId === null) return;
|
|
1174
|
+
let alive = true;
|
|
1175
|
+
const load = async () => {
|
|
1176
|
+
try {
|
|
1177
|
+
const r = await im.friendRequests("in", { limit: 50 });
|
|
1178
|
+
if (alive) setN(r.items.filter((x) => x.status === "pending").length);
|
|
1179
|
+
} catch {
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
void load();
|
|
1183
|
+
const off1 = im.on("friendRequest", () => {
|
|
1184
|
+
void load();
|
|
1185
|
+
});
|
|
1186
|
+
const off2 = onContacts(im, "pending", () => {
|
|
1187
|
+
void load();
|
|
1188
|
+
});
|
|
1189
|
+
return () => {
|
|
1190
|
+
alive = false;
|
|
1191
|
+
off1();
|
|
1192
|
+
off2();
|
|
1193
|
+
};
|
|
1194
|
+
}, [im]);
|
|
1195
|
+
return n;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1056
1198
|
// src/ui/widgets/Icon.tsx
|
|
1057
1199
|
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1058
1200
|
var PATHS = {
|
|
@@ -1135,7 +1277,36 @@ var PATHS = {
|
|
|
1135
1277
|
/* @__PURE__ */ jsx2("path", { d: "M18 8a6 6 0 0 0-9.3-5" }),
|
|
1136
1278
|
/* @__PURE__ */ jsx2("path", { d: "M6.3 6.3A6 6 0 0 0 6 8c0 7-3 9-3 9h14" }),
|
|
1137
1279
|
/* @__PURE__ */ jsx2("path", { d: "M3 3l18 18" })
|
|
1138
|
-
] })
|
|
1280
|
+
] }),
|
|
1281
|
+
add: /* @__PURE__ */ jsx2("path", { d: "M12 5v14M5 12h14" }),
|
|
1282
|
+
userPlus: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1283
|
+
/* @__PURE__ */ jsx2("circle", { cx: "9", cy: "8", r: "3.5" }),
|
|
1284
|
+
/* @__PURE__ */ jsx2("path", { d: "M2.5 20a6.5 6.5 0 0 1 13 0" }),
|
|
1285
|
+
/* @__PURE__ */ jsx2("path", { d: "M19 8v6M16 11h6" })
|
|
1286
|
+
] }),
|
|
1287
|
+
chatPlus: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1288
|
+
/* @__PURE__ */ jsx2("path", { d: "M4 5h16v11H9l-5 4z" }),
|
|
1289
|
+
/* @__PURE__ */ jsx2("path", { d: "M12 8v5M9.5 10.5h5" })
|
|
1290
|
+
] }),
|
|
1291
|
+
contacts: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1292
|
+
/* @__PURE__ */ jsx2("circle", { cx: "9", cy: "8", r: "3.5" }),
|
|
1293
|
+
/* @__PURE__ */ jsx2("path", { d: "M2.5 20a6.5 6.5 0 0 1 13 0" }),
|
|
1294
|
+
/* @__PURE__ */ jsx2("path", { d: "M16 4.5a3.5 3.5 0 0 1 0 7" }),
|
|
1295
|
+
/* @__PURE__ */ jsx2("path", { d: "M18 14a6 6 0 0 1 3.5 6" })
|
|
1296
|
+
] }),
|
|
1297
|
+
shield: /* @__PURE__ */ jsx2("path", { d: "M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6z" }),
|
|
1298
|
+
search: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1299
|
+
/* @__PURE__ */ jsx2("circle", { cx: "11", cy: "11", r: "7" }),
|
|
1300
|
+
/* @__PURE__ */ jsx2("path", { d: "M20 20l-4-4" })
|
|
1301
|
+
] }),
|
|
1302
|
+
edit: /* @__PURE__ */ jsx2("path", { d: "M4 20h4L19 9l-4-4L4 16z" }),
|
|
1303
|
+
grip: /* @__PURE__ */ jsx2("path", { d: "M5 8h14M5 12h14M5 16h14" }),
|
|
1304
|
+
minus: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1305
|
+
/* @__PURE__ */ jsx2("circle", { cx: "12", cy: "12", r: "9.5" }),
|
|
1306
|
+
/* @__PURE__ */ jsx2("path", { d: "M8 12h8" })
|
|
1307
|
+
] }),
|
|
1308
|
+
chevron: /* @__PURE__ */ jsx2("path", { d: "M9 5l7 7-7 7" }),
|
|
1309
|
+
minusLine: /* @__PURE__ */ jsx2("path", { d: "M5 12h14" })
|
|
1139
1310
|
};
|
|
1140
1311
|
function Icon({ name, size = 20 }) {
|
|
1141
1312
|
return /* @__PURE__ */ jsx2(
|
|
@@ -1200,7 +1371,7 @@ function Page({ title, actions, banner, footer, children, className, scroll = tr
|
|
|
1200
1371
|
}
|
|
1201
1372
|
|
|
1202
1373
|
// src/ui/chat/Composer.tsx
|
|
1203
|
-
import { forwardRef, useCallback as
|
|
1374
|
+
import { forwardRef, useCallback as useCallback5, useEffect as useEffect4, useImperativeHandle, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef4, useState as useState5 } from "react";
|
|
1204
1375
|
|
|
1205
1376
|
// src/core/mention.ts
|
|
1206
1377
|
var mentionToken = (m) => `@${m.name} `;
|
|
@@ -1270,7 +1441,7 @@ _MentionEditing.maxAt = 20;
|
|
|
1270
1441
|
var MentionEditing = _MentionEditing;
|
|
1271
1442
|
|
|
1272
1443
|
// src/ui/widgets/Avatar.tsx
|
|
1273
|
-
import { useState as
|
|
1444
|
+
import { useState as useState3 } from "react";
|
|
1274
1445
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1275
1446
|
var PALETTE = ["#0F766E", "#B45309", "#7C3AED", "#BE185D", "#4D7C0F", "#0369A1", "#9A3412", "#475569"];
|
|
1276
1447
|
function avatarColor(id) {
|
|
@@ -1284,7 +1455,7 @@ function avatarInitial(name, id) {
|
|
|
1284
1455
|
return String.fromCodePoint(s.codePointAt(0)).toUpperCase();
|
|
1285
1456
|
}
|
|
1286
1457
|
function Avatar({ id, name, url, size, group, onClick }) {
|
|
1287
|
-
const [broken, setBroken] =
|
|
1458
|
+
const [broken, setBroken] = useState3(null);
|
|
1288
1459
|
const label = name || id;
|
|
1289
1460
|
const style = size ? { ["--gkim-av"]: `${size}px` } : void 0;
|
|
1290
1461
|
const cls = `gkim-avatar${group ? " gkim-avatar--group" : ""}`;
|
|
@@ -1296,13 +1467,14 @@ function Avatar({ id, name, url, size, group, onClick }) {
|
|
|
1296
1467
|
}
|
|
1297
1468
|
|
|
1298
1469
|
// src/ui/widgets/Menu.tsx
|
|
1299
|
-
import { useCallback as
|
|
1470
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useLayoutEffect, useRef as useRef3, useState as useState4 } from "react";
|
|
1300
1471
|
import { createPortal } from "react-dom";
|
|
1301
1472
|
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1302
1473
|
function Menu({ entries, x, y, onClose, label }) {
|
|
1303
1474
|
const ref = useRef3(null);
|
|
1304
|
-
const [pos, setPos] =
|
|
1305
|
-
const [sub, setSub] =
|
|
1475
|
+
const [pos, setPos] = useState4({ left: x, top: y });
|
|
1476
|
+
const [sub, setSub] = useState4(null);
|
|
1477
|
+
const [subLeft, setSubLeft] = useState4(false);
|
|
1306
1478
|
useLayoutEffect(() => {
|
|
1307
1479
|
const el = ref.current;
|
|
1308
1480
|
if (!el) return;
|
|
@@ -1310,7 +1482,13 @@ function Menu({ entries, x, y, onClose, label }) {
|
|
|
1310
1482
|
const vw = window.innerWidth, vh = window.innerHeight;
|
|
1311
1483
|
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 });
|
|
1312
1484
|
}, [x, y]);
|
|
1313
|
-
|
|
1485
|
+
useLayoutEffect(() => {
|
|
1486
|
+
const el = ref.current?.querySelector(".gkim-menu--sub");
|
|
1487
|
+
if (!el || !ref.current) return setSubLeft(false);
|
|
1488
|
+
const r = ref.current.getBoundingClientRect();
|
|
1489
|
+
setSubLeft(r.right + el.offsetWidth + 12 > window.innerWidth);
|
|
1490
|
+
}, [sub, pos]);
|
|
1491
|
+
useEffect3(() => {
|
|
1314
1492
|
const prev = document.activeElement;
|
|
1315
1493
|
ref.current?.querySelector('[role="menuitem"]:not([disabled])')?.focus();
|
|
1316
1494
|
const down = (e) => {
|
|
@@ -1380,7 +1558,7 @@ function Menu({ entries, x, y, onClose, label }) {
|
|
|
1380
1558
|
it.icon,
|
|
1381
1559
|
/* @__PURE__ */ jsx5("span", { children: it.label }),
|
|
1382
1560
|
it.children && /* @__PURE__ */ jsx5("span", { className: "gkim-menu__arrow", children: "›" }),
|
|
1383
|
-
it.children && sub === i && /* @__PURE__ */ jsx5("div", { className:
|
|
1561
|
+
it.children && sub === i && /* @__PURE__ */ jsx5("div", { className: `gkim-menu gkim-menu--sub${subLeft ? " gkim-menu--sub-left" : ""}`, role: "menu", children: it.children.map((c, j) => /* @__PURE__ */ jsx5(
|
|
1384
1562
|
"span",
|
|
1385
1563
|
{
|
|
1386
1564
|
role: "menuitem",
|
|
@@ -1412,7 +1590,7 @@ function Menu({ entries, x, y, onClose, label }) {
|
|
|
1412
1590
|
return createPortal(menu, host);
|
|
1413
1591
|
}
|
|
1414
1592
|
function useContextMenu() {
|
|
1415
|
-
const [at, setAt] =
|
|
1593
|
+
const [at, setAt] = useState4(null);
|
|
1416
1594
|
const timer = useRef3(void 0);
|
|
1417
1595
|
const start = useRef3(null);
|
|
1418
1596
|
const bind = {
|
|
@@ -1439,7 +1617,7 @@ function useContextMenu() {
|
|
|
1439
1617
|
start.current = null;
|
|
1440
1618
|
}
|
|
1441
1619
|
};
|
|
1442
|
-
const close =
|
|
1620
|
+
const close = useCallback4(() => setAt(null), []);
|
|
1443
1621
|
return { at, open: setAt, close, bind };
|
|
1444
1622
|
}
|
|
1445
1623
|
|
|
@@ -1524,13 +1702,13 @@ var seq = 0;
|
|
|
1524
1702
|
var Composer = forwardRef(function Composer2(p, ref) {
|
|
1525
1703
|
const { im, strings: s, moreItems } = useImUi();
|
|
1526
1704
|
const { toast } = useFeedback();
|
|
1527
|
-
const [text, setText] =
|
|
1528
|
-
const [tray, setTray] =
|
|
1529
|
-
const [emoji, setEmoji] =
|
|
1530
|
-
const [more, setMore] =
|
|
1531
|
-
const [mention, setMention] =
|
|
1532
|
-
const [busy, setBusy] =
|
|
1533
|
-
const closeMore =
|
|
1705
|
+
const [text, setText] = useState5("");
|
|
1706
|
+
const [tray, setTray] = useState5([]);
|
|
1707
|
+
const [emoji, setEmoji] = useState5(false);
|
|
1708
|
+
const [more, setMore] = useState5(null);
|
|
1709
|
+
const [mention, setMention] = useState5(null);
|
|
1710
|
+
const [busy, setBusy] = useState5(false);
|
|
1711
|
+
const closeMore = useCallback5(() => setMore(null), []);
|
|
1534
1712
|
const ta = useRef4(null);
|
|
1535
1713
|
const media = useRef4(null);
|
|
1536
1714
|
const anyFile = useRef4(null);
|
|
@@ -1562,13 +1740,13 @@ var Composer = forwardRef(function Composer2(p, ref) {
|
|
|
1562
1740
|
};
|
|
1563
1741
|
useImperativeHandle(ref, () => ({ addFiles }));
|
|
1564
1742
|
const thumbs = useMemo3(() => /* @__PURE__ */ new Map(), []);
|
|
1565
|
-
|
|
1743
|
+
useEffect4(() => {
|
|
1566
1744
|
for (const [id, url] of thumbs) if (!tray.some((a) => a.id === id)) {
|
|
1567
1745
|
URL.revokeObjectURL(url);
|
|
1568
1746
|
thumbs.delete(id);
|
|
1569
1747
|
}
|
|
1570
1748
|
}, [tray, thumbs]);
|
|
1571
|
-
|
|
1749
|
+
useEffect4(() => () => {
|
|
1572
1750
|
for (const url of thumbs.values()) URL.revokeObjectURL(url);
|
|
1573
1751
|
}, [thumbs]);
|
|
1574
1752
|
const thumb = (a) => {
|
|
@@ -1827,19 +2005,19 @@ var Composer = forwardRef(function Composer2(p, ref) {
|
|
|
1827
2005
|
});
|
|
1828
2006
|
|
|
1829
2007
|
// src/ui/chat/MessageList.tsx
|
|
1830
|
-
import { Fragment as Fragment3, useCallback as
|
|
2008
|
+
import { Fragment as Fragment3, useCallback as useCallback6, useEffect as useEffect6, useLayoutEffect as useLayoutEffect3, useRef as useRef6 } from "react";
|
|
1831
2009
|
|
|
1832
2010
|
// src/ui/chat/MessageRow.tsx
|
|
1833
2011
|
import { memo, useRef as useRef5 } from "react";
|
|
1834
2012
|
|
|
1835
2013
|
// src/ui/chat/bubbles.tsx
|
|
1836
|
-
import { useEffect as
|
|
2014
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
1837
2015
|
import { messageCard } from "@guokit-dev/im";
|
|
1838
2016
|
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1839
2017
|
function useAsyncUrl(load) {
|
|
1840
|
-
const [url, setUrl] =
|
|
2018
|
+
const [url, setUrl] = useState6(null);
|
|
1841
2019
|
const enabled = load !== null;
|
|
1842
|
-
|
|
2020
|
+
useEffect5(() => {
|
|
1843
2021
|
if (!load) return;
|
|
1844
2022
|
let alive = true;
|
|
1845
2023
|
Promise.resolve().then(load).then((u) => {
|
|
@@ -1901,7 +2079,7 @@ function ImageBubble({ message: m, localUrl, progress, onImageClick }) {
|
|
|
1901
2079
|
const { im, strings: s } = useImUi();
|
|
1902
2080
|
const sent = m.status === "sent";
|
|
1903
2081
|
const remote = useAsyncUrl(sent && !localUrl ? () => im.imageUrl(m) : null);
|
|
1904
|
-
const [broken, setBroken] =
|
|
2082
|
+
const [broken, setBroken] = useState6(false);
|
|
1905
2083
|
const src = localUrl ?? remote;
|
|
1906
2084
|
const size = fit(m.content.width, m.content.height);
|
|
1907
2085
|
const img = src && !broken ? /* @__PURE__ */ jsx7("img", { src, alt: s.image, onError: () => setBroken(true) }) : /* @__PURE__ */ jsx7("span", { className: "gkim-media__ph", children: /* @__PURE__ */ jsx7(Icon, { name: "image" }) });
|
|
@@ -2141,14 +2319,14 @@ function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
|
2141
2319
|
const ref = useRef6(null);
|
|
2142
2320
|
const me = im.currentUserId;
|
|
2143
2321
|
const nearTop = (el) => el.scrollHeight - el.clientHeight + el.scrollTop < 200;
|
|
2144
|
-
const check =
|
|
2322
|
+
const check = useCallback6(() => {
|
|
2145
2323
|
const el = ref.current;
|
|
2146
2324
|
if (el && snap.hasMore && !snap.loadingMore && nearTop(el)) ctl.loadMore();
|
|
2147
2325
|
}, [ctl, snap.hasMore, snap.loadingMore]);
|
|
2148
2326
|
useLayoutEffect3(() => {
|
|
2149
2327
|
check();
|
|
2150
2328
|
}, [check, snap.messages]);
|
|
2151
|
-
|
|
2329
|
+
useEffect6(() => {
|
|
2152
2330
|
scrollRef.current = () => {
|
|
2153
2331
|
if (ref.current) ref.current.scrollTop = 0;
|
|
2154
2332
|
};
|
|
@@ -2156,7 +2334,7 @@ function MessageList({ ctl, snap, isGroup, nameOf, renderRow, scrollRef }) {
|
|
|
2156
2334
|
scrollRef.current = null;
|
|
2157
2335
|
};
|
|
2158
2336
|
}, [scrollRef]);
|
|
2159
|
-
|
|
2337
|
+
useEffect6(() => ctl.onNewMessage((m) => {
|
|
2160
2338
|
const el = ref.current;
|
|
2161
2339
|
if (el && (m.isSelf || el.scrollTop > -120)) el.scrollTop = 0;
|
|
2162
2340
|
}), [ctl]);
|
|
@@ -2218,8 +2396,8 @@ function ImChat(props) {
|
|
|
2218
2396
|
const key = "conversation" in target ? `c${target.conversation.id}` : "group" in target ? `g${target.group}` : `p${target.peer}`;
|
|
2219
2397
|
const isGroup = "group" in target || "conversation" in target && target.conversation.group !== null;
|
|
2220
2398
|
const groupId = "group" in target ? target.group : "conversation" in target ? target.conversation.group?.groupId ?? null : null;
|
|
2221
|
-
const [ctl, setCtl] =
|
|
2222
|
-
|
|
2399
|
+
const [ctl, setCtl] = useState7(null);
|
|
2400
|
+
useEffect7(() => {
|
|
2223
2401
|
const c = new ChatController(im, target);
|
|
2224
2402
|
setCtl(c);
|
|
2225
2403
|
void c.start();
|
|
@@ -2231,8 +2409,8 @@ function ImChat(props) {
|
|
|
2231
2409
|
};
|
|
2232
2410
|
}, [im, key]);
|
|
2233
2411
|
const snap = useSyncExternalStore(ctl?.subscribe ?? noSub, ctl?.getSnapshot ?? (() => EMPTY_SNAP));
|
|
2234
|
-
const [members, setMembers] =
|
|
2235
|
-
|
|
2412
|
+
const [members, setMembers] = useState7(null);
|
|
2413
|
+
useEffect7(() => {
|
|
2236
2414
|
if (!groupId) return;
|
|
2237
2415
|
const m = new MemberCache(im, groupId);
|
|
2238
2416
|
setMembers(m);
|
|
@@ -2245,29 +2423,29 @@ function ImChat(props) {
|
|
|
2245
2423
|
const memberMap = useSyncExternalStore(members?.subscribe ?? noSub, members?.getSnapshot ?? (() => EMPTY_MEMBERS));
|
|
2246
2424
|
const memberList = useMemo4(() => [...memberMap.values()], [memberMap]);
|
|
2247
2425
|
const urls = useMemo4(() => new ObjectUrlRegistry(), []);
|
|
2248
|
-
|
|
2426
|
+
useEffect7(() => () => urls.releaseAll(), [urls]);
|
|
2249
2427
|
urls.sync(snap.localFiles);
|
|
2250
2428
|
const conv = snap.conversation;
|
|
2251
2429
|
const myId = im.currentUserId;
|
|
2252
|
-
const nameOf =
|
|
2430
|
+
const nameOf = useCallback7((id) => {
|
|
2253
2431
|
const mm = memberMap.get(id);
|
|
2254
2432
|
if (mm && mm.nickname) return mm.nickname;
|
|
2255
2433
|
if (id === myId) return me.nickname || id;
|
|
2256
2434
|
if (conv?.peer && conv.peer.userId === id) return conversationTitle(conv, s);
|
|
2257
2435
|
return id;
|
|
2258
2436
|
}, [memberMap, myId, me.nickname, conv, s]);
|
|
2259
|
-
const avatarOf =
|
|
2437
|
+
const avatarOf = useCallback7((id) => {
|
|
2260
2438
|
const mm = memberMap.get(id);
|
|
2261
2439
|
if (mm?.avatarUrl) return mm.avatarUrl;
|
|
2262
2440
|
if (id === myId) return me.avatarUrl ?? "";
|
|
2263
2441
|
return conv?.peer && conv.peer.userId === id ? conv.peer.avatarUrl : "";
|
|
2264
2442
|
}, [memberMap, myId, me.avatarUrl, conv]);
|
|
2265
2443
|
const audio = useRef7(null);
|
|
2266
|
-
const [playing, setPlaying] =
|
|
2267
|
-
|
|
2444
|
+
const [playing, setPlaying] = useState7(null);
|
|
2445
|
+
useEffect7(() => () => {
|
|
2268
2446
|
audio.current?.pause();
|
|
2269
2447
|
}, []);
|
|
2270
|
-
const onVoice =
|
|
2448
|
+
const onVoice = useCallback7(async (m) => {
|
|
2271
2449
|
const a = audio.current ?? (audio.current = new Audio());
|
|
2272
2450
|
a.onended = () => setPlaying(null);
|
|
2273
2451
|
if (playing === m.clientMsgId) {
|
|
@@ -2282,22 +2460,29 @@ function ImChat(props) {
|
|
|
2282
2460
|
setPlaying(m.clientMsgId);
|
|
2283
2461
|
a.play().catch(() => setPlaying(null));
|
|
2284
2462
|
}, [im, playing]);
|
|
2285
|
-
const onImage =
|
|
2463
|
+
const onImage = useCallback7((m) => {
|
|
2286
2464
|
const images = snap.messages.filter((x) => x.type === "image" && x.status === "sent");
|
|
2287
2465
|
const index = images.findIndex((x) => x.clientMsgId === m.clientMsgId);
|
|
2288
2466
|
if (index >= 0) nav.open({ name: "imageViewer", images, index });
|
|
2289
2467
|
}, [snap.messages, nav]);
|
|
2290
|
-
const onVideo =
|
|
2468
|
+
const onVideo = useCallback7((m) => {
|
|
2291
2469
|
audio.current?.pause();
|
|
2292
2470
|
setPlaying(null);
|
|
2293
2471
|
nav.open({ name: "videoPlayer", message: m });
|
|
2294
2472
|
}, [nav]);
|
|
2295
|
-
const onResend =
|
|
2473
|
+
const onResend = useCallback7((m) => {
|
|
2296
2474
|
ctl?.resend(m).catch(() => toast(s.sendRejected));
|
|
2297
2475
|
}, [ctl, toast, s]);
|
|
2298
|
-
const
|
|
2476
|
+
const hostAvatar = callbacks.onAvatarTap;
|
|
2477
|
+
const onAvatar = useCallback7((userId) => {
|
|
2478
|
+
if (hostAvatar) hostAvatar(userId);
|
|
2479
|
+
else {
|
|
2480
|
+
rememberUser(im, userId, { nickname: nameOf(userId), avatarUrl: avatarOf(userId) });
|
|
2481
|
+
nav.open({ name: "userCard", userId });
|
|
2482
|
+
}
|
|
2483
|
+
}, [hostAvatar, nav, im, nameOf, avatarOf]);
|
|
2299
2484
|
const scrollToLatest = useRef7(null);
|
|
2300
|
-
const send =
|
|
2485
|
+
const send = useCallback7(async (text, at) => {
|
|
2301
2486
|
if (!ctl) return;
|
|
2302
2487
|
try {
|
|
2303
2488
|
const m = await ctl.sendText(text, at);
|
|
@@ -2307,7 +2492,7 @@ function ImChat(props) {
|
|
|
2307
2492
|
toast(s.operationFailed);
|
|
2308
2493
|
}
|
|
2309
2494
|
}, [ctl, toast, s]);
|
|
2310
|
-
const sendFile =
|
|
2495
|
+
const sendFile = useCallback7(async (a) => {
|
|
2311
2496
|
if (!ctl) return;
|
|
2312
2497
|
try {
|
|
2313
2498
|
let m;
|
|
@@ -2323,7 +2508,7 @@ function ImChat(props) {
|
|
|
2323
2508
|
}
|
|
2324
2509
|
}, [ctl, toast, s]);
|
|
2325
2510
|
const composer = useRef7(null);
|
|
2326
|
-
const [dragging, setDragging] =
|
|
2511
|
+
const [dragging, setDragging] = useState7(false);
|
|
2327
2512
|
const depth = useRef7(0);
|
|
2328
2513
|
const hasFiles = (e) => Array.from(e.dataTransfer.types).includes("Files");
|
|
2329
2514
|
const dropProps = snap.quit ? {} : {
|
|
@@ -2350,11 +2535,11 @@ function ImChat(props) {
|
|
|
2350
2535
|
composer.current?.addFiles(Array.from(e.dataTransfer.files));
|
|
2351
2536
|
}
|
|
2352
2537
|
};
|
|
2353
|
-
const [menu, setMenu] =
|
|
2354
|
-
const closeMenu =
|
|
2538
|
+
const [menu, setMenu] = useState7(null);
|
|
2539
|
+
const closeMenu = useCallback7(() => setMenu(null), []);
|
|
2355
2540
|
const { menuItems } = useImUi();
|
|
2356
2541
|
const recallMinutes = snap.features?.recallMinutes ?? 0;
|
|
2357
|
-
const entriesFor =
|
|
2542
|
+
const entriesFor = useCallback7((m) => {
|
|
2358
2543
|
const out = [];
|
|
2359
2544
|
if (m.type === "text") {
|
|
2360
2545
|
out.push({ label: s.copy, icon: /* @__PURE__ */ jsx10(Icon, { name: "copy", size: 16 }), onSelect: () => {
|
|
@@ -2363,7 +2548,7 @@ function ImChat(props) {
|
|
|
2363
2548
|
}
|
|
2364
2549
|
if (m.isSelf && m.id !== null && m.status === "sent" && recallMinutes > 0 && Date.now() - m.createdAt < recallMinutes * 6e4) {
|
|
2365
2550
|
out.push({ label: s.recall, icon: /* @__PURE__ */ jsx10(Icon, { name: "recall", size: 16 }), onSelect: () => {
|
|
2366
|
-
ctl?.recall(m).catch((e) => toast(e instanceof
|
|
2551
|
+
ctl?.recall(m).catch((e) => toast(e instanceof ImApiError2 && e.message ? e.message : s.operationFailed));
|
|
2367
2552
|
} });
|
|
2368
2553
|
}
|
|
2369
2554
|
if (!m.isSelf && m.id !== null) {
|
|
@@ -2374,7 +2559,7 @@ function ImChat(props) {
|
|
|
2374
2559
|
for (const it of menuItems?.(m) ?? []) out.push({ label: it.label, icon: it.icon, onSelect: () => it.onClick(m) });
|
|
2375
2560
|
return out;
|
|
2376
2561
|
}, [s, toast, recallMinutes, ctl, nav, menuItems]);
|
|
2377
|
-
const onMenu =
|
|
2562
|
+
const onMenu = useCallback7((m, x, y) => {
|
|
2378
2563
|
if (entriesFor(m).length) setMenu({ m, x, y });
|
|
2379
2564
|
}, [entriesFor]);
|
|
2380
2565
|
const hoverBar = (m) => {
|
|
@@ -2429,7 +2614,16 @@ function ImChat(props) {
|
|
|
2429
2614
|
}
|
|
2430
2615
|
if (!title) title = s.groupChat;
|
|
2431
2616
|
const groupInfo = callbacks.onGroupInfoTap;
|
|
2432
|
-
const actions = isGroup && groupId
|
|
2617
|
+
const actions = isGroup && groupId ? /* @__PURE__ */ jsx10(
|
|
2618
|
+
"button",
|
|
2619
|
+
{
|
|
2620
|
+
type: "button",
|
|
2621
|
+
className: "gkim-iconbtn",
|
|
2622
|
+
"aria-label": s.groupInfoTitle,
|
|
2623
|
+
onClick: () => groupInfo ? groupInfo(groupId) : nav.open({ name: "groupInfo", groupId }),
|
|
2624
|
+
children: /* @__PURE__ */ jsx10(Icon, { name: "more" })
|
|
2625
|
+
}
|
|
2626
|
+
) : null;
|
|
2433
2627
|
return /* @__PURE__ */ jsxs9(
|
|
2434
2628
|
Page,
|
|
2435
2629
|
{
|
|
@@ -2471,8 +2665,8 @@ function ImChat(props) {
|
|
|
2471
2665
|
}
|
|
2472
2666
|
|
|
2473
2667
|
// src/ui/conversation/ConversationList.tsx
|
|
2474
|
-
import { useState as
|
|
2475
|
-
import { ImApiError as
|
|
2668
|
+
import { useState as useState9 } from "react";
|
|
2669
|
+
import { ImApiError as ImApiError3 } from "@guokit-dev/im";
|
|
2476
2670
|
|
|
2477
2671
|
// src/ui/hooks.ts
|
|
2478
2672
|
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
@@ -2515,9 +2709,9 @@ function createConversationsStore(im) {
|
|
|
2515
2709
|
const v = getSnapshot();
|
|
2516
2710
|
if (v === last) return;
|
|
2517
2711
|
last = v;
|
|
2518
|
-
|
|
2712
|
+
listeners2.notify();
|
|
2519
2713
|
};
|
|
2520
|
-
const
|
|
2714
|
+
const listeners2 = new ListenerSet(
|
|
2521
2715
|
() => {
|
|
2522
2716
|
offs = [
|
|
2523
2717
|
im.on("conversations", (list) => {
|
|
@@ -2545,19 +2739,19 @@ function createConversationsStore(im) {
|
|
|
2545
2739
|
offs = [];
|
|
2546
2740
|
}
|
|
2547
2741
|
);
|
|
2548
|
-
return { subscribe: (fn) =>
|
|
2742
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot };
|
|
2549
2743
|
}
|
|
2550
2744
|
function valueStore(im, event, read) {
|
|
2551
2745
|
let off = null;
|
|
2552
2746
|
let last;
|
|
2553
|
-
const
|
|
2747
|
+
const listeners2 = new ListenerSet(
|
|
2554
2748
|
() => {
|
|
2555
2749
|
last = read();
|
|
2556
2750
|
off = im.on(event, () => {
|
|
2557
2751
|
const v = read();
|
|
2558
2752
|
if (v === last) return;
|
|
2559
2753
|
last = v;
|
|
2560
|
-
|
|
2754
|
+
listeners2.notify();
|
|
2561
2755
|
});
|
|
2562
2756
|
},
|
|
2563
2757
|
() => {
|
|
@@ -2565,7 +2759,53 @@ function valueStore(im, event, read) {
|
|
|
2565
2759
|
off = null;
|
|
2566
2760
|
}
|
|
2567
2761
|
);
|
|
2568
|
-
return { subscribe: (fn) =>
|
|
2762
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot: read };
|
|
2763
|
+
}
|
|
2764
|
+
var NO_FRIENDS = Object.freeze([]);
|
|
2765
|
+
function friendsStore(im) {
|
|
2766
|
+
const s = storesOf(im);
|
|
2767
|
+
return s.friends ?? (s.friends = createFriendsStore(im));
|
|
2768
|
+
}
|
|
2769
|
+
function createFriendsStore(im) {
|
|
2770
|
+
let snap = NO_FRIENDS;
|
|
2771
|
+
let owner = null;
|
|
2772
|
+
let offs = [];
|
|
2773
|
+
const getSnapshot = () => {
|
|
2774
|
+
const me = im.currentUserId;
|
|
2775
|
+
if (me === null) {
|
|
2776
|
+
snap = NO_FRIENDS;
|
|
2777
|
+
owner = null;
|
|
2778
|
+
return NO_FRIENDS;
|
|
2779
|
+
}
|
|
2780
|
+
return me === owner ? snap : NO_FRIENDS;
|
|
2781
|
+
};
|
|
2782
|
+
const listeners2 = new ListenerSet(
|
|
2783
|
+
() => {
|
|
2784
|
+
offs = [
|
|
2785
|
+
im.on("friendsChanged", (list) => {
|
|
2786
|
+
const me2 = im.currentUserId;
|
|
2787
|
+
if (me2 === null) return;
|
|
2788
|
+
snap = list;
|
|
2789
|
+
owner = me2;
|
|
2790
|
+
listeners2.notify();
|
|
2791
|
+
}),
|
|
2792
|
+
im.on("connection", () => listeners2.notify())
|
|
2793
|
+
];
|
|
2794
|
+
const me = im.currentUserId;
|
|
2795
|
+
if (me !== null) {
|
|
2796
|
+
try {
|
|
2797
|
+
snap = im.friends();
|
|
2798
|
+
owner = me;
|
|
2799
|
+
} catch {
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
},
|
|
2803
|
+
() => {
|
|
2804
|
+
offs.forEach((f) => f());
|
|
2805
|
+
offs = [];
|
|
2806
|
+
}
|
|
2807
|
+
);
|
|
2808
|
+
return { subscribe: (fn) => listeners2.add(fn), getSnapshot };
|
|
2569
2809
|
}
|
|
2570
2810
|
|
|
2571
2811
|
// src/ui/hooks.ts
|
|
@@ -2581,26 +2821,191 @@ function useTotalUnread() {
|
|
|
2581
2821
|
function useConnection() {
|
|
2582
2822
|
return useStore(connectionStore(useIm()));
|
|
2583
2823
|
}
|
|
2824
|
+
function useFriends() {
|
|
2825
|
+
return useStore(friendsStore(useIm()));
|
|
2826
|
+
}
|
|
2584
2827
|
|
|
2585
|
-
// src/ui/widgets/
|
|
2828
|
+
// src/ui/widgets/GroupAvatar.tsx
|
|
2829
|
+
import { useEffect as useEffect8, useRef as useRef8, useState as useState8, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
2830
|
+
|
|
2831
|
+
// src/core/groupAvatarCache.ts
|
|
2832
|
+
var _GroupAvatarCache = class _GroupAvatarCache {
|
|
2833
|
+
constructor(fetch, subscribeChanges, now = Date.now) {
|
|
2834
|
+
this.fetch = fetch;
|
|
2835
|
+
this.now = now;
|
|
2836
|
+
this.members = /* @__PURE__ */ new Map();
|
|
2837
|
+
this.stale = /* @__PURE__ */ new Set();
|
|
2838
|
+
this.failedAt = /* @__PURE__ */ new Map();
|
|
2839
|
+
this.wanted = /* @__PURE__ */ new Map();
|
|
2840
|
+
this.queue = [];
|
|
2841
|
+
this.inflight = /* @__PURE__ */ new Set();
|
|
2842
|
+
this.gen = /* @__PURE__ */ new Map();
|
|
2843
|
+
this.listeners = new ListenerSet();
|
|
2844
|
+
this.subscribe = (fn) => this.listeners.add(fn);
|
|
2845
|
+
/** 已拉到的前 9 名成员;没拉过或在拉为 undefined。没变化时引用不变。 */
|
|
2846
|
+
this.membersOf = (groupId) => this.members.get(groupId.toLowerCase());
|
|
2847
|
+
this.off = subscribeChanges((c) => this.onChange(c));
|
|
2848
|
+
}
|
|
2849
|
+
static of(im) {
|
|
2850
|
+
let c = _GroupAvatarCache.byIm.get(im);
|
|
2851
|
+
if (!c) {
|
|
2852
|
+
c = new _GroupAvatarCache(
|
|
2853
|
+
async (id) => (await im.groupMembers(id, { limit: 9 })).items,
|
|
2854
|
+
(fn) => im.on("groupChanged", fn)
|
|
2855
|
+
);
|
|
2856
|
+
_GroupAvatarCache.byIm.set(im, c);
|
|
2857
|
+
}
|
|
2858
|
+
return c;
|
|
2859
|
+
}
|
|
2860
|
+
/** 测试用:给某个实例换上自带的缓存。 */
|
|
2861
|
+
static set(im, cache3) {
|
|
2862
|
+
_GroupAvatarCache.byIm.set(im, cache3);
|
|
2863
|
+
}
|
|
2864
|
+
attach(groupId) {
|
|
2865
|
+
const k = groupId.toLowerCase();
|
|
2866
|
+
this.wanted.set(k, (this.wanted.get(k) ?? 0) + 1);
|
|
2867
|
+
this.enqueue(k);
|
|
2868
|
+
}
|
|
2869
|
+
detach(groupId) {
|
|
2870
|
+
const k = groupId.toLowerCase();
|
|
2871
|
+
const n = (this.wanted.get(k) ?? 0) - 1;
|
|
2872
|
+
if (n > 0) this.wanted.set(k, n);
|
|
2873
|
+
else {
|
|
2874
|
+
this.wanted.delete(k);
|
|
2875
|
+
this.queue = this.queue.filter((x) => x !== k);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
dispose() {
|
|
2879
|
+
this.off();
|
|
2880
|
+
this.listeners.clear();
|
|
2881
|
+
}
|
|
2882
|
+
enqueue(k) {
|
|
2883
|
+
if (this.members.has(k) && !this.stale.has(k) || this.inflight.has(k) || this.queue.includes(k)) return;
|
|
2884
|
+
const failed = this.failedAt.get(k);
|
|
2885
|
+
if (failed !== void 0 && this.now() - failed < _GroupAvatarCache.retryAfterMs) return;
|
|
2886
|
+
this.queue.push(k);
|
|
2887
|
+
this.pump();
|
|
2888
|
+
}
|
|
2889
|
+
pump() {
|
|
2890
|
+
while (this.inflight.size < _GroupAvatarCache.maxConcurrent && this.queue.length) {
|
|
2891
|
+
const k = this.queue.shift();
|
|
2892
|
+
if (!this.wanted.has(k)) continue;
|
|
2893
|
+
this.inflight.add(k);
|
|
2894
|
+
const g = this.gen.get(k) ?? 0;
|
|
2895
|
+
this.fetch(k).then(
|
|
2896
|
+
(items) => {
|
|
2897
|
+
if ((this.gen.get(k) ?? 0) !== g) return;
|
|
2898
|
+
this.members.set(k, items);
|
|
2899
|
+
this.stale.delete(k);
|
|
2900
|
+
this.failedAt.delete(k);
|
|
2901
|
+
this.listeners.notify();
|
|
2902
|
+
},
|
|
2903
|
+
() => {
|
|
2904
|
+
if ((this.gen.get(k) ?? 0) !== g) return;
|
|
2905
|
+
this.failedAt.set(k, this.now());
|
|
2906
|
+
}
|
|
2907
|
+
).finally(() => {
|
|
2908
|
+
this.inflight.delete(k);
|
|
2909
|
+
if ((this.gen.get(k) ?? 0) !== g && this.wanted.has(k)) this.enqueue(k);
|
|
2910
|
+
this.pump();
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
onChange(c) {
|
|
2915
|
+
const fields = c.message.content?.fields;
|
|
2916
|
+
const avatarChanged = c.action === "update" && !!fields && typeof fields === "object" && "avatar_url" in fields;
|
|
2917
|
+
if (!_GroupAvatarCache.memberActions.has(c.action) && !avatarChanged) return;
|
|
2918
|
+
const k = c.groupId.toLowerCase();
|
|
2919
|
+
this.gen.set(k, (this.gen.get(k) ?? 0) + 1);
|
|
2920
|
+
this.failedAt.delete(k);
|
|
2921
|
+
if (!this.wanted.has(k)) {
|
|
2922
|
+
this.members.delete(k);
|
|
2923
|
+
this.stale.delete(k);
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2926
|
+
if (this.members.has(k)) this.stale.add(k);
|
|
2927
|
+
if (!this.inflight.has(k)) this.enqueue(k);
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
_GroupAvatarCache.maxConcurrent = 3;
|
|
2931
|
+
_GroupAvatarCache.retryAfterMs = 6e4;
|
|
2932
|
+
_GroupAvatarCache.memberActions = /* @__PURE__ */ new Set(["create", "join", "quit", "kick", "dismiss"]);
|
|
2933
|
+
_GroupAvatarCache.byIm = /* @__PURE__ */ new WeakMap();
|
|
2934
|
+
var GroupAvatarCache = _GroupAvatarCache;
|
|
2935
|
+
|
|
2936
|
+
// src/ui/widgets/GroupAvatar.tsx
|
|
2586
2937
|
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2938
|
+
function GroupGrid({ members, label, size }) {
|
|
2939
|
+
const list = members.slice(0, 9);
|
|
2940
|
+
const cols = list.length <= 4 ? 2 : 3;
|
|
2941
|
+
const style = { ["--gkim-grid-cols"]: String(cols) };
|
|
2942
|
+
if (size) style["--gkim-av"] = `${size}px`;
|
|
2943
|
+
return /* @__PURE__ */ jsx11(
|
|
2944
|
+
"span",
|
|
2945
|
+
{
|
|
2946
|
+
className: "gkim-avatar gkim-avatar--group gkim-groupgrid",
|
|
2947
|
+
role: "img",
|
|
2948
|
+
"aria-label": label,
|
|
2949
|
+
style,
|
|
2950
|
+
"data-cols": cols,
|
|
2951
|
+
children: /* @__PURE__ */ jsx11("span", { className: "gkim-groupgrid__tiles", children: list.map((m) => /* @__PURE__ */ jsxs10("span", { className: "gkim-groupgrid__tile", children: [
|
|
2952
|
+
m.avatarUrl ? /* @__PURE__ */ jsx11("img", { src: m.avatarUrl, alt: "", onError: (e) => {
|
|
2953
|
+
e.currentTarget.style.display = "none";
|
|
2954
|
+
} }) : null,
|
|
2955
|
+
/* @__PURE__ */ jsx11("span", { style: { background: avatarColor(m.userId) }, children: avatarInitial(m.nickname, m.userId) })
|
|
2956
|
+
] }, m.userId)) })
|
|
2957
|
+
}
|
|
2958
|
+
);
|
|
2959
|
+
}
|
|
2960
|
+
function ImGroupAvatar({ groupId, name = "", url = "", size }) {
|
|
2961
|
+
const im = useIm();
|
|
2962
|
+
const cache3 = GroupAvatarCache.of(im);
|
|
2963
|
+
const ref = useRef8(null);
|
|
2964
|
+
const [visible, setVisible] = useState8(false);
|
|
2965
|
+
const want = !url && !!groupId;
|
|
2966
|
+
useEffect8(() => {
|
|
2967
|
+
if (!want || visible) return;
|
|
2968
|
+
const el = ref.current;
|
|
2969
|
+
if (!el || typeof IntersectionObserver === "undefined") {
|
|
2970
|
+
setVisible(true);
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
const io = new IntersectionObserver((es) => {
|
|
2974
|
+
if (es.some((e) => e.isIntersecting)) setVisible(true);
|
|
2975
|
+
});
|
|
2976
|
+
io.observe(el);
|
|
2977
|
+
return () => io.disconnect();
|
|
2978
|
+
}, [want, visible]);
|
|
2979
|
+
useEffect8(() => {
|
|
2980
|
+
if (!want || !visible) return;
|
|
2981
|
+
cache3.attach(groupId);
|
|
2982
|
+
return () => cache3.detach(groupId);
|
|
2983
|
+
}, [cache3, groupId, want, visible]);
|
|
2984
|
+
const members = useSyncExternalStore3(cache3.subscribe, () => want ? cache3.membersOf(groupId) : void 0, () => void 0);
|
|
2985
|
+
const label = name || groupId;
|
|
2986
|
+
if (want && members?.length) return /* @__PURE__ */ jsx11(GroupGrid, { members, label, size });
|
|
2987
|
+
return /* @__PURE__ */ jsx11("span", { ref, className: "gkim-groupavatar-slot", children: /* @__PURE__ */ jsx11(Avatar, { id: groupId, name, url: url || void 0, size, group: true }) });
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
// src/ui/widgets/UnreadBadge.tsx
|
|
2991
|
+
import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2587
2992
|
function Badge({ count = 0, dot = false, muted = false }) {
|
|
2588
|
-
if (dot) return /* @__PURE__ */
|
|
2993
|
+
if (dot) return /* @__PURE__ */ jsx12("span", { className: "gkim-badge gkim-badge--dot", "aria-hidden": "true" });
|
|
2589
2994
|
if (count <= 0) return null;
|
|
2590
|
-
return /* @__PURE__ */
|
|
2995
|
+
return /* @__PURE__ */ jsx12("span", { className: `gkim-badge${muted ? " gkim-badge--muted" : ""}`, children: count > 99 ? "99+" : count });
|
|
2591
2996
|
}
|
|
2592
2997
|
function ImUnreadBadge({ children }) {
|
|
2593
2998
|
const n = useTotalUnread();
|
|
2594
|
-
return /* @__PURE__ */
|
|
2999
|
+
return /* @__PURE__ */ jsxs11("span", { className: "gkim-badge-anchor", children: [
|
|
2595
3000
|
children,
|
|
2596
|
-
/* @__PURE__ */
|
|
3001
|
+
/* @__PURE__ */ jsx12(Badge, { count: n })
|
|
2597
3002
|
] });
|
|
2598
3003
|
}
|
|
2599
3004
|
|
|
2600
3005
|
// src/ui/conversation/ConversationList.tsx
|
|
2601
|
-
import { jsx as
|
|
2602
|
-
function
|
|
2603
|
-
return e instanceof
|
|
3006
|
+
import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
3007
|
+
function errorText2(e, fallback) {
|
|
3008
|
+
return e instanceof ImApiError3 && e.message ? e.message : fallback;
|
|
2604
3009
|
}
|
|
2605
3010
|
function Row({ c, selected, onOpen }) {
|
|
2606
3011
|
const { im, strings: s } = useImUi();
|
|
@@ -2613,7 +3018,7 @@ function Row({ c, selected, onOpen }) {
|
|
|
2613
3018
|
try {
|
|
2614
3019
|
await f();
|
|
2615
3020
|
} catch (e) {
|
|
2616
|
-
toast(
|
|
3021
|
+
toast(errorText2(e, s.operationFailed));
|
|
2617
3022
|
}
|
|
2618
3023
|
};
|
|
2619
3024
|
const entries = [
|
|
@@ -2627,8 +3032,8 @@ function Row({ c, selected, onOpen }) {
|
|
|
2627
3032
|
}
|
|
2628
3033
|
}
|
|
2629
3034
|
];
|
|
2630
|
-
return /* @__PURE__ */
|
|
2631
|
-
/* @__PURE__ */
|
|
3035
|
+
return /* @__PURE__ */ jsxs12("li", { className: `gkim-conv${c.pinned ? " gkim-conv--pinned" : ""}${selected ? " gkim-conv--selected" : ""}`, children: [
|
|
3036
|
+
/* @__PURE__ */ jsxs12(
|
|
2632
3037
|
"button",
|
|
2633
3038
|
{
|
|
2634
3039
|
type: "button",
|
|
@@ -2638,36 +3043,27 @@ function Row({ c, selected, onOpen }) {
|
|
|
2638
3043
|
"aria-label": c.unread > 0 ? `${title},${c.unread} 条未读` : title,
|
|
2639
3044
|
...menu.bind,
|
|
2640
3045
|
children: [
|
|
2641
|
-
/* @__PURE__ */
|
|
2642
|
-
/* @__PURE__ */
|
|
2643
|
-
|
|
2644
|
-
{
|
|
2645
|
-
id: g?.groupId ?? c.peer?.userId ?? "",
|
|
2646
|
-
name: title,
|
|
2647
|
-
url: g?.avatarUrl ?? c.peer?.avatarUrl,
|
|
2648
|
-
group: !!g,
|
|
2649
|
-
size: void 0
|
|
2650
|
-
}
|
|
2651
|
-
),
|
|
2652
|
-
c.unread > 0 && /* @__PURE__ */ jsx12("span", { className: "gkim-conv__badge", children: /* @__PURE__ */ jsx12(Badge, { count: c.unread, dot: c.muted }) })
|
|
3046
|
+
/* @__PURE__ */ jsxs12("span", { className: "gkim-conv__avatar", children: [
|
|
3047
|
+
g ? /* @__PURE__ */ jsx13(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl }) : /* @__PURE__ */ jsx13(Avatar, { id: c.peer?.userId ?? "", name: title, url: c.peer?.avatarUrl }),
|
|
3048
|
+
c.unread > 0 && /* @__PURE__ */ jsx13("span", { className: "gkim-conv__badge", children: /* @__PURE__ */ jsx13(Badge, { count: c.unread, dot: c.muted }) })
|
|
2653
3049
|
] }),
|
|
2654
|
-
/* @__PURE__ */
|
|
2655
|
-
/* @__PURE__ */
|
|
2656
|
-
/* @__PURE__ */
|
|
2657
|
-
/* @__PURE__ */
|
|
3050
|
+
/* @__PURE__ */ jsxs12("span", { className: "gkim-conv__body", children: [
|
|
3051
|
+
/* @__PURE__ */ jsxs12("span", { className: "gkim-conv__line", children: [
|
|
3052
|
+
/* @__PURE__ */ jsx13("span", { className: "gkim-conv__title", children: title }),
|
|
3053
|
+
/* @__PURE__ */ jsx13("span", { className: "gkim-conv__time", children: formatConversationTime(c.lastMsgAt, s) })
|
|
2658
3054
|
] }),
|
|
2659
|
-
/* @__PURE__ */
|
|
2660
|
-
/* @__PURE__ */
|
|
2661
|
-
sum.atMe && /* @__PURE__ */
|
|
3055
|
+
/* @__PURE__ */ jsxs12("span", { className: "gkim-conv__line", children: [
|
|
3056
|
+
/* @__PURE__ */ jsxs12("span", { className: "gkim-conv__preview", children: [
|
|
3057
|
+
sum.atMe && /* @__PURE__ */ jsx13("span", { className: "gkim-conv__at", children: sum.atMe }),
|
|
2662
3058
|
sum.text
|
|
2663
3059
|
] }),
|
|
2664
|
-
c.muted && /* @__PURE__ */
|
|
3060
|
+
c.muted && /* @__PURE__ */ jsx13("span", { className: "gkim-conv__muted", "aria-label": s.mute, children: /* @__PURE__ */ jsx13(Icon, { name: "mute", size: 14 }) })
|
|
2665
3061
|
] })
|
|
2666
3062
|
] })
|
|
2667
3063
|
]
|
|
2668
3064
|
}
|
|
2669
3065
|
),
|
|
2670
|
-
menu.at && /* @__PURE__ */
|
|
3066
|
+
menu.at && /* @__PURE__ */ jsx13(Menu, { entries, x: menu.at.x, y: menu.at.y, onClose: menu.close, label: title })
|
|
2671
3067
|
] });
|
|
2672
3068
|
}
|
|
2673
3069
|
function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, selectedId }) {
|
|
@@ -2677,8 +3073,8 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2677
3073
|
const conn = useConnection();
|
|
2678
3074
|
const nav = useNavContext();
|
|
2679
3075
|
const frame = useFrame();
|
|
2680
|
-
const [busy, setBusy] =
|
|
2681
|
-
|
|
3076
|
+
const [busy, setBusy] = useState9(false);
|
|
3077
|
+
const add = useContextMenu();
|
|
2682
3078
|
void showSearch;
|
|
2683
3079
|
const mainChat = nav.state.main?.name === "chat" ? nav.state.main.target : null;
|
|
2684
3080
|
const selected = selectedId !== void 0 ? selectedId : mainChat?.conversation?.id ?? null;
|
|
@@ -2689,14 +3085,14 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2689
3085
|
try {
|
|
2690
3086
|
await im.markAllRead();
|
|
2691
3087
|
} catch (e) {
|
|
2692
|
-
toast(
|
|
3088
|
+
toast(errorText2(e, s.operationFailed));
|
|
2693
3089
|
} finally {
|
|
2694
3090
|
setBusy(false);
|
|
2695
3091
|
}
|
|
2696
3092
|
};
|
|
2697
3093
|
const markAllBtn = (
|
|
2698
3094
|
// 总未读不含免打扰会话,按各会话判断,免打扰的也能一键清掉。
|
|
2699
|
-
/* @__PURE__ */
|
|
3095
|
+
/* @__PURE__ */ jsx13(
|
|
2700
3096
|
"button",
|
|
2701
3097
|
{
|
|
2702
3098
|
type: "button",
|
|
@@ -2705,37 +3101,65 @@ function ImConversationList({ onOpen, showAddMenu = true, showSearch = true, sel
|
|
|
2705
3101
|
title: s.markAllRead,
|
|
2706
3102
|
disabled: !anyUnread || busy,
|
|
2707
3103
|
onClick: markAll,
|
|
2708
|
-
children: /* @__PURE__ */
|
|
3104
|
+
children: /* @__PURE__ */ jsx13(Icon, { name: "checkAll" })
|
|
2709
3105
|
}
|
|
2710
3106
|
)
|
|
2711
3107
|
);
|
|
2712
|
-
const
|
|
2713
|
-
|
|
3108
|
+
const addEntries = [
|
|
3109
|
+
{ label: s.startGroupChat, icon: /* @__PURE__ */ jsx13(Icon, { name: "chatPlus", size: 18 }), onSelect: () => nav.open({ name: "selectFriends" }) },
|
|
3110
|
+
{ label: s.addFriend, icon: /* @__PURE__ */ jsx13(Icon, { name: "userPlus", size: 18 }), onSelect: () => nav.open({ name: "addFriend" }) }
|
|
3111
|
+
];
|
|
3112
|
+
const addBtn = showAddMenu ? /* @__PURE__ */ jsx13(
|
|
3113
|
+
"button",
|
|
3114
|
+
{
|
|
3115
|
+
type: "button",
|
|
3116
|
+
className: "gkim-iconbtn",
|
|
3117
|
+
"aria-label": s.startGroupChat + " / " + s.addFriend,
|
|
3118
|
+
"aria-haspopup": "menu",
|
|
3119
|
+
"aria-expanded": !!add.at,
|
|
3120
|
+
onClick: (e) => {
|
|
3121
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
3122
|
+
add.open({ x: r.left, y: r.bottom + 4 });
|
|
3123
|
+
},
|
|
3124
|
+
children: /* @__PURE__ */ jsx13(Icon, { name: "add" })
|
|
3125
|
+
}
|
|
3126
|
+
) : null;
|
|
3127
|
+
const addMenu = add.at && /* @__PURE__ */ jsx13(Menu, { entries: addEntries, x: add.at.x, y: add.at.y, onClose: add.close });
|
|
3128
|
+
const banner = conn === "disconnected" ? /* @__PURE__ */ jsx13("div", { className: "gkim-banner gkim-banner--danger", role: "status", children: s.disconnected }) : null;
|
|
3129
|
+
const list = convs.length === 0 ? /* @__PURE__ */ jsx13("div", { className: "gkim-empty gkim-grow", children: s.emptyConversations }) : /* @__PURE__ */ jsx13("ul", { className: "gkim-conv-list", "aria-label": s.conversationsTitle, children: convs.map((c) => /* @__PURE__ */ jsx13(Row, { c, selected: c.id === selected, onOpen: () => open(c) }, c.id)) });
|
|
2714
3130
|
if (frame.kind === "list") {
|
|
2715
|
-
return /* @__PURE__ */
|
|
2716
|
-
/* @__PURE__ */
|
|
2717
|
-
/* @__PURE__ */
|
|
2718
|
-
/* @__PURE__ */
|
|
2719
|
-
markAllBtn
|
|
3131
|
+
return /* @__PURE__ */ jsxs12("div", { className: "gkim-listpane", children: [
|
|
3132
|
+
/* @__PURE__ */ jsxs12("div", { className: "gkim-listpane__head", children: [
|
|
3133
|
+
/* @__PURE__ */ jsx13("h2", { className: "gkim-sr-only", children: s.conversationsTitle }),
|
|
3134
|
+
/* @__PURE__ */ jsx13("div", { className: "gkim-grow" }),
|
|
3135
|
+
markAllBtn,
|
|
3136
|
+
addBtn
|
|
2720
3137
|
] }),
|
|
2721
3138
|
banner,
|
|
2722
|
-
list
|
|
3139
|
+
list,
|
|
3140
|
+
addMenu
|
|
2723
3141
|
] });
|
|
2724
3142
|
}
|
|
2725
|
-
return /* @__PURE__ */
|
|
3143
|
+
return /* @__PURE__ */ jsxs12(Page, { title: s.conversationsTitle, actions: /* @__PURE__ */ jsxs12(Fragment5, { children: [
|
|
3144
|
+
markAllBtn,
|
|
3145
|
+
addBtn
|
|
3146
|
+
] }), banner, children: [
|
|
3147
|
+
list,
|
|
3148
|
+
addMenu
|
|
3149
|
+
] });
|
|
2726
3150
|
}
|
|
2727
3151
|
|
|
2728
3152
|
// src/ui/menu/Report.tsx
|
|
2729
|
-
import { useState as
|
|
2730
|
-
import { ImApiError as
|
|
2731
|
-
import { Fragment as
|
|
3153
|
+
import { useState as useState10 } from "react";
|
|
3154
|
+
import { ImApiError as ImApiError4, reportReasons } from "@guokit-dev/im";
|
|
3155
|
+
import { Fragment as Fragment6, jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2732
3156
|
function ReportDialog({ target, title, messageIds }) {
|
|
2733
3157
|
const { im, strings: s } = useImUi();
|
|
2734
3158
|
const { toast } = useFeedback();
|
|
2735
3159
|
const frame = useFrame();
|
|
2736
|
-
const [reason, setReason] =
|
|
2737
|
-
const [block, setBlock] =
|
|
2738
|
-
const [busy, setBusy] =
|
|
3160
|
+
const [reason, setReason] = useState10(null);
|
|
3161
|
+
const [block, setBlock] = useState10(false);
|
|
3162
|
+
const [busy, setBusy] = useState10(false);
|
|
2739
3163
|
const submit = async () => {
|
|
2740
3164
|
if (!reason) return;
|
|
2741
3165
|
setBusy(true);
|
|
@@ -2744,31 +3168,31 @@ function ReportDialog({ target, title, messageIds }) {
|
|
|
2744
3168
|
const r = await im.report(typeof target === "string" ? target : target.groupId, reason, { messageIds: messageIds?.length ? messageIds : void 0, block });
|
|
2745
3169
|
tip = r.duplicated ? s.reportDuplicated : s.reported;
|
|
2746
3170
|
} catch (e) {
|
|
2747
|
-
tip = e instanceof
|
|
3171
|
+
tip = e instanceof ImApiError4 && e.message ? e.message : s.operationFailed;
|
|
2748
3172
|
}
|
|
2749
3173
|
toast(tip);
|
|
2750
3174
|
frame.close();
|
|
2751
3175
|
};
|
|
2752
|
-
return /* @__PURE__ */
|
|
3176
|
+
return /* @__PURE__ */ jsxs13(
|
|
2753
3177
|
Page,
|
|
2754
3178
|
{
|
|
2755
3179
|
title,
|
|
2756
3180
|
className: "gkim-report",
|
|
2757
|
-
footer: /* @__PURE__ */
|
|
2758
|
-
/* @__PURE__ */
|
|
2759
|
-
/* @__PURE__ */
|
|
3181
|
+
footer: /* @__PURE__ */ jsxs13(Fragment6, { children: [
|
|
3182
|
+
/* @__PURE__ */ jsx14("button", { type: "button", className: "gkim-btn", onClick: frame.close, children: s.cancel }),
|
|
3183
|
+
/* @__PURE__ */ jsx14("button", { type: "button", className: "gkim-btn gkim-btn--primary", disabled: !reason || busy, onClick: submit, children: s.submit })
|
|
2760
3184
|
] }),
|
|
2761
3185
|
children: [
|
|
2762
|
-
/* @__PURE__ */
|
|
2763
|
-
/* @__PURE__ */
|
|
2764
|
-
reportReasons.map((r) => /* @__PURE__ */
|
|
2765
|
-
/* @__PURE__ */
|
|
2766
|
-
/* @__PURE__ */
|
|
3186
|
+
/* @__PURE__ */ jsxs13("fieldset", { className: "gkim-report__reasons", children: [
|
|
3187
|
+
/* @__PURE__ */ jsx14("legend", { className: "gkim-sr-only", children: title }),
|
|
3188
|
+
reportReasons.map((r) => /* @__PURE__ */ jsxs13("label", { className: `gkim-choice${reason === r ? " gkim-choice--on" : ""}`, children: [
|
|
3189
|
+
/* @__PURE__ */ jsx14("input", { type: "radio", name: "gkim-report-reason", value: r, checked: reason === r, disabled: busy, onChange: () => setReason(r) }),
|
|
3190
|
+
/* @__PURE__ */ jsx14("span", { children: s.reportReasons[r] ?? r })
|
|
2767
3191
|
] }, r))
|
|
2768
3192
|
] }),
|
|
2769
|
-
/* @__PURE__ */
|
|
2770
|
-
/* @__PURE__ */
|
|
2771
|
-
/* @__PURE__ */
|
|
3193
|
+
/* @__PURE__ */ jsxs13("label", { className: "gkim-check", children: [
|
|
3194
|
+
/* @__PURE__ */ jsx14("input", { type: "checkbox", checked: block, disabled: busy, onChange: (e) => setBlock(e.target.checked) }),
|
|
3195
|
+
/* @__PURE__ */ jsx14("span", { children: s.alsoBlock })
|
|
2772
3196
|
] })
|
|
2773
3197
|
]
|
|
2774
3198
|
}
|
|
@@ -2776,18 +3200,18 @@ function ReportDialog({ target, title, messageIds }) {
|
|
|
2776
3200
|
}
|
|
2777
3201
|
|
|
2778
3202
|
// src/ui/viewer/ImageViewer.tsx
|
|
2779
|
-
import { useEffect as
|
|
2780
|
-
import { jsx as
|
|
3203
|
+
import { useEffect as useEffect9, useState as useState11 } from "react";
|
|
3204
|
+
import { jsx as jsx15, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
2781
3205
|
var MIN = 1;
|
|
2782
3206
|
var MAX = 4;
|
|
2783
3207
|
function ImageViewer({ images, index }) {
|
|
2784
3208
|
const { im, strings: s } = useImUi();
|
|
2785
3209
|
const frame = useFrame();
|
|
2786
|
-
const [i, setI] =
|
|
2787
|
-
const [scale, setScale] =
|
|
2788
|
-
const [urls, setUrls] =
|
|
3210
|
+
const [i, setI] = useState11(index);
|
|
3211
|
+
const [scale, setScale] = useState11(1);
|
|
3212
|
+
const [urls, setUrls] = useState11({});
|
|
2789
3213
|
const m = images[i];
|
|
2790
|
-
|
|
3214
|
+
useEffect9(() => {
|
|
2791
3215
|
if (!m || m.clientMsgId in urls) return;
|
|
2792
3216
|
let alive = true;
|
|
2793
3217
|
im.imageUrl(m).then((u) => {
|
|
@@ -2814,33 +3238,33 @@ function ImageViewer({ images, index }) {
|
|
|
2814
3238
|
};
|
|
2815
3239
|
const onWheel = (e) => zoom(e.deltaY < 0 ? 0.25 : -0.25);
|
|
2816
3240
|
const url = m ? urls[m.clientMsgId] : null;
|
|
2817
|
-
return /* @__PURE__ */
|
|
2818
|
-
/* @__PURE__ */
|
|
2819
|
-
/* @__PURE__ */
|
|
2820
|
-
/* @__PURE__ */
|
|
2821
|
-
/* @__PURE__ */
|
|
2822
|
-
url && /* @__PURE__ */
|
|
2823
|
-
/* @__PURE__ */
|
|
3241
|
+
return /* @__PURE__ */ jsxs14("div", { className: "gkim-viewer", onKeyDown: onKey, children: [
|
|
3242
|
+
/* @__PURE__ */ jsxs14("div", { className: "gkim-viewer__bar", children: [
|
|
3243
|
+
/* @__PURE__ */ jsx15("span", { className: "gkim-viewer__count", children: fill(s.imageIndex, { n: i + 1, total: images.length }) }),
|
|
3244
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomOut, disabled: scale <= MIN, onClick: () => zoom(-0.5), children: /* @__PURE__ */ jsx15(Icon, { name: "zoomOut" }) }),
|
|
3245
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.zoomIn, disabled: scale >= MAX, onClick: () => zoom(0.5), children: /* @__PURE__ */ jsx15(Icon, { name: "zoomIn" }) }),
|
|
3246
|
+
url && /* @__PURE__ */ jsx15("a", { className: "gkim-viewer__btn", href: url, target: "_blank", rel: "noopener", "aria-label": s.openOriginal, title: s.openOriginal, children: /* @__PURE__ */ jsx15(Icon, { name: "external" }) }),
|
|
3247
|
+
/* @__PURE__ */ jsx15("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ jsx15(Icon, { name: "close" }) })
|
|
2824
3248
|
] }),
|
|
2825
|
-
/* @__PURE__ */
|
|
3249
|
+
/* @__PURE__ */ jsxs14("div", { className: "gkim-viewer__stage", onWheel, onClick: (e) => {
|
|
2826
3250
|
if (e.target === e.currentTarget) frame.close();
|
|
2827
3251
|
}, children: [
|
|
2828
|
-
url ? /* @__PURE__ */
|
|
2829
|
-
i > 0 && /* @__PURE__ */
|
|
2830
|
-
i < images.length - 1 && /* @__PURE__ */
|
|
3252
|
+
url ? /* @__PURE__ */ jsx15("img", { src: url, alt: s.image, style: { transform: `scale(${scale})` }, onDoubleClick: () => setScale((v) => v > 1 ? 1 : 2), draggable: false }) : /* @__PURE__ */ jsx15("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }),
|
|
3253
|
+
i > 0 && /* @__PURE__ */ jsx15("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--prev", "aria-label": s.prevImage, onClick: () => go(-1), children: /* @__PURE__ */ jsx15(Icon, { name: "back", size: 28 }) }),
|
|
3254
|
+
i < images.length - 1 && /* @__PURE__ */ jsx15("button", { type: "button", className: "gkim-viewer__nav gkim-viewer__nav--next", "aria-label": s.nextImage, onClick: () => go(1), children: /* @__PURE__ */ jsx15(Icon, { name: "back", size: 28 }) })
|
|
2831
3255
|
] })
|
|
2832
3256
|
] });
|
|
2833
3257
|
}
|
|
2834
3258
|
|
|
2835
3259
|
// src/ui/viewer/VideoPlayer.tsx
|
|
2836
|
-
import { useEffect as
|
|
2837
|
-
import { jsx as
|
|
3260
|
+
import { useEffect as useEffect10, useState as useState12 } from "react";
|
|
3261
|
+
import { jsx as jsx16, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2838
3262
|
function VideoPlayer({ message }) {
|
|
2839
3263
|
const { im, strings: s } = useImUi();
|
|
2840
3264
|
const frame = useFrame();
|
|
2841
|
-
const [url, setUrl] =
|
|
2842
|
-
const [failed, setFailed] =
|
|
2843
|
-
|
|
3265
|
+
const [url, setUrl] = useState12(null);
|
|
3266
|
+
const [failed, setFailed] = useState12(false);
|
|
3267
|
+
useEffect10(() => {
|
|
2844
3268
|
let alive = true;
|
|
2845
3269
|
im.videoUrl(message).then((u) => {
|
|
2846
3270
|
if (alive) {
|
|
@@ -2852,103 +3276,1809 @@ function VideoPlayer({ message }) {
|
|
|
2852
3276
|
alive = false;
|
|
2853
3277
|
};
|
|
2854
3278
|
}, [im, message]);
|
|
2855
|
-
return /* @__PURE__ */
|
|
2856
|
-
/* @__PURE__ */
|
|
2857
|
-
/* @__PURE__ */
|
|
2858
|
-
/* @__PURE__ */
|
|
3279
|
+
return /* @__PURE__ */ jsxs15("div", { className: "gkim-viewer", children: [
|
|
3280
|
+
/* @__PURE__ */ jsxs15("div", { className: "gkim-viewer__bar", children: [
|
|
3281
|
+
/* @__PURE__ */ jsx16("span", { className: "gkim-viewer__count" }),
|
|
3282
|
+
/* @__PURE__ */ jsx16("button", { type: "button", className: "gkim-viewer__btn", "aria-label": s.close, "data-autofocus": true, onClick: frame.close, children: /* @__PURE__ */ jsx16(Icon, { name: "close" }) })
|
|
2859
3283
|
] }),
|
|
2860
|
-
/* @__PURE__ */
|
|
3284
|
+
/* @__PURE__ */ jsx16("div", { className: "gkim-viewer__stage", onClick: (e) => {
|
|
2861
3285
|
if (e.target === e.currentTarget) frame.close();
|
|
2862
|
-
}, children: url ? /* @__PURE__ */
|
|
3286
|
+
}, children: url ? /* @__PURE__ */ jsx16("video", { src: url, controls: true, autoPlay: true, playsInline: true }) : failed ? /* @__PURE__ */ jsx16("span", { children: s.operationFailed }) : /* @__PURE__ */ jsx16("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) })
|
|
2863
3287
|
] });
|
|
2864
3288
|
}
|
|
2865
3289
|
|
|
2866
|
-
// src/ui/
|
|
2867
|
-
import {
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
3290
|
+
// src/ui/contacts/AddFriendDialog.tsx
|
|
3291
|
+
import { useState as useState13 } from "react";
|
|
3292
|
+
import { ImApiError as ImApiError5 } from "@guokit-dev/im";
|
|
3293
|
+
import { jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
3294
|
+
function ImAddFriend() {
|
|
3295
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3296
|
+
const nav = useNavContext();
|
|
3297
|
+
const frame = useFrame();
|
|
3298
|
+
const [q, setQ] = useState13("");
|
|
3299
|
+
const [busy, setBusy] = useState13(false);
|
|
3300
|
+
const [result, setResult] = useState13(void 0);
|
|
3301
|
+
const [error, setError] = useState13(null);
|
|
3302
|
+
const search = async () => {
|
|
3303
|
+
const text = q.trim();
|
|
3304
|
+
if (!text || busy) return;
|
|
3305
|
+
setBusy(true);
|
|
3306
|
+
setError(null);
|
|
3307
|
+
try {
|
|
3308
|
+
setResult({ r: await im.searchUser(text), q: text });
|
|
3309
|
+
} catch (e) {
|
|
3310
|
+
setError(e instanceof ImApiError5 && e.code === "IM_RATE_LIMITED" ? s.rateLimited : errorText(e, s.operationFailed));
|
|
3311
|
+
} finally {
|
|
3312
|
+
setBusy(false);
|
|
2877
3313
|
}
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
3314
|
+
};
|
|
3315
|
+
const view = (r) => {
|
|
3316
|
+
if (frame.kind === "dialog" || frame.kind === "page") nav.back();
|
|
3317
|
+
openUserCard({ im, callbacks, nav }, r.userId, { nickname: r.nickname, avatarUrl: r.avatarUrl });
|
|
3318
|
+
};
|
|
3319
|
+
let body = null;
|
|
3320
|
+
if (error) {
|
|
3321
|
+
body = /* @__PURE__ */ jsx17("p", { className: "gkim-addfriend__error", role: "alert", children: error });
|
|
3322
|
+
} else if (result && result.r === null) {
|
|
3323
|
+
body = /* @__PURE__ */ jsxs16("div", { className: "gkim-addfriend__none", children: [
|
|
3324
|
+
/* @__PURE__ */ jsx17("p", { className: "gkim-addfriend__none-title", children: s.userNotFound }),
|
|
3325
|
+
/* @__PURE__ */ jsx17("p", { className: "gkim-addfriend__tip", children: s.userNotFoundTip })
|
|
3326
|
+
] });
|
|
3327
|
+
} else if (result?.r?.isSelf) {
|
|
3328
|
+
body = /* @__PURE__ */ jsx17("div", { className: "gkim-addfriend__none", children: /* @__PURE__ */ jsx17("p", { className: "gkim-addfriend__none-title", children: s.searchSelf }) });
|
|
3329
|
+
} else if (result?.r) {
|
|
3330
|
+
const r = result.r;
|
|
3331
|
+
const name = r.nickname || r.userId;
|
|
3332
|
+
body = /* @__PURE__ */ jsxs16("div", { className: "gkim-addfriend__card", children: [
|
|
3333
|
+
/* @__PURE__ */ jsx17(Avatar, { id: r.userId, name, url: r.avatarUrl, size: 48 }),
|
|
3334
|
+
/* @__PURE__ */ jsxs16("div", { className: "gkim-addfriend__card-body", children: [
|
|
3335
|
+
/* @__PURE__ */ jsx17("div", { className: "gkim-addfriend__card-name", children: name }),
|
|
3336
|
+
/* @__PURE__ */ jsx17("div", { className: "gkim-addfriend__card-sub", children: fill(r.matchedBy === "search_key" ? s.matchedBySearchKey : s.matchedByUserId, { q: result.q }) })
|
|
3337
|
+
] }),
|
|
3338
|
+
/* @__PURE__ */ jsx17("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => view(r), children: s.view })
|
|
3339
|
+
] });
|
|
2886
3340
|
}
|
|
3341
|
+
return /* @__PURE__ */ jsxs16(Page, { title: s.addFriend, className: "gkim-addfriend", children: [
|
|
3342
|
+
/* @__PURE__ */ jsxs16("form", { className: "gkim-addfriend__bar", onSubmit: (e) => {
|
|
3343
|
+
e.preventDefault();
|
|
3344
|
+
void search();
|
|
3345
|
+
}, children: [
|
|
3346
|
+
/* @__PURE__ */ jsx17(
|
|
3347
|
+
"input",
|
|
3348
|
+
{
|
|
3349
|
+
className: "gkim-input",
|
|
3350
|
+
type: "search",
|
|
3351
|
+
value: q,
|
|
3352
|
+
"data-autofocus": true,
|
|
3353
|
+
placeholder: s.addFriendHint,
|
|
3354
|
+
"aria-label": s.addFriendHint,
|
|
3355
|
+
onChange: (e) => setQ(e.target.value)
|
|
3356
|
+
}
|
|
3357
|
+
),
|
|
3358
|
+
/* @__PURE__ */ jsx17("button", { type: "submit", className: "gkim-btn gkim-btn--primary", disabled: busy || !q.trim(), children: s.search })
|
|
3359
|
+
] }),
|
|
3360
|
+
/* @__PURE__ */ jsx17("p", { className: "gkim-addfriend__tip", children: s.addFriendTip }),
|
|
3361
|
+
!busy && body
|
|
3362
|
+
] });
|
|
2887
3363
|
}
|
|
2888
3364
|
|
|
2889
|
-
// src/ui/
|
|
2890
|
-
import {
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
3365
|
+
// src/ui/contacts/ContactsPage.tsx
|
|
3366
|
+
import { useMemo as useMemo5, useState as useState15 } from "react";
|
|
3367
|
+
|
|
3368
|
+
// src/core/pinyinIndex.ts
|
|
3369
|
+
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", "#"];
|
|
3370
|
+
var BOUND_LETTERS = "ABCDEFGHJKLMNOPQRSTWXYZ";
|
|
3371
|
+
var BOUNDS = "阿八嚓哒妸发旮哈讥咔垃妈拏噢妑七呥仨他屲夕丫帀";
|
|
3372
|
+
var HAN = /[㐀-䶿一-鿿豈-]/;
|
|
3373
|
+
var collator = null;
|
|
3374
|
+
function coll() {
|
|
3375
|
+
return collator ?? (collator = new Intl.Collator("zh-Hans-CN-u-co-pinyin", { sensitivity: "base", numeric: true }));
|
|
2898
3376
|
}
|
|
2899
|
-
function
|
|
2900
|
-
|
|
3377
|
+
function indexLetterOf(name) {
|
|
3378
|
+
const s = name.trim();
|
|
3379
|
+
if (!s) return "#";
|
|
3380
|
+
const ch = String.fromCodePoint(s.codePointAt(0));
|
|
3381
|
+
const c = ch.toUpperCase();
|
|
3382
|
+
if (c >= "A" && c <= "Z" && c.length === 1) return c;
|
|
3383
|
+
if (!HAN.test(ch)) return "#";
|
|
3384
|
+
const cl = coll();
|
|
3385
|
+
if (cl.compare(ch, BOUNDS[0]) < 0) return "#";
|
|
3386
|
+
let lo = 0, hi = BOUNDS.length - 1;
|
|
3387
|
+
while (lo < hi) {
|
|
3388
|
+
const mid = lo + hi + 1 >> 1;
|
|
3389
|
+
if (cl.compare(BOUNDS[mid], ch) <= 0) lo = mid;
|
|
3390
|
+
else hi = mid - 1;
|
|
3391
|
+
}
|
|
3392
|
+
return BOUND_LETTERS[lo];
|
|
2901
3393
|
}
|
|
2902
|
-
function
|
|
2903
|
-
const
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
3394
|
+
function indexSections(items, nameOf, idOf) {
|
|
3395
|
+
const by = /* @__PURE__ */ new Map();
|
|
3396
|
+
for (const it of items) {
|
|
3397
|
+
const name = nameOf(it);
|
|
3398
|
+
const l = indexLetterOf(name);
|
|
3399
|
+
let list = by.get(l);
|
|
3400
|
+
if (!list) by.set(l, list = []);
|
|
3401
|
+
list.push({ it, name, id: idOf(it) });
|
|
3402
|
+
}
|
|
3403
|
+
const cl = coll();
|
|
3404
|
+
const out = [];
|
|
3405
|
+
for (const letter of indexLetters) {
|
|
3406
|
+
const list = by.get(letter);
|
|
3407
|
+
if (!list) continue;
|
|
3408
|
+
list.sort((a, b) => cl.compare(a.name, b.name) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
3409
|
+
out.push({ letter, items: list.map((x) => x.it) });
|
|
3410
|
+
}
|
|
3411
|
+
return out;
|
|
2909
3412
|
}
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
3413
|
+
|
|
3414
|
+
// src/ui/widgets/IndexedList.tsx
|
|
3415
|
+
import { useRef as useRef9, useState as useState14 } from "react";
|
|
3416
|
+
import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
3417
|
+
var TOP = "↑";
|
|
3418
|
+
var BAR = [TOP, ...indexLetters];
|
|
3419
|
+
function IndexedList({ sections, renderItem, keyOf, header, footer, className }) {
|
|
3420
|
+
const s = useImUi().strings;
|
|
3421
|
+
const scroller = useRef9(null);
|
|
3422
|
+
const [touching, setTouching] = useState14(null);
|
|
3423
|
+
const present = new Set(sections.map((x) => x.letter));
|
|
3424
|
+
const jump = (letter) => {
|
|
3425
|
+
const box = scroller.current;
|
|
3426
|
+
if (!box) return;
|
|
3427
|
+
if (letter === TOP || !sections.length) {
|
|
3428
|
+
box.scrollTop = 0;
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3431
|
+
const want = indexLetters.indexOf(letter);
|
|
3432
|
+
const target = sections.find((x) => indexLetters.indexOf(x.letter) >= want) ?? sections[sections.length - 1];
|
|
3433
|
+
const el = box.querySelector(`[data-letter="${target.letter}"]`);
|
|
3434
|
+
if (el) box.scrollTop = el.offsetTop;
|
|
3435
|
+
};
|
|
3436
|
+
const touch = (e) => {
|
|
3437
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
3438
|
+
const i = Math.min(BAR.length - 1, Math.max(0, Math.floor((e.clientY - r.top) / r.height * BAR.length)));
|
|
3439
|
+
const l = BAR[i];
|
|
3440
|
+
if (l === touching) return;
|
|
3441
|
+
setTouching(l);
|
|
3442
|
+
jump(l);
|
|
3443
|
+
};
|
|
3444
|
+
return /* @__PURE__ */ jsxs17("div", { className: `gkim-indexed${className ? " " + className : ""}`, children: [
|
|
3445
|
+
/* @__PURE__ */ jsxs17("div", { className: "gkim-indexed__scroll", ref: scroller, children: [
|
|
3446
|
+
header,
|
|
3447
|
+
sections.map((sec) => /* @__PURE__ */ jsxs17("section", { "aria-label": sec.letter, children: [
|
|
3448
|
+
/* @__PURE__ */ jsx18("h3", { className: "gkim-indexed__head", "data-letter": sec.letter, children: sec.letter }),
|
|
3449
|
+
/* @__PURE__ */ jsx18("ul", { className: "gkim-indexed__list", children: sec.items.map((it) => /* @__PURE__ */ jsx18("li", { children: renderItem(it) }, keyOf(it))) })
|
|
3450
|
+
] }, sec.letter)),
|
|
3451
|
+
footer
|
|
3452
|
+
] }),
|
|
3453
|
+
sections.length > 0 && /* @__PURE__ */ jsx18(
|
|
3454
|
+
"div",
|
|
3455
|
+
{
|
|
3456
|
+
className: "gkim-indexbar",
|
|
3457
|
+
role: "toolbar",
|
|
3458
|
+
"aria-label": s.indexBar,
|
|
3459
|
+
onPointerDown: (e) => {
|
|
3460
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
3461
|
+
touch(e);
|
|
3462
|
+
},
|
|
3463
|
+
onPointerMove: (e) => {
|
|
3464
|
+
if (touching) touch(e);
|
|
3465
|
+
},
|
|
3466
|
+
onPointerUp: () => setTouching(null),
|
|
3467
|
+
onPointerCancel: () => setTouching(null),
|
|
3468
|
+
children: BAR.map((l) => /* @__PURE__ */ jsx18(
|
|
3469
|
+
"button",
|
|
3470
|
+
{
|
|
3471
|
+
type: "button",
|
|
3472
|
+
tabIndex: -1,
|
|
3473
|
+
"aria-label": l,
|
|
3474
|
+
className: `gkim-indexbar__l${present.has(l) ? " gkim-indexbar__l--on" : ""}`,
|
|
3475
|
+
onKeyDown: (e) => {
|
|
3476
|
+
if (e.key === "Enter") jump(l);
|
|
3477
|
+
},
|
|
3478
|
+
children: l
|
|
3479
|
+
},
|
|
3480
|
+
l
|
|
3481
|
+
))
|
|
3482
|
+
}
|
|
3483
|
+
),
|
|
3484
|
+
touching && touching !== TOP && /* @__PURE__ */ jsx18("div", { className: "gkim-indexbubble", "aria-hidden": "true", children: touching })
|
|
2915
3485
|
] });
|
|
2916
3486
|
}
|
|
2917
|
-
function DialogLayer({ stack, back }) {
|
|
2918
|
-
return /* @__PURE__ */ jsx17(Fragment6, { children: stack.map((r, i) => /* @__PURE__ */ jsx17(DialogBox, { back, children: /* @__PURE__ */ jsx17(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2919
|
-
}
|
|
2920
|
-
function OverlayBox({ children, back }) {
|
|
2921
|
-
const ref = useFocusTrap();
|
|
2922
|
-
return /* @__PURE__ */ jsx17("div", { className: "gkim-overlay", ref, tabIndex: -1, onKeyDown: escToBack(back), children });
|
|
2923
|
-
}
|
|
2924
|
-
function OverlayLayer({ stack, back }) {
|
|
2925
|
-
return /* @__PURE__ */ jsx17(Fragment6, { children: stack.map((r, i) => /* @__PURE__ */ jsx17(OverlayBox, { back, children: /* @__PURE__ */ jsx17(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
2926
|
-
}
|
|
2927
|
-
function LayerHost() {
|
|
2928
|
-
const { state: st, back, close } = useNavContext();
|
|
2929
|
-
return useMemo5(() => /* @__PURE__ */ jsxs15(Fragment6, { children: [
|
|
2930
|
-
/* @__PURE__ */ jsx17(DrawerLayer, { stack: st.drawer, back, close }),
|
|
2931
|
-
/* @__PURE__ */ jsx17(DialogLayer, { stack: st.dialog, back }),
|
|
2932
|
-
/* @__PURE__ */ jsx17(OverlayLayer, { stack: st.overlay, back })
|
|
2933
|
-
] }), [st, back, close]);
|
|
2934
|
-
}
|
|
2935
3487
|
|
|
2936
|
-
// src/ui/
|
|
2937
|
-
import { jsx as
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
3488
|
+
// src/ui/contacts/ContactsPage.tsx
|
|
3489
|
+
import { Fragment as Fragment7, jsx as jsx19, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
3490
|
+
function Entry({ label, tone, badge = 0, onClick }) {
|
|
3491
|
+
return /* @__PURE__ */ jsxs18("button", { type: "button", className: "gkim-contacts__entry", onClick, children: [
|
|
3492
|
+
/* @__PURE__ */ jsx19("span", { className: `gkim-contacts__entry-icon gkim-contacts__entry-icon--${tone}`, "aria-hidden": "true", children: label.slice(0, 1) }),
|
|
3493
|
+
/* @__PURE__ */ jsx19("span", { className: "gkim-contacts__entry-label", children: label }),
|
|
3494
|
+
badge > 0 && /* @__PURE__ */ jsx19(Badge, { count: badge })
|
|
3495
|
+
] });
|
|
3496
|
+
}
|
|
3497
|
+
function ImContacts({ onSelect }) {
|
|
3498
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3499
|
+
const nav = useNavContext();
|
|
3500
|
+
const frame = useFrame();
|
|
3501
|
+
const friends = useFriends();
|
|
3502
|
+
const [groups] = useFriendGroups(im);
|
|
3503
|
+
const pending = usePendingCount(im);
|
|
3504
|
+
const [query, setQuery] = useState15("");
|
|
3505
|
+
const [group, setGroup] = useState15(null);
|
|
3506
|
+
const curGroup = group !== null && groups?.some((g) => g.id === group) ? group : null;
|
|
3507
|
+
const q = query.trim().toLowerCase();
|
|
3508
|
+
const visible = useMemo5(() => friends.filter((f) => (curGroup === null || f.groupIds.includes(curGroup)) && (q === "" || f.remark.toLowerCase().includes(q) || f.nickname.toLowerCase().includes(q))), [friends, curGroup, q]);
|
|
3509
|
+
const sections = useMemo5(() => indexSections(visible, friendDisplayName, (f) => f.userId), [visible]);
|
|
3510
|
+
const counts = useMemo5(() => {
|
|
3511
|
+
const m = /* @__PURE__ */ new Map();
|
|
3512
|
+
for (const f of friends) for (const id of f.groupIds) m.set(id, (m.get(id) ?? 0) + 1);
|
|
3513
|
+
return m;
|
|
3514
|
+
}, [friends]);
|
|
3515
|
+
const selected = nav.state.main?.name === "contactProfile" ? nav.state.main.userId : null;
|
|
3516
|
+
const inWide = frame.kind === "list";
|
|
3517
|
+
const select = (f) => {
|
|
3518
|
+
if (onSelect) {
|
|
3519
|
+
onSelect(f.userId);
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
openUserCard({ im, callbacks, nav }, f.userId, void 0, inWide ? "contactProfile" : "userCard");
|
|
3523
|
+
};
|
|
3524
|
+
const addBtn = /* @__PURE__ */ jsx19(
|
|
3525
|
+
"button",
|
|
3526
|
+
{
|
|
3527
|
+
type: "button",
|
|
3528
|
+
className: "gkim-iconbtn",
|
|
3529
|
+
"aria-label": s.addFriend,
|
|
3530
|
+
title: s.addFriend,
|
|
3531
|
+
onClick: () => nav.open({ name: "addFriend" }),
|
|
3532
|
+
children: /* @__PURE__ */ jsx19(Icon, { name: "userPlus" })
|
|
3533
|
+
}
|
|
3534
|
+
);
|
|
3535
|
+
const search = /* @__PURE__ */ jsxs18("label", { className: "gkim-contacts__search", children: [
|
|
3536
|
+
/* @__PURE__ */ jsx19(Icon, { name: "search", size: 18 }),
|
|
3537
|
+
/* @__PURE__ */ jsx19(
|
|
3538
|
+
"input",
|
|
3539
|
+
{
|
|
3540
|
+
type: "search",
|
|
3541
|
+
value: query,
|
|
3542
|
+
placeholder: s.contactsSearchHint,
|
|
3543
|
+
"aria-label": s.contactsSearchHint,
|
|
3544
|
+
onChange: (e) => setQuery(e.target.value)
|
|
3545
|
+
}
|
|
3546
|
+
)
|
|
3547
|
+
] });
|
|
3548
|
+
const header = /* @__PURE__ */ jsxs18(Fragment7, { children: [
|
|
3549
|
+
!inWide && /* @__PURE__ */ jsx19("div", { className: "gkim-contacts__searchbar", children: search }),
|
|
3550
|
+
q === "" && /* @__PURE__ */ jsxs18(Fragment7, { children: [
|
|
3551
|
+
/* @__PURE__ */ jsxs18("div", { className: "gkim-contacts__entries", children: [
|
|
3552
|
+
/* @__PURE__ */ jsx19(Entry, { label: s.newFriends, tone: "new", badge: pending, onClick: () => nav.open({ name: "newFriends" }) }),
|
|
3553
|
+
/* @__PURE__ */ jsx19(Entry, { label: s.groupChats, tone: "group", onClick: () => nav.open({ name: "groupChats" }) }),
|
|
3554
|
+
/* @__PURE__ */ jsx19(Entry, { label: s.blocklist, tone: "block", onClick: () => nav.open({ name: "blocklist" }) })
|
|
3555
|
+
] }),
|
|
3556
|
+
groups && groups.length > 0 && /* @__PURE__ */ jsxs18("div", { className: "gkim-contacts__chips", role: "group", "aria-label": s.friendGroupsTitle, children: [
|
|
3557
|
+
/* @__PURE__ */ jsxs18("button", { type: "button", className: "gkim-chip", "aria-pressed": curGroup === null, onClick: () => setGroup(null), children: [
|
|
3558
|
+
s.allFriends,
|
|
3559
|
+
" ",
|
|
3560
|
+
friends.length
|
|
3561
|
+
] }),
|
|
3562
|
+
groups.map((g) => /* @__PURE__ */ jsxs18("button", { type: "button", className: "gkim-chip", "aria-pressed": curGroup === g.id, onClick: () => setGroup(g.id), children: [
|
|
3563
|
+
g.name,
|
|
3564
|
+
" ",
|
|
3565
|
+
counts.get(g.id) ?? 0
|
|
3566
|
+
] }, g.id))
|
|
3567
|
+
] })
|
|
3568
|
+
] })
|
|
3569
|
+
] });
|
|
3570
|
+
const list = /* @__PURE__ */ jsx19(
|
|
3571
|
+
IndexedList,
|
|
3572
|
+
{
|
|
3573
|
+
className: "gkim-contacts",
|
|
3574
|
+
sections,
|
|
3575
|
+
keyOf: (f) => f.userId,
|
|
3576
|
+
header,
|
|
3577
|
+
footer: visible.length === 0 ? /* @__PURE__ */ jsx19("div", { className: "gkim-empty gkim-contacts__empty", children: s.emptyContacts }) : null,
|
|
3578
|
+
renderItem: (f) => {
|
|
3579
|
+
const name = friendDisplayName(f);
|
|
3580
|
+
const on = f.userId === selected;
|
|
3581
|
+
return /* @__PURE__ */ jsxs18(
|
|
3582
|
+
"button",
|
|
3583
|
+
{
|
|
3584
|
+
type: "button",
|
|
3585
|
+
className: `gkim-friend${on ? " gkim-friend--selected" : ""}`,
|
|
3586
|
+
"aria-current": on || void 0,
|
|
3587
|
+
onClick: () => select(f),
|
|
3588
|
+
children: [
|
|
3589
|
+
/* @__PURE__ */ jsx19(Avatar, { id: f.userId, name, url: f.avatarUrl }),
|
|
3590
|
+
/* @__PURE__ */ jsx19("span", { className: "gkim-friend__name", children: name }),
|
|
3591
|
+
f.remark !== "" && f.nickname !== "" && /* @__PURE__ */ jsxs18("span", { className: "gkim-friend__sub", children: [
|
|
3592
|
+
"(",
|
|
3593
|
+
f.nickname,
|
|
3594
|
+
")"
|
|
3595
|
+
] })
|
|
3596
|
+
]
|
|
3597
|
+
}
|
|
3598
|
+
);
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
);
|
|
3602
|
+
if (inWide) {
|
|
3603
|
+
return /* @__PURE__ */ jsxs18("div", { className: "gkim-listpane", children: [
|
|
3604
|
+
/* @__PURE__ */ jsxs18("div", { className: "gkim-listpane__head", children: [
|
|
3605
|
+
/* @__PURE__ */ jsx19("h2", { className: "gkim-sr-only", children: s.contactsTitle }),
|
|
3606
|
+
search,
|
|
3607
|
+
addBtn
|
|
3608
|
+
] }),
|
|
3609
|
+
list
|
|
3610
|
+
] });
|
|
3611
|
+
}
|
|
3612
|
+
return /* @__PURE__ */ jsx19(Page, { title: s.contactsTitle, actions: addBtn, scroll: false, children: list });
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
// src/ui/contacts/FriendGroups.tsx
|
|
3616
|
+
import { useEffect as useEffect11, useMemo as useMemo6, useRef as useRef10, useState as useState16 } from "react";
|
|
3617
|
+
import { jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
3618
|
+
var GROUP_NAME_MAX = 20;
|
|
3619
|
+
function FriendGroups() {
|
|
3620
|
+
const { im, strings: s } = useImUi();
|
|
3621
|
+
const frame = useFrame();
|
|
3622
|
+
const { toast, confirm } = useFeedback();
|
|
3623
|
+
const friends = useFriends();
|
|
3624
|
+
const [groups] = useFriendGroups(im);
|
|
3625
|
+
const [local, setLocal] = useState16(null);
|
|
3626
|
+
useEffect11(() => setLocal(null), [groups]);
|
|
3627
|
+
const list = local ?? groups ?? [];
|
|
3628
|
+
const dragFrom = useRef10(null);
|
|
3629
|
+
const [dragging, setDragging] = useState16(null);
|
|
3630
|
+
const [prompt, setPrompt] = useState16(null);
|
|
3631
|
+
const [name, setName] = useState16("");
|
|
3632
|
+
const counts = useMemo6(() => {
|
|
3633
|
+
const m = /* @__PURE__ */ new Map();
|
|
3634
|
+
for (const f of friends) for (const id of f.groupIds) m.set(id, (m.get(id) ?? 0) + 1);
|
|
3635
|
+
return m;
|
|
3636
|
+
}, [friends]);
|
|
3637
|
+
const guard = async (f) => {
|
|
3638
|
+
try {
|
|
3639
|
+
await f();
|
|
3640
|
+
} catch (e) {
|
|
3641
|
+
toast(errorText(e, s.operationFailed));
|
|
3642
|
+
}
|
|
3643
|
+
notifyContacts(im, "groups");
|
|
3644
|
+
};
|
|
3645
|
+
const move = (from, to) => {
|
|
3646
|
+
const next = [...list];
|
|
3647
|
+
next.splice(to, 0, next.splice(from, 1)[0]);
|
|
3648
|
+
return next;
|
|
3649
|
+
};
|
|
3650
|
+
const commit = (next) => {
|
|
3651
|
+
setLocal(next);
|
|
3652
|
+
return guard(async () => {
|
|
3653
|
+
for (let i = 0; i < next.length; i++) {
|
|
3654
|
+
if (next[i].sort !== i) await im.updateFriendGroup(next[i].id, { sort: i });
|
|
3655
|
+
}
|
|
3656
|
+
});
|
|
3657
|
+
};
|
|
3658
|
+
const remove = async (g) => {
|
|
3659
|
+
if (!await confirm({ content: fill(s.deleteFriendGroupConfirm, { name: g.name }), ok: s.deleteFriendGroup, danger: true })) return;
|
|
3660
|
+
await guard(() => im.deleteFriendGroup(g.id));
|
|
3661
|
+
};
|
|
3662
|
+
const openPrompt = (p) => {
|
|
3663
|
+
setPrompt(p);
|
|
3664
|
+
setName(p.kind === "rename" ? p.group.name : "");
|
|
3665
|
+
};
|
|
3666
|
+
const submitPrompt = async () => {
|
|
3667
|
+
const n = name.trim();
|
|
3668
|
+
const p = prompt;
|
|
3669
|
+
if (!p || !n) return;
|
|
3670
|
+
setPrompt(null);
|
|
3671
|
+
if (p.kind === "new") await guard(() => im.createFriendGroup(n));
|
|
3672
|
+
else if (n !== p.group.name) await guard(() => im.updateFriendGroup(p.group.id, { name: n }));
|
|
3673
|
+
};
|
|
3674
|
+
return /* @__PURE__ */ jsxs19(
|
|
3675
|
+
Page,
|
|
3676
|
+
{
|
|
3677
|
+
title: s.friendGroupsTitle,
|
|
3678
|
+
className: "gkim-friendgroups",
|
|
3679
|
+
actions: /* @__PURE__ */ jsx20("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", onClick: frame.back, children: s.done }),
|
|
3680
|
+
children: [
|
|
3681
|
+
/* @__PURE__ */ jsx20("p", { className: "gkim-form__tip gkim-friendgroups__tip", children: s.friendGroupsTip }),
|
|
3682
|
+
/* @__PURE__ */ jsxs19("ul", { className: "gkim-friendgroups__list", children: [
|
|
3683
|
+
list.map((g, i) => /* @__PURE__ */ jsxs19(
|
|
3684
|
+
"li",
|
|
3685
|
+
{
|
|
3686
|
+
className: `gkim-friendgroup${dragging === i ? " gkim-friendgroup--dragging" : ""}`,
|
|
3687
|
+
draggable: true,
|
|
3688
|
+
onDragStart: (e) => {
|
|
3689
|
+
dragFrom.current = i;
|
|
3690
|
+
setDragging(i);
|
|
3691
|
+
e.dataTransfer?.setData("text/plain", String(g.id));
|
|
3692
|
+
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
|
|
3693
|
+
},
|
|
3694
|
+
onDragOver: (e) => {
|
|
3695
|
+
e.preventDefault();
|
|
3696
|
+
const from = dragFrom.current;
|
|
3697
|
+
if (from === null || from === i) return;
|
|
3698
|
+
setLocal(move(from, i));
|
|
3699
|
+
dragFrom.current = i;
|
|
3700
|
+
setDragging(i);
|
|
3701
|
+
},
|
|
3702
|
+
onDrop: (e) => e.preventDefault(),
|
|
3703
|
+
onDragEnd: () => {
|
|
3704
|
+
const was = dragFrom.current;
|
|
3705
|
+
dragFrom.current = null;
|
|
3706
|
+
setDragging(null);
|
|
3707
|
+
if (was !== null && local) void commit(local);
|
|
3708
|
+
},
|
|
3709
|
+
children: [
|
|
3710
|
+
/* @__PURE__ */ jsx20("button", { type: "button", className: "gkim-friendgroup__del", "aria-label": `${s.deleteFriendGroup} ${g.name}`, onClick: () => remove(g), children: /* @__PURE__ */ jsx20(Icon, { name: "minus", size: 22 }) }),
|
|
3711
|
+
/* @__PURE__ */ jsx20("span", { className: "gkim-friendgroup__name", children: g.name }),
|
|
3712
|
+
/* @__PURE__ */ jsx20("span", { className: "gkim-friendgroup__count", children: fill(s.peopleCount, { n: counts.get(g.id) ?? 0 }) }),
|
|
3713
|
+
/* @__PURE__ */ jsx20("button", { type: "button", className: "gkim-iconbtn", "aria-label": `${s.rename} ${g.name}`, onClick: () => openPrompt({ kind: "rename", group: g }), children: /* @__PURE__ */ jsx20(Icon, { name: "edit", size: 18 }) }),
|
|
3714
|
+
/* @__PURE__ */ jsx20(
|
|
3715
|
+
"button",
|
|
3716
|
+
{
|
|
3717
|
+
type: "button",
|
|
3718
|
+
className: "gkim-iconbtn gkim-friendgroup__grip",
|
|
3719
|
+
"aria-label": `${s.dragToSort} ${g.name}`,
|
|
3720
|
+
onKeyDown: (e) => {
|
|
3721
|
+
const to = e.key === "ArrowUp" ? i - 1 : e.key === "ArrowDown" ? i + 1 : -1;
|
|
3722
|
+
if (to < 0 || to >= list.length) return;
|
|
3723
|
+
e.preventDefault();
|
|
3724
|
+
void commit(move(i, to));
|
|
3725
|
+
},
|
|
3726
|
+
children: /* @__PURE__ */ jsx20(Icon, { name: "grip", size: 18 })
|
|
3727
|
+
}
|
|
3728
|
+
)
|
|
3729
|
+
]
|
|
3730
|
+
},
|
|
3731
|
+
g.id
|
|
3732
|
+
)),
|
|
3733
|
+
/* @__PURE__ */ jsx20("li", { children: /* @__PURE__ */ jsxs19("button", { type: "button", className: "gkim-friendgroups__new", onClick: () => openPrompt({ kind: "new" }), children: [
|
|
3734
|
+
/* @__PURE__ */ jsx20(Icon, { name: "add", size: 18 }),
|
|
3735
|
+
s.newFriendGroup
|
|
3736
|
+
] }) })
|
|
3737
|
+
] }),
|
|
3738
|
+
prompt && /* @__PURE__ */ jsxs19(
|
|
3739
|
+
"form",
|
|
3740
|
+
{
|
|
3741
|
+
className: "gkim-friendgroups__prompt",
|
|
3742
|
+
onSubmit: (e) => {
|
|
3743
|
+
e.preventDefault();
|
|
3744
|
+
void submitPrompt();
|
|
3745
|
+
},
|
|
3746
|
+
onKeyDown: (e) => {
|
|
3747
|
+
if (e.key === "Escape") {
|
|
3748
|
+
e.stopPropagation();
|
|
3749
|
+
setPrompt(null);
|
|
3750
|
+
}
|
|
3751
|
+
},
|
|
3752
|
+
children: [
|
|
3753
|
+
/* @__PURE__ */ jsx20("h3", { className: "gkim-friendgroups__prompt-title", children: prompt.kind === "new" ? s.newFriendGroup : `${s.rename}「${prompt.group.name}」` }),
|
|
3754
|
+
/* @__PURE__ */ jsx20(
|
|
3755
|
+
"input",
|
|
3756
|
+
{
|
|
3757
|
+
className: "gkim-input",
|
|
3758
|
+
autoFocus: true,
|
|
3759
|
+
value: name,
|
|
3760
|
+
maxLength: GROUP_NAME_MAX,
|
|
3761
|
+
placeholder: s.friendGroupName,
|
|
3762
|
+
"aria-label": s.friendGroupName,
|
|
3763
|
+
onChange: (e) => setName(e.target.value)
|
|
3764
|
+
}
|
|
3765
|
+
),
|
|
3766
|
+
/* @__PURE__ */ jsxs19("div", { className: "gkim-friendgroups__prompt-actions", children: [
|
|
3767
|
+
/* @__PURE__ */ jsx20("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => setPrompt(null), children: s.cancel }),
|
|
3768
|
+
/* @__PURE__ */ jsx20("button", { type: "submit", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: !name.trim(), children: s.confirm })
|
|
3769
|
+
] })
|
|
3770
|
+
]
|
|
3771
|
+
}
|
|
3772
|
+
)
|
|
3773
|
+
]
|
|
3774
|
+
}
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
|
|
3778
|
+
// src/ui/contacts/FriendSettings.tsx
|
|
3779
|
+
import { useState as useState17 } from "react";
|
|
3780
|
+
import { jsx as jsx21, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
3781
|
+
var REMARK_MAX = 32;
|
|
3782
|
+
var GROUP_NAME_MAX2 = 20;
|
|
3783
|
+
function FriendSettings({ userId }) {
|
|
3784
|
+
const { im, strings: s } = useImUi();
|
|
3785
|
+
const friends = useFriends();
|
|
3786
|
+
const friend = friends.find((f) => f.userId === userId) ?? safe(() => im.friend(userId), null);
|
|
3787
|
+
if (!friend) return /* @__PURE__ */ jsx21(Page, { title: s.remarkAndGroups });
|
|
3788
|
+
return /* @__PURE__ */ jsx21(Form, { friend });
|
|
3789
|
+
}
|
|
3790
|
+
function Form({ friend: f }) {
|
|
3791
|
+
const { im, strings: s } = useImUi();
|
|
3792
|
+
const nav = useNavContext();
|
|
3793
|
+
const frame = useFrame();
|
|
3794
|
+
const { toast } = useFeedback();
|
|
3795
|
+
const [groups] = useFriendGroups(im);
|
|
3796
|
+
const [remark, setRemark] = useState17(f.remark);
|
|
3797
|
+
const [picked, setPicked] = useState17(() => new Set(f.groupIds));
|
|
3798
|
+
const [draft, setDraft] = useState17(null);
|
|
3799
|
+
const [busy, setBusy] = useState17(false);
|
|
3800
|
+
const toggle = (id) => setPicked((old) => {
|
|
3801
|
+
const n = new Set(old);
|
|
3802
|
+
if (n.has(id)) n.delete(id);
|
|
3803
|
+
else n.add(id);
|
|
3804
|
+
return n;
|
|
3805
|
+
});
|
|
3806
|
+
const createGroup = async () => {
|
|
3807
|
+
const name = draft?.trim();
|
|
3808
|
+
if (!name) {
|
|
3809
|
+
setDraft(null);
|
|
3810
|
+
return;
|
|
3811
|
+
}
|
|
3812
|
+
try {
|
|
3813
|
+
const g = await im.createFriendGroup(name);
|
|
3814
|
+
setPicked((old) => new Set(old).add(g.id));
|
|
3815
|
+
setDraft(null);
|
|
3816
|
+
notifyContacts(im, "groups");
|
|
3817
|
+
} catch (e) {
|
|
3818
|
+
toast(errorText(e, s.operationFailed));
|
|
3819
|
+
}
|
|
3820
|
+
};
|
|
3821
|
+
const save = async () => {
|
|
3822
|
+
const r = remark.trim();
|
|
3823
|
+
const order = (groups ?? []).filter((g) => picked.has(g.id)).map((g) => g.id);
|
|
3824
|
+
const before = (groups ?? []).filter((g) => f.groupIds.includes(g.id)).map((g) => g.id);
|
|
3825
|
+
const groupsChanged = order.join(",") !== before.join(",");
|
|
3826
|
+
if (r === f.remark && !groupsChanged) {
|
|
3827
|
+
frame.back();
|
|
3828
|
+
return;
|
|
3829
|
+
}
|
|
3830
|
+
setBusy(true);
|
|
3831
|
+
try {
|
|
3832
|
+
await im.setFriend(f.userId, { remark: r === f.remark ? void 0 : r, groupIds: groupsChanged ? order : void 0 });
|
|
3833
|
+
frame.back();
|
|
3834
|
+
} catch (e) {
|
|
3835
|
+
setBusy(false);
|
|
3836
|
+
toast(errorText(e, s.operationFailed));
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3839
|
+
return /* @__PURE__ */ jsxs20(
|
|
3840
|
+
Page,
|
|
3841
|
+
{
|
|
3842
|
+
title: s.remarkAndGroups,
|
|
3843
|
+
className: "gkim-friendsettings",
|
|
3844
|
+
actions: /* @__PURE__ */ jsx21("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: busy || groups === null, onClick: save, children: s.done }),
|
|
3845
|
+
children: [
|
|
3846
|
+
/* @__PURE__ */ jsx21("label", { className: "gkim-form__label", htmlFor: `gkim-remark-${f.userId}`, children: s.remark }),
|
|
3847
|
+
/* @__PURE__ */ jsxs20("div", { className: "gkim-friendsettings__remark", children: [
|
|
3848
|
+
/* @__PURE__ */ jsx21(
|
|
3849
|
+
"input",
|
|
3850
|
+
{
|
|
3851
|
+
id: `gkim-remark-${f.userId}`,
|
|
3852
|
+
className: "gkim-input",
|
|
3853
|
+
value: remark,
|
|
3854
|
+
maxLength: REMARK_MAX,
|
|
3855
|
+
onChange: (e) => setRemark(e.target.value)
|
|
3856
|
+
}
|
|
3857
|
+
),
|
|
3858
|
+
remark !== "" && /* @__PURE__ */ jsx21("button", { type: "button", className: "gkim-friendsettings__clear", "aria-label": s.clearRemark, onClick: () => setRemark(""), children: /* @__PURE__ */ jsx21(Icon, { name: "close", size: 14 }) })
|
|
3859
|
+
] }),
|
|
3860
|
+
/* @__PURE__ */ jsx21("p", { className: "gkim-form__tip", children: fill(s.remarkTip, { name: f.nickname || f.userId }) }),
|
|
3861
|
+
/* @__PURE__ */ jsxs20("div", { className: "gkim-form__labelrow", children: [
|
|
3862
|
+
/* @__PURE__ */ jsx21("span", { className: "gkim-form__label", children: s.friendGroupsMulti }),
|
|
3863
|
+
/* @__PURE__ */ jsxs20("button", { type: "button", className: "gkim-linkbtn gkim-friendsettings__manage", onClick: () => nav.open({ name: "friendGroups" }), children: [
|
|
3864
|
+
s.manageFriendGroups,
|
|
3865
|
+
/* @__PURE__ */ jsx21(Icon, { name: "chevron", size: 14 })
|
|
3866
|
+
] })
|
|
3867
|
+
] }),
|
|
3868
|
+
/* @__PURE__ */ jsxs20("div", { className: "gkim-friendsettings__chips", role: "group", "aria-label": s.friendGroupsMulti, children: [
|
|
3869
|
+
(groups ?? []).map((g) => /* @__PURE__ */ jsxs20("button", { type: "button", className: "gkim-chip gkim-chip--check", "aria-pressed": picked.has(g.id), onClick: () => toggle(g.id), children: [
|
|
3870
|
+
picked.has(g.id) && /* @__PURE__ */ jsx21(Icon, { name: "check", size: 14 }),
|
|
3871
|
+
g.name
|
|
3872
|
+
] }, g.id)),
|
|
3873
|
+
draft === null ? /* @__PURE__ */ jsxs20("button", { type: "button", className: "gkim-chip gkim-chip--dashed", disabled: groups === null, onClick: () => setDraft(""), children: [
|
|
3874
|
+
/* @__PURE__ */ jsx21(Icon, { name: "add", size: 14 }),
|
|
3875
|
+
s.newFriendGroup
|
|
3876
|
+
] }) : /* @__PURE__ */ jsxs20("form", { className: "gkim-chip gkim-chip--input", onSubmit: (e) => {
|
|
3877
|
+
e.preventDefault();
|
|
3878
|
+
void createGroup();
|
|
3879
|
+
}, children: [
|
|
3880
|
+
/* @__PURE__ */ jsx21(
|
|
3881
|
+
"input",
|
|
3882
|
+
{
|
|
3883
|
+
autoFocus: true,
|
|
3884
|
+
value: draft,
|
|
3885
|
+
maxLength: GROUP_NAME_MAX2,
|
|
3886
|
+
placeholder: s.friendGroupName,
|
|
3887
|
+
"aria-label": s.friendGroupName,
|
|
3888
|
+
onChange: (e) => setDraft(e.target.value),
|
|
3889
|
+
onKeyDown: (e) => {
|
|
3890
|
+
if (e.key === "Escape") {
|
|
3891
|
+
e.stopPropagation();
|
|
3892
|
+
setDraft(null);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
),
|
|
3897
|
+
/* @__PURE__ */ jsx21("button", { type: "submit", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: !draft.trim(), children: s.add })
|
|
3898
|
+
] })
|
|
3899
|
+
] })
|
|
3900
|
+
]
|
|
3901
|
+
}
|
|
3902
|
+
);
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
// src/ui/contacts/NewFriendsPage.tsx
|
|
3906
|
+
import { useCallback as useCallback8, useEffect as useEffect12, useRef as useRef11, useState as useState18 } from "react";
|
|
3907
|
+
import { jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
3908
|
+
function RequestList({ box, hidden }) {
|
|
3909
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
3910
|
+
const nav = useNavContext();
|
|
3911
|
+
const { toast } = useFeedback();
|
|
3912
|
+
const [items, setItems] = useState18(null);
|
|
3913
|
+
const [busy, setBusy] = useState18(/* @__PURE__ */ new Set());
|
|
3914
|
+
const cursor = useRef11(null);
|
|
3915
|
+
const loading = useRef11(false);
|
|
3916
|
+
const fetch = useCallback8(async (reset) => {
|
|
3917
|
+
if (loading.current || !reset && !cursor.current) return;
|
|
3918
|
+
loading.current = true;
|
|
3919
|
+
try {
|
|
3920
|
+
const r = await im.friendRequests(box, { cursor: reset ? null : cursor.current });
|
|
3921
|
+
cursor.current = r.nextCursor;
|
|
3922
|
+
setItems((old) => reset || !old ? r.items : [...old, ...r.items]);
|
|
3923
|
+
} catch (e) {
|
|
3924
|
+
setItems((old) => old ?? []);
|
|
3925
|
+
toast(errorText(e, s.operationFailed));
|
|
3926
|
+
} finally {
|
|
3927
|
+
loading.current = false;
|
|
3928
|
+
}
|
|
3929
|
+
}, [im, box, toast, s]);
|
|
3930
|
+
useEffect12(() => {
|
|
3931
|
+
if (im.currentUserId === null) {
|
|
3932
|
+
setItems([]);
|
|
3933
|
+
return;
|
|
3934
|
+
}
|
|
3935
|
+
void fetch(true);
|
|
3936
|
+
return box === "in" ? im.on("friendRequest", () => {
|
|
3937
|
+
void fetch(true);
|
|
3938
|
+
}) : void 0;
|
|
3939
|
+
}, [im, box, fetch]);
|
|
3940
|
+
const handle = async (r, accept) => {
|
|
3941
|
+
setBusy((x) => new Set(x).add(r.requestId));
|
|
3942
|
+
try {
|
|
3943
|
+
if (accept) await im.acceptFriend(r.requestId);
|
|
3944
|
+
else await im.rejectFriend(r.requestId);
|
|
3945
|
+
const status = accept ? "accepted" : "rejected";
|
|
3946
|
+
setItems((old) => old?.map((x) => x.requestId === r.requestId ? { ...x, status, updatedAt: Date.now() } : x) ?? null);
|
|
3947
|
+
notifyContacts(im, "pending");
|
|
3948
|
+
} catch (e) {
|
|
3949
|
+
toast(errorText(e, s.operationFailed));
|
|
3950
|
+
} finally {
|
|
3951
|
+
setBusy((x) => {
|
|
3952
|
+
const n = new Set(x);
|
|
3953
|
+
n.delete(r.requestId);
|
|
3954
|
+
return n;
|
|
3955
|
+
});
|
|
3956
|
+
}
|
|
3957
|
+
};
|
|
3958
|
+
const statusText = (st) => st === "pending" ? s.requestPending : st === "accepted" ? s.requestAccepted : st === "rejected" ? s.requestRejected : s.requestExpired;
|
|
3959
|
+
const tip = /* @__PURE__ */ jsx22("p", { className: "gkim-requests__tip", children: s.requestsTip });
|
|
3960
|
+
return /* @__PURE__ */ jsxs21(
|
|
3961
|
+
"div",
|
|
3962
|
+
{
|
|
3963
|
+
className: "gkim-requests",
|
|
3964
|
+
role: "tabpanel",
|
|
3965
|
+
hidden,
|
|
3966
|
+
"aria-label": box === "in" ? s.requestsIn : s.requestsOut,
|
|
3967
|
+
onScroll: (e) => {
|
|
3968
|
+
const el = e.currentTarget;
|
|
3969
|
+
if (el.scrollHeight - el.scrollTop - el.clientHeight < 200) void fetch(false);
|
|
3970
|
+
},
|
|
3971
|
+
children: [
|
|
3972
|
+
items === null ? null : items.length === 0 ? /* @__PURE__ */ jsx22("div", { className: "gkim-empty gkim-requests__empty", children: s.emptyRequests }) : /* @__PURE__ */ jsx22("ul", { className: "gkim-requests__list", children: items.map((r) => {
|
|
3973
|
+
const name = r.nickname || r.userId;
|
|
3974
|
+
const b = busy.has(r.requestId);
|
|
3975
|
+
const open = () => openUserCard({ im, callbacks, nav }, r.userId, { nickname: r.nickname, avatarUrl: r.avatarUrl });
|
|
3976
|
+
return /* @__PURE__ */ jsxs21("li", { className: "gkim-request", children: [
|
|
3977
|
+
/* @__PURE__ */ jsxs21("button", { type: "button", className: "gkim-request__main", onClick: open, children: [
|
|
3978
|
+
/* @__PURE__ */ jsx22(Avatar, { id: r.userId, name, url: r.avatarUrl, size: 44 }),
|
|
3979
|
+
/* @__PURE__ */ jsxs21("span", { className: "gkim-request__body", children: [
|
|
3980
|
+
/* @__PURE__ */ jsx22("span", { className: "gkim-request__name", children: name }),
|
|
3981
|
+
r.message !== "" && /* @__PURE__ */ jsx22("span", { className: "gkim-request__msg", children: r.message })
|
|
3982
|
+
] })
|
|
3983
|
+
] }),
|
|
3984
|
+
r.status === "pending" && box === "in" ? /* @__PURE__ */ jsxs21("span", { className: "gkim-request__actions", children: [
|
|
3985
|
+
/* @__PURE__ */ jsx22("button", { type: "button", className: "gkim-btn gkim-btn--sm", disabled: b, onClick: () => handle(r, false), children: s.reject }),
|
|
3986
|
+
/* @__PURE__ */ jsx22("button", { type: "button", className: "gkim-btn gkim-btn--sm gkim-btn--primary", disabled: b, onClick: () => handle(r, true), children: s.accept })
|
|
3987
|
+
] }) : /* @__PURE__ */ jsx22("span", { className: "gkim-request__status", children: statusText(r.status) })
|
|
3988
|
+
] }, r.requestId);
|
|
3989
|
+
}) }),
|
|
3990
|
+
items !== null && tip
|
|
3991
|
+
]
|
|
3992
|
+
}
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
function ImNewFriends() {
|
|
3996
|
+
const { strings: s } = useImUi();
|
|
3997
|
+
const nav = useNavContext();
|
|
3998
|
+
const [tab, setTab] = useState18("in");
|
|
3999
|
+
const tabBtn = (b, label) => /* @__PURE__ */ jsx22("button", { type: "button", role: "tab", "aria-selected": tab === b, className: "gkim-tabs__tab", onClick: () => setTab(b), children: label });
|
|
4000
|
+
return /* @__PURE__ */ jsxs21(
|
|
4001
|
+
Page,
|
|
4002
|
+
{
|
|
4003
|
+
title: s.newFriends,
|
|
4004
|
+
className: "gkim-newfriends",
|
|
4005
|
+
scroll: false,
|
|
4006
|
+
actions: /* @__PURE__ */ jsx22("button", { type: "button", className: "gkim-btn gkim-btn--sm", onClick: () => nav.open({ name: "addFriend" }), children: s.addFriend }),
|
|
4007
|
+
children: [
|
|
4008
|
+
/* @__PURE__ */ jsxs21("div", { className: "gkim-tabs", role: "tablist", children: [
|
|
4009
|
+
tabBtn("in", s.requestsIn),
|
|
4010
|
+
tabBtn("out", s.requestsOut)
|
|
4011
|
+
] }),
|
|
4012
|
+
/* @__PURE__ */ jsx22(RequestList, { box: "in", hidden: tab !== "in" }),
|
|
4013
|
+
/* @__PURE__ */ jsx22(RequestList, { box: "out", hidden: tab !== "out" })
|
|
4014
|
+
]
|
|
4015
|
+
}
|
|
4016
|
+
);
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
// src/ui/contacts/UserCard.tsx
|
|
4020
|
+
import { useState as useState19 } from "react";
|
|
4021
|
+
import { ImApiError as ImApiError6 } from "@guokit-dev/im";
|
|
4022
|
+
import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
4023
|
+
var MESSAGE_MAX = 50;
|
|
4024
|
+
function ImUserCard({ userId }) {
|
|
4025
|
+
const { im, me, strings: s } = useImUi();
|
|
4026
|
+
const nav = useNavContext();
|
|
4027
|
+
const frame = useFrame();
|
|
4028
|
+
const { toast, confirm } = useFeedback();
|
|
4029
|
+
const friends = useFriends();
|
|
4030
|
+
useConversations();
|
|
4031
|
+
const [groups] = useFriendGroups(im);
|
|
4032
|
+
const menu = useContextMenu();
|
|
4033
|
+
const [message, setMessage] = useState19(() => me.nickname ? fill(s.friendRequestDefault, { name: me.nickname }) : "");
|
|
4034
|
+
const [busy, setBusy] = useState19(false);
|
|
4035
|
+
const [result, setResult] = useState19(null);
|
|
4036
|
+
const friend = friends.find((f) => f.userId === userId) ?? safe(() => im.friend(userId), null);
|
|
4037
|
+
const isSelf = im.currentUserId === userId;
|
|
4038
|
+
const hint = userHint(im, userId);
|
|
4039
|
+
const nickname = friend?.nickname || hint.nickname;
|
|
4040
|
+
const title = friend ? friendDisplayName(friend) : hint.nickname || userId;
|
|
4041
|
+
const avatarUrl = friend?.avatarUrl || hint.avatarUrl;
|
|
4042
|
+
const main = frame.kind === "main";
|
|
4043
|
+
const run = async (f) => {
|
|
4044
|
+
try {
|
|
4045
|
+
await f();
|
|
4046
|
+
return true;
|
|
4047
|
+
} catch (e) {
|
|
4048
|
+
toast(errorText(e, s.operationFailed));
|
|
4049
|
+
return false;
|
|
4050
|
+
}
|
|
4051
|
+
};
|
|
4052
|
+
const entries = [
|
|
4053
|
+
{
|
|
4054
|
+
label: s.blockUser,
|
|
4055
|
+
onSelect: async () => {
|
|
4056
|
+
if (await confirm({ title: s.blockUser, content: s.blockConfirm, danger: true })) void run(() => im.block(userId));
|
|
4057
|
+
}
|
|
4058
|
+
},
|
|
4059
|
+
{ label: s.report, onSelect: () => nav.open({ name: "report", target: userId, title: s.report }) },
|
|
4060
|
+
...friend ? [{
|
|
4061
|
+
label: s.deleteFriend,
|
|
4062
|
+
danger: true,
|
|
4063
|
+
onSelect: async () => {
|
|
4064
|
+
const ok = await confirm({ content: fill(s.deleteFriendConfirm, { name: friendDisplayName(friend) }), ok: s.deleteFriend, danger: true });
|
|
4065
|
+
if (ok && await run(() => im.deleteFriend(userId))) frame.back();
|
|
4066
|
+
}
|
|
4067
|
+
}] : []
|
|
4068
|
+
];
|
|
4069
|
+
const moreBtn = isSelf ? null : /* @__PURE__ */ jsx23(
|
|
4070
|
+
"button",
|
|
4071
|
+
{
|
|
4072
|
+
type: "button",
|
|
4073
|
+
className: "gkim-iconbtn",
|
|
4074
|
+
"aria-label": s.more,
|
|
4075
|
+
title: s.more,
|
|
4076
|
+
"aria-haspopup": "menu",
|
|
4077
|
+
"aria-expanded": !!menu.at,
|
|
4078
|
+
onClick: (e) => {
|
|
4079
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
4080
|
+
menu.open({ x: r.left, y: r.bottom + 4 });
|
|
4081
|
+
},
|
|
4082
|
+
children: /* @__PURE__ */ jsx23(Icon, { name: "more" })
|
|
4083
|
+
}
|
|
4084
|
+
);
|
|
4085
|
+
const add = async () => {
|
|
4086
|
+
setBusy(true);
|
|
4087
|
+
setResult(null);
|
|
4088
|
+
try {
|
|
4089
|
+
const r = await im.addFriend(userId, message.trim());
|
|
4090
|
+
setResult({ text: r.status === "friend" ? s.becameFriends : s.requestSent, error: false });
|
|
4091
|
+
} catch (e) {
|
|
4092
|
+
const code = e instanceof ImApiError6 ? e.code : "";
|
|
4093
|
+
const text = code === "IM_FRIEND_ADD_DENIED" ? s.addDenied : code === "IM_BLOCKED" ? s.addBlocked : code === "IM_RATE_LIMITED" ? s.rateLimited : errorText(e, s.operationFailed);
|
|
4094
|
+
setResult({ text, error: true });
|
|
4095
|
+
} finally {
|
|
4096
|
+
setBusy(false);
|
|
4097
|
+
}
|
|
4098
|
+
};
|
|
4099
|
+
const stranger = !friend && !isSelf;
|
|
4100
|
+
const head = /* @__PURE__ */ jsxs22("div", { className: `gkim-usercard__head${stranger ? " gkim-usercard__head--center" : ""}`, children: [
|
|
4101
|
+
/* @__PURE__ */ jsx23(Avatar, { id: userId, name: title, url: avatarUrl, size: stranger ? 72 : 64 }),
|
|
4102
|
+
/* @__PURE__ */ jsxs22("div", { className: "gkim-usercard__who", children: [
|
|
4103
|
+
/* @__PURE__ */ jsx23("div", { className: "gkim-usercard__name", children: title }),
|
|
4104
|
+
friend && friend.remark !== "" && nickname !== "" && /* @__PURE__ */ jsx23("div", { className: "gkim-usercard__sub", children: fill(s.nicknameLabel, { name: nickname }) }),
|
|
4105
|
+
/* @__PURE__ */ jsx23("div", { className: "gkim-usercard__sub", children: fill(s.accountLabel, { id: userId }) }),
|
|
4106
|
+
stranger && /* @__PURE__ */ jsx23("span", { className: "gkim-usercard__tag", children: s.notFriendYet })
|
|
4107
|
+
] }),
|
|
4108
|
+
main && moreBtn
|
|
4109
|
+
] });
|
|
4110
|
+
let body = null;
|
|
4111
|
+
if (friend) {
|
|
4112
|
+
const names = (groups ?? []).filter((g) => friend.groupIds.includes(g.id)).map((g) => g.name);
|
|
4113
|
+
body = /* @__PURE__ */ jsxs22(Fragment8, { children: [
|
|
4114
|
+
/* @__PURE__ */ jsxs22("div", { className: "gkim-usercard__rows", children: [
|
|
4115
|
+
/* @__PURE__ */ jsxs22("button", { type: "button", className: "gkim-usercard__row", onClick: () => nav.open({ name: "friendSettings", userId }), children: [
|
|
4116
|
+
/* @__PURE__ */ jsx23("span", { className: "gkim-usercard__label", children: s.remarkAndGroups }),
|
|
4117
|
+
/* @__PURE__ */ jsx23("span", { className: "gkim-usercard__value", children: names.join("、") }),
|
|
4118
|
+
/* @__PURE__ */ jsx23(Icon, { name: "chevron", size: 16 })
|
|
4119
|
+
] }),
|
|
4120
|
+
friend.createdAt > 0 && /* @__PURE__ */ jsxs22("div", { className: "gkim-usercard__row", children: [
|
|
4121
|
+
/* @__PURE__ */ jsx23("span", { className: "gkim-usercard__label", children: s.friendSince }),
|
|
4122
|
+
/* @__PURE__ */ jsx23("span", { className: "gkim-usercard__value", children: ymd(friend.createdAt) })
|
|
4123
|
+
] })
|
|
4124
|
+
] }),
|
|
4125
|
+
/* @__PURE__ */ jsx23("button", { type: "button", className: "gkim-btn gkim-btn--primary gkim-usercard__chat", onClick: () => {
|
|
4126
|
+
nav.open({ name: "chat", target: { peer: userId } });
|
|
4127
|
+
if (!nav.workspace) nav.close();
|
|
4128
|
+
}, children: s.sendMessage })
|
|
4129
|
+
] });
|
|
4130
|
+
} else if (stranger) {
|
|
4131
|
+
body = /* @__PURE__ */ jsxs22("form", { className: "gkim-usercard__request", onSubmit: (e) => {
|
|
4132
|
+
e.preventDefault();
|
|
4133
|
+
void add();
|
|
4134
|
+
}, children: [
|
|
4135
|
+
/* @__PURE__ */ jsx23("label", { className: "gkim-usercard__request-title", htmlFor: `gkim-req-${userId}`, children: s.friendRequestTitle }),
|
|
4136
|
+
/* @__PURE__ */ jsx23(
|
|
4137
|
+
"textarea",
|
|
4138
|
+
{
|
|
4139
|
+
id: `gkim-req-${userId}`,
|
|
4140
|
+
className: "gkim-input gkim-usercard__message",
|
|
4141
|
+
rows: 3,
|
|
4142
|
+
maxLength: MESSAGE_MAX,
|
|
4143
|
+
value: message,
|
|
4144
|
+
onChange: (e) => setMessage(e.target.value)
|
|
4145
|
+
}
|
|
4146
|
+
),
|
|
4147
|
+
/* @__PURE__ */ jsxs22("div", { className: "gkim-usercard__count", children: [
|
|
4148
|
+
message.length,
|
|
4149
|
+
" / ",
|
|
4150
|
+
MESSAGE_MAX
|
|
4151
|
+
] }),
|
|
4152
|
+
/* @__PURE__ */ jsx23("button", { type: "submit", className: "gkim-btn gkim-btn--primary gkim-usercard__send", disabled: busy, children: s.sendRequest }),
|
|
4153
|
+
result && /* @__PURE__ */ jsx23("p", { className: `gkim-usercard__result${result.error ? " gkim-usercard__result--error" : ""}`, role: result.error ? "alert" : "status", children: result.text })
|
|
4154
|
+
] });
|
|
4155
|
+
}
|
|
4156
|
+
const menuEl = menu.at && /* @__PURE__ */ jsx23(Menu, { entries, x: menu.at.x, y: menu.at.y, onClose: menu.close, label: title });
|
|
4157
|
+
if (main) {
|
|
4158
|
+
return /* @__PURE__ */ jsxs22("section", { className: "gkim-usercard gkim-usercard--main", "aria-label": s.userCardTitle, children: [
|
|
4159
|
+
/* @__PURE__ */ jsxs22("div", { className: "gkim-usercard__card", children: [
|
|
4160
|
+
head,
|
|
4161
|
+
body
|
|
4162
|
+
] }),
|
|
4163
|
+
menuEl
|
|
4164
|
+
] });
|
|
4165
|
+
}
|
|
4166
|
+
return /* @__PURE__ */ jsxs22(Page, { title: s.userCardTitle, className: "gkim-usercard", actions: moreBtn, children: [
|
|
4167
|
+
head,
|
|
4168
|
+
body,
|
|
4169
|
+
menuEl
|
|
4170
|
+
] });
|
|
4171
|
+
}
|
|
4172
|
+
|
|
4173
|
+
// src/ui/contacts/routes.tsx
|
|
4174
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
4175
|
+
function renderContactsRoute(route) {
|
|
4176
|
+
switch (route.name) {
|
|
4177
|
+
case "contacts":
|
|
4178
|
+
return /* @__PURE__ */ jsx24(ImContacts, {});
|
|
4179
|
+
case "contactProfile":
|
|
4180
|
+
case "userCard":
|
|
4181
|
+
return /* @__PURE__ */ jsx24(ImUserCard, { userId: route.userId }, route.userId);
|
|
4182
|
+
case "newFriends":
|
|
4183
|
+
return /* @__PURE__ */ jsx24(ImNewFriends, {});
|
|
4184
|
+
case "friendSettings":
|
|
4185
|
+
return /* @__PURE__ */ jsx24(FriendSettings, { userId: route.userId }, route.userId);
|
|
4186
|
+
case "friendGroups":
|
|
4187
|
+
return /* @__PURE__ */ jsx24(FriendGroups, {});
|
|
4188
|
+
case "addFriend":
|
|
4189
|
+
return /* @__PURE__ */ jsx24(ImAddFriend, {});
|
|
4190
|
+
default:
|
|
4191
|
+
return void 0;
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
|
|
4195
|
+
// src/ui/group/GroupChats.tsx
|
|
4196
|
+
import { useMemo as useMemo7 } from "react";
|
|
4197
|
+
import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
4198
|
+
function GroupChatsPage() {
|
|
4199
|
+
const { strings: s } = useImUi();
|
|
4200
|
+
const nav = useNavContext();
|
|
4201
|
+
const convs = useConversations();
|
|
4202
|
+
const groups = useMemo7(() => convs.filter((c) => c.group !== null && !c.group.quit).sort((a, b) => b.lastMsgAt - a.lastMsgAt), [convs]);
|
|
4203
|
+
return /* @__PURE__ */ jsx25(Page, { title: s.groupChats, className: "gkim-gchats", children: groups.length === 0 ? /* @__PURE__ */ jsx25("div", { className: "gkim-empty gkim-grow", children: s.emptyGroupChats }) : /* @__PURE__ */ jsx25("ul", { className: "gkim-gchats__list", "aria-label": s.groupChats, children: groups.map((c) => {
|
|
4204
|
+
const g = c.group;
|
|
4205
|
+
const title = conversationTitle(c, s);
|
|
4206
|
+
return /* @__PURE__ */ jsx25("li", { children: /* @__PURE__ */ jsxs23("button", { type: "button", className: "gkim-gchats__row", onClick: () => {
|
|
4207
|
+
nav.open({ name: "chat", target: { conversation: c } });
|
|
4208
|
+
if (!nav.workspace) nav.close();
|
|
4209
|
+
}, children: [
|
|
4210
|
+
/* @__PURE__ */ jsx25(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl, size: 40 }),
|
|
4211
|
+
/* @__PURE__ */ jsx25("span", { className: "gkim-gchats__title", children: g.memberCount > 0 ? `${title}(${g.memberCount})` : title })
|
|
4212
|
+
] }) }, c.id);
|
|
4213
|
+
}) }) });
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
// src/ui/group/GroupInfo.tsx
|
|
4217
|
+
import { useRef as useRef12, useState as useState21 } from "react";
|
|
4218
|
+
|
|
4219
|
+
// src/ui/group/shared.tsx
|
|
4220
|
+
import { useCallback as useCallback9, useEffect as useEffect13, useMemo as useMemo8, useState as useState20, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
4221
|
+
import { ImApiError as ImApiError7 } from "@guokit-dev/im";
|
|
4222
|
+
import { Fragment as Fragment9, jsx as jsx26, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
4223
|
+
var noSub2 = () => () => {
|
|
4224
|
+
};
|
|
4225
|
+
var EMPTY_MEMBERS2 = /* @__PURE__ */ new Map();
|
|
4226
|
+
function sameId(a, b) {
|
|
4227
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
4228
|
+
}
|
|
4229
|
+
function errorText3(e, s) {
|
|
4230
|
+
return e instanceof ImApiError7 && e.message ? e.message : s.operationFailed;
|
|
4231
|
+
}
|
|
4232
|
+
function memberName(m) {
|
|
4233
|
+
return m.nickname !== "" ? m.nickname : m.userId;
|
|
4234
|
+
}
|
|
4235
|
+
function roleName(role, s) {
|
|
4236
|
+
return role === 2 ? s.roleOwner : role === 1 ? s.roleAdmin : s.roleMember;
|
|
4237
|
+
}
|
|
4238
|
+
function remainingText(ms, s) {
|
|
4239
|
+
const m = Math.max(1, Math.ceil(ms / 6e4));
|
|
4240
|
+
if (m < 60) return fill(s.durationMinutes, { n: m });
|
|
4241
|
+
const h = Math.ceil(m / 60);
|
|
4242
|
+
if (h < 24) return fill(s.durationHours, { n: h });
|
|
4243
|
+
return fill(s.durationDays, { n: Math.ceil(h / 24) });
|
|
4244
|
+
}
|
|
4245
|
+
var two2 = (n) => String(n).padStart(2, "0");
|
|
4246
|
+
function ymd2(ms, withTime = false) {
|
|
4247
|
+
const d = new Date(ms);
|
|
4248
|
+
const day = `${d.getFullYear()}/${two2(d.getMonth() + 1)}/${two2(d.getDate())}`;
|
|
4249
|
+
return withTime ? `${day} ${two2(d.getHours())}:${two2(d.getMinutes())}` : day;
|
|
4250
|
+
}
|
|
4251
|
+
function useGroup(groupId) {
|
|
4252
|
+
const im = useIm();
|
|
4253
|
+
const [group, setGroup] = useState20(null);
|
|
4254
|
+
const [error, setError] = useState20(null);
|
|
4255
|
+
const reload = useCallback9(async () => {
|
|
4256
|
+
try {
|
|
4257
|
+
const g = await im.group(groupId);
|
|
4258
|
+
setGroup(g);
|
|
4259
|
+
setError(null);
|
|
4260
|
+
} catch (e) {
|
|
4261
|
+
setError(e);
|
|
4262
|
+
}
|
|
4263
|
+
}, [im, groupId]);
|
|
4264
|
+
useEffect13(() => {
|
|
4265
|
+
void reload();
|
|
4266
|
+
return im.on("groupChanged", (c) => {
|
|
4267
|
+
if (sameId(c.groupId, groupId)) void reload();
|
|
4268
|
+
});
|
|
4269
|
+
}, [im, groupId, reload]);
|
|
4270
|
+
return { group, error, reload, setGroup };
|
|
4271
|
+
}
|
|
4272
|
+
function useMembers(groupId) {
|
|
4273
|
+
const im = useIm();
|
|
4274
|
+
const [cache3, setCache] = useState20(null);
|
|
4275
|
+
useEffect13(() => {
|
|
4276
|
+
if (groupId === null) return;
|
|
4277
|
+
const m = new MemberCache(im, groupId);
|
|
4278
|
+
setCache(m);
|
|
4279
|
+
m.start();
|
|
4280
|
+
return () => {
|
|
4281
|
+
m.dispose();
|
|
4282
|
+
setCache(null);
|
|
4283
|
+
};
|
|
4284
|
+
}, [im, groupId]);
|
|
4285
|
+
const map = useSyncExternalStore4(cache3?.subscribe ?? noSub2, cache3?.getSnapshot ?? (() => EMPTY_MEMBERS2));
|
|
4286
|
+
const members = useMemo8(() => [...map.values()], [map]);
|
|
4287
|
+
return { cache: cache3, map, members };
|
|
4288
|
+
}
|
|
4289
|
+
function useGroupConversation(groupId) {
|
|
4290
|
+
const convs = useConversations();
|
|
4291
|
+
return convs.find((c) => c.group !== null && sameId(c.group.groupId, groupId)) ?? null;
|
|
4292
|
+
}
|
|
4293
|
+
function Switch({ label, checked, onChange, disabled }) {
|
|
4294
|
+
return /* @__PURE__ */ jsx26(
|
|
4295
|
+
"button",
|
|
4296
|
+
{
|
|
4297
|
+
type: "button",
|
|
4298
|
+
role: "switch",
|
|
4299
|
+
"aria-checked": checked,
|
|
4300
|
+
"aria-label": label,
|
|
4301
|
+
disabled,
|
|
4302
|
+
className: `gkim-gswitch${checked ? " gkim-gswitch--on" : ""}`,
|
|
4303
|
+
onClick: () => onChange(!checked),
|
|
4304
|
+
children: /* @__PURE__ */ jsx26("span", { className: "gkim-gswitch__knob" })
|
|
4305
|
+
}
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4308
|
+
function SettingRow({ title, value, sub, trailing, onClick }) {
|
|
4309
|
+
const inner = /* @__PURE__ */ jsxs24(Fragment9, { children: [
|
|
4310
|
+
/* @__PURE__ */ jsxs24("span", { className: "gkim-gset__text", children: [
|
|
4311
|
+
/* @__PURE__ */ jsx26("span", { className: "gkim-gset__title", children: title }),
|
|
4312
|
+
sub && /* @__PURE__ */ jsx26("span", { className: "gkim-gset__sub", children: sub })
|
|
4313
|
+
] }),
|
|
4314
|
+
value !== void 0 && /* @__PURE__ */ jsx26("span", { className: "gkim-gset__value", children: value }),
|
|
4315
|
+
trailing,
|
|
4316
|
+
onClick && /* @__PURE__ */ jsx26("span", { className: "gkim-gset__chev", "aria-hidden": "true", children: "›" })
|
|
4317
|
+
] });
|
|
4318
|
+
return onClick ? /* @__PURE__ */ jsx26("button", { type: "button", className: "gkim-gset gkim-gset--btn", onClick, children: inner }) : /* @__PURE__ */ jsx26("div", { className: "gkim-gset", children: inner });
|
|
4319
|
+
}
|
|
4320
|
+
|
|
4321
|
+
// src/ui/group/GroupInfo.tsx
|
|
4322
|
+
import { jsx as jsx27, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
4323
|
+
var CELLS = 9;
|
|
4324
|
+
function ImGroupInfo({ groupId }) {
|
|
4325
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
4326
|
+
const { toast, confirm } = useFeedback();
|
|
4327
|
+
const nav = useNavContext();
|
|
4328
|
+
const frame = useFrame();
|
|
4329
|
+
const { group: g, error } = useGroup(groupId);
|
|
4330
|
+
const { members } = useMembers(groupId);
|
|
4331
|
+
const conv = useGroupConversation(groupId);
|
|
4332
|
+
const [naming, setNaming] = useState21(null);
|
|
4333
|
+
const cancelName = useRef12(false);
|
|
4334
|
+
const run = async (f) => {
|
|
4335
|
+
try {
|
|
4336
|
+
await f();
|
|
4337
|
+
return true;
|
|
4338
|
+
} catch (e) {
|
|
4339
|
+
toast(errorText3(e, s));
|
|
4340
|
+
return false;
|
|
4341
|
+
}
|
|
4342
|
+
};
|
|
4343
|
+
if (!g) {
|
|
4344
|
+
return /* @__PURE__ */ jsx27(Page, { title: s.groupInfoTitle, className: "gkim-ginfo", children: /* @__PURE__ */ jsx27("div", { className: "gkim-empty gkim-grow", children: error ? errorText3(error, s) : "" }) });
|
|
4345
|
+
}
|
|
4346
|
+
const active = !g.quit && !g.dismissed;
|
|
4347
|
+
const isAdmin = active && g.role >= 1;
|
|
4348
|
+
const isOwner = active && g.role === 2;
|
|
4349
|
+
const canInvite = active && (!g.inviteAdminOnly || isAdmin);
|
|
4350
|
+
const buttons = (canInvite ? 1 : 0) + (isAdmin ? 1 : 0);
|
|
4351
|
+
const shown = members.slice(0, CELLS - buttons);
|
|
4352
|
+
const title = g.name !== "" ? g.name : s.groupChat;
|
|
4353
|
+
const adminCount = members.filter((m) => m.role === 1).length;
|
|
4354
|
+
const openMembers = () => nav.open({ name: "groupMembers", groupId });
|
|
4355
|
+
const saveName = async () => {
|
|
4356
|
+
const name = (naming ?? "").trim();
|
|
4357
|
+
setNaming(null);
|
|
4358
|
+
if (!name || name === g.name) return;
|
|
4359
|
+
await run(() => im.updateGroup(g.groupId, { name }));
|
|
4360
|
+
};
|
|
4361
|
+
const nameKey = (e) => {
|
|
4362
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) {
|
|
4363
|
+
e.preventDefault();
|
|
4364
|
+
e.currentTarget.blur();
|
|
4365
|
+
} else if (e.key === "Escape") {
|
|
4366
|
+
e.stopPropagation();
|
|
4367
|
+
cancelName.current = true;
|
|
4368
|
+
setNaming(null);
|
|
4369
|
+
}
|
|
4370
|
+
};
|
|
4371
|
+
const nameBlur = () => {
|
|
4372
|
+
if (cancelName.current) {
|
|
4373
|
+
cancelName.current = false;
|
|
4374
|
+
return;
|
|
4375
|
+
}
|
|
4376
|
+
void saveName();
|
|
4377
|
+
};
|
|
4378
|
+
const clear = async () => {
|
|
4379
|
+
if (!conv) return;
|
|
4380
|
+
if (await confirm({ content: s.clearHistoryConfirm, ok: s.clearHistory, danger: true })) await run(() => im.clearConversation(conv.id));
|
|
4381
|
+
};
|
|
4382
|
+
const quit = async () => {
|
|
4383
|
+
if (g.role === 2) {
|
|
4384
|
+
toast(s.ownerQuitTip);
|
|
4385
|
+
return;
|
|
4386
|
+
}
|
|
4387
|
+
if (!await confirm({ title: s.quitGroup, content: s.quitGroupConfirm, ok: s.quitGroup, danger: true })) return;
|
|
4388
|
+
if (await run(() => im.quitGroup(g.groupId))) frame.close();
|
|
4389
|
+
};
|
|
4390
|
+
const dismiss = async () => {
|
|
4391
|
+
if (!await confirm({ title: s.dismissGroup, content: s.dismissGroupConfirm, ok: s.dismissGroup, danger: true })) return;
|
|
4392
|
+
if (await run(() => im.dismissGroup(g.groupId))) frame.close();
|
|
4393
|
+
};
|
|
4394
|
+
return /* @__PURE__ */ jsxs25(Page, { title: s.groupInfoTitle, className: "gkim-ginfo", children: [
|
|
4395
|
+
/* @__PURE__ */ jsxs25("div", { className: "gkim-ginfo__head", children: [
|
|
4396
|
+
/* @__PURE__ */ jsx27(ImGroupAvatar, { groupId: g.groupId, name: title, url: g.avatarUrl, size: 56 }),
|
|
4397
|
+
/* @__PURE__ */ jsxs25("div", { className: "gkim-ginfo__headtext", children: [
|
|
4398
|
+
/* @__PURE__ */ jsx27("div", { className: "gkim-ginfo__name", children: title }),
|
|
4399
|
+
/* @__PURE__ */ jsx27("div", { className: "gkim-ginfo__meta", children: fill(s.groupIdAndCount, { id: g.groupId, n: g.memberCount }) })
|
|
4400
|
+
] })
|
|
4401
|
+
] }),
|
|
4402
|
+
active && /* @__PURE__ */ jsxs25("div", { className: "gkim-gsection", children: [
|
|
4403
|
+
/* @__PURE__ */ jsxs25("ul", { className: "gkim-ginfo__grid", "aria-label": s.groupMembersTitle, children: [
|
|
4404
|
+
shown.map((m) => {
|
|
4405
|
+
const name = memberName(m);
|
|
4406
|
+
return /* @__PURE__ */ jsx27("li", { children: /* @__PURE__ */ jsxs25("button", { type: "button", className: "gkim-ginfo__cell", onClick: () => openUserCard({ im, callbacks, nav }, m.userId, m), children: [
|
|
4407
|
+
/* @__PURE__ */ jsxs25("span", { className: "gkim-ginfo__cellav", children: [
|
|
4408
|
+
/* @__PURE__ */ jsx27(Avatar, { id: m.userId, name, url: m.avatarUrl || void 0, size: 48 }),
|
|
4409
|
+
m.role > 0 && /* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__role", children: m.role === 2 ? s.roleOwner : s.roleAdmin })
|
|
4410
|
+
] }),
|
|
4411
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__celllabel", children: name })
|
|
4412
|
+
] }) }, m.userId);
|
|
4413
|
+
}),
|
|
4414
|
+
canInvite && /* @__PURE__ */ jsx27("li", { children: /* @__PURE__ */ jsxs25("button", { type: "button", className: "gkim-ginfo__cell", onClick: () => nav.open({ name: "selectFriends", groupId }), children: [
|
|
4415
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__dashed", children: /* @__PURE__ */ jsx27(Icon, { name: "add" }) }),
|
|
4416
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__celllabel", children: s.inviteMember })
|
|
4417
|
+
] }) }),
|
|
4418
|
+
isAdmin && /* @__PURE__ */ jsx27("li", { children: /* @__PURE__ */ jsxs25("button", { type: "button", className: "gkim-ginfo__cell", onClick: openMembers, children: [
|
|
4419
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__dashed", children: /* @__PURE__ */ jsx27(Icon, { name: "minusLine" }) }),
|
|
4420
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-ginfo__celllabel", children: s.removeMember })
|
|
4421
|
+
] }) })
|
|
4422
|
+
] }),
|
|
4423
|
+
/* @__PURE__ */ jsxs25("button", { type: "button", className: "gkim-ginfo__all", onClick: openMembers, children: [
|
|
4424
|
+
fill(s.viewAllMembers, { n: g.memberCount }),
|
|
4425
|
+
/* @__PURE__ */ jsx27("span", { "aria-hidden": "true", children: " ›" })
|
|
4426
|
+
] })
|
|
4427
|
+
] }),
|
|
4428
|
+
active && /* @__PURE__ */ jsxs25("div", { className: "gkim-gsection", children: [
|
|
4429
|
+
naming !== null ? /* @__PURE__ */ jsxs25("div", { className: "gkim-gset", children: [
|
|
4430
|
+
/* @__PURE__ */ jsx27("span", { className: "gkim-gset__title", children: s.groupNameLabel }),
|
|
4431
|
+
/* @__PURE__ */ jsx27(
|
|
4432
|
+
"input",
|
|
4433
|
+
{
|
|
4434
|
+
className: "gkim-ginfo__nameinput",
|
|
4435
|
+
"aria-label": s.groupNameLabel,
|
|
4436
|
+
autoFocus: true,
|
|
4437
|
+
maxLength: 64,
|
|
4438
|
+
value: naming,
|
|
4439
|
+
onChange: (e) => setNaming(e.target.value),
|
|
4440
|
+
onKeyDown: nameKey,
|
|
4441
|
+
onBlur: nameBlur
|
|
4442
|
+
}
|
|
4443
|
+
)
|
|
4444
|
+
] }) : /* @__PURE__ */ jsx27(SettingRow, { title: s.groupNameLabel, value: title, onClick: isAdmin ? () => setNaming(g.name) : void 0 }),
|
|
4445
|
+
/* @__PURE__ */ jsx27(
|
|
4446
|
+
SettingRow,
|
|
4447
|
+
{
|
|
4448
|
+
title: s.groupNotice,
|
|
4449
|
+
value: g.notice === "" ? s.notSet : g.notice,
|
|
4450
|
+
onClick: () => nav.open({ name: "groupNotice", groupId })
|
|
4451
|
+
}
|
|
4452
|
+
)
|
|
4453
|
+
] }),
|
|
4454
|
+
active && conv && /* @__PURE__ */ jsxs25("div", { className: "gkim-gsection", children: [
|
|
4455
|
+
/* @__PURE__ */ jsx27(SettingRow, { title: s.mute, trailing: /* @__PURE__ */ jsx27(Switch, { label: s.mute, checked: conv.muted, onChange: (v) => run(() => im.setMuted(conv.id, v)) }) }),
|
|
4456
|
+
/* @__PURE__ */ jsx27(SettingRow, { title: s.pinChat, trailing: /* @__PURE__ */ jsx27(Switch, { label: s.pinChat, checked: conv.pinned, onChange: (v) => run(() => im.setPinned(conv.id, v)) }) })
|
|
4457
|
+
] }),
|
|
4458
|
+
isAdmin && /* @__PURE__ */ jsxs25("div", { className: "gkim-gsection", children: [
|
|
4459
|
+
/* @__PURE__ */ jsx27("h3", { className: "gkim-gsection__head", children: s.groupManage }),
|
|
4460
|
+
/* @__PURE__ */ jsx27(
|
|
4461
|
+
SettingRow,
|
|
4462
|
+
{
|
|
4463
|
+
title: s.muteAll,
|
|
4464
|
+
sub: s.muteAllTip,
|
|
4465
|
+
trailing: /* @__PURE__ */ jsx27(Switch, { label: s.muteAll, checked: g.muteAll, onChange: (v) => run(() => im.updateGroup(g.groupId, { muteAll: v })) })
|
|
4466
|
+
}
|
|
4467
|
+
),
|
|
4468
|
+
/* @__PURE__ */ jsx27(
|
|
4469
|
+
SettingRow,
|
|
4470
|
+
{
|
|
4471
|
+
title: s.inviteAdminOnly,
|
|
4472
|
+
trailing: /* @__PURE__ */ jsx27(Switch, { label: s.inviteAdminOnly, checked: g.inviteAdminOnly, onChange: (v) => run(() => im.updateGroup(g.groupId, { inviteAdminOnly: v })) })
|
|
4473
|
+
}
|
|
4474
|
+
),
|
|
4475
|
+
isOwner && /* @__PURE__ */ jsx27(SettingRow, { title: s.groupAdmins, value: fill(s.peopleCount, { n: adminCount }), onClick: openMembers }),
|
|
4476
|
+
isOwner && /* @__PURE__ */ jsx27(SettingRow, { title: s.transferOwner, onClick: openMembers })
|
|
4477
|
+
] }),
|
|
4478
|
+
/* @__PURE__ */ jsxs25("div", { className: "gkim-gsection gkim-ginfo__danger", children: [
|
|
4479
|
+
conv && /* @__PURE__ */ jsx27("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: clear, children: s.clearHistory }),
|
|
4480
|
+
active && /* @__PURE__ */ jsx27("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: quit, children: s.quitGroup }),
|
|
4481
|
+
isOwner && /* @__PURE__ */ jsx27("button", { type: "button", className: "gkim-ginfo__dangerbtn", onClick: dismiss, children: s.dismissGroup })
|
|
4482
|
+
] }),
|
|
4483
|
+
isOwner && /* @__PURE__ */ jsx27("p", { className: "gkim-ginfo__tip", children: s.ownerQuitTip })
|
|
4484
|
+
] });
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
// src/ui/group/GroupMembers.tsx
|
|
4488
|
+
import { useCallback as useCallback10, useState as useState22 } from "react";
|
|
4489
|
+
import { jsx as jsx28, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
4490
|
+
function GroupMembersPage({ groupId, now = Date.now }) {
|
|
4491
|
+
const { im, strings: s, callbacks } = useImUi();
|
|
4492
|
+
const { toast, confirm } = useFeedback();
|
|
4493
|
+
const nav = useNavContext();
|
|
4494
|
+
const { group, reload } = useGroup(groupId);
|
|
4495
|
+
const { cache: cache3, members } = useMembers(groupId);
|
|
4496
|
+
const [query, setQuery] = useState22("");
|
|
4497
|
+
const [menu, setMenu] = useState22(null);
|
|
4498
|
+
const closeMenu = useCallback10(() => setMenu(null), []);
|
|
4499
|
+
const t = now();
|
|
4500
|
+
const muted = (m) => m.muteUntil !== null && m.muteUntil > t;
|
|
4501
|
+
const q = query.trim().toLowerCase();
|
|
4502
|
+
const list = q ? members.filter((m) => m.nickname.toLowerCase().includes(q) || m.userId.toLowerCase().includes(q)) : members;
|
|
4503
|
+
const count = group?.memberCount || members.length;
|
|
4504
|
+
const me = im.currentUserId;
|
|
4505
|
+
const myRole = group && !group.quit && !group.dismissed ? group.role : 0;
|
|
4506
|
+
const run = async (f) => {
|
|
4507
|
+
try {
|
|
4508
|
+
await f();
|
|
4509
|
+
} catch (e) {
|
|
4510
|
+
toast(errorText3(e, s));
|
|
4511
|
+
}
|
|
4512
|
+
await cache3?.reload();
|
|
4513
|
+
await reload();
|
|
4514
|
+
};
|
|
4515
|
+
const entriesOf = (m) => {
|
|
4516
|
+
const name = memberName(m);
|
|
4517
|
+
const isOwner = myRole === 2;
|
|
4518
|
+
const canManage = isOwner || myRole === 1 && m.role === 0;
|
|
4519
|
+
const role = roleName(m.role, s);
|
|
4520
|
+
const out = [
|
|
4521
|
+
{ label: `${name} · ${m.joinedAt ? fill(s.joinedAt, { role, date: ymd2(m.joinedAt) }) : role}`, disabled: true, onSelect: () => {
|
|
4522
|
+
} },
|
|
4523
|
+
{ label: s.viewProfile, onSelect: () => openUserCard({ im, callbacks, nav }, m.userId, m) }
|
|
4524
|
+
];
|
|
4525
|
+
if (isOwner) {
|
|
4526
|
+
out.push({ label: m.role === 1 ? s.unsetAdmin : s.setAdmin, onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { role: m.role === 1 ? 0 : 1 })) });
|
|
4527
|
+
}
|
|
4528
|
+
if (canManage) {
|
|
4529
|
+
if (muted(m)) {
|
|
4530
|
+
out.push({ label: s.unmuteMember, onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { muteMinutes: 0 })) });
|
|
4531
|
+
} else {
|
|
4532
|
+
out.push({
|
|
4533
|
+
label: s.muteMember,
|
|
4534
|
+
onSelect: () => {
|
|
4535
|
+
},
|
|
4536
|
+
children: Object.entries(s.muteDurations).map(([sec, label]) => ({
|
|
4537
|
+
label,
|
|
4538
|
+
onSelect: () => run(() => im.setGroupMember(groupId, m.userId, { muteMinutes: Math.round(Number(sec) / 60) }))
|
|
4539
|
+
}))
|
|
4540
|
+
});
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
if (isOwner) {
|
|
4544
|
+
out.push({
|
|
4545
|
+
label: s.transferTo,
|
|
4546
|
+
onSelect: async () => {
|
|
4547
|
+
if (await confirm({ title: s.transferOwner, content: fill(s.transferConfirm, { name }), danger: true })) await run(() => im.transferGroup(groupId, m.userId));
|
|
4548
|
+
}
|
|
4549
|
+
});
|
|
4550
|
+
}
|
|
4551
|
+
if (canManage) {
|
|
4552
|
+
out.push({
|
|
4553
|
+
label: s.kickMember,
|
|
4554
|
+
danger: true,
|
|
4555
|
+
onSelect: async () => {
|
|
4556
|
+
if (await confirm({ content: fill(s.kickConfirm, { name }), ok: s.kickMember, danger: true })) await run(() => im.removeGroupMember(groupId, m.userId));
|
|
4557
|
+
}
|
|
4558
|
+
});
|
|
4559
|
+
}
|
|
4560
|
+
return out;
|
|
4561
|
+
};
|
|
4562
|
+
const openMenu = (m, el) => {
|
|
4563
|
+
const r = el.getBoundingClientRect();
|
|
4564
|
+
setMenu({ m, at: { x: r.right, y: r.bottom + 4 } });
|
|
4565
|
+
};
|
|
4566
|
+
return /* @__PURE__ */ jsxs26(Page, { title: count > 0 ? `${s.groupMembersTitle}(${count})` : s.groupMembersTitle, className: "gkim-gmembers", children: [
|
|
4567
|
+
/* @__PURE__ */ jsxs26("div", { className: "gkim-gsearch", children: [
|
|
4568
|
+
/* @__PURE__ */ jsx28(Icon, { name: "search", size: 16 }),
|
|
4569
|
+
/* @__PURE__ */ jsx28("input", { type: "search", placeholder: s.searchMembers, "aria-label": s.searchMembers, value: query, onChange: (e) => setQuery(e.target.value) })
|
|
4570
|
+
] }),
|
|
4571
|
+
/* @__PURE__ */ jsx28("ul", { className: "gkim-gmembers__list", "aria-label": s.groupMembersTitle, children: list.map((m) => {
|
|
4572
|
+
const name = memberName(m);
|
|
4573
|
+
const self = m.userId === me;
|
|
4574
|
+
return /* @__PURE__ */ jsxs26(
|
|
4575
|
+
"li",
|
|
4576
|
+
{
|
|
4577
|
+
className: `gkim-gmember${menu?.m.userId === m.userId ? " gkim-gmember--active" : ""}`,
|
|
4578
|
+
onClick: self ? void 0 : (e) => openMenu(m, e.currentTarget.querySelector(".gkim-gmember__more") ?? e.currentTarget),
|
|
4579
|
+
children: [
|
|
4580
|
+
/* @__PURE__ */ jsx28(Avatar, { id: m.userId, name, url: m.avatarUrl || void 0, size: 40 }),
|
|
4581
|
+
/* @__PURE__ */ jsx28("span", { className: "gkim-gmember__name", children: name }),
|
|
4582
|
+
m.role === 2 && /* @__PURE__ */ jsx28("span", { className: "gkim-gtag gkim-gtag--owner", children: s.roleOwner }),
|
|
4583
|
+
m.role === 1 && /* @__PURE__ */ jsx28("span", { className: "gkim-gtag gkim-gtag--admin", children: s.roleAdmin }),
|
|
4584
|
+
muted(m) && /* @__PURE__ */ jsx28("span", { className: "gkim-gtag gkim-gtag--muted", children: fill(s.mutedRemaining, { time: remainingText(m.muteUntil - t, s) }) }),
|
|
4585
|
+
/* @__PURE__ */ jsx28("span", { className: "gkim-grow" }),
|
|
4586
|
+
!self && /* @__PURE__ */ jsx28(
|
|
4587
|
+
"button",
|
|
4588
|
+
{
|
|
4589
|
+
type: "button",
|
|
4590
|
+
className: "gkim-iconbtn gkim-gmember__more",
|
|
4591
|
+
"aria-label": `${s.more} ${name}`,
|
|
4592
|
+
"aria-haspopup": "menu",
|
|
4593
|
+
onClick: (e) => {
|
|
4594
|
+
e.stopPropagation();
|
|
4595
|
+
openMenu(m, e.currentTarget);
|
|
4596
|
+
},
|
|
4597
|
+
children: /* @__PURE__ */ jsx28(Icon, { name: "more" })
|
|
4598
|
+
}
|
|
4599
|
+
)
|
|
4600
|
+
]
|
|
4601
|
+
},
|
|
4602
|
+
m.userId
|
|
4603
|
+
);
|
|
4604
|
+
}) }),
|
|
4605
|
+
menu && /* @__PURE__ */ jsx28(Menu, { entries: entriesOf(menu.m), x: menu.at.x, y: menu.at.y, onClose: closeMenu, label: memberName(menu.m) })
|
|
4606
|
+
] });
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4609
|
+
// src/ui/group/GroupNotice.tsx
|
|
4610
|
+
import { useState as useState23 } from "react";
|
|
4611
|
+
import { Fragment as Fragment10, jsx as jsx29, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
4612
|
+
var MAX2 = 1e3;
|
|
4613
|
+
function GroupNoticePage({ groupId }) {
|
|
4614
|
+
const { im, strings: s } = useImUi();
|
|
4615
|
+
const { toast } = useFeedback();
|
|
4616
|
+
const { group: g, error, setGroup } = useGroup(groupId);
|
|
4617
|
+
const { map } = useMembers(groupId);
|
|
4618
|
+
const [text, setText] = useState23(null);
|
|
4619
|
+
const [busy, setBusy] = useState23(false);
|
|
4620
|
+
if (!g) {
|
|
4621
|
+
return /* @__PURE__ */ jsx29(Page, { title: s.groupNotice, children: /* @__PURE__ */ jsx29("div", { className: "gkim-empty gkim-grow", children: error ? errorText3(error, s) : "" }) });
|
|
4622
|
+
}
|
|
4623
|
+
const canEdit = g.role >= 1 && !g.quit && !g.dismissed;
|
|
4624
|
+
if (text !== null) {
|
|
4625
|
+
const publish = async () => {
|
|
4626
|
+
setBusy(true);
|
|
4627
|
+
try {
|
|
4628
|
+
setGroup(await im.updateGroup(g.groupId, { notice: text.trim() }));
|
|
4629
|
+
setText(null);
|
|
4630
|
+
} catch (e) {
|
|
4631
|
+
toast(errorText3(e, s));
|
|
4632
|
+
} finally {
|
|
4633
|
+
setBusy(false);
|
|
4634
|
+
}
|
|
4635
|
+
};
|
|
4636
|
+
return /* @__PURE__ */ jsxs27(
|
|
4637
|
+
Page,
|
|
4638
|
+
{
|
|
4639
|
+
title: s.groupNotice,
|
|
4640
|
+
className: "gkim-gnotice gkim-gnotice--edit",
|
|
4641
|
+
actions: /* @__PURE__ */ jsxs27(Fragment10, { children: [
|
|
4642
|
+
/* @__PURE__ */ jsx29("button", { type: "button", className: "gkim-gnotice__link", disabled: busy, onClick: () => setText(null), children: s.cancel }),
|
|
4643
|
+
/* @__PURE__ */ jsx29("button", { type: "button", className: "gkim-btn gkim-btn--primary gkim-gnotice__publish", disabled: busy || text.trim() === g.notice, onClick: publish, children: s.publish })
|
|
4644
|
+
] }),
|
|
4645
|
+
children: [
|
|
4646
|
+
/* @__PURE__ */ jsx29(
|
|
4647
|
+
"textarea",
|
|
4648
|
+
{
|
|
4649
|
+
className: "gkim-gnotice__field",
|
|
4650
|
+
"aria-label": s.groupNotice,
|
|
4651
|
+
placeholder: s.noticeHint,
|
|
4652
|
+
maxLength: MAX2,
|
|
4653
|
+
autoFocus: true,
|
|
4654
|
+
value: text,
|
|
4655
|
+
onChange: (e) => setText(e.target.value),
|
|
4656
|
+
onKeyDown: (e) => {
|
|
4657
|
+
if (e.key === "Escape") {
|
|
4658
|
+
e.stopPropagation();
|
|
4659
|
+
if (!busy) setText(null);
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
}
|
|
4663
|
+
),
|
|
4664
|
+
/* @__PURE__ */ jsxs27("div", { className: "gkim-gnotice__foot", children: [
|
|
4665
|
+
/* @__PURE__ */ jsx29("span", { children: s.noticePublishTip }),
|
|
4666
|
+
/* @__PURE__ */ jsxs27("span", { children: [
|
|
4667
|
+
text.length,
|
|
4668
|
+
" / ",
|
|
4669
|
+
MAX2
|
|
4670
|
+
] })
|
|
4671
|
+
] })
|
|
4672
|
+
]
|
|
4673
|
+
}
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
4676
|
+
const by = g.noticeBy;
|
|
4677
|
+
const isSystem = by === "@system";
|
|
4678
|
+
const m = isSystem ? void 0 : map.get(by);
|
|
4679
|
+
const name = isSystem ? s.system : m?.nickname || by;
|
|
4680
|
+
return /* @__PURE__ */ jsxs27(
|
|
4681
|
+
Page,
|
|
4682
|
+
{
|
|
4683
|
+
title: s.groupNotice,
|
|
4684
|
+
className: "gkim-gnotice",
|
|
4685
|
+
actions: canEdit && /* @__PURE__ */ jsx29("button", { type: "button", className: "gkim-gnotice__link", onClick: () => setText(g.notice), children: s.editNotice }),
|
|
4686
|
+
children: [
|
|
4687
|
+
g.notice === "" ? /* @__PURE__ */ jsx29("div", { className: "gkim-empty gkim-gnotice__empty", children: s.emptyNotice }) : /* @__PURE__ */ jsxs27(Fragment10, { children: [
|
|
4688
|
+
by !== "" && /* @__PURE__ */ jsxs27("div", { className: "gkim-gnotice__by", children: [
|
|
4689
|
+
/* @__PURE__ */ jsx29(Avatar, { id: by, name, url: m?.avatarUrl || void 0, size: 36 }),
|
|
4690
|
+
/* @__PURE__ */ jsxs27("div", { children: [
|
|
4691
|
+
/* @__PURE__ */ jsx29("div", { className: "gkim-gnotice__name", children: name }),
|
|
4692
|
+
g.noticeAt !== null && /* @__PURE__ */ jsx29("div", { className: "gkim-gnotice__time", children: fill(s.noticePublishedAt, { date: ymd2(g.noticeAt, true) }) })
|
|
4693
|
+
] })
|
|
4694
|
+
] }),
|
|
4695
|
+
/* @__PURE__ */ jsx29("div", { className: "gkim-gnotice__text", children: g.notice })
|
|
4696
|
+
] }),
|
|
4697
|
+
/* @__PURE__ */ jsx29("p", { className: "gkim-gnotice__tip", children: s.noticeEditTip })
|
|
4698
|
+
]
|
|
4699
|
+
}
|
|
4700
|
+
);
|
|
4701
|
+
}
|
|
4702
|
+
|
|
4703
|
+
// src/ui/group/SelectFriends.tsx
|
|
4704
|
+
import { useMemo as useMemo9, useState as useState24 } from "react";
|
|
4705
|
+
import { Fragment as Fragment11, jsx as jsx30, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
4706
|
+
var MAX3 = 50;
|
|
4707
|
+
var friendName = (f) => f.remark || f.nickname || f.userId;
|
|
4708
|
+
function SelectFriendsDialog({ groupId }) {
|
|
4709
|
+
const { im, me, strings: s } = useImUi();
|
|
4710
|
+
const { toast } = useFeedback();
|
|
4711
|
+
const nav = useNavContext();
|
|
4712
|
+
const frame = useFrame();
|
|
4713
|
+
const friends = useFriends();
|
|
4714
|
+
const invite = groupId !== void 0;
|
|
4715
|
+
const { map } = useMembers(groupId ?? null);
|
|
4716
|
+
const existing = useMemo9(() => new Set(invite ? [...map.keys()].map((k) => k.toLowerCase()) : []), [map, invite]);
|
|
4717
|
+
const [picked, setPicked] = useState24([]);
|
|
4718
|
+
const [query, setQuery] = useState24("");
|
|
4719
|
+
const [busy, setBusy] = useState24(false);
|
|
4720
|
+
const inGroup = (f) => existing.has(f.userId.toLowerCase());
|
|
4721
|
+
const isPicked = (f) => picked.some((p) => p.userId === f.userId);
|
|
4722
|
+
const toggle = (f) => {
|
|
4723
|
+
if (inGroup(f)) return;
|
|
4724
|
+
setPicked((list) => list.some((p) => p.userId === f.userId) ? list.filter((p) => p.userId !== f.userId) : list.length < MAX3 ? [...list, f] : list);
|
|
4725
|
+
};
|
|
4726
|
+
const q = query.trim().toLowerCase();
|
|
4727
|
+
const sections = useMemo9(() => {
|
|
4728
|
+
const visible = q ? friends.filter((f) => f.remark.toLowerCase().includes(q) || f.nickname.toLowerCase().includes(q)) : friends;
|
|
4729
|
+
return indexSections(visible, friendName, (f) => f.userId);
|
|
4730
|
+
}, [friends, q]);
|
|
4731
|
+
const defaultName = () => {
|
|
4732
|
+
const parts = [...me.nickname ? [me.nickname] : [], ...picked.slice(0, 2).map((f) => f.nickname || f.userId)];
|
|
4733
|
+
return Array.from(parts.join(s.groupNameSeparator)).slice(0, 64).join("");
|
|
4734
|
+
};
|
|
4735
|
+
const done = async () => {
|
|
4736
|
+
const ids = picked.map((f) => f.userId);
|
|
4737
|
+
setBusy(true);
|
|
4738
|
+
try {
|
|
4739
|
+
if (groupId !== void 0) {
|
|
4740
|
+
const r = await im.addGroupMembers(groupId, ids);
|
|
4741
|
+
if (r.skipped.length) toast(fill(s.skippedMembers, { n: r.skipped.length }));
|
|
4742
|
+
frame.close();
|
|
4743
|
+
} else {
|
|
4744
|
+
const r = await im.createGroup({ name: defaultName(), members: ids });
|
|
4745
|
+
if (r.skipped.length) toast(fill(s.skippedMembers, { n: r.skipped.length }));
|
|
4746
|
+
frame.close();
|
|
4747
|
+
nav.open({ name: "chat", target: { group: r.group.groupId } });
|
|
4748
|
+
}
|
|
4749
|
+
} catch (e) {
|
|
4750
|
+
setBusy(false);
|
|
4751
|
+
toast(errorText3(e, s));
|
|
4752
|
+
}
|
|
4753
|
+
};
|
|
4754
|
+
return /* @__PURE__ */ jsx30(
|
|
4755
|
+
Page,
|
|
4756
|
+
{
|
|
4757
|
+
title: invite ? s.inviteToGroup : s.startGroupChat,
|
|
4758
|
+
className: "gkim-selfriends",
|
|
4759
|
+
scroll: false,
|
|
4760
|
+
footer: /* @__PURE__ */ jsxs28(Fragment11, { children: [
|
|
4761
|
+
/* @__PURE__ */ jsx30("button", { type: "button", className: "gkim-btn", onClick: frame.close, children: s.cancel }),
|
|
4762
|
+
/* @__PURE__ */ jsx30("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 })
|
|
4763
|
+
] }),
|
|
4764
|
+
children: /* @__PURE__ */ jsxs28("div", { className: "gkim-selfriends__panes", children: [
|
|
4765
|
+
/* @__PURE__ */ jsxs28("div", { className: "gkim-selfriends__left", children: [
|
|
4766
|
+
/* @__PURE__ */ jsxs28("div", { className: "gkim-gsearch", children: [
|
|
4767
|
+
/* @__PURE__ */ jsx30(Icon, { name: "search", size: 16 }),
|
|
4768
|
+
/* @__PURE__ */ jsx30("input", { type: "search", placeholder: s.searchFriends, "aria-label": s.searchFriends, value: query, onChange: (e) => setQuery(e.target.value) })
|
|
4769
|
+
] }),
|
|
4770
|
+
/* @__PURE__ */ jsx30(
|
|
4771
|
+
IndexedList,
|
|
4772
|
+
{
|
|
4773
|
+
sections,
|
|
4774
|
+
keyOf: (f) => f.userId,
|
|
4775
|
+
renderItem: (f) => {
|
|
4776
|
+
const disabled = inGroup(f);
|
|
4777
|
+
const name = friendName(f);
|
|
4778
|
+
return /* @__PURE__ */ jsxs28("label", { className: `gkim-selfriends__row${disabled ? " gkim-selfriends__row--off" : ""}`, children: [
|
|
4779
|
+
/* @__PURE__ */ jsx30("input", { type: "checkbox", checked: disabled || isPicked(f), disabled, onChange: () => toggle(f), "aria-label": name }),
|
|
4780
|
+
/* @__PURE__ */ jsx30(Avatar, { id: f.userId, name, url: f.avatarUrl || void 0, size: 36 }),
|
|
4781
|
+
/* @__PURE__ */ jsx30("span", { className: "gkim-selfriends__name", children: name }),
|
|
4782
|
+
disabled && /* @__PURE__ */ jsx30("span", { className: "gkim-selfriends__in", children: s.alreadyInGroup })
|
|
4783
|
+
] });
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
)
|
|
4787
|
+
] }),
|
|
4788
|
+
/* @__PURE__ */ jsxs28("div", { className: "gkim-selfriends__right", children: [
|
|
4789
|
+
/* @__PURE__ */ jsx30("div", { className: "gkim-selfriends__count", children: fill(s.selectedCount, { n: picked.length, max: MAX3 }) }),
|
|
4790
|
+
/* @__PURE__ */ jsx30("ul", { className: "gkim-selfriends__picked", "aria-label": s.selectFriendsTitle, children: picked.map((f) => {
|
|
4791
|
+
const name = friendName(f);
|
|
4792
|
+
return /* @__PURE__ */ jsxs28("li", { className: "gkim-selfriends__chip", children: [
|
|
4793
|
+
/* @__PURE__ */ jsx30(Avatar, { id: f.userId, name, url: f.avatarUrl || void 0, size: 32 }),
|
|
4794
|
+
/* @__PURE__ */ jsx30("span", { className: "gkim-selfriends__name", children: name }),
|
|
4795
|
+
/* @__PURE__ */ jsx30("button", { type: "button", className: "gkim-iconbtn gkim-selfriends__x", "aria-label": `${s.removeMember} ${name}`, onClick: () => toggle(f), children: /* @__PURE__ */ jsx30(Icon, { name: "close", size: 16 }) })
|
|
4796
|
+
] }, f.userId);
|
|
4797
|
+
}) })
|
|
4798
|
+
] })
|
|
4799
|
+
] })
|
|
4800
|
+
}
|
|
4801
|
+
);
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4804
|
+
// src/ui/group/routes.tsx
|
|
4805
|
+
import { jsx as jsx31 } from "react/jsx-runtime";
|
|
4806
|
+
function renderGroupRoute(route) {
|
|
4807
|
+
switch (route.name) {
|
|
4808
|
+
case "groupChats":
|
|
4809
|
+
return /* @__PURE__ */ jsx31(GroupChatsPage, {});
|
|
4810
|
+
case "groupInfo":
|
|
4811
|
+
return /* @__PURE__ */ jsx31(ImGroupInfo, { groupId: route.groupId }, route.groupId);
|
|
4812
|
+
case "groupMembers":
|
|
4813
|
+
return /* @__PURE__ */ jsx31(GroupMembersPage, { groupId: route.groupId }, route.groupId);
|
|
4814
|
+
case "groupNotice":
|
|
4815
|
+
return /* @__PURE__ */ jsx31(GroupNoticePage, { groupId: route.groupId }, route.groupId);
|
|
4816
|
+
case "selectFriends":
|
|
4817
|
+
return /* @__PURE__ */ jsx31(SelectFriendsDialog, { groupId: route.groupId });
|
|
4818
|
+
default:
|
|
4819
|
+
return void 0;
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
// src/ui/privacy/PrivacyPage.tsx
|
|
4824
|
+
import { useCallback as useCallback11, useEffect as useEffect14, useRef as useRef13, useState as useState25 } from "react";
|
|
4825
|
+
import { ImApiError as ImApiError8 } from "@guokit-dev/im";
|
|
4826
|
+
import { jsx as jsx32, jsxs as jsxs29 } from "react/jsx-runtime";
|
|
4827
|
+
var PAGE = 50;
|
|
4828
|
+
function errorText4(e, fallback) {
|
|
4829
|
+
return e instanceof ImApiError8 && e.message ? e.message : fallback;
|
|
4830
|
+
}
|
|
4831
|
+
function ymd3(ms) {
|
|
4832
|
+
const d = new Date(ms);
|
|
4833
|
+
return `${d.getFullYear()}/${String(d.getMonth() + 1).padStart(2, "0")}/${String(d.getDate()).padStart(2, "0")}`;
|
|
4834
|
+
}
|
|
4835
|
+
function Blocklist({ onCount }) {
|
|
4836
|
+
const { im, strings: s } = useImUi();
|
|
4837
|
+
const { toast } = useFeedback();
|
|
4838
|
+
const [items, setItems] = useState25(null);
|
|
4839
|
+
const [hasMore, setHasMore] = useState25(false);
|
|
4840
|
+
const [busy, setBusy] = useState25(/* @__PURE__ */ new Set());
|
|
4841
|
+
const loading = useRef13(false);
|
|
4842
|
+
const fetchMore = useCallback11(async (reset = false) => {
|
|
4843
|
+
if (loading.current) return;
|
|
4844
|
+
loading.current = true;
|
|
4845
|
+
try {
|
|
4846
|
+
const r = await im.blocks({ offset: reset ? 0 : items?.length ?? 0, limit: PAGE });
|
|
4847
|
+
setItems((old) => reset || !old ? r.items : [...old, ...r.items]);
|
|
4848
|
+
setHasMore(r.hasMore);
|
|
4849
|
+
} catch (e) {
|
|
4850
|
+
setItems((old) => old ?? []);
|
|
4851
|
+
toast(errorText4(e, s.operationFailed));
|
|
4852
|
+
} finally {
|
|
4853
|
+
loading.current = false;
|
|
4854
|
+
}
|
|
4855
|
+
}, [im, items, toast, s]);
|
|
4856
|
+
useEffect14(() => {
|
|
4857
|
+
fetchMore(true);
|
|
4858
|
+
}, [im]);
|
|
4859
|
+
useEffect14(() => {
|
|
4860
|
+
if (items) onCount?.(hasMore ? `${items.length}+` : String(items.length));
|
|
4861
|
+
}, [items, hasMore, onCount]);
|
|
4862
|
+
const unblock = async (b) => {
|
|
4863
|
+
setBusy((x) => new Set(x).add(b.userId));
|
|
4864
|
+
try {
|
|
4865
|
+
await im.unblock(b.userId);
|
|
4866
|
+
setItems((old) => old?.filter((x) => x.userId !== b.userId) ?? null);
|
|
4867
|
+
} catch (e) {
|
|
4868
|
+
toast(errorText4(e, s.operationFailed));
|
|
4869
|
+
} finally {
|
|
4870
|
+
setBusy((x) => {
|
|
4871
|
+
const n = new Set(x);
|
|
4872
|
+
n.delete(b.userId);
|
|
4873
|
+
return n;
|
|
4874
|
+
});
|
|
4875
|
+
}
|
|
4876
|
+
};
|
|
4877
|
+
if (!items) return /* @__PURE__ */ jsx32("div", { className: "gkim-loading", children: /* @__PURE__ */ jsx32("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) });
|
|
4878
|
+
if (!items.length) return /* @__PURE__ */ jsx32("div", { className: "gkim-empty gkim-privacy__empty", children: s.emptyBlocklist });
|
|
4879
|
+
return /* @__PURE__ */ jsxs29(
|
|
4880
|
+
"ul",
|
|
4881
|
+
{
|
|
4882
|
+
className: "gkim-blocklist",
|
|
4883
|
+
"aria-label": s.blocklist,
|
|
4884
|
+
onScroll: (e) => {
|
|
4885
|
+
const el = e.currentTarget;
|
|
4886
|
+
if (hasMore && el.scrollHeight - el.scrollTop - el.clientHeight < 200) fetchMore();
|
|
4887
|
+
},
|
|
4888
|
+
children: [
|
|
4889
|
+
items.map((b) => {
|
|
4890
|
+
const name = b.nickname || fill(s.unknownUser, { id: b.userId });
|
|
4891
|
+
return /* @__PURE__ */ jsxs29("li", { className: "gkim-blocklist__row", children: [
|
|
4892
|
+
/* @__PURE__ */ jsx32(Avatar, { id: b.userId, name, url: b.avatarUrl || void 0 }),
|
|
4893
|
+
/* @__PURE__ */ jsxs29("span", { className: "gkim-blocklist__body", children: [
|
|
4894
|
+
/* @__PURE__ */ jsx32("span", { className: "gkim-blocklist__name", children: name }),
|
|
4895
|
+
/* @__PURE__ */ jsx32("span", { className: "gkim-blocklist__date", children: fill(s.blockedAt, { date: ymd3(b.createdAt) }) })
|
|
4896
|
+
] }),
|
|
4897
|
+
/* @__PURE__ */ jsx32(
|
|
4898
|
+
"button",
|
|
4899
|
+
{
|
|
4900
|
+
type: "button",
|
|
4901
|
+
className: "gkim-btn gkim-btn--sm",
|
|
4902
|
+
disabled: busy.has(b.userId),
|
|
4903
|
+
"aria-label": `${s.unblock} ${name}`,
|
|
4904
|
+
onClick: () => unblock(b),
|
|
4905
|
+
children: s.unblock
|
|
4906
|
+
}
|
|
4907
|
+
)
|
|
4908
|
+
] }, b.userId);
|
|
4909
|
+
}),
|
|
4910
|
+
hasMore && /* @__PURE__ */ jsx32("li", { className: "gkim-blocklist__more", children: /* @__PURE__ */ jsx32("button", { type: "button", className: "gkim-linkbtn", onClick: () => fetchMore(), children: "…" }) })
|
|
4911
|
+
]
|
|
4912
|
+
}
|
|
4913
|
+
);
|
|
4914
|
+
}
|
|
4915
|
+
function ImPrivacy() {
|
|
4916
|
+
const { im, strings: s } = useImUi();
|
|
4917
|
+
const { toast } = useFeedback();
|
|
4918
|
+
const frame = useFrame();
|
|
4919
|
+
const nav = useNavContext();
|
|
4920
|
+
const [policy, setPolicy] = useState25(null);
|
|
4921
|
+
const [count, setCount] = useState25(null);
|
|
4922
|
+
const inline = frame.kind === "main";
|
|
4923
|
+
useEffect14(() => {
|
|
4924
|
+
let live = true;
|
|
4925
|
+
im.features().then((f) => {
|
|
4926
|
+
if (live) setPolicy(f.addPolicy);
|
|
4927
|
+
}, () => {
|
|
4928
|
+
if (live) setPolicy((p) => p ?? 0);
|
|
4929
|
+
});
|
|
4930
|
+
if (!inline) im.blocks({ limit: 100 }).then((r) => {
|
|
4931
|
+
if (live) setCount(r.hasMore ? `${r.items.length}+` : String(r.items.length));
|
|
4932
|
+
}, () => {
|
|
4933
|
+
});
|
|
4934
|
+
return () => {
|
|
4935
|
+
live = false;
|
|
4936
|
+
};
|
|
4937
|
+
}, [im, inline]);
|
|
4938
|
+
const choose = async (p) => {
|
|
4939
|
+
const old = policy;
|
|
4940
|
+
if (p === old) return;
|
|
4941
|
+
setPolicy(p);
|
|
4942
|
+
try {
|
|
4943
|
+
await im.setFriendAddPolicy(p);
|
|
4944
|
+
} catch (e) {
|
|
4945
|
+
setPolicy(old);
|
|
4946
|
+
toast(errorText4(e, s.operationFailed));
|
|
4947
|
+
}
|
|
4948
|
+
};
|
|
4949
|
+
const onCount = useCallback11((t) => setCount(t), []);
|
|
4950
|
+
return /* @__PURE__ */ jsxs29(Page, { title: s.privacyTitle, className: "gkim-privacy", children: [
|
|
4951
|
+
/* @__PURE__ */ jsxs29("section", { className: "gkim-privacy__card", "aria-labelledby": "gkim-privacy-policy", children: [
|
|
4952
|
+
/* @__PURE__ */ jsx32("h3", { id: "gkim-privacy-policy", className: "gkim-privacy__h", children: s.addMeWhen }),
|
|
4953
|
+
policy === null ? /* @__PURE__ */ jsx32("div", { className: "gkim-loading", children: /* @__PURE__ */ jsx32("span", { className: "gkim-msglist__spinner", role: "img", "aria-label": "…" }) }) : /* @__PURE__ */ jsx32("div", { role: "radiogroup", "aria-labelledby": "gkim-privacy-policy", className: "gkim-privacy__options", children: s.addPolicyTitles.map((t, i) => /* @__PURE__ */ jsxs29("label", { className: `gkim-privacy__opt${policy === i ? " gkim-privacy__opt--on" : ""}`, children: [
|
|
4954
|
+
/* @__PURE__ */ jsx32("input", { type: "radio", name: "gkim-add-policy", checked: policy === i, onChange: () => choose(i) }),
|
|
4955
|
+
/* @__PURE__ */ jsxs29("span", { className: "gkim-privacy__opt-text", children: [
|
|
4956
|
+
/* @__PURE__ */ jsx32("span", { className: "gkim-privacy__opt-title", children: t }),
|
|
4957
|
+
s.addPolicyTips[i] && /* @__PURE__ */ jsx32("span", { className: "gkim-privacy__opt-tip", children: s.addPolicyTips[i] })
|
|
4958
|
+
] })
|
|
4959
|
+
] }, i)) })
|
|
4960
|
+
] }),
|
|
4961
|
+
inline ? /* @__PURE__ */ jsxs29("section", { className: "gkim-privacy__card", "aria-labelledby": "gkim-privacy-block", children: [
|
|
4962
|
+
/* @__PURE__ */ jsxs29("h3", { id: "gkim-privacy-block", className: "gkim-privacy__h", children: [
|
|
4963
|
+
s.blocklist,
|
|
4964
|
+
count !== null && /* @__PURE__ */ jsx32("span", { className: "gkim-privacy__count", children: count })
|
|
4965
|
+
] }),
|
|
4966
|
+
/* @__PURE__ */ jsx32("p", { className: "gkim-privacy__tip", children: s.blocklistTip }),
|
|
4967
|
+
/* @__PURE__ */ jsx32(Blocklist, { onCount })
|
|
4968
|
+
] }) : /* @__PURE__ */ jsx32("section", { className: "gkim-privacy__card gkim-privacy__card--row", children: /* @__PURE__ */ jsxs29("button", { type: "button", className: "gkim-row", onClick: () => nav.open({ name: "blocklist" }), children: [
|
|
4969
|
+
/* @__PURE__ */ jsx32("span", { className: "gkim-grow", children: s.blocklist }),
|
|
4970
|
+
count !== null && /* @__PURE__ */ jsx32("span", { className: "gkim-row__value", children: fill(s.peopleCount, { n: count }) }),
|
|
4971
|
+
/* @__PURE__ */ jsx32(Icon, { name: "chevron", size: 16 })
|
|
4972
|
+
] }) })
|
|
4973
|
+
] });
|
|
4974
|
+
}
|
|
4975
|
+
function BlocklistPage() {
|
|
4976
|
+
const s = useImUi().strings;
|
|
4977
|
+
return /* @__PURE__ */ jsxs29(Page, { title: s.blocklist, className: "gkim-privacy", children: [
|
|
4978
|
+
/* @__PURE__ */ jsx32("p", { className: "gkim-privacy__tip gkim-privacy__tip--page", children: s.blocklistTip }),
|
|
4979
|
+
/* @__PURE__ */ jsx32(Blocklist, {})
|
|
4980
|
+
] });
|
|
4981
|
+
}
|
|
4982
|
+
|
|
4983
|
+
// src/ui/privacy/routes.tsx
|
|
4984
|
+
import { jsx as jsx33 } from "react/jsx-runtime";
|
|
4985
|
+
function renderPrivacyRoute(route) {
|
|
4986
|
+
switch (route.name) {
|
|
4987
|
+
case "privacy":
|
|
4988
|
+
return /* @__PURE__ */ jsx33(ImPrivacy, {});
|
|
4989
|
+
case "blocklist":
|
|
4990
|
+
return /* @__PURE__ */ jsx33(BlocklistPage, {});
|
|
4991
|
+
default:
|
|
4992
|
+
return void 0;
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
|
|
4996
|
+
// src/ui/routes.tsx
|
|
4997
|
+
import { jsx as jsx34 } from "react/jsx-runtime";
|
|
4998
|
+
function renderRoute(route) {
|
|
4999
|
+
switch (route.name) {
|
|
5000
|
+
case "conversations":
|
|
5001
|
+
return /* @__PURE__ */ jsx34(ImConversationList, {});
|
|
5002
|
+
case "chat": {
|
|
5003
|
+
const t = route.target;
|
|
5004
|
+
if (t.conversation) return /* @__PURE__ */ jsx34(ImChat, { conversation: t.conversation }, `c${t.conversation.id}`);
|
|
5005
|
+
if (t.group) return /* @__PURE__ */ jsx34(ImChat, { group: t.group }, `g${t.group}`);
|
|
5006
|
+
return /* @__PURE__ */ jsx34(ImChat, { peer: t.peer }, `p${t.peer}`);
|
|
5007
|
+
}
|
|
5008
|
+
case "report":
|
|
5009
|
+
return /* @__PURE__ */ jsx34(ReportDialog, { target: route.target, title: route.title, messageIds: route.messageIds });
|
|
5010
|
+
case "imageViewer":
|
|
5011
|
+
return /* @__PURE__ */ jsx34(ImageViewer, { images: route.images, index: route.index });
|
|
5012
|
+
case "videoPlayer":
|
|
5013
|
+
return /* @__PURE__ */ jsx34(VideoPlayer, { message: route.message });
|
|
5014
|
+
default:
|
|
5015
|
+
return renderContactsRoute(route) ?? renderGroupRoute(route) ?? renderPrivacyRoute(route) ?? null;
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
|
|
5019
|
+
// src/ui/layout/Layers.tsx
|
|
5020
|
+
import { Fragment as Fragment12, jsx as jsx35, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
5021
|
+
function escToBack(back) {
|
|
5022
|
+
return (e) => {
|
|
5023
|
+
if (e.key === "Escape") {
|
|
5024
|
+
e.stopPropagation();
|
|
5025
|
+
back();
|
|
5026
|
+
}
|
|
5027
|
+
};
|
|
5028
|
+
}
|
|
5029
|
+
function FrameBox({ frame, children }) {
|
|
5030
|
+
return /* @__PURE__ */ jsx35(FrameContext.Provider, { value: frame, children });
|
|
5031
|
+
}
|
|
5032
|
+
function DrawerLayer({ stack, back, close }) {
|
|
5033
|
+
const ref = useFocusTrap(stack.length > 0);
|
|
5034
|
+
if (!stack.length) return null;
|
|
5035
|
+
return /* @__PURE__ */ jsxs30("div", { className: "gkim-drawer-layer", children: [
|
|
5036
|
+
/* @__PURE__ */ jsx35("div", { className: "gkim-scrim", onClick: close }),
|
|
5037
|
+
/* @__PURE__ */ jsx35("aside", { className: "gkim-drawer", ref, tabIndex: -1, onKeyDown: escToBack(back), children: stack.map((r, i) => /* @__PURE__ */ jsx35("div", { className: "gkim-stack-item", hidden: i !== stack.length - 1, children: /* @__PURE__ */ jsx35(FrameBox, { frame: { kind: "drawer", canBack: i > 0, back, close }, children: renderRoute(r) }) }, i)) })
|
|
5038
|
+
] });
|
|
5039
|
+
}
|
|
5040
|
+
function DialogBox({ children, back }) {
|
|
5041
|
+
const ref = useFocusTrap();
|
|
5042
|
+
return /* @__PURE__ */ jsxs30("div", { className: "gkim-dialog-layer", onKeyDown: escToBack(back), children: [
|
|
5043
|
+
/* @__PURE__ */ jsx35("div", { className: "gkim-scrim", onClick: back }),
|
|
5044
|
+
/* @__PURE__ */ jsx35("div", { className: "gkim-dialog", ref, tabIndex: -1, children })
|
|
5045
|
+
] });
|
|
5046
|
+
}
|
|
5047
|
+
function DialogLayer({ stack, back }) {
|
|
5048
|
+
return /* @__PURE__ */ jsx35(Fragment12, { children: stack.map((r, i) => /* @__PURE__ */ jsx35(DialogBox, { back, children: /* @__PURE__ */ jsx35(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
5049
|
+
}
|
|
5050
|
+
function OverlayBox({ children, back }) {
|
|
5051
|
+
const ref = useFocusTrap();
|
|
5052
|
+
return /* @__PURE__ */ jsx35("div", { className: "gkim-overlay", ref, tabIndex: -1, onKeyDown: escToBack(back), children });
|
|
5053
|
+
}
|
|
5054
|
+
function OverlayLayer({ stack, back }) {
|
|
5055
|
+
return /* @__PURE__ */ jsx35(Fragment12, { children: stack.map((r, i) => /* @__PURE__ */ jsx35(OverlayBox, { back, children: /* @__PURE__ */ jsx35(FrameBox, { frame: { kind: "dialog", canBack: false, back, close: back }, children: renderRoute(r) }) }, i)) });
|
|
5056
|
+
}
|
|
5057
|
+
function LayerHost() {
|
|
5058
|
+
const { state: st, back, close } = useNavContext();
|
|
5059
|
+
return useMemo10(() => /* @__PURE__ */ jsxs30(Fragment12, { children: [
|
|
5060
|
+
/* @__PURE__ */ jsx35(DrawerLayer, { stack: st.drawer, back, close }),
|
|
5061
|
+
/* @__PURE__ */ jsx35(DialogLayer, { stack: st.dialog, back }),
|
|
5062
|
+
/* @__PURE__ */ jsx35(OverlayLayer, { stack: st.overlay, back })
|
|
5063
|
+
] }), [st, back, close]);
|
|
5064
|
+
}
|
|
5065
|
+
|
|
5066
|
+
// src/ui/context.tsx
|
|
5067
|
+
import { jsx as jsx36, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
5068
|
+
var UiContext = createContext4(null);
|
|
5069
|
+
var EMPTY2 = {};
|
|
5070
|
+
var NO_ITEMS = [];
|
|
5071
|
+
function chatTargetOf(t) {
|
|
5072
|
+
const c = t.conversation;
|
|
5073
|
+
const peerId = c ? c.group ? null : c.peer?.userId ?? null : t.peer ?? null;
|
|
5074
|
+
const groupId = c ? c.group?.groupId ?? null : t.group ?? null;
|
|
2945
5075
|
return { peerId, groupId, conversationId: c?.id ?? null, to: peerId ?? "" };
|
|
2946
5076
|
}
|
|
2947
5077
|
function GuokitImUi(props) {
|
|
2948
5078
|
const { im, me, theme, strings, callbacks, messageRenderers, moreItems, menuItems, className, style, children } = props;
|
|
2949
|
-
const merged =
|
|
5079
|
+
const merged = useMemo11(() => mergeStrings(strings), [strings]);
|
|
2950
5080
|
const cb = callbacks ?? EMPTY2;
|
|
2951
|
-
const value =
|
|
5081
|
+
const value = useMemo11(() => ({
|
|
2952
5082
|
im,
|
|
2953
5083
|
me: me ?? EMPTY2,
|
|
2954
5084
|
strings: merged,
|
|
@@ -2957,16 +5087,16 @@ function GuokitImUi(props) {
|
|
|
2957
5087
|
moreItems: moreItems ?? NO_ITEMS,
|
|
2958
5088
|
menuItems
|
|
2959
5089
|
}), [im, me, merged, cb, messageRenderers, moreItems, menuItems]);
|
|
2960
|
-
const cbRef =
|
|
5090
|
+
const cbRef = useRef14(cb);
|
|
2961
5091
|
cbRef.current = cb;
|
|
2962
|
-
|
|
2963
|
-
const onMainOrList =
|
|
5092
|
+
useEffect15(() => im.on("kickedOut", () => cbRef.current.onKickedOut?.()), [im]);
|
|
5093
|
+
const onMainOrList = useCallback12((r) => {
|
|
2964
5094
|
if (r.name === "chat") cbRef.current.onOpenConversation?.(chatTargetOf(r.target));
|
|
2965
5095
|
}, []);
|
|
2966
5096
|
const nav = useNavState(false, onMainOrList);
|
|
2967
|
-
return /* @__PURE__ */
|
|
5097
|
+
return /* @__PURE__ */ jsx36(UiContext.Provider, { value, children: /* @__PURE__ */ jsx36(NavContext.Provider, { value: nav, children: /* @__PURE__ */ jsx36("div", { className: className ? `gkim-root ${className}` : "gkim-root", style: { ...themeVars(theme), ...style }, children: /* @__PURE__ */ jsxs31(FeedbackProvider, { labels: { ok: merged.confirm, cancel: merged.cancel }, children: [
|
|
2968
5098
|
children,
|
|
2969
|
-
/* @__PURE__ */
|
|
5099
|
+
/* @__PURE__ */ jsx36(LayerHost, {})
|
|
2970
5100
|
] }) }) }) });
|
|
2971
5101
|
}
|
|
2972
5102
|
function useImUi() {
|
|
@@ -2979,13 +5109,13 @@ function useIm() {
|
|
|
2979
5109
|
}
|
|
2980
5110
|
|
|
2981
5111
|
// src/ui/layout/ImWorkspace.tsx
|
|
2982
|
-
import { useEffect as
|
|
5112
|
+
import { useEffect as useEffect16, useRef as useRef15 } from "react";
|
|
2983
5113
|
|
|
2984
5114
|
// src/ui/layout/useWide.ts
|
|
2985
|
-
import { useLayoutEffect as useLayoutEffect4, useState as
|
|
5115
|
+
import { useLayoutEffect as useLayoutEffect4, useState as useState26 } from "react";
|
|
2986
5116
|
var WIDE_MIN = 768;
|
|
2987
5117
|
function useWide(ref) {
|
|
2988
|
-
const [wide, setWide] =
|
|
5118
|
+
const [wide, setWide] = useState26(true);
|
|
2989
5119
|
useLayoutEffect4(() => {
|
|
2990
5120
|
const el = ref.current;
|
|
2991
5121
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
@@ -3000,33 +5130,78 @@ function useWide(ref) {
|
|
|
3000
5130
|
}
|
|
3001
5131
|
|
|
3002
5132
|
// src/ui/layout/ImWorkspace.tsx
|
|
3003
|
-
import { Fragment as
|
|
3004
|
-
function
|
|
3005
|
-
|
|
5133
|
+
import { Fragment as Fragment13, jsx as jsx37, jsxs as jsxs32 } from "react/jsx-runtime";
|
|
5134
|
+
function currentTab(st) {
|
|
5135
|
+
if (st.main?.name === "privacy" || st.main?.name === "blocklist") return "privacy";
|
|
5136
|
+
return st.list.name === "contacts" ? "contacts" : "messages";
|
|
5137
|
+
}
|
|
5138
|
+
function useTabs(nav) {
|
|
5139
|
+
const { strings: s } = useImUi();
|
|
3006
5140
|
const unread = useTotalUnread();
|
|
5141
|
+
const cur = currentTab(nav.state);
|
|
5142
|
+
const go = (t) => {
|
|
5143
|
+
if (t === "messages") nav.open({ name: "conversations" });
|
|
5144
|
+
else if (t === "contacts") nav.open({ name: "contacts" });
|
|
5145
|
+
else nav.open({ name: "privacy" });
|
|
5146
|
+
};
|
|
5147
|
+
return [
|
|
5148
|
+
{ key: "messages", label: s.navMessages, icon: "message", badge: unread },
|
|
5149
|
+
{ key: "contacts", label: s.contactsTitle, icon: "contacts", badge: 0 },
|
|
5150
|
+
{ key: "privacy", label: s.privacyTitle, icon: "shield", badge: 0 }
|
|
5151
|
+
].map((t) => ({ ...t, current: t.key === cur, onClick: () => go(t.key) }));
|
|
5152
|
+
}
|
|
5153
|
+
function Rail({ nav }) {
|
|
5154
|
+
const { im, me } = useImUi();
|
|
5155
|
+
const tabs = useTabs(nav);
|
|
3007
5156
|
const uid = im.currentUserId ?? "";
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
5157
|
+
const item = (t) => /* @__PURE__ */ jsxs32(
|
|
5158
|
+
"button",
|
|
5159
|
+
{
|
|
5160
|
+
type: "button",
|
|
5161
|
+
className: "gkim-rail__item",
|
|
5162
|
+
"aria-label": t.label,
|
|
5163
|
+
title: t.label,
|
|
5164
|
+
"aria-current": t.current ? "page" : void 0,
|
|
5165
|
+
onClick: t.onClick,
|
|
5166
|
+
children: [
|
|
5167
|
+
/* @__PURE__ */ jsx37(Icon, { name: t.icon, size: 22 }),
|
|
5168
|
+
t.badge > 0 && /* @__PURE__ */ jsx37(Badge, { count: t.badge })
|
|
5169
|
+
]
|
|
5170
|
+
},
|
|
5171
|
+
t.key
|
|
5172
|
+
);
|
|
5173
|
+
return /* @__PURE__ */ jsxs32("nav", { className: "gkim-rail", "aria-label": "IM", children: [
|
|
5174
|
+
/* @__PURE__ */ jsx37(Avatar, { id: uid, name: me.nickname ?? "", url: me.avatarUrl, size: 36 }),
|
|
5175
|
+
item(tabs[0]),
|
|
5176
|
+
item(tabs[1]),
|
|
5177
|
+
/* @__PURE__ */ jsx37("div", { className: "gkim-grow" }),
|
|
5178
|
+
item(tabs[2])
|
|
3014
5179
|
] });
|
|
3015
5180
|
}
|
|
5181
|
+
function TabBar({ nav }) {
|
|
5182
|
+
const tabs = useTabs(nav);
|
|
5183
|
+
return /* @__PURE__ */ jsx37("div", { className: "gkim-tabbar", role: "tablist", "aria-label": "IM", children: tabs.map((t) => /* @__PURE__ */ jsxs32("button", { type: "button", role: "tab", "aria-selected": t.current, className: "gkim-tabbar__item", onClick: t.onClick, children: [
|
|
5184
|
+
/* @__PURE__ */ jsxs32("span", { className: "gkim-tabbar__icon", children: [
|
|
5185
|
+
/* @__PURE__ */ jsx37(Icon, { name: t.icon, size: 22 }),
|
|
5186
|
+
t.badge > 0 && /* @__PURE__ */ jsx37(Badge, { count: t.badge })
|
|
5187
|
+
] }),
|
|
5188
|
+
/* @__PURE__ */ jsx37("span", { children: t.label })
|
|
5189
|
+
] }, t.key)) });
|
|
5190
|
+
}
|
|
3016
5191
|
function Wide({ nav }) {
|
|
3017
5192
|
const { state: st, back, close } = nav;
|
|
3018
5193
|
const { strings: s } = useImUi();
|
|
3019
5194
|
const noop2 = () => {
|
|
3020
5195
|
};
|
|
3021
|
-
return /* @__PURE__ */
|
|
3022
|
-
/* @__PURE__ */
|
|
3023
|
-
/* @__PURE__ */
|
|
3024
|
-
/* @__PURE__ */
|
|
3025
|
-
st.main ? /* @__PURE__ */
|
|
3026
|
-
/* @__PURE__ */
|
|
5196
|
+
return /* @__PURE__ */ jsxs32(Fragment13, { children: [
|
|
5197
|
+
/* @__PURE__ */ jsx37(Rail, { nav }),
|
|
5198
|
+
/* @__PURE__ */ jsx37("div", { className: `gkim-listcol${st.main?.name === "privacy" || st.main?.name === "blocklist" ? " gkim-listcol--hidden" : ""}`, children: /* @__PURE__ */ jsx37(FrameContext.Provider, { value: { kind: "list", canBack: false, back: noop2, close: noop2 }, children: renderRoute(st.list) }) }),
|
|
5199
|
+
/* @__PURE__ */ jsxs32("div", { className: "gkim-main", children: [
|
|
5200
|
+
st.main ? /* @__PURE__ */ jsx37(FrameContext.Provider, { value: { kind: "main", canBack: false, back, close }, children: renderRoute(st.main) }) : /* @__PURE__ */ jsx37("div", { className: "gkim-empty gkim-main__empty", children: s.selectConversation }),
|
|
5201
|
+
/* @__PURE__ */ jsx37(DrawerLayer, { stack: st.drawer, back, close })
|
|
3027
5202
|
] }),
|
|
3028
|
-
/* @__PURE__ */
|
|
3029
|
-
/* @__PURE__ */
|
|
5203
|
+
/* @__PURE__ */ jsx37(DialogLayer, { stack: st.dialog, back }),
|
|
5204
|
+
/* @__PURE__ */ jsx37(OverlayLayer, { stack: st.overlay, back })
|
|
3030
5205
|
] });
|
|
3031
5206
|
}
|
|
3032
5207
|
function Narrow({ nav }) {
|
|
@@ -3037,36 +5212,45 @@ function Narrow({ nav }) {
|
|
|
3037
5212
|
...st.drawer.map((route, i) => ({ key: `d${i}`, route })),
|
|
3038
5213
|
...st.dialog.map((route, i) => ({ key: `g${i}`, route }))
|
|
3039
5214
|
];
|
|
3040
|
-
return /* @__PURE__ */
|
|
3041
|
-
pages.map((p, i) => /* @__PURE__ */
|
|
3042
|
-
|
|
5215
|
+
return /* @__PURE__ */ jsxs32(Fragment13, { children: [
|
|
5216
|
+
pages.map((p, i) => /* @__PURE__ */ jsxs32("div", { className: "gkim-stack-item gkim-narrow-page", hidden: i !== pages.length - 1, children: [
|
|
5217
|
+
/* @__PURE__ */ jsx37(FrameContext.Provider, { value: { kind: "page", canBack: i > 0, back, close: back }, children: renderRoute(p.route) }),
|
|
5218
|
+
i === 0 && /* @__PURE__ */ jsx37(TabBar, { nav })
|
|
5219
|
+
] }, p.key)),
|
|
5220
|
+
/* @__PURE__ */ jsx37(OverlayLayer, { stack: st.overlay, back })
|
|
3043
5221
|
] });
|
|
3044
5222
|
}
|
|
3045
5223
|
function ImWorkspace({ className }) {
|
|
3046
|
-
const ref =
|
|
5224
|
+
const ref = useRef15(null);
|
|
3047
5225
|
const wide = useWide(ref);
|
|
3048
5226
|
const { callbacks } = useImUi();
|
|
3049
5227
|
const nav = useNavState(true);
|
|
3050
|
-
const onNavigate =
|
|
5228
|
+
const onNavigate = useRef15(callbacks.onNavigate);
|
|
3051
5229
|
onNavigate.current = callbacks.onNavigate;
|
|
3052
|
-
const last =
|
|
3053
|
-
|
|
5230
|
+
const last = useRef15(nav.state);
|
|
5231
|
+
useEffect16(() => {
|
|
3054
5232
|
if (last.current === nav.state) return;
|
|
3055
5233
|
last.current = nav.state;
|
|
3056
5234
|
onNavigate.current?.(topRoute(nav.state));
|
|
3057
5235
|
}, [nav.state]);
|
|
3058
|
-
return /* @__PURE__ */
|
|
5236
|
+
return /* @__PURE__ */ jsx37(NavContext.Provider, { value: nav, children: /* @__PURE__ */ jsx37("div", { ref, className: `gkim-workspace gkim-workspace--${wide ? "wide" : "narrow"}${className ? " " + className : ""}`, children: wide ? /* @__PURE__ */ jsx37(Wide, { nav }) : /* @__PURE__ */ jsx37(Narrow, { nav }) }) });
|
|
3059
5237
|
}
|
|
3060
5238
|
export {
|
|
3061
5239
|
GuokitImUi,
|
|
3062
5240
|
Avatar as ImAvatar,
|
|
3063
5241
|
ImChat,
|
|
5242
|
+
ImContacts,
|
|
3064
5243
|
ImConversationList,
|
|
5244
|
+
ImGroupAvatar,
|
|
5245
|
+
ImGroupInfo,
|
|
5246
|
+
ImPrivacy,
|
|
3065
5247
|
ImUnreadBadge,
|
|
5248
|
+
ImUserCard,
|
|
3066
5249
|
ImWorkspace,
|
|
3067
5250
|
defaultStrings,
|
|
3068
5251
|
useConnection,
|
|
3069
5252
|
useConversations,
|
|
5253
|
+
useFriends,
|
|
3070
5254
|
useIm,
|
|
3071
5255
|
useImNavigator,
|
|
3072
5256
|
useTotalUnread
|