@celljs/ta-rooms 4.13.1 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/web/index.js +58 -17
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@celljs/ta-rooms",
3
- "version": "4.13.1",
3
+ "version": "4.14.0",
4
4
  "description": "A pi package for Ta: rooms shared with other Ta through the relay, end to end: who asks to join and the owner's answer, your rooms and their members, your Ta friends, and links that invite",
5
5
  "keywords": [
6
6
  "pi-package"
7
7
  ],
8
- "homepage": "https://github.com/cellbang/cell",
8
+ "homepage": "https://github.com/cellbang/ta",
9
9
  "bugs": {
10
- "url": "https://github.com/cellbang/cell/issues"
10
+ "url": "https://github.com/cellbang/ta/issues"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -27,9 +27,9 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.13.1",
31
- "@celljs/ta-relay": "4.13.1",
32
- "@celljs/ta-web": "4.13.1",
30
+ "@celljs/ta-protocol": "4.14.0",
31
+ "@celljs/ta-relay": "4.14.0",
32
+ "@celljs/ta-web": "4.14.0",
33
33
  "@types/react": "^19.3.0"
34
34
  },
35
35
  "publishConfig": {
package/web/index.js CHANGED
@@ -119,9 +119,18 @@ var RelayIdentityUtil;
119
119
  }
120
120
  RelayIdentityUtil2.check = check;
121
121
  function publicOf(identity) {
122
- return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
122
+ return withLook({ id: identity.id, name: identity.name, sign: identity.sign, box: identity.box }, identity.look);
123
123
  }
124
124
  RelayIdentityUtil2.publicOf = publicOf;
125
+ function isLook(look) {
126
+ return typeof look === "string" && /^[a-z][a-z0-9-]{0,31}$/.test(look);
127
+ }
128
+ RelayIdentityUtil2.isLook = isLook;
129
+ function withLook(value, look) {
130
+ const { look: _, ...rest } = value;
131
+ return isLook(look) ? { ...rest, look } : rest;
132
+ }
133
+ RelayIdentityUtil2.withLook = withLook;
125
134
  async function sign(identity, text) {
126
135
  const key = await subtle().importKey("jwk", identity.signKey, SIGN, false, ["sign"]);
127
136
  return RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
@@ -346,6 +355,7 @@ var RelayFriendsUtil;
346
355
  return {
347
356
  id: friend.id,
348
357
  name: String((_a = friend.name) !== null && _a !== undefined ? _a : "").slice(0, 40),
358
+ ...RelayIdentityUtil.isLook(friend.look) ? { look: friend.look } : {},
349
359
  ...typeof friend.sign === "string" ? { sign: friend.sign } : {},
350
360
  ...typeof friend.box === "string" ? { box: friend.box } : {},
351
361
  metAt: friend.metAt,
@@ -368,7 +378,14 @@ var RelayFriendsUtil;
368
378
  }
369
379
  RelayFriendsUtil2.mergeFriend = mergeFriend;
370
380
  function requestOf(offer) {
371
- return { id: offer.id, name: offer.name, at: offer.at, via: "room", room: offer.room };
381
+ return {
382
+ id: offer.id,
383
+ name: offer.name,
384
+ ...RelayIdentityUtil.isLook(offer.look) ? { look: offer.look } : {},
385
+ at: offer.at,
386
+ via: "room",
387
+ room: offer.room
388
+ };
372
389
  }
373
390
  RelayFriendsUtil2.requestOf = requestOf;
374
391
  function book(value) {
@@ -1155,6 +1172,31 @@ class RoomBook {
1155
1172
  }
1156
1173
  }
1157
1174
  var book = new RoomBook;
1175
+ var RoomLooks;
1176
+ ((RoomLooks) => {
1177
+ const known = new WeakMap;
1178
+ function of(state) {
1179
+ let looks = known.get(state);
1180
+ if (!looks) {
1181
+ looks = new Map;
1182
+ for (const each of [...state.requests, ...state.friendRequests, ...state.friends ?? [], ...(state.rooms ?? []).flatMap((room) => room.members)]) {
1183
+ if (each.look) {
1184
+ looks.set(each.id, each.look);
1185
+ }
1186
+ }
1187
+ known.set(state, looks);
1188
+ }
1189
+ return looks;
1190
+ }
1191
+ RoomLooks.of = of;
1192
+ function faceOf(state, id) {
1193
+ return id === state.identity?.id ? { double: true } : { look: of(state).get(id) };
1194
+ }
1195
+ RoomLooks.faceOf = faceOf;
1196
+ })(RoomLooks ||= {});
1197
+ function useBookState() {
1198
+ return React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get());
1199
+ }
1158
1200
  function useBook() {
1159
1201
  const state = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get());
