@decentnetwork/beagle 0.1.146 → 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 +602 -203
- 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
|
|
@@ -504,7 +504,7 @@ window.__DK_UI_VERSION="0.1.146";
|
|
|
504
504
|
return "[" + word + "] " + media.name;
|
|
505
505
|
}
|
|
506
506
|
var SENT_TIME_MIN_EARLY_MS = 2 * 6e4;
|
|
507
|
-
var
|
|
507
|
+
var UTC_MARKER_CUTOFF_MS = Date.UTC(2026, 10, 24, 20, 31, 0);
|
|
508
508
|
function parseMarkerUtc(s) {
|
|
509
509
|
const m = /^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{2}):(\d{2})$/.exec(String(s || "").trim());
|
|
510
510
|
if (!m)
|
|
@@ -522,18 +522,18 @@ window.__DK_UI_VERSION="0.1.146";
|
|
|
522
522
|
return Math.floor(n);
|
|
523
523
|
return Math.floor(n * 1e3);
|
|
524
524
|
}
|
|
525
|
-
function pickSentTime(arrivalMs, sentMs,
|
|
525
|
+
function pickSentTime(arrivalMs, sentMs, notBeforeMs = -Infinity) {
|
|
526
526
|
if (!arrivalMs || sentMs == null)
|
|
527
527
|
return arrivalMs;
|
|
528
|
+
if (sentMs < notBeforeMs)
|
|
529
|
+
return arrivalMs;
|
|
528
530
|
const early = arrivalMs - sentMs;
|
|
529
531
|
if (early < SENT_TIME_MIN_EARLY_MS)
|
|
530
532
|
return arrivalMs;
|
|
531
|
-
if (early > maxEarlyMs)
|
|
532
|
-
return arrivalMs;
|
|
533
533
|
return sentMs;
|
|
534
534
|
}
|
|
535
535
|
function groupSentTime(row) {
|
|
536
|
-
var _a, _b, _c
|
|
536
|
+
var _a, _b, _c;
|
|
537
537
|
const arrival = row && row.ts;
|
|
538
538
|
if (!row || row.dir === "out" || !arrival)
|
|
539
539
|
return { ts: arrival, key: null };
|
|
@@ -547,19 +547,21 @@ window.__DK_UI_VERSION="0.1.146";
|
|
|
547
547
|
}
|
|
548
548
|
const msg = j && j.message;
|
|
549
549
|
if (msg && typeof msg === "object") {
|
|
550
|
-
const
|
|
550
|
+
const meta = (_a = msg.file && msg.file.sent_at_ms) != null ? _a : msg.sent_at_ms;
|
|
551
|
+
const raw = meta != null ? meta : msg.timestamp;
|
|
551
552
|
const sent2 = epochMs(raw);
|
|
552
553
|
const origin = j.origin && (j.origin.userid || j.origin.friendid || j.origin.nickname) || "";
|
|
553
554
|
const body = typeof msg.text === "string" ? msg.text : msg.file ? JSON.stringify(msg.file) : "";
|
|
554
|
-
|
|
555
|
+
const ts = pickSentTime(arrival, sent2, meta != null ? UTC_MARKER_CUTOFF_MS : -Infinity);
|
|
556
|
+
return { ts, key: sent2 != null ? `cgp1|${origin}|${raw}|${body}` : null };
|
|
555
557
|
}
|
|
556
558
|
}
|
|
557
559
|
if (row.file) {
|
|
558
|
-
const raw = (
|
|
560
|
+
const raw = (_c = (_b = row.sent_at_ms) != null ? _b : row.file.sent_at_ms) != null ? _c : row.origin && row.origin.sent_at_ms;
|
|
559
561
|
const sent2 = epochMs(raw);
|
|
560
562
|
if (sent2 != null) {
|
|
561
563
|
const who = row.origin && (row.origin.userid || row.origin.nickname) || "";
|
|
562
|
-
return { ts: pickSentTime(arrival, sent2), key: `file|${who}|${raw}|${row.file.name}|${row.file.size}` };
|
|
564
|
+
return { ts: pickSentTime(arrival, sent2, UTC_MARKER_CUTOFF_MS), key: `file|${who}|${raw}|${row.file.name}|${row.file.size}` };
|
|
563
565
|
}
|
|
564
566
|
return { ts: arrival, key: null };
|
|
565
567
|
}
|
|
@@ -567,7 +569,7 @@ window.__DK_UI_VERSION="0.1.146";
|
|
|
567
569
|
const sent = marker ? parseMarkerUtc(marker) : null;
|
|
568
570
|
if (sent == null)
|
|
569
571
|
return { ts: arrival, key: null };
|
|
570
|
-
return { ts: pickSentTime(arrival, sent,
|
|
572
|
+
return { ts: pickSentTime(arrival, sent, UTC_MARKER_CUTOFF_MS), key: `relay|${text}` };
|
|
571
573
|
}
|
|
572
574
|
function datedThread(rows) {
|
|
573
575
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -2434,6 +2436,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2434
2436
|
return { lookup, peek };
|
|
2435
2437
|
}
|
|
2436
2438
|
var verifier = createEnsVerifier();
|
|
2439
|
+
var ensVerifier = verifier;
|
|
2437
2440
|
function useEnsRecord(userid) {
|
|
2438
2441
|
const [rec, setRec] = React.useState(() => verifier.peek(userid));
|
|
2439
2442
|
React.useEffect(() => {
|
|
@@ -2483,6 +2486,466 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2483
2486
|
const v = useEnsVerdict(userid, name);
|
|
2484
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 }));
|
|
2485
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
|
+
}
|
|
2486
2949
|
var DK_CMD_HIST_KEY = "beagle.assistant.history";
|
|
2487
2950
|
var DK_CMD_HIST_MAX = 50;
|
|
2488
2951
|
function RequestsBlock({ T, requests, onAct }) {
|
|
@@ -2642,6 +3105,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2642
3105
|
function PeerRow({ peer, T, active, onClick, muted, isProtocol, fix }) {
|
|
2643
3106
|
const name = peer.alias || peer.userId;
|
|
2644
3107
|
const row = rosterRow(peer, isProtocol || (() => false), fix);
|
|
3108
|
+
const mentioned = useMentionFlags().has(peer.id);
|
|
2645
3109
|
return /* @__PURE__ */ React.createElement("button", { onClick, style: {
|
|
2646
3110
|
display: "flex",
|
|
2647
3111
|
alignItems: "center",
|
|
@@ -2670,7 +3134,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2670
3134
|
textOverflow: "ellipsis",
|
|
2671
3135
|
flex: 1,
|
|
2672
3136
|
minWidth: 0
|
|
2673
|
-
} }, 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 })));
|
|
2674
3138
|
}
|
|
2675
3139
|
function dkActivityTs(p, isProtocol, fix) {
|
|
2676
3140
|
const row = rosterRow(p, isProtocol || (() => false), fix);
|
|
@@ -3349,10 +3813,12 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3349
3813
|
const submitted = read.form && answered ? answered.get(read.form.custom_id) : null;
|
|
3350
3814
|
const rtcFile = !mine && !m.file ? dkRtcFileFromText(peer.userId || peer.id, m.text) : null;
|
|
3351
3815
|
const callRec = !m.file ? dkCallFromText(m.text) : null;
|
|
3816
|
+
const mentionsMe = isGroup && !mine && !m.file && typeof m.text === "string" && messageMentionsMe(m.text, mentionNames());
|
|
3352
3817
|
return /* @__PURE__ */ React.createElement(
|
|
3353
3818
|
"div",
|
|
3354
3819
|
{
|
|
3355
3820
|
onClick: selMode ? () => onToggleSel(m.id) : void 0,
|
|
3821
|
+
"data-mention": mentionsMe ? "1" : void 0,
|
|
3356
3822
|
style: {
|
|
3357
3823
|
display: "flex",
|
|
3358
3824
|
justifyContent: mine ? "flex-end" : "flex-start",
|
|
@@ -3361,8 +3827,10 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3361
3827
|
margin: "3px 0",
|
|
3362
3828
|
cursor: selMode ? "pointer" : "default",
|
|
3363
3829
|
borderRadius: 8,
|
|
3364
|
-
|
|
3365
|
-
|
|
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
|
|
3366
3834
|
}
|
|
3367
3835
|
},
|
|
3368
3836
|
selMode && /* @__PURE__ */ React.createElement("div", { style: {
|
|
@@ -3974,6 +4442,48 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3974
4442
|
setSelMode(false);
|
|
3975
4443
|
};
|
|
3976
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]);
|
|
3977
4487
|
const [hist, setHist] = React.useState([]);
|
|
3978
4488
|
const histIdx = React.useRef(null);
|
|
3979
4489
|
const histStash = React.useRef("");
|
|
@@ -4260,15 +4770,84 @@ ${peer.address}`
|
|
|
4260
4770
|
e.target.value = "";
|
|
4261
4771
|
}
|
|
4262
4772
|
}
|
|
4263
|
-
), !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(
|
|
4264
4815
|
"input",
|
|
4265
4816
|
{
|
|
4817
|
+
ref: inputRef,
|
|
4266
4818
|
value: draft,
|
|
4267
4819
|
onChange: (e) => {
|
|
4268
4820
|
histIdx.current = null;
|
|
4269
4821
|
setDraft(e.target.value);
|
|
4822
|
+
if (isGroup) {
|
|
4823
|
+
setMq(mentionQuery(e.target.value, e.target.selectionStart));
|
|
4824
|
+
setMSel(0);
|
|
4825
|
+
}
|
|
4270
4826
|
},
|
|
4827
|
+
onBlur: () => setTimeout(() => setMq(null), 120),
|
|
4271
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
|
+
}
|
|
4272
4851
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
4273
4852
|
e.preventDefault();
|
|
4274
4853
|
sendDraft();
|
|
@@ -4282,7 +4861,7 @@ ${peer.address}`
|
|
|
4282
4861
|
placeholder: phone ? `${T.message}\u2026` : `${T.message} ${verifiedLabel(peer.app ? null : peer.userId, peer.alias) || shortKey(peer.userId, 6, 4)}\u2026`,
|
|
4283
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 }
|
|
4284
4863
|
}
|
|
4285
|
-
), /* @__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 }))),
|
|
4286
4865
|
theater && /* @__PURE__ */ React.createElement("div", { onClick: () => setTheater(null), style: {
|
|
4287
4866
|
position: "absolute",
|
|
4288
4867
|
inset: 0,
|
|
@@ -7265,193 +7844,6 @@ ${peer.address}`
|
|
|
7265
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 }))))));
|
|
7266
7845
|
}
|
|
7267
7846
|
Object.assign(window, { NetworkTab });
|
|
7268
|
-
var dkAudioCtx = null;
|
|
7269
|
-
function dkAudio() {
|
|
7270
|
-
if (dkAudioCtx && dkAudioCtx.state !== "closed")
|
|
7271
|
-
return dkAudioCtx;
|
|
7272
|
-
try {
|
|
7273
|
-
dkAudioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
7274
|
-
} catch (e) {
|
|
7275
|
-
dkAudioCtx = null;
|
|
7276
|
-
}
|
|
7277
|
-
return dkAudioCtx;
|
|
7278
|
-
}
|
|
7279
|
-
function dkUnlockAudioOnGesture() {
|
|
7280
|
-
const unlock = () => {
|
|
7281
|
-
const c = dkAudio();
|
|
7282
|
-
if (c && c.state === "suspended")
|
|
7283
|
-
c.resume().catch(() => {
|
|
7284
|
-
});
|
|
7285
|
-
};
|
|
7286
|
-
window.addEventListener("pointerdown", unlock, { passive: true });
|
|
7287
|
-
window.addEventListener("keydown", unlock, { passive: true });
|
|
7288
|
-
return () => {
|
|
7289
|
-
window.removeEventListener("pointerdown", unlock);
|
|
7290
|
-
window.removeEventListener("keydown", unlock);
|
|
7291
|
-
};
|
|
7292
|
-
}
|
|
7293
|
-
function dkChime(kind) {
|
|
7294
|
-
const c = dkAudio();
|
|
7295
|
-
if (!c)
|
|
7296
|
-
return;
|
|
7297
|
-
if (c.state === "suspended")
|
|
7298
|
-
c.resume().catch(() => {
|
|
7299
|
-
});
|
|
7300
|
-
const notes = kind === "request" ? [[660, 0], [880, 0.14]] : [[880, 0], [1175, 0.11]];
|
|
7301
|
-
const t0 = c.currentTime;
|
|
7302
|
-
for (const [freq, at] of notes) {
|
|
7303
|
-
const o = c.createOscillator(), g = c.createGain();
|
|
7304
|
-
o.type = "sine";
|
|
7305
|
-
o.frequency.value = freq;
|
|
7306
|
-
o.connect(g);
|
|
7307
|
-
g.connect(c.destination);
|
|
7308
|
-
const t = t0 + at;
|
|
7309
|
-
g.gain.setValueAtTime(1e-4, t);
|
|
7310
|
-
g.gain.exponentialRampToValueAtTime(0.18, t + 0.015);
|
|
7311
|
-
g.gain.exponentialRampToValueAtTime(1e-4, t + 0.17);
|
|
7312
|
-
o.start(t);
|
|
7313
|
-
o.stop(t + 0.2);
|
|
7314
|
-
}
|
|
7315
|
-
}
|
|
7316
|
-
var dkFlash = { timer: null, title: "", link: null, href: null, badged: null, on: false, n: 0, label: "" };
|
|
7317
|
-
function dkBadgedIcon(href) {
|
|
7318
|
-
return new Promise((res, rej) => {
|
|
7319
|
-
const img = new Image();
|
|
7320
|
-
img.onload = () => {
|
|
7321
|
-
try {
|
|
7322
|
-
if (!img.naturalWidth)
|
|
7323
|
-
return rej(new Error("icon has no intrinsic size"));
|
|
7324
|
-
const s = 64, cv = document.createElement("canvas");
|
|
7325
|
-
cv.width = s;
|
|
7326
|
-
cv.height = s;
|
|
7327
|
-
const cx = cv.getContext("2d");
|
|
7328
|
-
cx.drawImage(img, 0, 0, s, s);
|
|
7329
|
-
cx.beginPath();
|
|
7330
|
-
cx.arc(s - 14, 14, 12, 0, Math.PI * 2);
|
|
7331
|
-
cx.fillStyle = "#e5484d";
|
|
7332
|
-
cx.fill();
|
|
7333
|
-
cx.lineWidth = 3;
|
|
7334
|
-
cx.strokeStyle = "#fff";
|
|
7335
|
-
cx.stroke();
|
|
7336
|
-
res(cv.toDataURL("image/png"));
|
|
7337
|
-
} catch (e) {
|
|
7338
|
-
rej(e);
|
|
7339
|
-
}
|
|
7340
|
-
};
|
|
7341
|
-
img.onerror = () => rej(new Error("icon failed to load"));
|
|
7342
|
-
img.src = href;
|
|
7343
|
-
});
|
|
7344
|
-
}
|
|
7345
|
-
function dkFlashTick() {
|
|
7346
|
-
dkFlash.on = !dkFlash.on;
|
|
7347
|
-
document.title = `(${dkFlash.n}) ${dkFlash.on ? dkFlash.label : dkFlash.title}`;
|
|
7348
|
-
}
|
|
7349
|
-
function dkFlashStart(label, count) {
|
|
7350
|
-
dkFlash.n += count || 1;
|
|
7351
|
-
dkFlash.label = label;
|
|
7352
|
-
if (dkFlash.timer)
|
|
7353
|
-
return;
|
|
7354
|
-
dkFlash.title = document.title;
|
|
7355
|
-
dkFlash.link = document.querySelector('link[rel~="icon"]');
|
|
7356
|
-
dkFlash.href = dkFlash.link ? dkFlash.link.href : null;
|
|
7357
|
-
dkFlash.badged = null;
|
|
7358
|
-
dkFlash.on = false;
|
|
7359
|
-
if (dkFlash.href) {
|
|
7360
|
-
dkBadgedIcon(dkFlash.href).then((b) => {
|
|
7361
|
-
dkFlash.badged = b;
|
|
7362
|
-
if (dkFlash.timer && dkFlash.link)
|
|
7363
|
-
dkFlash.link.href = b;
|
|
7364
|
-
}).catch(() => {
|
|
7365
|
-
});
|
|
7366
|
-
}
|
|
7367
|
-
dkFlashTick();
|
|
7368
|
-
dkFlash.timer = setInterval(dkFlashTick, 1e3);
|
|
7369
|
-
}
|
|
7370
|
-
function dkFlashStop() {
|
|
7371
|
-
if (!dkFlash.timer)
|
|
7372
|
-
return;
|
|
7373
|
-
clearInterval(dkFlash.timer);
|
|
7374
|
-
dkFlash.timer = null;
|
|
7375
|
-
dkFlash.n = 0;
|
|
7376
|
-
document.title = dkFlash.title;
|
|
7377
|
-
if (dkFlash.link && dkFlash.href)
|
|
7378
|
-
dkFlash.link.href = dkFlash.href;
|
|
7379
|
-
}
|
|
7380
|
-
function dkLooking() {
|
|
7381
|
-
return document.visibilityState === "visible" && document.hasFocus();
|
|
7382
|
-
}
|
|
7383
|
-
function useIncomingAlerts({ T, peers, requests, loaded, activeId, sound = true, flash = true, muted, isProtocol }) {
|
|
7384
|
-
const prev = React.useRef(null);
|
|
7385
|
-
const mutedRef = React.useRef(/* @__PURE__ */ new Set());
|
|
7386
|
-
mutedRef.current = new Set(muted || []);
|
|
7387
|
-
React.useEffect(() => dkUnlockAudioOnGesture(), []);
|
|
7388
|
-
React.useEffect(() => {
|
|
7389
|
-
if (!flash)
|
|
7390
|
-
dkFlashStop();
|
|
7391
|
-
}, [flash]);
|
|
7392
|
-
React.useEffect(() => {
|
|
7393
|
-
const seen = () => {
|
|
7394
|
-
if (dkLooking())
|
|
7395
|
-
dkFlashStop();
|
|
7396
|
-
};
|
|
7397
|
-
window.addEventListener("focus", seen);
|
|
7398
|
-
window.addEventListener("pointerdown", seen, { passive: true });
|
|
7399
|
-
document.addEventListener("visibilitychange", seen);
|
|
7400
|
-
return () => {
|
|
7401
|
-
window.removeEventListener("focus", seen);
|
|
7402
|
-
window.removeEventListener("pointerdown", seen);
|
|
7403
|
-
document.removeEventListener("visibilitychange", seen);
|
|
7404
|
-
dkFlashStop();
|
|
7405
|
-
};
|
|
7406
|
-
}, []);
|
|
7407
|
-
React.useEffect(() => {
|
|
7408
|
-
if (!loaded)
|
|
7409
|
-
return;
|
|
7410
|
-
const byId = /* @__PURE__ */ new Map();
|
|
7411
|
-
for (const p of peers || []) {
|
|
7412
|
-
if (p && p.app)
|
|
7413
|
-
continue;
|
|
7414
|
-
const dir = p.lastDir || (String(p.lastMsg || "").startsWith("you: ") ? "out" : "in");
|
|
7415
|
-
const quiet = typeof isProtocol === "function" && lastIsProtocol(p, isProtocol);
|
|
7416
|
-
byId.set(p.id, { ts: p.lastTs || 0, dir, quiet });
|
|
7417
|
-
}
|
|
7418
|
-
const reqIds = new Set((requests || []).map((r) => r.id));
|
|
7419
|
-
const was = prev.current;
|
|
7420
|
-
prev.current = { byId, reqIds };
|
|
7421
|
-
if (!was)
|
|
7422
|
-
return;
|
|
7423
|
-
let msgs = 0, elsewhere = 0, reqs = 0, loud = 0, loudElsewhere = 0;
|
|
7424
|
-
for (const [id, cur] of byId) {
|
|
7425
|
-
if (cur.dir !== "in" || !cur.ts)
|
|
7426
|
-
continue;
|
|
7427
|
-
if (cur.quiet)
|
|
7428
|
-
continue;
|
|
7429
|
-
const old = was.byId.get(id);
|
|
7430
|
-
if (old ? cur.ts <= old.ts : Date.now() - cur.ts > 3e4)
|
|
7431
|
-
continue;
|
|
7432
|
-
msgs += 1;
|
|
7433
|
-
if (id !== activeId)
|
|
7434
|
-
elsewhere += 1;
|
|
7435
|
-
if (!mutedRef.current.has(id)) {
|
|
7436
|
-
loud += 1;
|
|
7437
|
-
if (id !== activeId)
|
|
7438
|
-
loudElsewhere += 1;
|
|
7439
|
-
}
|
|
7440
|
-
}
|
|
7441
|
-
for (const id of reqIds)
|
|
7442
|
-
if (!was.reqIds.has(id))
|
|
7443
|
-
reqs += 1;
|
|
7444
|
-
if (!msgs && !reqs)
|
|
7445
|
-
return;
|
|
7446
|
-
const looking = dkLooking();
|
|
7447
|
-
if (sound && (reqs || loud) && !(looking && !reqs && !loudElsewhere))
|
|
7448
|
-
dkChime(reqs && !loud ? "request" : "message");
|
|
7449
|
-
if (flash && !looking) {
|
|
7450
|
-
const label = msgs ? T && T.alertMsg || "New message" : T && T.alertReq || "New friend request";
|
|
7451
|
-
dkFlashStart(label, msgs + reqs);
|
|
7452
|
-
}
|
|
7453
|
-
}, [peers, requests, loaded, activeId, T, sound, flash]);
|
|
7454
|
-
}
|
|
7455
7847
|
var TWEAKS_STORAGE_KEY = "decentlan.tweaks";
|
|
7456
7848
|
function useTweaks(defaults) {
|
|
7457
7849
|
const [values, setValues] = React.useState(() => {
|
|
@@ -7796,6 +8188,9 @@ ${peer.address}`
|
|
|
7796
8188
|
joinGroup: "Join group",
|
|
7797
8189
|
cardIsFriend: "Already in your chats.",
|
|
7798
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",
|
|
7799
8194
|
ensVerified: "Verified: this beagles.eth name is registered to this user.",
|
|
7800
8195
|
ensVerifiedReplaced: "Registered beagles.eth name for this user. Their device shows {claimed}, which is not registered to them.",
|
|
7801
8196
|
ensSelfClaimed: "self-claimed",
|
|
@@ -8030,6 +8425,9 @@ ${peer.address}`
|
|
|
8030
8425
|
joinGroup: "\u52A0\u5165\u7FA4",
|
|
8031
8426
|
cardIsFriend: "\u5DF2\u5728\u4F60\u7684\u4F1A\u8BDD\u91CC\u3002",
|
|
8032
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",
|
|
8033
8431
|
ensVerified: "\u5DF2\u9A8C\u8BC1:\u8FD9\u4E2A beagles.eth \u540D\u5B57\u6CE8\u518C\u5728\u6B64\u7528\u6237\u540D\u4E0B\u3002",
|
|
8034
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",
|
|
8035
8433
|
ensSelfClaimed: "\u81EA\u79F0",
|
|
@@ -8364,6 +8762,7 @@ ${peer.address}`
|
|
|
8364
8762
|
muted: mutedIds,
|
|
8365
8763
|
isProtocol
|
|
8366
8764
|
});
|
|
8765
|
+
useGroupMentions({ T, me, peers, activeId, loaded: data.loaded, sound: t.alertSound !== false, muted: mutedIds });
|
|
8367
8766
|
const assistant = useAssistant({
|
|
8368
8767
|
lang: t.lang,
|
|
8369
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",
|