@decentnetwork/beagle 0.1.13 → 0.1.14

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.
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.13";
1
+ window.__DK_UI_VERSION="0.1.14";
2
2
  const ICON_PATHS = {
3
3
  // ---- tab bar (the four must feel like one set) ----
4
4
  users: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
@@ -1553,13 +1553,85 @@ function dkSplitGroupSender(text) {
1553
1553
  const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
1554
1554
  return m ? { sender: m[1], body: m[2] } : null;
1555
1555
  }
1556
+ function dkParseCGP1(text) {
1557
+ const t = String(text || "").trim();
1558
+ if (!t.startsWith("CGP1 "))
1559
+ return null;
1560
+ let j = null;
1561
+ try {
1562
+ j = JSON.parse(t.slice(5));
1563
+ } catch (e) {
1564
+ return null;
1565
+ }
1566
+ if (!j || j.type !== "carrier_group_message" || j.chat_type !== "group")
1567
+ return null;
1568
+ const origin = j.origin || {};
1569
+ const senderId = origin.userid || origin.friendid || null;
1570
+ const sender = origin.nickname || origin.user_info && origin.user_info.name || (senderId ? senderId.slice(0, 10) : "member");
1571
+ const body = j.message && j.message.text || j.render && j.render.plain || "";
1572
+ return { sender, senderId, body: String(body), ts: null, strong: true };
1573
+ }
1556
1574
  function dkGroupParse(text) {
1575
+ const cgp = dkParseCGP1(text);
1576
+ if (cgp)
1577
+ return cgp;
1557
1578
  const t = String(text || "");
1558
1579
  const { body: noTs, ts } = dkStripGroupTs(t);
1559
1580
  const split = dkSplitGroupSender(noTs.trim());
1560
1581
  if (!split)
1561
1582
  return null;
1562
- return { sender: split.sender, body: split.body.trim(), ts, strong: !!ts };
1583
+ return { sender: split.sender, senderId: null, body: split.body.trim(), ts, strong: !!ts };
1584
+ }
1585
+ function DkGroupSender({ grp, T }) {
1586
+ const [open, setOpen] = React.useState(false);
1587
+ const [busy, setBusy] = React.useState(false);
1588
+ const [done, setDone] = React.useState(null);
1589
+ const seed = grp.senderId || grp.sender;
1590
+ const addFriend = () => {
1591
+ setBusy(true);
1592
+ fetch("/api/add", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ address: grp.senderId }) }).then((r) => r.json()).then((r) => setDone(r.ok ? T && T.addSent || "request sent" : r.error || "failed")).catch((e) => setDone(String(e && e.message || e))).finally(() => setBusy(false));
1593
+ };
1594
+ return /* @__PURE__ */ React.createElement("span", { style: { position: "relative", display: "inline-flex", alignItems: "center", gap: 5, margin: "0 3px 2px" } }, /* @__PURE__ */ React.createElement(
1595
+ "button",
1596
+ {
1597
+ onClick: () => setOpen((v) => !v),
1598
+ style: { display: "inline-flex", alignItems: "center", gap: 5, background: "none", border: "none", padding: 0, cursor: "pointer" }
1599
+ },
1600
+ /* @__PURE__ */ React.createElement(DkIdenticon, { seed, size: 16, radius: 4 }),
1601
+ /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--faint)" } }, grp.sender)
1602
+ ), open && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", { onClick: () => setOpen(false), style: { position: "fixed", inset: 0, zIndex: 40 } }), /* @__PURE__ */ React.createElement("span", { style: {
1603
+ position: "absolute",
1604
+ left: 0,
1605
+ top: 20,
1606
+ zIndex: 50,
1607
+ width: 240,
1608
+ padding: 12,
1609
+ borderRadius: 10,
1610
+ background: "var(--panel-2)",
1611
+ border: "1px solid var(--line)",
1612
+ boxShadow: "0 14px 40px rgba(0,0,0,0.4)",
1613
+ display: "flex",
1614
+ flexDirection: "column",
1615
+ gap: 8
1616
+ } }, /* @__PURE__ */ React.createElement("span", { style: { display: "flex", alignItems: "center", gap: 8 } }, /* @__PURE__ */ React.createElement(DkIdenticon, { seed, size: 34, radius: 8 }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 12.5, fontWeight: 700, color: "var(--text)", wordBreak: "break-all" } }, grp.sender)), grp.senderId ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Mono, { size: 10.5, dim: true, copy: grp.senderId, title: grp.senderId }, shortKey(grp.senderId, 12, 8)), /* @__PURE__ */ React.createElement(
1617
+ "button",
1618
+ {
1619
+ onClick: addFriend,
1620
+ disabled: busy || !!done,
1621
+ style: {
1622
+ padding: "6px 10px",
1623
+ borderRadius: 8,
1624
+ border: "none",
1625
+ background: "var(--accent)",
1626
+ color: "#fff",
1627
+ fontFamily: "var(--ui)",
1628
+ fontSize: 12,
1629
+ cursor: busy || done ? "default" : "pointer",
1630
+ opacity: busy ? 0.6 : 1
1631
+ }
1632
+ },
1633
+ done || (T && T.add || "Add friend")
1634
+ )) : /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--ui)", fontSize: 11.5, color: "var(--dim)", lineHeight: 1.45 } }, T && T.groupSenderUnknown || "The group relays only this display name. Register Beagle as a group agent (/agent add <beagle address> in the group) to receive full member identities you can add as friends."))));
1563
1635
  }
