@decentnetwork/beagle 0.1.147 → 0.1.148
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/desktop/app.js +590 -193
- package/package.json +2 -2
package/dist/desktop/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
window.__DK_UI_VERSION="0.1.
|
|
1
|
+
window.__DK_UI_VERSION="0.1.148";
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// packages/beagle-ui/dist/beagle-ui.js
|
|
@@ -2436,6 +2436,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2436
2436
|
return { lookup, peek };
|
|
2437
2437
|
}
|
|
2438
2438
|
var verifier = createEnsVerifier();
|
|
2439
|
+
var ensVerifier = verifier;
|
|
2439
2440
|
function useEnsRecord(userid) {
|
|
2440
2441
|
const [rec, setRec] = React.useState(() => verifier.peek(userid));
|
|
2441
2442
|
React.useEffect(() => {
|
|
@@ -2485,6 +2486,466 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2485
2486
|
const v = useEnsVerdict(userid, name);
|
|
2486
2487
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", { style, title: v.claimed ? v.claimed + " \u2192 " + v.label : void 0 }, v.label || fallback), /* @__PURE__ */ React.createElement(DkEnsMark, { verdict: v, T, size: markSize }));
|
|
2487
2488
|
}
|
|
2489
|
+
var AT = "[@\uFF20]";
|
|
2490
|
+
var WORD = "\\p{L}\\p{N}_";
|
|
2491
|
+
function escapeRe(s) {
|
|
2492
|
+
return String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2493
|
+
}
|
|
2494
|
+
function clean(s) {
|
|
2495
|
+
return String(s == null ? "" : s).replace(/[\u0000-\u001f\u007f]+/g, "").trim();
|
|
2496
|
+
}
|
|
2497
|
+
function myMentionNames(me) {
|
|
2498
|
+
const out = [];
|
|
2499
|
+
const add = (s) => {
|
|
2500
|
+
const v = clean(s);
|
|
2501
|
+
if (v && !out.some((x) => x.toLowerCase() === v.toLowerCase()))
|
|
2502
|
+
out.push(v);
|
|
2503
|
+
};
|
|
2504
|
+
const ens = clean(me && me.ens);
|
|
2505
|
+
if (ens) {
|
|
2506
|
+
add(/\.beagles\.eth$/i.test(ens) ? ens : ens + ".beagles.eth");
|
|
2507
|
+
add(ens.replace(/\.beagles\.eth$/i, ""));
|
|
2508
|
+
}
|
|
2509
|
+
add(me && me.name);
|
|
2510
|
+
return out;
|
|
2511
|
+
}
|
|
2512
|
+
function groupMessageBody(text) {
|
|
2513
|
+
const t = String(text == null ? "" : text);
|
|
2514
|
+
if (t.startsWith("CGP1 ")) {
|
|
2515
|
+
try {
|
|
2516
|
+
const j = JSON.parse(t.slice(5));
|
|
2517
|
+
const msg = j && j.message || {};
|
|
2518
|
+
const o = j && j.origin || {};
|
|
2519
|
+
const body = typeof msg.text === "string" ? msg.text : j.render && j.render.plain || "";
|
|
2520
|
+
return {
|
|
2521
|
+
body: stripGroupTs(body).body.trim(),
|
|
2522
|
+
sender: clean(o.nickname || o.user_info && o.user_info.name || "") || null,
|
|
2523
|
+
senderId: o.userid || o.friendid || null
|
|
2524
|
+
};
|
|
2525
|
+
} catch (e) {
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
const noTs = stripGroupTs(t).body.trim();
|
|
2529
|
+
const split = splitGroupSender(noTs);
|
|
2530
|
+
return split ? { body: split.body.trim(), sender: clean(split.sender), senderId: null } : { body: noTs, sender: null, senderId: null };
|
|
2531
|
+
}
|
|
2532
|
+
function looksLikeGroupText(text) {
|
|
2533
|
+
const t = String(text == null ? "" : text);
|
|
2534
|
+
if (t.startsWith("CGP1 "))
|
|
2535
|
+
return true;
|
|
2536
|
+
const { body, ts } = stripGroupTs(t);
|
|
2537
|
+
return !!ts && !!splitGroupSender(body.trim());
|
|
2538
|
+
}
|
|
2539
|
+
function mentionsName(body, names) {
|
|
2540
|
+
const text = String(body == null ? "" : body);
|
|
2541
|
+
if (!/[@@]/.test(text))
|
|
2542
|
+
return false;
|
|
2543
|
+
for (const n of names || []) {
|
|
2544
|
+
const name = clean(n);
|
|
2545
|
+
if (!name)
|
|
2546
|
+
continue;
|
|
2547
|
+
const re = new RegExp(
|
|
2548
|
+
`(^|[^${WORD}.@\uFF20])${AT}${escapeRe(name)}(?:\\.beagles\\.eth)?(?=$|[^${WORD}\\-.]|\\.(?![${WORD}]))`,
|
|
2549
|
+
"iu"
|
|
2550
|
+
);
|
|
2551
|
+
if (re.test(text))
|
|
2552
|
+
return true;
|
|
2553
|
+
}
|
|
2554
|
+
return false;
|
|
2555
|
+
}
|
|
2556
|
+
function messageMentionsMe(text, names) {
|
|
2557
|
+
if (!names || !names.length)
|
|
2558
|
+
return false;
|
|
2559
|
+
return mentionsName(groupMessageBody(text).body, names);
|
|
2560
|
+
}
|
|
2561
|
+
function mentionQuery(value, caret) {
|
|
2562
|
+
const v = String(value == null ? "" : value);
|
|
2563
|
+
const end = caret == null ? v.length : Math.min(caret, v.length);
|
|
2564
|
+
const head = v.slice(0, end);
|
|
2565
|
+
const m = /(^|\s)([@@])([^\s@@]*)$/u.exec(head);
|
|
2566
|
+
if (!m)
|
|
2567
|
+
return null;
|
|
2568
|
+
return { start: end - m[3].length - 1, end, query: m[3] };
|
|
2569
|
+
}
|
|
2570
|
+
function applyMention(value, q, name) {
|
|
2571
|
+
const v = String(value == null ? "" : value);
|
|
2572
|
+
const ins = "@" + clean(name) + " ";
|
|
2573
|
+
const rest = v.slice(q.end).replace(/^\s+/, "");
|
|
2574
|
+
return { value: v.slice(0, q.start) + ins + rest, caret: q.start + ins.length };
|
|
2575
|
+
}
|
|
2576
|
+
function memberCandidates(rows, { myUserId = "", myNames = [] } = {}) {
|
|
2577
|
+
const mine = new Set(myNames.map((n) => n.toLowerCase()));
|
|
2578
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2579
|
+
for (let i = (rows || []).length - 1; i >= 0; i--) {
|
|
2580
|
+
const r = rows[i];
|
|
2581
|
+
if (!r || r.day || r.from === "me" || r.dir === "out")
|
|
2582
|
+
continue;
|
|
2583
|
+
let sender = null, senderId = null;
|
|
2584
|
+
if (r.file && r.origin) {
|
|
2585
|
+
sender = clean(r.origin.nickname) || null;
|
|
2586
|
+
senderId = r.origin.userid || null;
|
|
2587
|
+
} else if (typeof r.text === "string") {
|
|
2588
|
+
({ sender, senderId } = groupMessageBody(r.text));
|
|
2589
|
+
}
|
|
2590
|
+
if (!sender && !senderId)
|
|
2591
|
+
continue;
|
|
2592
|
+
if (senderId && senderId === myUserId)
|
|
2593
|
+
continue;
|
|
2594
|
+
if (sender && mine.has(sender.toLowerCase()))
|
|
2595
|
+
continue;
|
|
2596
|
+
const key = senderId || "name:" + sender.toLowerCase();
|
|
2597
|
+
if (!seen.has(key))
|
|
2598
|
+
seen.set(key, { key, sender: sender || senderId.slice(0, 10), senderId });
|
|
2599
|
+
}
|
|
2600
|
+
return [...seen.values()];
|
|
2601
|
+
}
|
|
2602
|
+
function mentionInsertName(member, record) {
|
|
2603
|
+
const reg = record && typeof record.name === "string" ? clean(record.name) : "";
|
|
2604
|
+
if (reg)
|
|
2605
|
+
return reg.replace(/\.beagles\.eth$/i, "");
|
|
2606
|
+
return clean(member && member.sender);
|
|
2607
|
+
}
|
|
2608
|
+
function filterCandidates(cands, query) {
|
|
2609
|
+
const q = String(query || "").toLowerCase();
|
|
2610
|
+
if (!q)
|
|
2611
|
+
return cands;
|
|
2612
|
+
return cands.filter((c) => [c.insert, c.sender].some((s) => String(s || "").toLowerCase().includes(q)));
|
|
2613
|
+
}
|
|
2614
|
+
var dkAudioCtx = null;
|
|
2615
|
+
function dkAudio() {
|
|
2616
|
+
if (dkAudioCtx && dkAudioCtx.state !== "closed")
|
|
2617
|
+
return dkAudioCtx;
|
|
2618
|
+
try {
|
|
2619
|
+
dkAudioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
2620
|
+
} catch (e) {
|
|
2621
|
+
dkAudioCtx = null;
|
|
2622
|
+
}
|
|
2623
|
+
return dkAudioCtx;
|
|
2624
|
+
}
|
|
2625
|
+
function dkUnlockAudioOnGesture() {
|
|
2626
|
+
const unlock = () => {
|
|
2627
|
+
const c = dkAudio();
|
|
2628
|
+
if (c && c.state === "suspended")
|
|
2629
|
+
c.resume().catch(() => {
|
|
2630
|
+
});
|
|
2631
|
+
};
|
|
2632
|
+
window.addEventListener("pointerdown", unlock, { passive: true });
|
|
2633
|
+
window.addEventListener("keydown", unlock, { passive: true });
|
|
2634
|
+
return () => {
|
|
2635
|
+
window.removeEventListener("pointerdown", unlock);
|
|
2636
|
+
window.removeEventListener("keydown", unlock);
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
function dkChime(kind) {
|
|
2640
|
+
const c = dkAudio();
|
|
2641
|
+
if (!c)
|
|
2642
|
+
return;
|
|
2643
|
+
if (c.state === "suspended")
|
|
2644
|
+
c.resume().catch(() => {
|
|
2645
|
+
});
|
|
2646
|
+
const notes = kind === "request" ? [[660, 0], [880, 0.14]] : [[880, 0], [1175, 0.11]];
|
|
2647
|
+
const t0 = c.currentTime;
|
|
2648
|
+
for (const [freq, at] of notes) {
|
|
2649
|
+
const o = c.createOscillator(), g = c.createGain();
|
|
2650
|
+
o.type = "sine";
|
|
2651
|
+
o.frequency.value = freq;
|
|
2652
|
+
o.connect(g);
|
|
2653
|
+
g.connect(c.destination);
|
|
2654
|
+
const t = t0 + at;
|
|
2655
|
+
g.gain.setValueAtTime(1e-4, t);
|
|
2656
|
+
g.gain.exponentialRampToValueAtTime(0.18, t + 0.015);
|
|
2657
|
+
g.gain.exponentialRampToValueAtTime(1e-4, t + 0.17);
|
|
2658
|
+
o.start(t);
|
|
2659
|
+
o.stop(t + 0.2);
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
var dkFlash = { timer: null, title: "", link: null, href: null, badged: null, on: false, n: 0, label: "" };
|
|
2663
|
+
function dkBadgedIcon(href) {
|
|
2664
|
+
return new Promise((res, rej) => {
|
|
2665
|
+
const img = new Image();
|
|
2666
|
+
img.onload = () => {
|
|
2667
|
+
try {
|
|
2668
|
+
if (!img.naturalWidth)
|
|
2669
|
+
return rej(new Error("icon has no intrinsic size"));
|
|
2670
|
+
const s = 64, cv = document.createElement("canvas");
|
|
2671
|
+
cv.width = s;
|
|
2672
|
+
cv.height = s;
|
|
2673
|
+
const cx = cv.getContext("2d");
|
|
2674
|
+
cx.drawImage(img, 0, 0, s, s);
|
|
2675
|
+
cx.beginPath();
|
|
2676
|
+
cx.arc(s - 14, 14, 12, 0, Math.PI * 2);
|
|
2677
|
+
cx.fillStyle = "#e5484d";
|
|
2678
|
+
cx.fill();
|
|
2679
|
+
cx.lineWidth = 3;
|
|
2680
|
+
cx.strokeStyle = "#fff";
|
|
2681
|
+
cx.stroke();
|
|
2682
|
+
res(cv.toDataURL("image/png"));
|
|
2683
|
+
} catch (e) {
|
|
2684
|
+
rej(e);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
img.onerror = () => rej(new Error("icon failed to load"));
|
|
2688
|
+
img.src = href;
|
|
2689
|
+
});
|
|
2690
|
+
}
|
|
2691
|
+
function dkFlashTick() {
|
|
2692
|
+
dkFlash.on = !dkFlash.on;
|
|
2693
|
+
document.title = `(${dkFlash.n}) ${dkFlash.on ? dkFlash.label : dkFlash.title}`;
|
|
2694
|
+
}
|
|
2695
|
+
function dkFlashStart(label, count) {
|
|
2696
|
+
dkFlash.n += count || 1;
|
|
2697
|
+
dkFlash.label = label;
|
|
2698
|
+
if (dkFlash.timer)
|
|
2699
|
+
return;
|
|
2700
|
+
dkFlash.title = document.title;
|
|
2701
|
+
dkFlash.link = document.querySelector('link[rel~="icon"]');
|
|
2702
|
+
dkFlash.href = dkFlash.link ? dkFlash.link.href : null;
|
|
2703
|
+
dkFlash.badged = null;
|
|
2704
|
+
dkFlash.on = false;
|
|
2705
|
+
if (dkFlash.href) {
|
|
2706
|
+
dkBadgedIcon(dkFlash.href).then((b) => {
|
|
2707
|
+
dkFlash.badged = b;
|
|
2708
|
+
if (dkFlash.timer && dkFlash.link)
|
|
2709
|
+
dkFlash.link.href = b;
|
|
2710
|
+
}).catch(() => {
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
dkFlashTick();
|
|
2714
|
+
dkFlash.timer = setInterval(dkFlashTick, 1e3);
|
|
2715
|
+
}
|
|
2716
|
+
function dkFlashStop() {
|
|
2717
|
+
if (!dkFlash.timer)
|
|
2718
|
+
return;
|
|
2719
|
+
clearInterval(dkFlash.timer);
|
|
2720
|
+
dkFlash.timer = null;
|
|
2721
|
+
dkFlash.n = 0;
|
|
2722
|
+
document.title = dkFlash.title;
|
|
2723
|
+
if (dkFlash.link && dkFlash.href)
|
|
2724
|
+
dkFlash.link.href = dkFlash.href;
|
|
2725
|
+
}
|
|
2726
|
+
function dkLooking() {
|
|
2727
|
+
return document.visibilityState === "visible" && document.hasFocus();
|
|
2728
|
+
}
|
|
2729
|
+
function useIncomingAlerts({ T, peers, requests, loaded, activeId, sound = true, flash = true, muted, isProtocol }) {
|
|
2730
|
+
const prev = React.useRef(null);
|
|
2731
|
+
const mutedRef = React.useRef(/* @__PURE__ */ new Set());
|
|
2732
|
+
mutedRef.current = new Set(muted || []);
|
|
2733
|
+
React.useEffect(() => dkUnlockAudioOnGesture(), []);
|
|
2734
|
+
React.useEffect(() => {
|
|
2735
|
+
if (!flash)
|
|
2736
|
+
dkFlashStop();
|
|
2737
|
+
}, [flash]);
|
|
2738
|
+
React.useEffect(() => {
|
|
2739
|
+
const seen = () => {
|
|
2740
|
+
if (dkLooking())
|
|
2741
|
+
dkFlashStop();
|
|
2742
|
+
};
|
|
2743
|
+
window.addEventListener("focus", seen);
|
|
2744
|
+
window.addEventListener("pointerdown", seen, { passive: true });
|
|
2745
|
+
document.addEventListener("visibilitychange", seen);
|
|
2746
|
+
return () => {
|
|
2747
|
+
window.removeEventListener("focus", seen);
|
|
2748
|
+
window.removeEventListener("pointerdown", seen);
|
|
2749
|
+
document.removeEventListener("visibilitychange", seen);
|
|
2750
|
+
dkFlashStop();
|
|
2751
|
+
};
|
|
2752
|
+
}, []);
|
|
2753
|
+
React.useEffect(() => {
|
|
2754
|
+
if (!loaded)
|
|
2755
|
+
return;
|
|
2756
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2757
|
+
for (const p of peers || []) {
|
|
2758
|
+
if (p && p.app)
|
|
2759
|
+
continue;
|
|
2760
|
+
const dir = p.lastDir || (String(p.lastMsg || "").startsWith("you: ") ? "out" : "in");
|
|
2761
|
+
const quiet = typeof isProtocol === "function" && lastIsProtocol(p, isProtocol);
|
|
2762
|
+
byId.set(p.id, { ts: p.lastTs || 0, dir, quiet });
|
|
2763
|
+
}
|
|
2764
|
+
const reqIds = new Set((requests || []).map((r) => r.id));
|
|
2765
|
+
const was = prev.current;
|
|
2766
|
+
prev.current = { byId, reqIds };
|
|
2767
|
+
if (!was)
|
|
2768
|
+
return;
|
|
2769
|
+
let msgs = 0, elsewhere = 0, reqs = 0, loud = 0, loudElsewhere = 0;
|
|
2770
|
+
for (const [id, cur] of byId) {
|
|
2771
|
+
if (cur.dir !== "in" || !cur.ts)
|
|
2772
|
+
continue;
|
|
2773
|
+
if (cur.quiet)
|
|
2774
|
+
continue;
|
|
2775
|
+
const old = was.byId.get(id);
|
|
2776
|
+
if (old ? cur.ts <= old.ts : Date.now() - cur.ts > 3e4)
|
|
2777
|
+
continue;
|
|
2778
|
+
msgs += 1;
|
|
2779
|
+
if (id !== activeId)
|
|
2780
|
+
elsewhere += 1;
|
|
2781
|
+
if (!mutedRef.current.has(id)) {
|
|
2782
|
+
loud += 1;
|
|
2783
|
+
if (id !== activeId)
|
|
2784
|
+
loudElsewhere += 1;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
for (const id of reqIds)
|
|
2788
|
+
if (!was.reqIds.has(id))
|
|
2789
|
+
reqs += 1;
|
|
2790
|
+
if (!msgs && !reqs)
|
|
2791
|
+
return;
|
|
2792
|
+
const looking = dkLooking();
|
|
2793
|
+
if (sound && (reqs || loud) && !(looking && !reqs && !loudElsewhere))
|
|
2794
|
+
dkChime(reqs && !loud ? "request" : "message");
|
|
2795
|
+
if (flash && !looking) {
|
|
2796
|
+
const label = msgs ? T && T.alertMsg || "New message" : T && T.alertReq || "New friend request";
|
|
2797
|
+
dkFlashStart(label, msgs + reqs);
|
|
2798
|
+
}
|
|
2799
|
+
}, [peers, requests, loaded, activeId, T, sound, flash]);
|
|
2800
|
+
}
|
|
2801
|
+
var MW_FLAGS_KEY = "dk.mentions.v1";
|
|
2802
|
+
var mwNames = [];
|
|
2803
|
+
var mwUserId = "";
|
|
2804
|
+
var mwFlags = mwLoadFlags();
|
|
2805
|
+
var mwSubs = /* @__PURE__ */ new Set();
|
|
2806
|
+
function mwLoadFlags() {
|
|
2807
|
+
try {
|
|
2808
|
+
const raw = JSON.parse(localStorage.getItem(MW_FLAGS_KEY) || "{}");
|
|
2809
|
+
return new Map(Object.entries(raw).filter(([, v]) => typeof v === "number"));
|
|
2810
|
+
} catch (e) {
|
|
2811
|
+
return /* @__PURE__ */ new Map();
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
function mwSaveFlags() {
|
|
2815
|
+
try {
|
|
2816
|
+
localStorage.setItem(MW_FLAGS_KEY, JSON.stringify(Object.fromEntries(mwFlags)));
|
|
2817
|
+
} catch (e) {
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
function mwChanged() {
|
|
2821
|
+
for (const f of mwSubs)
|
|
2822
|
+
f();
|
|
2823
|
+
}
|
|
2824
|
+
function setMentionIdentity(me) {
|
|
2825
|
+
mwNames = myMentionNames(me);
|
|
2826
|
+
mwUserId = me && me.userId || "";
|
|
2827
|
+
}
|
|
2828
|
+
function mentionNames() {
|
|
2829
|
+
return mwNames;
|
|
2830
|
+
}
|
|
2831
|
+
function mentionUserId() {
|
|
2832
|
+
return mwUserId;
|
|
2833
|
+
}
|
|
2834
|
+
function flagMention(peerId, ts) {
|
|
2835
|
+
if (!peerId)
|
|
2836
|
+
return;
|
|
2837
|
+
mwFlags.set(peerId, Math.max(mwFlags.get(peerId) || 0, ts || Date.now()));
|
|
2838
|
+
mwSaveFlags();
|
|
2839
|
+
mwChanged();
|
|
2840
|
+
}
|
|
2841
|
+
function clearMention(peerId) {
|
|
2842
|
+
if (!mwFlags.has(peerId))
|
|
2843
|
+
return;
|
|
2844
|
+
mwFlags.delete(peerId);
|
|
2845
|
+
mwSaveFlags();
|
|
2846
|
+
mwChanged();
|
|
2847
|
+
}
|
|
2848
|
+
function useMentionFlags() {
|
|
2849
|
+
const [, bump] = React.useState(0);
|
|
2850
|
+
React.useEffect(() => {
|
|
2851
|
+
const f = () => bump((n) => n + 1);
|
|
2852
|
+
mwSubs.add(f);
|
|
2853
|
+
return () => {
|
|
2854
|
+
mwSubs.delete(f);
|
|
2855
|
+
};
|
|
2856
|
+
}, []);
|
|
2857
|
+
return mwFlags;
|
|
2858
|
+
}
|
|
2859
|
+
function mwNotify(T, groupName, sender, body, peerId) {
|
|
2860
|
+
try {
|
|
2861
|
+
if (typeof Notification === "undefined" || Notification.permission !== "granted")
|
|
2862
|
+
return;
|
|
2863
|
+
const title = (T && T.mentionNotifyTitle || "{sender} mentioned you in {group}").replace("{sender}", sender || "\u2026").replace("{group}", groupName || "");
|
|
2864
|
+
const n = new Notification(title, { body: String(body || "").slice(0, 180), tag: "dk-mention-" + peerId });
|
|
2865
|
+
n.onclick = () => {
|
|
2866
|
+
try {
|
|
2867
|
+
window.focus();
|
|
2868
|
+
} catch (e) {
|
|
2869
|
+
}
|
|
2870
|
+
n.close();
|
|
2871
|
+
};
|
|
2872
|
+
} catch (e) {
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
function useGroupMentions({ T, me, peers, activeId, loaded, sound = true, muted }) {
|
|
2876
|
+
React.useEffect(() => {
|
|
2877
|
+
setMentionIdentity(me);
|
|
2878
|
+
}, [me && me.name, me && me.ens, me && me.userId]);
|
|
2879
|
+
const prev = React.useRef(null);
|
|
2880
|
+
const groups = React.useRef(/* @__PURE__ */ new Set());
|
|
2881
|
+
const inFlight = React.useRef(/* @__PURE__ */ new Set());
|
|
2882
|
+
const Tref = React.useRef(T);
|
|
2883
|
+
Tref.current = T;
|
|
2884
|
+
const soundRef = React.useRef(sound);
|
|
2885
|
+
soundRef.current = sound;
|
|
2886
|
+
const mutedRef = React.useRef(/* @__PURE__ */ new Set());
|
|
2887
|
+
mutedRef.current = new Set(muted || []);
|
|
2888
|
+
React.useEffect(() => {
|
|
2889
|
+
if (activeId)
|
|
2890
|
+
clearMention(activeId);
|
|
2891
|
+
}, [activeId]);
|
|
2892
|
+
React.useEffect(() => {
|
|
2893
|
+
try {
|
|
2894
|
+
if (activeId && groups.current.has(activeId) && typeof Notification !== "undefined" && Notification.permission === "default") {
|
|
2895
|
+
Notification.requestPermission().catch(() => {
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2898
|
+
} catch (e) {
|
|
2899
|
+
}
|
|
2900
|
+
}, [activeId]);
|
|
2901
|
+
React.useEffect(() => {
|
|
2902
|
+
if (!loaded)
|
|
2903
|
+
return;
|
|
2904
|
+
const was = prev.current;
|
|
2905
|
+
const now = /* @__PURE__ */ new Map();
|
|
2906
|
+
for (const p of peers || []) {
|
|
2907
|
+
if (!p || p.app)
|
|
2908
|
+
continue;
|
|
2909
|
+
now.set(p.id, p.lastTs || 0);
|
|
2910
|
+
if (looksLikeGroupText(p.lastMsg))
|
|
2911
|
+
groups.current.add(p.id);
|
|
2912
|
+
}
|
|
2913
|
+
prev.current = now;
|
|
2914
|
+
if (!was || !mwNames.length)
|
|
2915
|
+
return;
|
|
2916
|
+
for (const p of peers || []) {
|
|
2917
|
+
if (!p || p.app || !groups.current.has(p.id))
|
|
2918
|
+
continue;
|
|
2919
|
+
const since = was.get(p.id);
|
|
2920
|
+
const ts = now.get(p.id);
|
|
2921
|
+
if (since == null || !ts || ts <= since)
|
|
2922
|
+
continue;
|
|
2923
|
+
if (p.lastDir === "out")
|
|
2924
|
+
continue;
|
|
2925
|
+
if (inFlight.current.has(p.id))
|
|
2926
|
+
continue;
|
|
2927
|
+
inFlight.current.add(p.id);
|
|
2928
|
+
dkGet("/api/chat-history?peer=" + encodeURIComponent(p.id) + "&limit=60").then((d) => {
|
|
2929
|
+
const rows = (d && d.chats && d.chats[p.id] || []).filter((m) => m && m.dir !== "out" && (m.ts || 0) > since);
|
|
2930
|
+
const hits = rows.filter((m) => !m.file && messageMentionsMe(m.text, mwNames));
|
|
2931
|
+
if (!hits.length)
|
|
2932
|
+
return;
|
|
2933
|
+
const last = hits[hits.length - 1];
|
|
2934
|
+
const reading = p.id === activeId && typeof document !== "undefined" && document.visibilityState === "visible" && document.hasFocus();
|
|
2935
|
+
if (!reading)
|
|
2936
|
+
flagMention(p.id, last.ts);
|
|
2937
|
+
const g = groupMessageBody(last.text);
|
|
2938
|
+
if (!reading)
|
|
2939
|
+
mwNotify(Tref.current, p.alias || "", g.sender, g.body, p.id);
|
|
2940
|
+
if (soundRef.current && !reading && mutedRef.current.has(p.id))
|
|
2941
|
+
dkChime("message");
|
|
2942
|
+
}).catch(() => {
|
|
2943
|
+
}).finally(() => {
|
|
2944
|
+
inFlight.current.delete(p.id);
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
}, [peers, loaded, activeId]);
|
|
2948
|
+
}
|
|
2488
2949
|
var DK_CMD_HIST_KEY = "beagle.assistant.history";
|
|
2489
2950
|
var DK_CMD_HIST_MAX = 50;
|
|
2490
2951
|
function RequestsBlock({ T, requests, onAct }) {
|
|
@@ -2644,6 +3105,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2644
3105
|
function PeerRow({ peer, T, active, onClick, muted, isProtocol, fix }) {
|
|
2645
3106
|
const name = peer.alias || peer.userId;
|
|
2646
3107
|
const row = rosterRow(peer, isProtocol || (() => false), fix);
|
|
3108
|
+
const mentioned = useMentionFlags().has(peer.id);
|
|
2647
3109
|
return /* @__PURE__ */ React.createElement("button", { onClick, style: {
|
|
2648
3110
|
display: "flex",
|
|
2649
3111
|
alignItems: "center",
|
|
@@ -2672,7 +3134,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2672
3134
|
textOverflow: "ellipsis",
|
|
2673
3135
|
flex: 1,
|
|
2674
3136
|
minWidth: 0
|
|
2675
|
-
} }, dkRowPreview(row.preview, T)))), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 4, flexShrink: 0 } }, /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--faint)" } }, row.lastTime), peer.app ? null : row.unread ? /* @__PURE__ */ React.createElement(Unread, { n: row.unread }) : peer.pending ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 11, stroke: 2.2, color: "var(--warn, #d29922)", title: "friend request pending" }) : /* @__PURE__ */ React.createElement(StatusDot, { online: peer.online })));
|
|
3137
|
+
} }, mentioned && /* @__PURE__ */ React.createElement("span", { style: { color: "var(--danger)", fontWeight: 700, marginRight: 4 } }, T && T.mentionYou || "[@ you]"), dkRowPreview(row.preview, T)))), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 4, flexShrink: 0 } }, /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--faint)" } }, row.lastTime), peer.app ? null : row.unread ? /* @__PURE__ */ React.createElement(Unread, { n: row.unread }) : peer.pending ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 11, stroke: 2.2, color: "var(--warn, #d29922)", title: "friend request pending" }) : /* @__PURE__ */ React.createElement(StatusDot, { online: peer.online })));
|
|
2676
3138
|
}
|
|
2677
3139
|
function dkActivityTs(p, isProtocol, fix) {
|
|
2678
3140
|
const row = rosterRow(p, isProtocol || (() => false), fix);
|
|
@@ -3351,10 +3813,12 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3351
3813
|
const submitted = read.form && answered ? answered.get(read.form.custom_id) : null;
|
|
3352
3814
|
const rtcFile = !mine && !m.file ? dkRtcFileFromText(peer.userId || peer.id, m.text) : null;
|
|
3353
3815
|
const callRec = !m.file ? dkCallFromText(m.text) : null;
|
|
3816
|
+
const mentionsMe = isGroup && !mine && !m.file && typeof m.text === "string" && messageMentionsMe(m.text, mentionNames());
|
|
3354
3817
|
return /* @__PURE__ */ React.createElement(
|
|
3355
3818
|
"div",
|
|
3356
3819
|
{
|
|
3357
3820
|
onClick: selMode ? () => onToggleSel(m.id) : void 0,
|
|
3821
|
+
"data-mention": mentionsMe ? "1" : void 0,
|
|
3358
3822
|
style: {
|
|
3359
3823
|
display: "flex",
|
|
3360
3824
|
justifyContent: mine ? "flex-end" : "flex-start",
|
|
@@ -3363,8 +3827,10 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3363
3827
|
margin: "3px 0",
|
|
3364
3828
|
cursor: selMode ? "pointer" : "default",
|
|
3365
3829
|
borderRadius: 8,
|
|
3366
|
-
|
|
3367
|
-
|
|
3830
|
+
// A group message that @mentions me stands out (feedback#23).
|
|
3831
|
+
boxShadow: mentionsMe ? "inset 3px 0 0 var(--accent)" : void 0,
|
|
3832
|
+
background: selMode && selected ? "rgba(91,140,255,0.12)" : mentionsMe ? "color-mix(in oklab, var(--accent), transparent 88%)" : "transparent",
|
|
3833
|
+
padding: selMode ? "2px 4px" : mentionsMe ? "3px 4px 3px 8px" : 0
|
|
3368
3834
|
}
|
|
3369
3835
|
},
|
|
3370
3836
|
selMode && /* @__PURE__ */ React.createElement("div", { style: {
|
|
@@ -3976,6 +4442,48 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3976
4442
|
setSelMode(false);
|
|
3977
4443
|
};
|
|
3978
4444
|
const [draft, setDraft] = React.useState("");
|
|
4445
|
+
const inputRef = React.useRef(null);
|
|
4446
|
+
const [mq, setMq] = React.useState(null);
|
|
4447
|
+
const [mSel, setMSel] = React.useState(0);
|
|
4448
|
+
const [, bumpEns] = React.useState(0);
|
|
4449
|
+
const members = React.useMemo(() => isGroup ? memberCandidates(threadProp || [], { myUserId: mentionUserId(), myNames: mentionNames() }) : [], [isGroup, threadProp]);
|
|
4450
|
+
React.useEffect(() => {
|
|
4451
|
+
if (!mq)
|
|
4452
|
+
return void 0;
|
|
4453
|
+
let live = true;
|
|
4454
|
+
for (const mm of members) {
|
|
4455
|
+
if (mm.senderId && ensVerifier.peek(mm.senderId) === void 0) {
|
|
4456
|
+
ensVerifier.lookup(mm.senderId).then(() => {
|
|
4457
|
+
if (live)
|
|
4458
|
+
bumpEns((n) => n + 1);
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
return () => {
|
|
4463
|
+
live = false;
|
|
4464
|
+
};
|
|
4465
|
+
}, [!!mq, members]);
|
|
4466
|
+
const mCands = mq ? filterCandidates(members.map((mm) => ({ ...mm, insert: mentionInsertName(mm, mm.senderId ? ensVerifier.peek(mm.senderId) : null) })), mq.query).slice(0, 8) : [];
|
|
4467
|
+
const pickMention = (c) => {
|
|
4468
|
+
if (!mq || !c)
|
|
4469
|
+
return;
|
|
4470
|
+
const r = applyMention(draft, mq, c.insert);
|
|
4471
|
+
setDraft(r.value);
|
|
4472
|
+
setMq(null);
|
|
4473
|
+
requestAnimationFrame(() => {
|
|
4474
|
+
const el = inputRef.current;
|
|
4475
|
+
if (el) {
|
|
4476
|
+
el.focus();
|
|
4477
|
+
try {
|
|
4478
|
+
el.setSelectionRange(r.caret, r.caret);
|
|
4479
|
+
} catch (e) {
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
});
|
|
4483
|
+
};
|
|
4484
|
+
React.useEffect(() => {
|
|
4485
|
+
setMq(null);
|
|
4486
|
+
}, [peer.id]);
|
|
3979
4487
|
const [hist, setHist] = React.useState([]);
|
|
3980
4488
|
const histIdx = React.useRef(null);
|
|
3981
4489
|
const histStash = React.useRef("");
|
|
@@ -4262,15 +4770,84 @@ ${peer.address}`
|
|
|
4262
4770
|
e.target.value = "";
|
|
4263
4771
|
}
|
|
4264
4772
|
}
|
|
4265
|
-
), !peer.app && /* @__PURE__ */ React.createElement(Btn, { icon: "paperclip", title: T.sendFile, onClick: () => fileRef.current && fileRef.current.click() }), /* @__PURE__ */ React.createElement(
|
|
4773
|
+
), !peer.app && /* @__PURE__ */ React.createElement(Btn, { icon: "paperclip", title: T.sendFile, onClick: () => fileRef.current && fileRef.current.click() }), /* @__PURE__ */ React.createElement("div", { style: { position: "relative", flex: 1, minWidth: 0, display: "flex" } }, mq && mCands.length > 0 && /* @__PURE__ */ React.createElement("div", { "data-testid": "mention-picker", style: {
|
|
4774
|
+
position: "absolute",
|
|
4775
|
+
left: 0,
|
|
4776
|
+
bottom: 44,
|
|
4777
|
+
zIndex: 30,
|
|
4778
|
+
width: "min(320px, 100%)",
|
|
4779
|
+
maxHeight: 280,
|
|
4780
|
+
overflowY: "auto",
|
|
4781
|
+
background: "var(--panel-2)",
|
|
4782
|
+
border: "1px solid var(--line)",
|
|
4783
|
+
borderRadius: 10,
|
|
4784
|
+
boxShadow: "0 14px 40px rgba(0,0,0,0.35)",
|
|
4785
|
+
padding: 4
|
|
4786
|
+
} }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--ui)", fontSize: 10.5, color: "var(--faint)", padding: "4px 8px" } }, T && T.mentionPickerHint || "Mention someone who has written in this group"), mCands.map((c, i) => /* @__PURE__ */ React.createElement(
|
|
4787
|
+
"button",
|
|
4788
|
+
{
|
|
4789
|
+
key: c.key,
|
|
4790
|
+
onMouseDown: (e) => {
|
|
4791
|
+
e.preventDefault();
|
|
4792
|
+
pickMention(c);
|
|
4793
|
+
},
|
|
4794
|
+
onMouseEnter: () => setMSel(i),
|
|
4795
|
+
style: {
|
|
4796
|
+
display: "flex",
|
|
4797
|
+
alignItems: "center",
|
|
4798
|
+
gap: 8,
|
|
4799
|
+
width: "100%",
|
|
4800
|
+
textAlign: "left",
|
|
4801
|
+
padding: "6px 8px",
|
|
4802
|
+
borderRadius: 7,
|
|
4803
|
+
border: "none",
|
|
4804
|
+
cursor: "pointer",
|
|
4805
|
+
background: i === mSel ? "var(--chip)" : "transparent",
|
|
4806
|
+
color: "var(--text)",
|
|
4807
|
+
fontFamily: "var(--ui)",
|
|
4808
|
+
fontSize: 13
|
|
4809
|
+
}
|
|
4810
|
+
},
|
|
4811
|
+
/* @__PURE__ */ React.createElement(DkEnsAvatar, { userid: c.senderId, name: c.sender, fallbackSeed: c.senderId || c.sender, size: 22, radius: 6 }),
|
|
4812
|
+
/* @__PURE__ */ React.createElement("span", { style: { fontWeight: 600, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, "@", c.insert),
|
|
4813
|
+
c.insert !== c.sender && /* @__PURE__ */ React.createElement("span", { style: { fontSize: 11, color: "var(--faint)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, c.sender)
|
|
4814
|
+
))), /* @__PURE__ */ React.createElement(
|
|
4266
4815
|
"input",
|
|
4267
4816
|
{
|
|
4817
|
+
ref: inputRef,
|
|
4268
4818
|
value: draft,
|
|
4269
4819
|
onChange: (e) => {
|
|
4270
4820
|
histIdx.current = null;
|
|
4271
4821
|
setDraft(e.target.value);
|
|
4822
|
+
if (isGroup) {
|
|
4823
|
+
setMq(mentionQuery(e.target.value, e.target.selectionStart));
|
|
4824
|
+
setMSel(0);
|
|
4825
|
+
}
|
|
4272
4826
|
},
|
|
4827
|
+
onBlur: () => setTimeout(() => setMq(null), 120),
|
|
4273
4828
|
onKeyDown: (e) => {
|
|
4829
|
+
if (mq && mCands.length) {
|
|
4830
|
+
if (e.key === "ArrowDown") {
|
|
4831
|
+
e.preventDefault();
|
|
4832
|
+
setMSel((mSel + 1) % mCands.length);
|
|
4833
|
+
return;
|
|
4834
|
+
}
|
|
4835
|
+
if (e.key === "ArrowUp") {
|
|
4836
|
+
e.preventDefault();
|
|
4837
|
+
setMSel((mSel + mCands.length - 1) % mCands.length);
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
4841
|
+
e.preventDefault();
|
|
4842
|
+
pickMention(mCands[Math.min(mSel, mCands.length - 1)]);
|
|
4843
|
+
return;
|
|
4844
|
+
}
|
|
4845
|
+
if (e.key === "Escape") {
|
|
4846
|
+
e.preventDefault();
|
|
4847
|
+
setMq(null);
|
|
4848
|
+
return;
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4274
4851
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
4275
4852
|
e.preventDefault();
|
|
4276
4853
|
sendDraft();
|
|
@@ -4284,7 +4861,7 @@ ${peer.address}`
|
|
|
4284
4861
|
placeholder: phone ? `${T.message}\u2026` : `${T.message} ${verifiedLabel(peer.app ? null : peer.userId, peer.alias) || shortKey(peer.userId, 6, 4)}\u2026`,
|
|
4285
4862
|
style: { flex: 1, height: 38, borderRadius: 9, border: "1px solid var(--line)", background: "var(--panel-2)", color: "var(--text)", fontFamily: "var(--ui)", fontSize: 13.5, padding: "0 14px", outline: "none", minWidth: 0 }
|
|
4286
4863
|
}
|
|
4287
|
-
), /* @__PURE__ */ React.createElement(Btn, { tone: "solid", icon: "arrowUp", title: T.send, onClick: sendDraft }))),
|
|
4864
|
+
)), /* @__PURE__ */ React.createElement(Btn, { tone: "solid", icon: "arrowUp", title: T.send, onClick: sendDraft }))),
|
|
4288
4865
|
theater && /* @__PURE__ */ React.createElement("div", { onClick: () => setTheater(null), style: {
|
|
4289
4866
|
position: "absolute",
|
|
4290
4867
|
inset: 0,
|
|
@@ -7267,193 +7844,6 @@ ${peer.address}`
|
|
|
7267
7844
|
return /* @__PURE__ */ React.createElement("div", { style: { flex: 1, overflow: "auto", background: "var(--bg)" } }, /* @__PURE__ */ React.createElement("div", { className: "dk-page", style: { maxWidth: 1040, margin: "0 auto", padding: "24px 28px 60px", display: "flex", flexDirection: "column", gap: 26 } }, /* @__PURE__ */ React.createElement(MyNode, { T, me, activeExit, peers, reqCount }), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 12 } }, /* @__PURE__ */ React.createElement(Section, { label: T.peerRouting, count: peers.length }), /* @__PURE__ */ React.createElement(PeerTable, { T, peers, onOpenChat }), !peers.length && /* @__PURE__ */ React.createElement("div", { style: { padding: "14px 16px", borderRadius: 11, border: "1px dashed var(--line)", fontFamily: "var(--ui)", fontSize: 12.5, color: "var(--faint)" } }, T.noPeersYet || "No friends yet \u2014 add one from Chat and it shows up here with its route.")), lanless ? null : /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 12 } }, /* @__PURE__ */ React.createElement(Section, { label: T.exitNodes, trailing: /* @__PURE__ */ React.createElement("div", { style: { display: "flex", gap: 6 } }, ctl.refresh && onRefreshExits && /* @__PURE__ */ React.createElement(ReconnectBtn, { T, ip: null, onReconnect: () => onRefreshExits(), label: T.exitRefresh || "Refresh" }), ctl.reconnectAll && onReconnectExit && /* @__PURE__ */ React.createElement(ReconnectBtn, { T, ip: null, onReconnect: onReconnectExit, label: T.exitReconnectAll || "Reconnect all" }), /* @__PURE__ */ React.createElement(Btn, { icon: "plus", size: "sm" }, T.addExit)) }), ctl.noExitNotice && /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4, padding: "11px 14px", borderRadius: 10, background: "var(--panel-2)", border: "1px dashed var(--line)" } }, /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 12.5, fontWeight: 700, color: "var(--text)" } }, T.noExitAvailable || "No exit available \u2014 routing and proxy are off."), anyFailed && /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--ui)", fontSize: 12, color: "var(--dim)" } }, T.noExitHint || "Every exit failed 3 times and is no longer checked automatically. Press Reconnect to try one again.")), ctl.fallbackNotice && /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10, padding: "11px 14px", borderRadius: 10, background: "color-mix(in oklab, var(--warn), transparent 90%)", border: "1px solid color-mix(in oklab, var(--warn), transparent 70%)" } }, /* @__PURE__ */ React.createElement(Icon, { name: "route", size: 17, color: "var(--warn)", stroke: 2 }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 12.5, color: "var(--text)" } }, T.routeFellBack || "Routing fell back to direct: every exit it used failed. Reconnect one to route through it again.")), activeExit && /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10, padding: "11px 14px", borderRadius: 10, background: "color-mix(in oklab, var(--warn), transparent 90%)", border: "1px solid color-mix(in oklab, var(--warn), transparent 70%)" } }, /* @__PURE__ */ React.createElement(Icon, { name: "route", size: 17, color: "var(--warn)", stroke: 2 }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 12.5, color: "var(--text)" } }, T.egressVia), /* @__PURE__ */ React.createElement(Mono, { size: 13, copy: activeExit }, activeExit), /* @__PURE__ */ React.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React.createElement(Btn, { tone: "danger", icon: "unlink", size: "sm", onClick: () => onSetExit(null) }, T.stopRouting)), /* @__PURE__ */ React.createElement("div", { className: "dk-grid1", style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 } }, exits.map((r) => /* @__PURE__ */ React.createElement(ExitCard, { key: r.region, T, region: r, activeExit, onSetExit, onReconnect: ctl.reconnect ? onReconnectExit : null, featureOn }))))));
|
|
7268
7845
|
}
|
|
7269
7846
|
Object.assign(window, { NetworkTab });
|
|
7270
|
-
var dkAudioCtx = null;
|
|
7271
|
-
function dkAudio() {
|
|
7272
|
-
if (dkAudioCtx && dkAudioCtx.state !== "closed")
|
|
7273
|
-
return dkAudioCtx;
|
|
7274
|
-
try {
|
|
7275
|
-
dkAudioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
7276
|
-
} catch (e) {
|
|
7277
|
-
dkAudioCtx = null;
|
|
7278
|
-
}
|
|
7279
|
-
return dkAudioCtx;
|
|
7280
|
-
}
|
|
7281
|
-
function dkUnlockAudioOnGesture() {
|
|
7282
|
-
const unlock = () => {
|
|
7283
|
-
const c = dkAudio();
|
|
7284
|
-
if (c && c.state === "suspended")
|
|
7285
|
-
c.resume().catch(() => {
|
|
7286
|
-
});
|
|
7287
|
-
};
|
|
7288
|
-
window.addEventListener("pointerdown", unlock, { passive: true });
|
|
7289
|
-
window.addEventListener("keydown", unlock, { passive: true });
|
|
7290
|
-
return () => {
|
|
7291
|
-
window.removeEventListener("pointerdown", unlock);
|
|
7292
|
-
window.removeEventListener("keydown", unlock);
|
|
7293
|
-
};
|
|
7294
|
-
}
|
|
7295
|
-
function dkChime(kind) {
|
|
7296
|
-
const c = dkAudio();
|
|
7297
|
-
if (!c)
|
|
7298
|
-
return;
|
|
7299
|
-
if (c.state === "suspended")
|
|
7300
|
-
c.resume().catch(() => {
|
|
7301
|
-
});
|
|
7302
|
-
const notes = kind === "request" ? [[660, 0], [880, 0.14]] : [[880, 0], [1175, 0.11]];
|
|
7303
|
-
const t0 = c.currentTime;
|
|
7304
|
-
for (const [freq, at] of notes) {
|
|
7305
|
-
const o = c.createOscillator(), g = c.createGain();
|
|
7306
|
-
o.type = "sine";
|
|
7307
|
-
o.frequency.value = freq;
|
|
7308
|
-
o.connect(g);
|
|
7309
|
-
g.connect(c.destination);
|
|
7310
|
-
const t = t0 + at;
|
|
7311
|
-
g.gain.setValueAtTime(1e-4, t);
|
|
7312
|
-
g.gain.exponentialRampToValueAtTime(0.18, t + 0.015);
|
|
7313
|
-
g.gain.exponentialRampToValueAtTime(1e-4, t + 0.17);
|
|
7314
|
-
o.start(t);
|
|
7315
|
-
o.stop(t + 0.2);
|
|
7316
|
-
}
|
|
7317
|
-
}
|
|
7318
|
-
var dkFlash = { timer: null, title: "", link: null, href: null, badged: null, on: false, n: 0, label: "" };
|
|
7319
|
-
function dkBadgedIcon(href) {
|
|
7320
|
-
return new Promise((res, rej) => {
|
|
7321
|
-
const img = new Image();
|
|
7322
|
-
img.onload = () => {
|
|
7323
|
-
try {
|
|
7324
|
-
if (!img.naturalWidth)
|
|
7325
|
-
return rej(new Error("icon has no intrinsic size"));
|
|
7326
|
-
const s = 64, cv = document.createElement("canvas");
|
|
7327
|
-
cv.width = s;
|
|
7328
|
-
cv.height = s;
|
|
7329
|
-
const cx = cv.getContext("2d");
|
|
7330
|
-
cx.drawImage(img, 0, 0, s, s);
|
|
7331
|
-
cx.beginPath();
|
|
7332
|
-
cx.arc(s - 14, 14, 12, 0, Math.PI * 2);
|
|
7333
|
-
cx.fillStyle = "#e5484d";
|
|
7334
|
-
cx.fill();
|
|
7335
|
-
cx.lineWidth = 3;
|
|
7336
|
-
cx.strokeStyle = "#fff";
|
|
7337
|
-
cx.stroke();
|
|
7338
|
-
res(cv.toDataURL("image/png"));
|
|
7339
|
-
} catch (e) {
|
|
7340
|
-
rej(e);
|
|
7341
|
-
}
|
|
7342
|
-
};
|
|
7343
|
-
img.onerror = () => rej(new Error("icon failed to load"));
|
|
7344
|
-
img.src = href;
|
|
7345
|
-
});
|
|
7346
|
-
}
|
|
7347
|
-
function dkFlashTick() {
|
|
7348
|
-
dkFlash.on = !dkFlash.on;
|
|
7349
|
-
document.title = `(${dkFlash.n}) ${dkFlash.on ? dkFlash.label : dkFlash.title}`;
|
|
7350
|
-
}
|
|
7351
|
-
function dkFlashStart(label, count) {
|
|
7352
|
-
dkFlash.n += count || 1;
|
|
7353
|
-
dkFlash.label = label;
|
|
7354
|
-
if (dkFlash.timer)
|
|
7355
|
-
return;
|
|
7356
|
-
dkFlash.title = document.title;
|
|
7357
|
-
dkFlash.link = document.querySelector('link[rel~="icon"]');
|
|
7358
|
-
dkFlash.href = dkFlash.link ? dkFlash.link.href : null;
|
|
7359
|
-
dkFlash.badged = null;
|
|
7360
|
-
dkFlash.on = false;
|
|
7361
|
-
if (dkFlash.href) {
|
|
7362
|
-
dkBadgedIcon(dkFlash.href).then((b) => {
|
|
7363
|
-
dkFlash.badged = b;
|
|
7364
|
-
if (dkFlash.timer && dkFlash.link)
|
|
7365
|
-
dkFlash.link.href = b;
|
|
7366
|
-
}).catch(() => {
|
|
7367
|
-
});
|
|
7368
|
-
}
|
|
7369
|
-
dkFlashTick();
|
|
7370
|
-
dkFlash.timer = setInterval(dkFlashTick, 1e3);
|
|
7371
|
-
}
|
|
7372
|
-
function dkFlashStop() {
|
|
7373
|
-
if (!dkFlash.timer)
|
|
7374
|
-
return;
|
|
7375
|
-
clearInterval(dkFlash.timer);
|
|
7376
|
-
dkFlash.timer = null;
|
|
7377
|
-
dkFlash.n = 0;
|
|
7378
|
-
document.title = dkFlash.title;
|
|
7379
|
-
if (dkFlash.link && dkFlash.href)
|
|
7380
|
-
dkFlash.link.href = dkFlash.href;
|
|
7381
|
-
}
|
|
7382
|
-
function dkLooking() {
|
|
7383
|
-
return document.visibilityState === "visible" && document.hasFocus();
|
|
7384
|
-
}
|
|
7385
|
-
function useIncomingAlerts({ T, peers, requests, loaded, activeId, sound = true, flash = true, muted, isProtocol }) {
|
|
7386
|
-
const prev = React.useRef(null);
|
|
7387
|
-
const mutedRef = React.useRef(/* @__PURE__ */ new Set());
|
|
7388
|
-
mutedRef.current = new Set(muted || []);
|
|
7389
|
-
React.useEffect(() => dkUnlockAudioOnGesture(), []);
|
|
7390
|
-
React.useEffect(() => {
|
|
7391
|
-
if (!flash)
|
|
7392
|
-
dkFlashStop();
|
|
7393
|
-
}, [flash]);
|
|
7394
|
-
React.useEffect(() => {
|
|
7395
|
-
const seen = () => {
|
|
7396
|
-
if (dkLooking())
|
|
7397
|
-
dkFlashStop();
|
|
7398
|
-
};
|
|
7399
|
-
window.addEventListener("focus", seen);
|
|
7400
|
-
window.addEventListener("pointerdown", seen, { passive: true });
|
|
7401
|
-
document.addEventListener("visibilitychange", seen);
|
|
7402
|
-
return () => {
|
|
7403
|
-
window.removeEventListener("focus", seen);
|
|
7404
|
-
window.removeEventListener("pointerdown", seen);
|
|
7405
|
-
document.removeEventListener("visibilitychange", seen);
|
|
7406
|
-
dkFlashStop();
|
|
7407
|
-
};
|
|
7408
|
-
}, []);
|
|
7409
|
-
React.useEffect(() => {
|
|
7410
|
-
if (!loaded)
|
|
7411
|
-
return;
|
|
7412
|
-
const byId = /* @__PURE__ */ new Map();
|
|
7413
|
-
for (const p of peers || []) {
|
|
7414
|
-
if (p && p.app)
|
|
7415
|
-
continue;
|
|
7416
|
-
const dir = p.lastDir || (String(p.lastMsg || "").startsWith("you: ") ? "out" : "in");
|
|
7417
|
-
const quiet = typeof isProtocol === "function" && lastIsProtocol(p, isProtocol);
|
|
7418
|
-
byId.set(p.id, { ts: p.lastTs || 0, dir, quiet });
|
|
7419
|
-
}
|
|
7420
|
-
const reqIds = new Set((requests || []).map((r) => r.id));
|
|
7421
|
-
const was = prev.current;
|
|
7422
|
-
prev.current = { byId, reqIds };
|
|
7423
|
-
if (!was)
|
|
7424
|
-
return;
|
|
7425
|
-
let msgs = 0, elsewhere = 0, reqs = 0, loud = 0, loudElsewhere = 0;
|
|
7426
|
-
for (const [id, cur] of byId) {
|
|
7427
|
-
if (cur.dir !== "in" || !cur.ts)
|
|
7428
|
-
continue;
|
|
7429
|
-
if (cur.quiet)
|
|
7430
|
-
continue;
|
|
7431
|
-
const old = was.byId.get(id);
|
|
7432
|
-
if (old ? cur.ts <= old.ts : Date.now() - cur.ts > 3e4)
|
|
7433
|
-
continue;
|
|
7434
|
-
msgs += 1;
|
|
7435
|
-
if (id !== activeId)
|
|
7436
|
-
elsewhere += 1;
|
|
7437
|
-
if (!mutedRef.current.has(id)) {
|
|
7438
|
-
loud += 1;
|
|
7439
|
-
if (id !== activeId)
|
|
7440
|
-
loudElsewhere += 1;
|
|
7441
|
-
}
|
|
7442
|
-
}
|
|
7443
|
-
for (const id of reqIds)
|
|
7444
|
-
if (!was.reqIds.has(id))
|
|
7445
|
-
reqs += 1;
|
|
7446
|
-
if (!msgs && !reqs)
|
|
7447
|
-
return;
|
|
7448
|
-
const looking = dkLooking();
|
|
7449
|
-
if (sound && (reqs || loud) && !(looking && !reqs && !loudElsewhere))
|
|
7450
|
-
dkChime(reqs && !loud ? "request" : "message");
|
|
7451
|
-
if (flash && !looking) {
|
|
7452
|
-
const label = msgs ? T && T.alertMsg || "New message" : T && T.alertReq || "New friend request";
|
|
7453
|
-
dkFlashStart(label, msgs + reqs);
|
|
7454
|
-
}
|
|
7455
|
-
}, [peers, requests, loaded, activeId, T, sound, flash]);
|
|
7456
|
-
}
|
|
7457
7847
|
var TWEAKS_STORAGE_KEY = "decentlan.tweaks";
|
|
7458
7848
|
function useTweaks(defaults) {
|
|
7459
7849
|
const [values, setValues] = React.useState(() => {
|
|
@@ -7798,6 +8188,9 @@ ${peer.address}`
|
|
|
7798
8188
|
joinGroup: "Join group",
|
|
7799
8189
|
cardIsFriend: "Already in your chats.",
|
|
7800
8190
|
cardNoEns: "No beagles.eth name registered.",
|
|
8191
|
+
mentionYou: "[@ you]",
|
|
8192
|
+
mentionNotifyTitle: "{sender} mentioned you in {group}",
|
|
8193
|
+
mentionPickerHint: "Mention someone who has written in this group",
|
|
7801
8194
|
ensVerified: "Verified: this beagles.eth name is registered to this user.",
|
|
7802
8195
|
ensVerifiedReplaced: "Registered beagles.eth name for this user. Their device shows {claimed}, which is not registered to them.",
|
|
7803
8196
|
ensSelfClaimed: "self-claimed",
|
|
@@ -8032,6 +8425,9 @@ ${peer.address}`
|
|
|
8032
8425
|
joinGroup: "\u52A0\u5165\u7FA4",
|
|
8033
8426
|
cardIsFriend: "\u5DF2\u5728\u4F60\u7684\u4F1A\u8BDD\u91CC\u3002",
|
|
8034
8427
|
cardNoEns: "\u5BF9\u65B9\u8FD8\u6CA1\u6709\u6CE8\u518C beagles.eth \u540D\u5B57\u3002",
|
|
8428
|
+
mentionYou: "[\u6709\u4EBA@\u4F60]",
|
|
8429
|
+
mentionNotifyTitle: "{sender} \u5728 {group} \u4E2D@\u4E86\u4F60",
|
|
8430
|
+
mentionPickerHint: "@ \u5728\u8FD9\u4E2A\u7FA4\u91CC\u53D1\u8FC7\u8A00\u7684\u4EBA",
|
|
8035
8431
|
ensVerified: "\u5DF2\u9A8C\u8BC1:\u8FD9\u4E2A beagles.eth \u540D\u5B57\u6CE8\u518C\u5728\u6B64\u7528\u6237\u540D\u4E0B\u3002",
|
|
8036
8432
|
ensVerifiedReplaced: "\u6B64\u7528\u6237\u6CE8\u518C\u7684 beagles.eth \u540D\u5B57\u3002\u5BF9\u65B9\u8BBE\u5907\u663E\u793A\u7684\u662F {claimed},\u5B83\u5E76\u6CA1\u6709\u6CE8\u518C\u5728\u5BF9\u65B9\u540D\u4E0B\u3002",
|
|
8037
8433
|
ensSelfClaimed: "\u81EA\u79F0",
|
|
@@ -8366,6 +8762,7 @@ ${peer.address}`
|
|
|
8366
8762
|
muted: mutedIds,
|
|
8367
8763
|
isProtocol
|
|
8368
8764
|
});
|
|
8765
|
+
useGroupMentions({ T, me, peers, activeId, loaded: data.loaded, sound: t.alertSound !== false, muted: mutedIds });
|
|
8369
8766
|
const assistant = useAssistant({
|
|
8370
8767
|
lang: t.lang,
|
|
8371
8768
|
T,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/beagle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.148",
|
|
4
4
|
"description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"start": "node dist/cli.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@decentnetwork/beagle-ui": "^0.2.
|
|
29
|
+
"@decentnetwork/beagle-ui": "^0.2.50",
|
|
30
30
|
"@decentnetwork/chat-components": "^0.1.3",
|
|
31
31
|
"@decentnetwork/lan": "^0.1.316",
|
|
32
32
|
"@decentnetwork/peer": "^0.1.178",
|