@nethesis/chat-island 0.1.8 → 0.1.9
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/dist/contacts.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +146 -140
- package/dist-widget/index.widget.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3124,31 +3124,37 @@ var An = (e) => {
|
|
|
3124
3124
|
totalUnread: () => Object.values(t().conversations).reduce((e, t) => e + t.unread, 0)
|
|
3125
3125
|
}));
|
|
3126
3126
|
//#endregion
|
|
3127
|
+
//#region src/contacts.ts
|
|
3128
|
+
function Pn(e, t, n) {
|
|
3129
|
+
return Object.values(e ?? {}).filter((e) => e?.username && e.username !== n).map((e) => ({
|
|
3130
|
+
username: e.username,
|
|
3131
|
+
name: e.name || e.username,
|
|
3132
|
+
avatar: t?.[e.username],
|
|
3133
|
+
presence: e.mainPresence,
|
|
3134
|
+
number: e.endpoints?.mainextension?.[0]?.id
|
|
3135
|
+
}));
|
|
3136
|
+
}
|
|
3137
|
+
//#endregion
|
|
3127
3138
|
//#region src/api.ts
|
|
3128
|
-
async function
|
|
3139
|
+
async function Fn(e, t, n) {
|
|
3129
3140
|
let r = await fetch(`https://${e}/api${n}`, { headers: { Authorization: `Bearer ${t}` } });
|
|
3130
3141
|
if (!r.ok) throw Error(`${n}: HTTP ${r.status}`);
|
|
3131
3142
|
return await r.json();
|
|
3132
3143
|
}
|
|
3133
|
-
async function
|
|
3134
|
-
let i = await
|
|
3144
|
+
async function In(e, t, n, r) {
|
|
3145
|
+
let i = await Fn(e, t, "/user/endpoints/all"), a = {};
|
|
3135
3146
|
try {
|
|
3136
|
-
a = await
|
|
3147
|
+
a = await Fn(e, t, "/user/all_avatars");
|
|
3137
3148
|
} catch {}
|
|
3138
3149
|
let o = Object.values(i).find((e) => e.username === n)?.name;
|
|
3139
|
-
return o && r?.(o),
|
|
3140
|
-
username: e.username,
|
|
3141
|
-
name: e.name || e.username,
|
|
3142
|
-
avatar: a[e.username],
|
|
3143
|
-
presence: e.mainPresence
|
|
3144
|
-
})).sort((e, t) => e.name.localeCompare(t.name));
|
|
3150
|
+
return o && r?.(o), Pn(i, a, n).sort((e, t) => e.name.localeCompare(t.name));
|
|
3145
3151
|
}
|
|
3146
|
-
async function
|
|
3152
|
+
async function Ln(e, t) {
|
|
3147
3153
|
let n = await fetch(`https://${e}/chat-gw/push/mobile`, { headers: { Authorization: `Bearer ${t}` } });
|
|
3148
3154
|
if (!n.ok) throw Error(`push/mobile: HTTP ${n.status}`);
|
|
3149
3155
|
return (await n.json()).users;
|
|
3150
3156
|
}
|
|
3151
|
-
async function
|
|
3157
|
+
async function Rn(e, t, n) {
|
|
3152
3158
|
let r = await fetch(`https://${e}/chat-gw/conversations/${encodeURIComponent(n)}`, {
|
|
3153
3159
|
method: "DELETE",
|
|
3154
3160
|
headers: { Authorization: `Bearer ${t}` }
|
|
@@ -3157,16 +3163,16 @@ async function Ln(e, t, n) {
|
|
|
3157
3163
|
}
|
|
3158
3164
|
//#endregion
|
|
3159
3165
|
//#region src/push.ts
|
|
3160
|
-
var
|
|
3166
|
+
var zn = (e) => {
|
|
3161
3167
|
let t = atob((e + "=".repeat((4 - e.length % 4) % 4)).replace(/-/g, "+").replace(/_/g, "/"));
|
|
3162
3168
|
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
3163
|
-
},
|
|
3164
|
-
function
|
|
3165
|
-
|
|
3169
|
+
}, Bn = !1;
|
|
3170
|
+
function Vn() {
|
|
3171
|
+
Bn || (Bn = !0, navigator.serviceWorker.addEventListener("message", (e) => {
|
|
3166
3172
|
e.data?.type === "chat-island-open" && typeof e.data.username == "string" && window.dispatchEvent(new CustomEvent("chat-island-open", { detail: { username: e.data.username } }));
|
|
3167
3173
|
}));
|
|
3168
3174
|
}
|
|
3169
|
-
async function
|
|
3175
|
+
async function Hn(e, t) {
|
|
3170
3176
|
if (!("serviceWorker" in navigator) || !("PushManager" in window)) throw Error("push not supported by this browser");
|
|
3171
3177
|
if (Notification.permission === "denied" || Notification.permission !== "granted" && await Notification.requestPermission() !== "granted") return null;
|
|
3172
3178
|
let n = `https://${e.host}/chat-gw`, r = await fetch(`${n}/push/vapid`);
|
|
@@ -3175,7 +3181,7 @@ async function Vn(e, t) {
|
|
|
3175
3181
|
await navigator.serviceWorker.ready;
|
|
3176
3182
|
let o = await a.pushManager.getSubscription() ?? await a.pushManager.subscribe({
|
|
3177
3183
|
userVisibleOnly: !0,
|
|
3178
|
-
applicationServerKey:
|
|
3184
|
+
applicationServerKey: zn(i.publicKey)
|
|
3179
3185
|
}), s = await fetch(`${n}/push/web`, {
|
|
3180
3186
|
method: "POST",
|
|
3181
3187
|
headers: {
|
|
@@ -3186,7 +3192,7 @@ async function Vn(e, t) {
|
|
|
3186
3192
|
});
|
|
3187
3193
|
if (!s.ok) throw Error(`push/web: HTTP ${s.status} ${(await s.text()).slice(0, 120)}`);
|
|
3188
3194
|
let c = await s.json();
|
|
3189
|
-
return
|
|
3195
|
+
return Vn(), {
|
|
3190
3196
|
node: c.node,
|
|
3191
3197
|
service: c.service
|
|
3192
3198
|
};
|
|
@@ -3202,8 +3208,8 @@ function X(e, t) {
|
|
|
3202
3208
|
}
|
|
3203
3209
|
//#endregion
|
|
3204
3210
|
//#region src/components/Avatar.tsx
|
|
3205
|
-
var
|
|
3206
|
-
function
|
|
3211
|
+
var Un = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
|
|
3212
|
+
function Wn({ contact: e, username: t, size: n = 40 }) {
|
|
3207
3213
|
let r = e?.name || t, i = {
|
|
3208
3214
|
width: n,
|
|
3209
3215
|
height: n,
|
|
@@ -3218,13 +3224,13 @@ function Un({ contact: e, username: t, size: n = 40 }) {
|
|
|
3218
3224
|
}) : /* @__PURE__ */ d("div", {
|
|
3219
3225
|
style: i,
|
|
3220
3226
|
className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900",
|
|
3221
|
-
children:
|
|
3227
|
+
children: Un(r)
|
|
3222
3228
|
});
|
|
3223
3229
|
}
|
|
3224
|
-
function
|
|
3230
|
+
function Gn({ online: e, presence: t, mobile: n }) {
|
|
3225
3231
|
return /* @__PURE__ */ d("span", { className: `ci-absolute ci-bottom-0 ci-right-0 ci-w-3 ci-h-3 ci-rounded-full ci-ring-2 ci-ring-gray-50 dark:ci-ring-gray-950 ${t === "dnd" || t === "busy" ? "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark" : e || n ? "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark" : "ci-bg-gray-400 dark:ci-bg-gray-600"}` });
|
|
3226
3232
|
}
|
|
3227
|
-
function
|
|
3233
|
+
function Kn({ name: e, size: t = 40, avatar: n }) {
|
|
3228
3234
|
let r = {
|
|
3229
3235
|
width: t,
|
|
3230
3236
|
height: t,
|
|
@@ -3239,12 +3245,12 @@ function Gn({ name: e, size: t = 40, avatar: n }) {
|
|
|
3239
3245
|
}) : /* @__PURE__ */ d("div", {
|
|
3240
3246
|
style: r,
|
|
3241
3247
|
className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-iconSecondary dark:ci-bg-iconSecondaryDark ci-text-white",
|
|
3242
|
-
children:
|
|
3248
|
+
children: Un(e || "G")
|
|
3243
3249
|
});
|
|
3244
3250
|
}
|
|
3245
3251
|
//#endregion
|
|
3246
3252
|
//#region src/components/Button.tsx
|
|
3247
|
-
var
|
|
3253
|
+
var qn = "ci-flex ci-content-center ci-items-center ci-justify-center ci-tracking-wide ci-duration-200 ci-transform ci-outline-none focus:ci-ring-2 focus:ci-z-20 focus:ci-ring-offset-2 disabled:ci-opacity-40 disabled:ci-cursor-not-allowed ci-border ci-border-transparent focus:ci-ring-offset-white dark:focus:ci-ring-offset-black ci-text-sm ci-leading-4 ci-transition-colors ci-shrink-0 ci-font-light", Jn = {
|
|
3248
3254
|
default: "ci-bg-phoneIslandActive dark:ci-bg-phoneIslandActiveDark hover:ci-bg-gray-500 dark:hover:ci-bg-gray-50 focus:ci-ring-emerald-500 dark:focus:ci-ring-emerald-300 ci-text-primaryInvert dark:ci-text-primaryInvertDark ci-h-12 ci-w-12 ci-rounded-full",
|
|
3249
3255
|
green: "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark hover:ci-bg-phoneIslandCallHover dark:hover:ci-bg-phoneIslandCallHoverDark focus:ci-ring-green-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
|
|
3250
3256
|
red: "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark hover:ci-bg-phoneIslandCloseHover dark:hover:ci-bg-phoneIslandCloseHoverDark focus:ci-ring-emerald-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
|
|
@@ -3257,7 +3263,7 @@ function Z({ variant: e, className: t = "", children: n, ...r }) {
|
|
|
3257
3263
|
return /* @__PURE__ */ d("button", {
|
|
3258
3264
|
type: "button",
|
|
3259
3265
|
"aria-label": r["aria-label"] ?? r.title,
|
|
3260
|
-
className: `${
|
|
3266
|
+
className: `${qn} ${Jn[e]} ${t}`,
|
|
3261
3267
|
...r,
|
|
3262
3268
|
children: n
|
|
3263
3269
|
});
|
|
@@ -3425,7 +3431,7 @@ var Q = {
|
|
|
3425
3431
|
};
|
|
3426
3432
|
//#endregion
|
|
3427
3433
|
//#region src/components/Dock.tsx
|
|
3428
|
-
function
|
|
3434
|
+
function Yn({ onDragStart: e, pushButton: t = !0 }) {
|
|
3429
3435
|
let { order: n, open: r, conversations: i, contacts: a, online: o, mobile: s, openChat: c, removeHead: l, picker: p, setPicker: m, status: h, push: g, enablePush: _, newChatButton: v } = J(w((e) => ({
|
|
3430
3436
|
order: e.order,
|
|
3431
3437
|
open: e.open,
|
|
@@ -3455,15 +3461,15 @@ function Jn({ onDragStart: e, pushButton: t = !0 }) {
|
|
|
3455
3461
|
title: t?.kind === "group" ? t.name ?? e : a[e]?.name ?? e,
|
|
3456
3462
|
onClick: () => n ? J.getState().closeChat() : c(e),
|
|
3457
3463
|
className: `ci-relative ci-rounded-full ci-shadow-lg ci-transition-transform hover:ci-scale-105 ci-ring-2 ci-border-0 ci-p-0 ci-bg-transparent ${n ? "ci-ring-iconSecondary dark:ci-ring-iconSecondaryDark" : "ci-ring-gray-50 dark:ci-ring-gray-950"}`,
|
|
3458
|
-
children: [t?.kind === "group" ? /* @__PURE__ */ d(
|
|
3464
|
+
children: [t?.kind === "group" ? /* @__PURE__ */ d(Kn, {
|
|
3459
3465
|
name: t.name ?? e,
|
|
3460
3466
|
size: 48,
|
|
3461
3467
|
avatar: t.avatar
|
|
3462
|
-
}) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(
|
|
3468
|
+
}) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Wn, {
|
|
3463
3469
|
contact: a[e],
|
|
3464
3470
|
username: e,
|
|
3465
3471
|
size: 48
|
|
3466
|
-
}), /* @__PURE__ */ d(
|
|
3472
|
+
}), /* @__PURE__ */ d(Gn, {
|
|
3467
3473
|
online: o[e],
|
|
3468
3474
|
presence: a[e]?.presence,
|
|
3469
3475
|
mobile: s[e]
|
|
@@ -3499,7 +3505,7 @@ function Jn({ onDragStart: e, pushButton: t = !0 }) {
|
|
|
3499
3505
|
}
|
|
3500
3506
|
//#endregion
|
|
3501
3507
|
//#region src/shortcodes.ts
|
|
3502
|
-
var
|
|
3508
|
+
var Xn = {
|
|
3503
3509
|
"+1": "👍",
|
|
3504
3510
|
thumbsup: "👍",
|
|
3505
3511
|
"-1": "👎",
|
|
@@ -3693,13 +3699,13 @@ var Yn = {
|
|
|
3693
3699
|
zzz: "💤",
|
|
3694
3700
|
sweat_drops: "💦",
|
|
3695
3701
|
dash: "💨"
|
|
3696
|
-
},
|
|
3702
|
+
}, Zn = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, Qn = /:([a-z0-9_+-]+):/g, $n = (e) => e.replace(Qn, (e, t) => Xn[t] ?? e);
|
|
3697
3703
|
function $(e) {
|
|
3698
|
-
return e.includes(":") ? e.split(
|
|
3704
|
+
return e.includes(":") ? e.split(Zn).map((e, t) => t % 2 ? e : $n(e)).join("") : e;
|
|
3699
3705
|
}
|
|
3700
3706
|
//#endregion
|
|
3701
3707
|
//#region src/components/EmojiPicker.tsx
|
|
3702
|
-
var
|
|
3708
|
+
var er = [
|
|
3703
3709
|
{
|
|
3704
3710
|
label: "Smileys",
|
|
3705
3711
|
icon: "😀",
|
|
@@ -3730,7 +3736,7 @@ var $n = [
|
|
|
3730
3736
|
icon: "☕",
|
|
3731
3737
|
emojis: "☕ 🍵 🥤 🍕 🍔 🍟 🌭 🥪 🌮 🍝 🍣 🍩 🍪 🍫 🍎 🍌 🍓 🥐 🚗 🚕 🚌 🚆 ✈️ 🚀 🏠 🏢 🏖️ 🌍 ☀️ 🌤️ 🌧️ ⛈️ ❄️ ⚡ 🌈 🌙"
|
|
3732
3738
|
}
|
|
3733
|
-
],
|
|
3739
|
+
], tr = [
|
|
3734
3740
|
"👍",
|
|
3735
3741
|
"❤️",
|
|
3736
3742
|
"😂",
|
|
@@ -3738,7 +3744,7 @@ var $n = [
|
|
|
3738
3744
|
"😢",
|
|
3739
3745
|
"🙏"
|
|
3740
3746
|
];
|
|
3741
|
-
function
|
|
3747
|
+
function nr({ onPick: e, onClose: t, className: n = "" }) {
|
|
3742
3748
|
let [r, a] = c(0), o = s(null);
|
|
3743
3749
|
return i(() => {
|
|
3744
3750
|
let e = (e) => o.current && !o.current.contains(e.target) && t(), n = (e) => {
|
|
@@ -3754,7 +3760,7 @@ function tr({ onPick: e, onClose: t, className: n = "" }) {
|
|
|
3754
3760
|
className: `ci-z-30 ci-w-[21rem] ci-max-w-full ci-rounded-2xl ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-2xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ci-select-none ${n}`,
|
|
3755
3761
|
children: [/* @__PURE__ */ d("div", {
|
|
3756
3762
|
className: "ci-flex ci-gap-1 ci-px-2 ci-pt-2 ci-border-b ci-border-gray-300 dark:ci-border-gray-700",
|
|
3757
|
-
children:
|
|
3763
|
+
children: er.map((e, t) => /* @__PURE__ */ d("button", {
|
|
3758
3764
|
type: "button",
|
|
3759
3765
|
title: e.label,
|
|
3760
3766
|
"aria-label": e.label,
|
|
@@ -3768,7 +3774,7 @@ function tr({ onPick: e, onClose: t, className: n = "" }) {
|
|
|
3768
3774
|
}, e.label))
|
|
3769
3775
|
}), /* @__PURE__ */ d("div", {
|
|
3770
3776
|
className: "ci-grid ci-grid-cols-7 ci-gap-1 ci-p-2 ci-h-64 ci-overflow-y-auto",
|
|
3771
|
-
children:
|
|
3777
|
+
children: er[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
|
|
3772
3778
|
type: "button",
|
|
3773
3779
|
onClick: () => e(t),
|
|
3774
3780
|
style: {
|
|
@@ -3783,27 +3789,27 @@ function tr({ onPick: e, onClose: t, className: n = "" }) {
|
|
|
3783
3789
|
}
|
|
3784
3790
|
//#endregion
|
|
3785
3791
|
//#region src/components/MessageList.tsx
|
|
3786
|
-
var
|
|
3792
|
+
var rr = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), ir = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), ar = (e) => {
|
|
3787
3793
|
let t = e.split("/").pop() || "file";
|
|
3788
3794
|
try {
|
|
3789
3795
|
return decodeURIComponent(t);
|
|
3790
3796
|
} catch {
|
|
3791
3797
|
return t;
|
|
3792
3798
|
}
|
|
3793
|
-
},
|
|
3799
|
+
}, or = (e) => {
|
|
3794
3800
|
try {
|
|
3795
3801
|
return new URL(e).protocol === "https:";
|
|
3796
3802
|
} catch {
|
|
3797
3803
|
return !1;
|
|
3798
3804
|
}
|
|
3799
|
-
},
|
|
3805
|
+
}, sr = (e) => new Date(e).toLocaleTimeString([], {
|
|
3800
3806
|
hour: "2-digit",
|
|
3801
3807
|
minute: "2-digit"
|
|
3802
|
-
}),
|
|
3808
|
+
}), cr = (e) => new Date(e).toLocaleDateString([], {
|
|
3803
3809
|
weekday: "short",
|
|
3804
3810
|
day: "numeric",
|
|
3805
3811
|
month: "short"
|
|
3806
|
-
}),
|
|
3812
|
+
}), lr = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), ur = (e) => {
|
|
3807
3813
|
if (!e.startsWith("{\"")) return null;
|
|
3808
3814
|
try {
|
|
3809
3815
|
let t = JSON.parse(e);
|
|
@@ -3814,17 +3820,17 @@ var nr = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), rr = (e) => /\
|
|
|
3814
3820
|
} catch {
|
|
3815
3821
|
return null;
|
|
3816
3822
|
}
|
|
3817
|
-
},
|
|
3818
|
-
return
|
|
3823
|
+
}, dr = n(function({ url: e }) {
|
|
3824
|
+
return or(e) ? rr(e) ? /* @__PURE__ */ d("a", {
|
|
3819
3825
|
href: e,
|
|
3820
3826
|
target: "_blank",
|
|
3821
3827
|
rel: "noreferrer",
|
|
3822
3828
|
children: /* @__PURE__ */ d("img", {
|
|
3823
3829
|
src: e,
|
|
3824
|
-
alt:
|
|
3830
|
+
alt: ar(e),
|
|
3825
3831
|
className: "ci-max-w-full ci-max-h-60 ci-rounded-2xl ci-block"
|
|
3826
3832
|
})
|
|
3827
|
-
}) :
|
|
3833
|
+
}) : ir(e) ? /* @__PURE__ */ d("audio", {
|
|
3828
3834
|
controls: !0,
|
|
3829
3835
|
src: e,
|
|
3830
3836
|
className: "ci-max-w-full"
|
|
@@ -3841,15 +3847,15 @@ var nr = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), rr = (e) => /\
|
|
|
3841
3847
|
stroke: "currentColor",
|
|
3842
3848
|
strokeWidth: "2",
|
|
3843
3849
|
children: /* @__PURE__ */ d("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
|
|
3844
|
-
}),
|
|
3850
|
+
}), ar(e)]
|
|
3845
3851
|
}) : /* @__PURE__ */ d("span", {
|
|
3846
3852
|
className: "ci-break-all",
|
|
3847
3853
|
children: e
|
|
3848
3854
|
});
|
|
3849
|
-
}),
|
|
3850
|
-
function
|
|
3855
|
+
}), fr = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
|
|
3856
|
+
function pr({ text: e }) {
|
|
3851
3857
|
let t = [], n = 0;
|
|
3852
|
-
for (let r of e.matchAll(
|
|
3858
|
+
for (let r of e.matchAll(fr)) {
|
|
3853
3859
|
let i = r[0], a = r.index ?? 0;
|
|
3854
3860
|
a > n && t.push($(e.slice(n, a))), r[1] ? t.push(/* @__PURE__ */ d("code", {
|
|
3855
3861
|
className: "ci-px-1 ci-py-0.5 ci-rounded ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-[0.85em]",
|
|
@@ -3870,17 +3876,17 @@ function fr({ text: e }) {
|
|
|
3870
3876
|
}
|
|
3871
3877
|
return n < e.length && t.push($(e.slice(n))), /* @__PURE__ */ d(u, { children: t });
|
|
3872
3878
|
}
|
|
3873
|
-
var
|
|
3879
|
+
var mr = n(function({ text: e }) {
|
|
3874
3880
|
let t = e.split(/```[^\n]*\n?([\s\S]*?)```/g);
|
|
3875
3881
|
return /* @__PURE__ */ d("span", {
|
|
3876
3882
|
className: "ci-whitespace-pre-wrap ci-break-words",
|
|
3877
3883
|
children: t.map((e, t) => t % 2 ? /* @__PURE__ */ d("pre", {
|
|
3878
3884
|
className: "ci-my-1 ci-p-2 ci-rounded-xl ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-xs ci-overflow-x-auto ci-whitespace-pre",
|
|
3879
3885
|
children: e.replace(/\n$/, "")
|
|
3880
|
-
}, t) : /* @__PURE__ */ d(
|
|
3886
|
+
}, t) : /* @__PURE__ */ d(pr, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
|
|
3881
3887
|
});
|
|
3882
3888
|
});
|
|
3883
|
-
function
|
|
3889
|
+
function hr({ text: e, count: t }) {
|
|
3884
3890
|
return /* @__PURE__ */ f("span", {
|
|
3885
3891
|
className: "ci-italic ci-opacity-80",
|
|
3886
3892
|
children: [
|
|
@@ -3893,7 +3899,7 @@ function mr({ text: e, count: t }) {
|
|
|
3893
3899
|
]
|
|
3894
3900
|
});
|
|
3895
3901
|
}
|
|
3896
|
-
function
|
|
3902
|
+
function gr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
|
|
3897
3903
|
if (!e) return null;
|
|
3898
3904
|
let a = /* @__PURE__ */ new Map();
|
|
3899
3905
|
for (let [t, n] of Object.entries(e)) for (let e of n) a.set(e, [...a.get(e) ?? [], t]);
|
|
@@ -3918,7 +3924,7 @@ function hr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
|
|
|
3918
3924
|
})
|
|
3919
3925
|
}) : null;
|
|
3920
3926
|
}
|
|
3921
|
-
function
|
|
3927
|
+
function _r({ reply: e, messages: t, mine: n, name: r }) {
|
|
3922
3928
|
let i = t.find((t) => t.oid === e.id), a = i ? i.oob ? "Attachment" : i.body : e.quote?.replace(/^[^:]*: /, "") ?? "", o = (t) => {
|
|
3923
3929
|
t.stopPropagation();
|
|
3924
3930
|
let n = document.querySelector(`.chat-island-root [data-oid="${CSS.escape(e.id)}"]`);
|
|
@@ -3942,7 +3948,7 @@ function gr({ reply: e, messages: t, mine: n, name: r }) {
|
|
|
3942
3948
|
})]
|
|
3943
3949
|
});
|
|
3944
3950
|
}
|
|
3945
|
-
function
|
|
3951
|
+
function vr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u, onReply: p }) {
|
|
3946
3952
|
let m = J((e) => e.contacts), h = s(null), g = s(!0), [_, v] = c(null), [y, b] = c(null), x = (e) => m[e]?.name ?? e;
|
|
3947
3953
|
i(() => {
|
|
3948
3954
|
let e = h.current;
|
|
@@ -3976,7 +3982,7 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
3976
3982
|
children: "Scroll up for older messages"
|
|
3977
3983
|
}),
|
|
3978
3984
|
e.map((t, n) => {
|
|
3979
|
-
let r = e[n - 1], i = !r || !
|
|
3985
|
+
let r = e[n - 1], i = !r || !lr(r.ts, t.ts), s = r && !i && r.mine === t.mine && r.nick === t.nick && t.ts - r.ts < 12e4, c = a && !t.mine && t.nick ? x(t.nick) : null, h = t.oid, g = !!u && !!h && !t.pending, y = g && /* @__PURE__ */ d("button", {
|
|
3980
3986
|
type: "button",
|
|
3981
3987
|
title: "React",
|
|
3982
3988
|
"aria-label": "React to this message",
|
|
@@ -3999,14 +4005,14 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
3999
4005
|
"data-oid": t.oid,
|
|
4000
4006
|
children: [i && /* @__PURE__ */ d("div", {
|
|
4001
4007
|
className: "ci-text-center ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-py-2",
|
|
4002
|
-
children:
|
|
4008
|
+
children: cr(t.ts)
|
|
4003
4009
|
}), /* @__PURE__ */ f("div", {
|
|
4004
4010
|
className: `ci-group ci-flex ci-items-start ci-gap-1.5 ${t.mine ? "ci-justify-end" : "ci-justify-start"} ${s ? "ci-mt-0.5" : "ci-mt-2"}`,
|
|
4005
4011
|
children: [
|
|
4006
4012
|
c && /* @__PURE__ */ d("span", {
|
|
4007
4013
|
className: "ci-w-7 ci-shrink-0",
|
|
4008
4014
|
title: c,
|
|
4009
|
-
children: !s && /* @__PURE__ */ d(
|
|
4015
|
+
children: !s && /* @__PURE__ */ d(Wn, {
|
|
4010
4016
|
contact: m[t.nick],
|
|
4011
4017
|
username: t.nick,
|
|
4012
4018
|
size: 28
|
|
@@ -4021,7 +4027,7 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
4021
4027
|
role: "menu",
|
|
4022
4028
|
onClick: (e) => e.stopPropagation(),
|
|
4023
4029
|
className: `ci-absolute ci-bottom-full ci-mb-1 ci-z-20 ci-flex ci-items-center ci-gap-0.5 ci-p-1 ci-rounded-full ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ${t.mine ? "ci-right-0" : "ci-left-0"}`,
|
|
4024
|
-
children: [
|
|
4030
|
+
children: [tr.map((e) => /* @__PURE__ */ d("button", {
|
|
4025
4031
|
type: "button",
|
|
4026
4032
|
role: "menuitem",
|
|
4027
4033
|
"aria-label": e,
|
|
@@ -4045,28 +4051,28 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
4045
4051
|
})]
|
|
4046
4052
|
}),
|
|
4047
4053
|
/* @__PURE__ */ f("div", {
|
|
4048
|
-
title:
|
|
4049
|
-
onDoubleClick: () => g && C(h,
|
|
4054
|
+
title: sr(t.ts),
|
|
4055
|
+
onDoubleClick: () => g && C(h, tr[0]),
|
|
4050
4056
|
className: `ci-px-3.5 ci-py-2 ci-rounded-3xl ci-text-sm ci-select-text ci-cursor-text ${t.mine ? "ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900 ci-rounded-br-lg" : "ci-bg-elevationL2 ci-text-gray-900 dark:ci-bg-elevationL2Dark dark:ci-text-white ci-rounded-bl-lg"} ${t.pending ? "ci-opacity-60" : ""}`,
|
|
4051
4057
|
children: [
|
|
4052
|
-
t.reply && /* @__PURE__ */ d(
|
|
4058
|
+
t.reply && /* @__PURE__ */ d(_r, {
|
|
4053
4059
|
reply: t.reply,
|
|
4054
4060
|
messages: e,
|
|
4055
4061
|
mine: t.mine,
|
|
4056
4062
|
name: (e) => e === l ? "You" : x(e)
|
|
4057
4063
|
}),
|
|
4058
|
-
t.oob ? /* @__PURE__ */ d(
|
|
4059
|
-
t.oob && t.body && t.body !== t.oob && t.body !==
|
|
4064
|
+
t.oob ? /* @__PURE__ */ d(dr, { url: t.oob }) : ur(t.body) ? /* @__PURE__ */ d(hr, { ...ur(t.body) }) : /* @__PURE__ */ d(mr, { text: t.body }),
|
|
4065
|
+
t.oob && t.body && t.body !== t.oob && t.body !== ar(t.oob) && /* @__PURE__ */ d("div", {
|
|
4060
4066
|
className: "ci-text-xs ci-opacity-80 ci-mt-1",
|
|
4061
4067
|
children: t.body
|
|
4062
4068
|
}),
|
|
4063
4069
|
/* @__PURE__ */ d("span", {
|
|
4064
4070
|
className: "ci-block ci-text-right ci-text-[10px] ci-leading-none ci-opacity-60 ci-mt-1",
|
|
4065
|
-
children:
|
|
4071
|
+
children: sr(t.ts)
|
|
4066
4072
|
})
|
|
4067
4073
|
]
|
|
4068
4074
|
}),
|
|
4069
|
-
h && /* @__PURE__ */ d(
|
|
4075
|
+
h && /* @__PURE__ */ d(gr, {
|
|
4070
4076
|
forMsg: o?.[h],
|
|
4071
4077
|
me: l,
|
|
4072
4078
|
mine: t.mine,
|
|
@@ -4089,7 +4095,7 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
4089
4095
|
})
|
|
4090
4096
|
})
|
|
4091
4097
|
]
|
|
4092
|
-
}), y && /* @__PURE__ */ d(
|
|
4098
|
+
}), y && /* @__PURE__ */ d(nr, {
|
|
4093
4099
|
className: "ci-absolute ci-bottom-2 ci-left-1/2 ci--translate-x-1/2",
|
|
4094
4100
|
onPick: (e) => C(y, e),
|
|
4095
4101
|
onClose: () => b(null)
|
|
@@ -4098,7 +4104,7 @@ function _r({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
|
|
|
4098
4104
|
}
|
|
4099
4105
|
//#endregion
|
|
4100
4106
|
//#region src/ogg.ts
|
|
4101
|
-
function
|
|
4107
|
+
function yr(e, t, n) {
|
|
4102
4108
|
let r = e[t];
|
|
4103
4109
|
if (r === void 0) return null;
|
|
4104
4110
|
let i = 1;
|
|
@@ -4112,7 +4118,7 @@ function vr(e, t, n) {
|
|
|
4112
4118
|
unknown: !n && o
|
|
4113
4119
|
};
|
|
4114
4120
|
}
|
|
4115
|
-
var
|
|
4121
|
+
var br = /* @__PURE__ */ new Set([
|
|
4116
4122
|
408125543,
|
|
4117
4123
|
524531317,
|
|
4118
4124
|
374648427,
|
|
@@ -4120,18 +4126,18 @@ var yr = /* @__PURE__ */ new Set([
|
|
|
4120
4126
|
225,
|
|
4121
4127
|
160
|
|
4122
4128
|
]);
|
|
4123
|
-
function
|
|
4129
|
+
function xr(e) {
|
|
4124
4130
|
let t = {
|
|
4125
4131
|
channels: 1,
|
|
4126
4132
|
packets: []
|
|
4127
4133
|
}, n = 0;
|
|
4128
4134
|
for (; n < e.length;) {
|
|
4129
|
-
let r =
|
|
4135
|
+
let r = yr(e, n, !0);
|
|
4130
4136
|
if (!r) break;
|
|
4131
|
-
let i =
|
|
4137
|
+
let i = yr(e, n + r.len, !1);
|
|
4132
4138
|
if (!i) break;
|
|
4133
4139
|
let a = n + r.len + i.len;
|
|
4134
|
-
if (
|
|
4140
|
+
if (br.has(r.value)) {
|
|
4135
4141
|
n = a;
|
|
4136
4142
|
continue;
|
|
4137
4143
|
}
|
|
@@ -4140,14 +4146,14 @@ function br(e) {
|
|
|
4140
4146
|
if (r.value === 25506) t.head = e.slice(a, o);
|
|
4141
4147
|
else if (r.value === 159) t.channels = e[a] || 1;
|
|
4142
4148
|
else if (r.value === 163 || r.value === 161) {
|
|
4143
|
-
let n =
|
|
4149
|
+
let n = yr(e, a, !1);
|
|
4144
4150
|
n && (e[a + n.len + 2] >> 1 & 3 || t.packets.push(e.slice(a + n.len + 3, o)));
|
|
4145
4151
|
}
|
|
4146
4152
|
n = o;
|
|
4147
4153
|
}
|
|
4148
4154
|
return t;
|
|
4149
4155
|
}
|
|
4150
|
-
function
|
|
4156
|
+
function Sr(e) {
|
|
4151
4157
|
if (!e.length) return 0;
|
|
4152
4158
|
let t = e[0], n = t >> 3, r;
|
|
4153
4159
|
r = n < 12 ? [
|
|
@@ -4164,7 +4170,7 @@ function xr(e) {
|
|
|
4164
4170
|
let i = t & 3, a = i === 0 ? 1 : i === 3 ? (e[1] ?? 0) & 63 : 2;
|
|
4165
4171
|
return Math.round(a * r * 48);
|
|
4166
4172
|
}
|
|
4167
|
-
var
|
|
4173
|
+
var Cr = (() => {
|
|
4168
4174
|
let e = /* @__PURE__ */ new Uint32Array(256);
|
|
4169
4175
|
for (let t = 0; t < 256; t++) {
|
|
4170
4176
|
let n = t << 24;
|
|
@@ -4173,12 +4179,12 @@ var Sr = (() => {
|
|
|
4173
4179
|
}
|
|
4174
4180
|
return e;
|
|
4175
4181
|
})();
|
|
4176
|
-
function
|
|
4182
|
+
function wr(e) {
|
|
4177
4183
|
let t = 0;
|
|
4178
|
-
for (let n = 0; n < e.length; n++) t = (t << 8 ^
|
|
4184
|
+
for (let n = 0; n < e.length; n++) t = (t << 8 ^ Cr[(t >>> 24 ^ e[n]) & 255]) >>> 0;
|
|
4179
4185
|
return t;
|
|
4180
4186
|
}
|
|
4181
|
-
function
|
|
4187
|
+
function Tr(e, t, n, r, i) {
|
|
4182
4188
|
let a = [];
|
|
4183
4189
|
for (let t of e) {
|
|
4184
4190
|
let e = t.length;
|
|
@@ -4194,29 +4200,29 @@ function wr(e, t, n, r, i) {
|
|
|
4194
4200
|
], 0), s[5] = i, c.setUint32(6, t % 4294967296, !0), c.setUint32(10, Math.floor(t / 4294967296), !0), c.setUint32(14, n, !0), c.setUint32(18, r, !0), s[26] = a.length, s.set(a, 27);
|
|
4195
4201
|
let l = 27 + a.length;
|
|
4196
4202
|
for (let t of e) s.set(t, l), l += t.length;
|
|
4197
|
-
return c.setUint32(22,
|
|
4203
|
+
return c.setUint32(22, wr(s), !0), s;
|
|
4198
4204
|
}
|
|
4199
|
-
function
|
|
4205
|
+
function Er(e) {
|
|
4200
4206
|
let t = /* @__PURE__ */ new Uint8Array(19), n = new DataView(t.buffer);
|
|
4201
4207
|
return t.set(new TextEncoder().encode("OpusHead"), 0), t[8] = 1, t[9] = e, n.setUint16(10, 312, !0), n.setUint32(12, 48e3, !0), t;
|
|
4202
4208
|
}
|
|
4203
|
-
function
|
|
4209
|
+
function Dr() {
|
|
4204
4210
|
let e = new TextEncoder().encode("chat-island"), t = new Uint8Array(12 + e.length + 4);
|
|
4205
4211
|
return t.set(new TextEncoder().encode("OpusTags"), 0), new DataView(t.buffer).setUint32(8, e.length, !0), t.set(e, 12), t;
|
|
4206
4212
|
}
|
|
4207
|
-
function
|
|
4208
|
-
let { head: t, channels: n, packets: r } =
|
|
4213
|
+
function Or(e) {
|
|
4214
|
+
let { head: t, channels: n, packets: r } = xr(e);
|
|
4209
4215
|
if (!r.length) return null;
|
|
4210
|
-
let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [
|
|
4216
|
+
let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [Tr([i ? t : Er(n)], 0, a, 0, 2), Tr([Dr()], 0, a, 1, 0)], s = 0, c = 2;
|
|
4211
4217
|
for (let e = 0; e < r.length;) {
|
|
4212
4218
|
let t = [], n = 0;
|
|
4213
4219
|
for (; e < r.length && t.length < 50;) {
|
|
4214
4220
|
let i = Math.floor(r[e].length / 255) + 1;
|
|
4215
4221
|
if (n + i > 255) break;
|
|
4216
|
-
t.push(r[e]), n += i, s +=
|
|
4222
|
+
t.push(r[e]), n += i, s += Sr(r[e]), e++;
|
|
4217
4223
|
}
|
|
4218
4224
|
if (!t.length) return null;
|
|
4219
|
-
o.push(
|
|
4225
|
+
o.push(Tr(t, s, a, c++, e >= r.length ? 4 : 0));
|
|
4220
4226
|
}
|
|
4221
4227
|
let l = o.reduce((e, t) => e + t.length, 0), u = new Uint8Array(l), d = 0;
|
|
4222
4228
|
for (let e of o) u.set(e, d), d += e.length;
|
|
@@ -4224,22 +4230,22 @@ function Dr(e) {
|
|
|
4224
4230
|
}
|
|
4225
4231
|
//#endregion
|
|
4226
4232
|
//#region src/components/Composer.tsx
|
|
4227
|
-
var
|
|
4233
|
+
var kr = [
|
|
4228
4234
|
"audio/ogg;codecs=opus",
|
|
4229
4235
|
"audio/webm;codecs=opus",
|
|
4230
4236
|
"audio/mp4",
|
|
4231
4237
|
"audio/webm"
|
|
4232
4238
|
];
|
|
4233
|
-
async function
|
|
4239
|
+
async function Ar(e, t) {
|
|
4234
4240
|
let n = Date.now();
|
|
4235
4241
|
if (/webm/.test(t) && /opus/.test(t)) try {
|
|
4236
|
-
let t =
|
|
4242
|
+
let t = Or(new Uint8Array(await new Blob(e).arrayBuffer()));
|
|
4237
4243
|
if (t) return new File([t], `voice-${n}.ogg`, { type: "audio/ogg" });
|
|
4238
4244
|
} catch {}
|
|
4239
|
-
return new File(e, `voice-${n}.${
|
|
4245
|
+
return new File(e, `voice-${n}.${jr(t)}`, { type: t.split(";")[0] });
|
|
4240
4246
|
}
|
|
4241
|
-
var
|
|
4242
|
-
function
|
|
4247
|
+
var jr = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", Mr = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
|
|
4248
|
+
function Nr({ onSend: e, onTyping: t, onFile: n, disabled: r, focusKey: o }) {
|
|
4243
4249
|
let [l, u] = c(""), [p, m] = c(!1), h = s(null), g = s(null), _ = s(null), v = s(), y = s(!1), [b, x] = c(null), [S, C] = c(0), w = s(!1), T = s(!1), ee = s(!1), E = s({});
|
|
4244
4250
|
i(() => _.current?.focus(), []), i(() => () => {
|
|
4245
4251
|
ee.current = !0, w.current = !0, window.clearTimeout(v.current);
|
|
@@ -4280,9 +4286,9 @@ function Mr({ onSend: e, onTyping: t, onFile: n, disabled: r, focusKey: o }) {
|
|
|
4280
4286
|
t.getTracks().forEach((e) => e.stop());
|
|
4281
4287
|
return;
|
|
4282
4288
|
}
|
|
4283
|
-
let r =
|
|
4289
|
+
let r = kr.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
|
|
4284
4290
|
i.ondataavailable = (e) => e.data.size && a.push(e.data), i.onstop = () => {
|
|
4285
|
-
t.getTracks().forEach((e) => e.stop()), E.current = {}, x(null), !w.current && a.length &&
|
|
4291
|
+
t.getTracks().forEach((e) => e.stop()), E.current = {}, x(null), !w.current && a.length && Ar(a, i.mimeType || r || "").then(n);
|
|
4286
4292
|
}, w.current = !1, i.start(), E.current = {
|
|
4287
4293
|
r: i,
|
|
4288
4294
|
stream: t
|
|
@@ -4311,7 +4317,7 @@ function Mr({ onSend: e, onTyping: t, onFile: n, disabled: r, focusKey: o }) {
|
|
|
4311
4317
|
}),
|
|
4312
4318
|
/* @__PURE__ */ f("div", {
|
|
4313
4319
|
className: "ci-flex-1 ci-flex ci-items-center ci-gap-2 ci-px-4 ci-py-2.5 ci-rounded-3xl ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-sm",
|
|
4314
|
-
children: [/* @__PURE__ */ d("span", { className: "ci-w-2.5 ci-h-2.5 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-animate-pulse" }), /* @__PURE__ */ f("span", { children: ["Recording ",
|
|
4320
|
+
children: [/* @__PURE__ */ d("span", { className: "ci-w-2.5 ci-h-2.5 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-animate-pulse" }), /* @__PURE__ */ f("span", { children: ["Recording ", Mr(S)] })]
|
|
4315
4321
|
}),
|
|
4316
4322
|
/* @__PURE__ */ d(Z, {
|
|
4317
4323
|
variant: "green",
|
|
@@ -4325,7 +4331,7 @@ function Mr({ onSend: e, onTyping: t, onFile: n, disabled: r, focusKey: o }) {
|
|
|
4325
4331
|
}) : /* @__PURE__ */ f("div", {
|
|
4326
4332
|
className: "ci-relative ci-flex ci-items-center ci-gap-2 ci-px-3 ci-py-3",
|
|
4327
4333
|
children: [
|
|
4328
|
-
p && /* @__PURE__ */ d(
|
|
4334
|
+
p && /* @__PURE__ */ d(nr, {
|
|
4329
4335
|
className: "ci-absolute ci-bottom-full ci-left-3 ci-mb-1",
|
|
4330
4336
|
onPick: k,
|
|
4331
4337
|
onClose: () => m(!1)
|
|
@@ -4391,14 +4397,14 @@ function Mr({ onSend: e, onTyping: t, onFile: n, disabled: r, focusKey: o }) {
|
|
|
4391
4397
|
}
|
|
4392
4398
|
//#endregion
|
|
4393
4399
|
//#region src/components/ChatWindow.tsx
|
|
4394
|
-
var
|
|
4400
|
+
var Pr = (e) => !!e && ![
|
|
4395
4401
|
"offline",
|
|
4396
4402
|
"dnd",
|
|
4397
4403
|
"busy",
|
|
4398
4404
|
"ringing",
|
|
4399
4405
|
"onhold"
|
|
4400
4406
|
].includes(e);
|
|
4401
|
-
function
|
|
4407
|
+
function Fr({ peer: e, actions: t, onDragStart: n }) {
|
|
4402
4408
|
let { c: r, contacts: a, online: o, mobile: s, status: l, closeChat: p, openChat: m, markRead: h, order: g, me: _ } = J(w((t) => ({
|
|
4403
4409
|
c: t.conversations[e],
|
|
4404
4410
|
contacts: t.contacts,
|
|
@@ -4444,17 +4450,17 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4444
4450
|
className: `ci-flex ci-items-center ci-gap-3 ci-px-4 ci-py-3 ci-rounded-t-3xl ${n ? "ci-cursor-grab active:ci-cursor-grabbing ci-touch-none" : ""}`,
|
|
4445
4451
|
onPointerDown: n,
|
|
4446
4452
|
children: [
|
|
4447
|
-
r.kind === "group" ? /* @__PURE__ */ d(
|
|
4453
|
+
r.kind === "group" ? /* @__PURE__ */ d(Kn, {
|
|
4448
4454
|
name: r.name ?? e,
|
|
4449
4455
|
size: 36,
|
|
4450
4456
|
avatar: r.avatar
|
|
4451
4457
|
}) : /* @__PURE__ */ f("span", {
|
|
4452
4458
|
className: "ci-relative",
|
|
4453
|
-
children: [/* @__PURE__ */ d(
|
|
4459
|
+
children: [/* @__PURE__ */ d(Wn, {
|
|
4454
4460
|
contact: y,
|
|
4455
4461
|
username: e,
|
|
4456
4462
|
size: 36
|
|
4457
|
-
}), /* @__PURE__ */ d(
|
|
4463
|
+
}), /* @__PURE__ */ d(Gn, {
|
|
4458
4464
|
online: o[e],
|
|
4459
4465
|
presence: y?.presence,
|
|
4460
4466
|
mobile: s[e]
|
|
@@ -4477,7 +4483,7 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4477
4483
|
children: l === "online" ? r.kind === "group" ? D.map(E).join(", ") : r.typing ? "typing…" : o[e] ? "online" : s[e] ? "Mobile" : "offline" : l
|
|
4478
4484
|
})]
|
|
4479
4485
|
}),
|
|
4480
|
-
r.kind !== "group" && y?.number &&
|
|
4486
|
+
r.kind !== "group" && y?.number && Pr(y.presence) && /* @__PURE__ */ d(Z, {
|
|
4481
4487
|
variant: "call",
|
|
4482
4488
|
title: `Call ${y.number}`,
|
|
4483
4489
|
"aria-label": "Call",
|
|
@@ -4504,11 +4510,11 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4504
4510
|
children: [
|
|
4505
4511
|
/* @__PURE__ */ f("span", {
|
|
4506
4512
|
className: "ci-relative",
|
|
4507
|
-
children: [/* @__PURE__ */ d(
|
|
4513
|
+
children: [/* @__PURE__ */ d(Wn, {
|
|
4508
4514
|
contact: a[e],
|
|
4509
4515
|
username: e,
|
|
4510
4516
|
size: 28
|
|
4511
|
-
}), e !== _ && /* @__PURE__ */ d(
|
|
4517
|
+
}), e !== _ && /* @__PURE__ */ d(Gn, {
|
|
4512
4518
|
online: o[e],
|
|
4513
4519
|
presence: a[e]?.presence,
|
|
4514
4520
|
mobile: s[e]
|
|
@@ -4524,7 +4530,7 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4524
4530
|
"aria-label": "Chat",
|
|
4525
4531
|
onClick: () => m(e),
|
|
4526
4532
|
children: Q.chat
|
|
4527
|
-
}), a[e]?.number &&
|
|
4533
|
+
}), a[e]?.number && Pr(a[e]?.presence) && /* @__PURE__ */ d(Z, {
|
|
4528
4534
|
variant: "call",
|
|
4529
4535
|
title: `Call ${a[e]?.number}`,
|
|
4530
4536
|
"aria-label": "Call",
|
|
@@ -4540,7 +4546,7 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4540
4546
|
/* @__PURE__ */ f("div", {
|
|
4541
4547
|
className: "ci-flex-1 ci-min-h-0 ci-flex ci-flex-col ci-overflow-hidden ci-rounded-b-3xl",
|
|
4542
4548
|
children: [
|
|
4543
|
-
/* @__PURE__ */ d(
|
|
4549
|
+
/* @__PURE__ */ d(vr, {
|
|
4544
4550
|
messages: r.messages,
|
|
4545
4551
|
typing: r.typing,
|
|
4546
4552
|
group: r.kind === "group",
|
|
@@ -4570,7 +4576,7 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4570
4576
|
children: Q.close
|
|
4571
4577
|
})]
|
|
4572
4578
|
}),
|
|
4573
|
-
/* @__PURE__ */ d(
|
|
4579
|
+
/* @__PURE__ */ d(Nr, {
|
|
4574
4580
|
focusKey: T,
|
|
4575
4581
|
disabled: l !== "online",
|
|
4576
4582
|
onSend: (n) => t.send(e, n, S ?? void 0).then(() => C(null)),
|
|
@@ -4584,11 +4590,11 @@ function Pr({ peer: e, actions: t, onDragStart: n }) {
|
|
|
4584
4590
|
}
|
|
4585
4591
|
//#endregion
|
|
4586
4592
|
//#region src/components/NewChat.tsx
|
|
4587
|
-
async function
|
|
4593
|
+
async function Ir(e) {
|
|
4588
4594
|
let t = await createImageBitmap(e), n = Math.min(t.width, t.height), r = document.createElement("canvas");
|
|
4589
4595
|
return r.width = r.height = 128, r.getContext("2d")?.drawImage(t, (t.width - n) / 2, (t.height - n) / 2, n, n, 0, 0, 128, 128), r.toDataURL("image/jpeg", .8);
|
|
4590
4596
|
}
|
|
4591
|
-
function
|
|
4597
|
+
function Lr({ onOpen: e, onCreateGroup: t }) {
|
|
4592
4598
|
let { contacts: n, online: r, mobile: i, setPicker: a } = J(), [l, p] = c(""), [m, h] = c([]), [g, _] = c(""), [v, y] = c(!1), [b, x] = c(), S = s(null), C = o(() => {
|
|
4593
4599
|
let e = Object.values(n), t = l.trim().toLowerCase();
|
|
4594
4600
|
return t ? e.filter((e) => (e.name ?? "").toLowerCase().includes(t) || e.username.includes(t)) : e;
|
|
@@ -4645,11 +4651,11 @@ function Ir({ onOpen: e, onCreateGroup: t }) {
|
|
|
4645
4651
|
children: [
|
|
4646
4652
|
/* @__PURE__ */ f("span", {
|
|
4647
4653
|
className: "ci-relative",
|
|
4648
|
-
children: [/* @__PURE__ */ d(
|
|
4654
|
+
children: [/* @__PURE__ */ d(Wn, {
|
|
4649
4655
|
contact: e,
|
|
4650
4656
|
username: e.username,
|
|
4651
4657
|
size: 36
|
|
4652
|
-
}), /* @__PURE__ */ d(
|
|
4658
|
+
}), /* @__PURE__ */ d(Gn, {
|
|
4653
4659
|
online: r[e.username],
|
|
4654
4660
|
presence: e.presence,
|
|
4655
4661
|
mobile: i[e.username]
|
|
@@ -4696,7 +4702,7 @@ function Ir({ onOpen: e, onCreateGroup: t }) {
|
|
|
4696
4702
|
type: "file",
|
|
4697
4703
|
accept: "image/*",
|
|
4698
4704
|
hidden: !0,
|
|
4699
|
-
onChange: (e) => e.target.files?.[0] &&
|
|
4705
|
+
onChange: (e) => e.target.files?.[0] && Ir(e.target.files[0]).then(x).catch(() => {})
|
|
4700
4706
|
}),
|
|
4701
4707
|
/* @__PURE__ */ d("button", {
|
|
4702
4708
|
type: "button",
|
|
@@ -4731,22 +4737,22 @@ function Ir({ onOpen: e, onCreateGroup: t }) {
|
|
|
4731
4737
|
}
|
|
4732
4738
|
//#endregion
|
|
4733
4739
|
//#region src/theme.ts
|
|
4734
|
-
var
|
|
4740
|
+
var Rr = "chat-island-theme", zr = () => {
|
|
4735
4741
|
try {
|
|
4736
|
-
let e = localStorage.getItem(
|
|
4742
|
+
let e = localStorage.getItem(Rr);
|
|
4737
4743
|
return e === "light" || e === "dark" || e === "system" ? e : void 0;
|
|
4738
4744
|
} catch {
|
|
4739
4745
|
return;
|
|
4740
4746
|
}
|
|
4741
4747
|
};
|
|
4742
|
-
function
|
|
4743
|
-
let [t, n] = c(() => e ??
|
|
4744
|
-
return i(() => n(e ??
|
|
4748
|
+
function Br(e) {
|
|
4749
|
+
let [t, n] = c(() => e ?? zr()), [r, a] = c(!1);
|
|
4750
|
+
return i(() => n(e ?? zr()), [e]), i(() => {
|
|
4745
4751
|
let e = (e) => {
|
|
4746
4752
|
let t = e.detail?.theme;
|
|
4747
4753
|
if (t === "light" || t === "dark" || t === "system") {
|
|
4748
4754
|
try {
|
|
4749
|
-
localStorage.setItem(
|
|
4755
|
+
localStorage.setItem(Rr, t);
|
|
4750
4756
|
} catch {}
|
|
4751
4757
|
n(t);
|
|
4752
4758
|
}
|
|
@@ -4772,7 +4778,7 @@ function zr(e) {
|
|
|
4772
4778
|
}
|
|
4773
4779
|
//#endregion
|
|
4774
4780
|
//#region src/ChatIsland.tsx
|
|
4775
|
-
function
|
|
4781
|
+
function Vr() {
|
|
4776
4782
|
let e = J.getState();
|
|
4777
4783
|
return Object.values(e.conversations).map((t) => {
|
|
4778
4784
|
let n = t.messages[t.messages.length - 1], r = e.contacts[t.peer];
|
|
@@ -4787,7 +4793,7 @@ function Br() {
|
|
|
4787
4793
|
unread: t.unread,
|
|
4788
4794
|
members: t.members,
|
|
4789
4795
|
last: n ? {
|
|
4790
|
-
body:
|
|
4796
|
+
body: Wr(n.body),
|
|
4791
4797
|
ts: n.ts,
|
|
4792
4798
|
mine: n.mine,
|
|
4793
4799
|
oob: n.oob,
|
|
@@ -4796,7 +4802,7 @@ function Br() {
|
|
|
4796
4802
|
};
|
|
4797
4803
|
}).filter((e) => e.last || e.kind === "group").sort((e, t) => (t.last?.ts ?? 0) - (e.last?.ts ?? 0));
|
|
4798
4804
|
}
|
|
4799
|
-
var
|
|
4805
|
+
var Hr = class extends t {
|
|
4800
4806
|
state = { failed: !1 };
|
|
4801
4807
|
failures = [];
|
|
4802
4808
|
static getDerivedStateFromError() {
|
|
@@ -4814,7 +4820,7 @@ var Vr = class extends t {
|
|
|
4814
4820
|
return this.state.failed ? null : this.props.children;
|
|
4815
4821
|
}
|
|
4816
4822
|
};
|
|
4817
|
-
function
|
|
4823
|
+
function Ur(e) {
|
|
4818
4824
|
try {
|
|
4819
4825
|
let [t, n, r] = atob(e).split(":");
|
|
4820
4826
|
return t && n && r ? {
|
|
@@ -4826,9 +4832,9 @@ function Hr(e) {
|
|
|
4826
4832
|
return null;
|
|
4827
4833
|
}
|
|
4828
4834
|
}
|
|
4829
|
-
var
|
|
4830
|
-
function
|
|
4831
|
-
let g = o(() =>
|
|
4835
|
+
var Wr = (e) => (ur(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
|
|
4836
|
+
function Gr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWorker: r, maxHeads: a = 5, newChatButton: l = !0, notifications: u = "click", sound: p = !0, drag: m = !0, onDragStart: h }) {
|
|
4837
|
+
let g = o(() => Ur(e), [e]), _ = Br(n), v = s(g), y = s(p), b = s(u);
|
|
4832
4838
|
i(() => {
|
|
4833
4839
|
v.current = g, y.current = p, b.current = u;
|
|
4834
4840
|
}, [
|
|
@@ -4891,7 +4897,7 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
4891
4897
|
if (!t || !n) return;
|
|
4892
4898
|
let r = J.getState().conversations[e];
|
|
4893
4899
|
try {
|
|
4894
|
-
r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await
|
|
4900
|
+
r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await Rn(n.host, n.token, e), J.getState().removeConversation(e);
|
|
4895
4901
|
} catch (e) {
|
|
4896
4902
|
Y("chat-island-error", {
|
|
4897
4903
|
scope: "delete",
|
|
@@ -5003,7 +5009,7 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
5003
5009
|
};
|
|
5004
5010
|
C.current = t;
|
|
5005
5011
|
let i = () => {
|
|
5006
|
-
r && !E.current && (E.current = !0,
|
|
5012
|
+
r && !E.current && (E.current = !0, Hn(g, r).then((e) => {
|
|
5007
5013
|
if (!e) {
|
|
5008
5014
|
E.current = !1, J.setState({ push: Notification.permission === "denied" ? "denied" : "ask" });
|
|
5009
5015
|
return;
|
|
@@ -5024,14 +5030,14 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
5024
5030
|
});
|
|
5025
5031
|
let s = () => t.stop();
|
|
5026
5032
|
window.addEventListener("pagehide", s), t.start();
|
|
5027
|
-
let c = () =>
|
|
5033
|
+
let c = () => Ln(g.host, g.token).then(e.setMobile).catch(() => {});
|
|
5028
5034
|
c();
|
|
5029
5035
|
let u = window.setInterval(c, 12e4);
|
|
5030
|
-
|
|
5036
|
+
In(g.host, g.token, g.username, (e) => J.setState({ myName: e })).then(e.setContacts).catch((e) => Y("chat-island-error", {
|
|
5031
5037
|
scope: "contacts",
|
|
5032
5038
|
message: e.message
|
|
5033
5039
|
}));
|
|
5034
|
-
let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && M.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations:
|
|
5040
|
+
let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && M.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Vr() }));
|
|
5035
5041
|
return () => {
|
|
5036
5042
|
window.removeEventListener("pagehide", s), window.clearInterval(u), _(), p(), m(), d(), f(), h(), D.current && t.disablePush(D.current.service, D.current.node).catch(() => {}), D.current = null, t.stop(), C.current = null, E.current = !1;
|
|
5037
5043
|
};
|
|
@@ -5045,7 +5051,7 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
5045
5051
|
j === "online" && N && C.current?.announce(N.split(","));
|
|
5046
5052
|
}, [j, N]);
|
|
5047
5053
|
let ne = J((e) => Object.values(e.conversations).map((e) => `${e.peer}:${e.kind}:${e.name ?? ""}:${(e.members ?? []).length}:${e.unread}:${e.messages[e.messages.length - 1]?.id ?? ""}`).join("|") + "#" + Object.keys(e.contacts).length + "#" + Object.values(e.online).filter(Boolean).length);
|
|
5048
|
-
i(() => Y("chat-island-conversations", { conversations:
|
|
5054
|
+
i(() => Y("chat-island-conversations", { conversations: Vr() }), [ne]);
|
|
5049
5055
|
let re = J((e) => Object.values(e.conversations).reduce((e, t) => e + t.unread, 0));
|
|
5050
5056
|
if (i(() => Y("chat-island-unread", { total: re }), [re]), !g) return null;
|
|
5051
5057
|
let ie = m && !h && k.anchor ? {
|
|
@@ -5058,17 +5064,17 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
5058
5064
|
onClickCapture: k.onClickCapture,
|
|
5059
5065
|
className: `chat-island-root ${_ ? "ci-dark" : ""} ci-fixed ${ae} ci-z-[9999] ci-flex ci-items-end ci-gap-3 ci-font-sans ci-select-none`,
|
|
5060
5066
|
"data-status": j,
|
|
5061
|
-
children: /* @__PURE__ */ f(
|
|
5062
|
-
te && /* @__PURE__ */ d(
|
|
5067
|
+
children: /* @__PURE__ */ f(Hr, { children: [
|
|
5068
|
+
te && /* @__PURE__ */ d(Fr, {
|
|
5063
5069
|
peer: te,
|
|
5064
5070
|
actions: M,
|
|
5065
5071
|
onDragStart: h ?? (m ? k.start : void 0)
|
|
5066
5072
|
}),
|
|
5067
|
-
A && /* @__PURE__ */ d(
|
|
5073
|
+
A && /* @__PURE__ */ d(Lr, {
|
|
5068
5074
|
onOpen: (e) => J.getState().openChat(e),
|
|
5069
5075
|
onCreateGroup: M.createGroup
|
|
5070
5076
|
}),
|
|
5071
|
-
/* @__PURE__ */ d(
|
|
5077
|
+
/* @__PURE__ */ d(Yn, {
|
|
5072
5078
|
onDragStart: h ?? (m ? k.start : void 0),
|
|
5073
5079
|
pushButton: u !== "auto"
|
|
5074
5080
|
})
|
|
@@ -5076,4 +5082,4 @@ function Wr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
|
|
|
5076
5082
|
});
|
|
5077
5083
|
}
|
|
5078
5084
|
//#endregion
|
|
5079
|
-
export {
|
|
5085
|
+
export { Gr as ChatIsland, Pn as contactsFromOperators };
|