1564
1636
  function dkThreadIsGroup(thread) {
1565
1637
  return (thread || []).some((m) => !m.day && m.dir !== "out" && !m.file && (dkGroupParse(m.text) || {}).strong);
@@ -2002,7 +2074,7 @@ function Msg({ m, peer, T, onTheater, onDelete, onCancel, onRetry, onReveal, onC
2002
2074
  )
2003
2075
  );
2004
2076
  })()
2005
- ) : nativeMedia ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4, maxWidth: "min(420px, 88%)" } }, nativeMedia.sender && /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--faint)" } }, nativeMedia.sender), nativeMedia.kind === "image" ? /* @__PURE__ */ React.createElement(
2077
+ ) : nativeMedia ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4, maxWidth: "min(420px, 88%)" } }, nativeMedia.sender && /* @__PURE__ */ React.createElement(DkGroupSender, { grp: { sender: nativeMedia.sender, senderId: null }, T }), nativeMedia.kind === "image" ? /* @__PURE__ */ React.createElement(
2006
2078
  "img",
2007
2079
  {
2008
2080
  src: nativeMedia.url,
@@ -2017,7 +2089,7 @@ function Msg({ m, peer, T, onTheater, onDelete, onCancel, onRetry, onReveal, onC
2017
2089
  }
2018
2090
  }
2019
2091
  }
2020
- ) : nativeMedia.kind === "audio" ? /* @__PURE__ */ React.createElement("audio", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%" } }) : /* @__PURE__ */ React.createElement("video", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%", borderRadius: 12, border: "1px solid var(--line)" } })) : /* @__PURE__ */ React.createElement(React.Fragment, null, grp && /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--faint)", margin: "0 3px 2px" } }, grp.sender), /* @__PURE__ */ React.createElement("div", { style: {
2092
+ ) : nativeMedia.kind === "audio" ? /* @__PURE__ */ React.createElement("audio", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%" } }) : /* @__PURE__ */ React.createElement("video", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%", borderRadius: 12, border: "1px solid var(--line)" } })) : /* @__PURE__ */ React.createElement(React.Fragment, null, grp && /* @__PURE__ */ React.createElement(DkGroupSender, { grp, T }), /* @__PURE__ */ React.createElement("div", { style: {
2021
2093
  padding: "8px 12px",
2022
2094
  borderRadius: 12,
2023
2095
  borderBottomRightRadius: mine ? 4 : 12,
@@ -3582,6 +3654,7 @@ const STR = {
3582
3654
  open: "open",
3583
3655
  retry: "Retry",
3584
3656
  cancel: "Cancel",
3657
+ groupSenderUnknown: "The group relays only this display name. Register Beagle as a group agent (/agent add <beagle address> in the group) to receive full member identities you can add as friends.",
3585
3658
  pendingFriend: "Waiting for them to accept your friend request \u2014 messages will queue and deliver once they do.",
3586
3659
  cancelling: "Cancelling\u2026",
3587
3660
  cancelled: "Transfer cancelled",
@@ -3679,6 +3752,7 @@ const STR = {
3679
3752
  open: "\u6253\u5F00",
3680
3753
  retry: "\u91CD\u8BD5",
3681
3754
  cancel: "\u53D6\u6D88",
3755
+ groupSenderUnknown: "\u7FA4\u670D\u52A1\u53EA\u8F6C\u53D1\u4E86\u663E\u793A\u540D\uFF0C\u62FF\u4E0D\u5230\u8BE5\u6210\u5458\u7684\u5B8C\u6574\u8EAB\u4EFD\u3002\u5728\u7FA4\u91CC\u6267\u884C /agent add <beagle \u5730\u5740> \u628A Beagle \u6CE8\u518C\u4E3A\u7FA4 agent \u540E\uFF0C\u5373\u53EF\u6536\u5230\u5B8C\u6574\u8EAB\u4EFD\u5E76\u4E00\u952E\u52A0\u597D\u53CB\u3002",
3682
3756
  pendingFriend: "\u7B49\u5F85\u5BF9\u65B9\u63A5\u53D7\u597D\u53CB\u8BF7\u6C42 \u2014 \u6D88\u606F\u4F1A\u5148\u6392\u961F\uFF0C\u5BF9\u65B9\u63A5\u53D7\u540E\u81EA\u52A8\u9001\u8FBE\u3002",
3683
3757
  cancelling: "\u6B63\u5728\u53D6\u6D88\u2026",
3684
3758
  cancelled: "\u5DF2\u53D6\u6D88\u4F20\u8F93",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
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",