1160
1202
  React.useEffect(() => {
@@ -1264,12 +1306,14 @@ function initial(name) {
1264
1306
  return Array.from(name.trim())[0]?.toUpperCase() ?? "?";
1265
1307
  }
1266
1308
  function Face({ id, name, size = 34, online, face }) {
1309
+ const state = useBookState();
1267
1310
  if (pi.ui.Face) {
1268
1311
  return /* @__PURE__ */ React.createElement(pi.ui.Face, {
1269
1312
  seed: id,
1270
1313
  face,
1271
1314
  size,
1272
- online
1315
+ online,
1316
+ ...RoomLooks.faceOf(state, id)
1273
1317
  });
1274
1318
  }
1275
1319
  const n = tint(id);
@@ -1290,12 +1334,13 @@ function RoomFace({ room, size = 40, unread }) {
1290
1334
  const page = usePageOf(room);
1291
1335
  const Mark = page?.icon;
1292
1336
  const members = faceMembers(room, useAgents(room));
1337
+ const state = useBookState();
1293
1338
  return /* @__PURE__ */ React.createElement("span", {
1294
1339
  className: "trm-room-face",
1295
1340
  style: { width: size, height: size },
1296
1341
  "aria-hidden": "true"
1297
1342
  }, pi.ui.GroupFace ? /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
1298
- members: members.map((member) => ({ seed: member.id, face: member.face })),
1343
+ members: members.map((member) => ({ seed: member.id, face: member.face, ...RoomLooks.faceOf(state, member.id) })),
1299
1344
  size
1300
1345
  }) : /* @__PURE__ */ React.createElement(Face, {
1301
1346
  id: members[0]?.id ?? room.id,
@@ -2649,23 +2694,20 @@ function FriendsPage() {
2649
2694
  }, friendRequests.map((request) => /* @__PURE__ */ React.createElement(FriendRequestRow, {
2650
2695
  key: request.id,
2651
2696
  request
2652
- })))), /* @__PURE__ */ React.createElement("section", {
2653
- className: "trm-section"
2654
- }, !!friends?.length && /* @__PURE__ */ React.createElement("h3", null, `${t("friends")} · ${friends.length}`), friends === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
2655
- rows: 3
2656
- }) : null : friends.length === 0 ? /* @__PURE__ */ React.createElement("div", {
2657
- className: "trm-friends-empty"
2658
- }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
2659
- compact: true,
2697
+ })))), friends?.length === 0 ? /* @__PURE__ */ React.createElement(pi.ui.Empty, {
2660
2698
  title: t("friendsEmpty"),
2661
2699
  hint: t("friendsEmptyHint")
2662
- }), /* @__PURE__ */ React.createElement("button", {
2700
+ }, /* @__PURE__ */ React.createElement("button", {
2663
2701
  type: "button",
2664
2702
  className: "ta-button ta-primary",
2665
2703
  onClick: openAddFriend
2666
2704
  }, /* @__PURE__ */ React.createElement(Add, {
2667
2705
  size: 14
2668
- }), " ", t("addFriend"))) : /* @__PURE__ */ React.createElement("ul", {
2706
+ }), " ", t("addFriend"))) : /* @__PURE__ */ React.createElement("section", {
2707
+ className: "trm-section"
2708
+ }, !!friends?.length && /* @__PURE__ */ React.createElement("h3", null, `${t("friends")} · ${friends.length}`), friends === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
2709
+ rows: 3
2710
+ }) : null : /* @__PURE__ */ React.createElement("ul", {
2669
2711
  className: "trm-rooms"
2670
2712
  }, friends.map((friend) => /* @__PURE__ */ React.createElement(FriendRow, {
2671
2713
  key: friend.id,
@@ -2705,7 +2747,7 @@ function FriendsEntry() {
2705
2747
  }), /* @__PURE__ */ React.createElement("span", {
2706
2748
  className: "trm-grow"
2707
2749
  }), list.length > 0 && pi.ui.GroupFace && /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
2708
- members: list.slice(0, 4).map((friend) => ({ seed: friend.id })),
2750
+ members: list.slice(0, 4).map((friend) => ({ seed: friend.id, look: friend.look })),
2709
2751
  size: 24
2710
2752
  }), /* @__PURE__ */ React.createElement("span", {
2711
2753
  className: "trm-quiet"
@@ -3866,13 +3908,12 @@ button.trm-member { cursor: pointer; }
3866
3908
  .trm-center { justify-content: center; }
3867
3909
  .trm-join { display: flex; align-items: center; gap: 12px; }
3868
3910
  .trm-friends-page { max-width: 720px; margin: 0 auto; width: 100%; overflow-y: auto; height: 100%; }
3869
- .trm-friends-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0 20px; }
3870
3911
  .trm-friends-other { gap: 18px; padding-top: 4px; }
3871
3912
  .trm-friends-entry { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--ta-surface, transparent); color: inherit; font: inherit; cursor: pointer; text-align: left; }
3872
3913
  @media (hover: hover) { .trm-friends-entry:hover { background: var(--ta-hover); } }
3873
3914
  .trm-friends-entry-label { font-weight: 500; }
3874
3915
  .trm-grow { flex: 1; }
3875
- .trm-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ta-amber, #f5a524); }
3916
+ .trm-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ta-yellow); }
3876
3917
  .trm-join-name { font-size: calc(15px * var(--ta-font-scale)); }
3877
3918
  .trm-dialog .trm-join:has(.trm-join-name) { flex-direction: column; text-align: center; gap: 8px; }
3878
3919
  .trm-member-friend { color: var(--ta-muted); }