@palbase/web 1.6.2 → 1.7.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.
package/dist/index.cjs CHANGED
@@ -1900,6 +1900,10 @@ var MessagingPaths = {
1900
1900
  groupMessages: (displayId) => `${GROUPS}/${seg(displayId)}/messages`,
1901
1901
  groupCommits: (displayId) => `${GROUPS}/${seg(displayId)}/commits`,
1902
1902
  groupRead: (displayId) => `${GROUPS}/${seg(displayId)}/read`,
1903
+ // Server-metadata cluster: the per-(user,group) notify scope (mute toggle, GET/PUT)
1904
+ // + the caller's own unread view (GET). {gid} is the grp_ display_id (M3 #7).
1905
+ groupNotify: (displayId) => `${GROUPS}/${seg(displayId)}/notify`,
1906
+ groupUnread: (displayId) => `${GROUPS}/${seg(displayId)}/unread`,
1903
1907
  deviceWelcomes: (deviceId) => `${DEVICES}/${seg(deviceId)}/welcomes`,
1904
1908
  deviceQueue: (deviceId) => `${DEVICES}/${seg(deviceId)}/queue`,
1905
1909
  deviceQueueAck: (deviceId) => `${DEVICES}/${seg(deviceId)}/queue/ack`,
@@ -3478,6 +3482,18 @@ var Chat = class {
3478
3482
  lastSeenAt: ts ? new Date(ts * 1e3) : null
3479
3483
  });
3480
3484
  this.emit();
3485
+ } else if (event === "delivered" || event === "read") {
3486
+ const seq = typeof payload.up_to_server_seq === "number" ? payload.up_to_server_seq : null;
3487
+ if (seq === null) return;
3488
+ let changed = false;
3489
+ this.messageList = this.messageList.map((m) => {
3490
+ if (m.direction !== "outgoing" || m.serverSeq > seq) return m;
3491
+ const cur = event === "delivered" ? m.deliveredUpTo ?? -1 : m.readUpTo ?? -1;
3492
+ if (seq <= cur) return m;
3493
+ changed = true;
3494
+ return event === "delivered" ? { ...m, deliveredUpTo: seq } : { ...m, readUpTo: seq };
3495
+ });
3496
+ if (changed) this.emit();
3481
3497
  }
3482
3498
  }
3483
3499
  kindOf(incoming) {
@@ -3726,6 +3742,31 @@ var Chat = class {
3726
3742
  this.readWatermark = Math.max(this.readWatermark, message.serverSeq);
3727
3743
  this.emit();
3728
3744
  }
3745
+ // ── Server-metadata cluster: notify scope (mute) + server unread ──
3746
+ /** Set this chat's notify scope (the mute toggle). `'none'` mutes the push wake;
3747
+ * `'all'` unmutes (the default). Materializes a draft first (the scope is a
3748
+ * per-(user,group) server row), PUTs `/notify`, and returns the server-echoed scope.
3749
+ * Mirrors iOS `Chat.setNotifyScope`. */
3750
+ async setNotifyScope(scope) {
3751
+ const group = await this.materializeIfNeeded();
3752
+ return this.backend.setNotifyScope(group, scope);
3753
+ }
3754
+ /** Refresh + return this chat's notify scope from the server (fail-OPEN to `'all'`).
3755
+ * Returns `'all'` for a draft chat (no server row yet). */
3756
+ async getNotifyScope() {
3757
+ if (!this._group) return "all";
3758
+ return this.backend.getNotifyScope(this._group);
3759
+ }
3760
+ /** Fetch the caller's authoritative SERVER unread count (opaque server metadata).
3761
+ * Returns the clamped count (`max(0, …)`); `0` for a draft chat. The local computed
3762
+ * `unreadCount` getter stays the instant, offline best-effort badge — this is the
3763
+ * canonical count on demand. Named distinctly so it does not shadow the observable
3764
+ * `unreadCount` snapshot getter. Mirrors iOS `Chat.refreshUnread`. */
3765
+ async unreadCountFromServer() {
3766
+ if (!this._group) return 0;
3767
+ const v = await this.backend.unread(this._group);
3768
+ return Math.max(0, v.unreadCount);
3769
+ }
3729
3770
  // ── Reactions ──
3730
3771
  /** Add an emoji reaction to a message. No-op if the message isn't reactable
3731
3772
  * (empty clientMsgId — a legacy/system row). The reaction folds locally with
@@ -4164,7 +4205,7 @@ var MessageDeliverySource = class {
4164
4205
  if (this.observed.has(group.displayId)) return;
4165
4206
  try {
4166
4207
  const channel = this.rt.realtime.channel(`messaging:conv:${group.rfcGroupId}`);
4167
- const subs = ["presence", "typing", "read"].map(
4208
+ const subs = ["presence", "typing", "read", "delivered"].map(
4168
4209
  (ev) => channel.on(ev, (payload) => {
4169
4210
  this.hub.emitConv(group.displayId, { event: ev, payload });
4170
4211
  })
@@ -4204,6 +4245,40 @@ var MessageDeliverySource = class {
4204
4245
  body: { read_seq: upToServerSeq, read_epoch: group.currentEpoch, is_private: false }
4205
4246
  });
4206
4247
  }
4248
+ // ── Server-metadata cluster: notify scope (mute) + unread (HTTP) ──
4249
+ /** PUT `/v1/messaging/groups/{gid}/notify` — set the caller's per-(user,group) notify
4250
+ * scope (`'all'`|`'none'`). The server stores the opaque enum verbatim and stays blind.
4251
+ * Returns the server-echoed scope (fail-OPEN to `'all'` on an unknown value). */
4252
+ async setNotifyScope(group, scope) {
4253
+ const res = await palbeRequest(
4254
+ this.rt,
4255
+ "PUT",
4256
+ MessagingPaths.groupNotify(group.displayId),
4257
+ { body: { notify_scope: scope } }
4258
+ );
4259
+ return res.notify_scope === "none" ? "none" : "all";
4260
+ }
4261
+ /** GET `/v1/messaging/groups/{gid}/notify` — the caller's notify scope. An absent
4262
+ * server row / unknown value reads as `'all'` (fail-OPEN — never silently mutes). */
4263
+ async getNotifyScope(group) {
4264
+ const res = await palbeRequest(
4265
+ this.rt,
4266
+ "GET",
4267
+ MessagingPaths.groupNotify(group.displayId)
4268
+ );
4269
+ return res.notify_scope === "none" ? "none" : "all";
4270
+ }
4271
+ /** GET `/v1/messaging/groups/{gid}/unread` — the caller's OWN unread view (opaque
4272
+ * server metadata). Maps the snake_case wire → the camelCase `UnreadView`. */
4273
+ async unread(group) {
4274
+ const res = await palbeRequest(this.rt, "GET", MessagingPaths.groupUnread(group.displayId));
4275
+ return {
4276
+ groupMaxSeq: res.group_max_seq,
4277
+ lastReadSeq: res.last_read_seq,
4278
+ deliveredSeq: res.delivered_seq,
4279
+ unreadCount: res.unread_count
4280
+ };
4281
+ }
4207
4282
  };
4208
4283
  function isOwnEchoOrConsumed(e) {
4209
4284
  const msg = e instanceof Error ? e.message : String(e);
@@ -6361,6 +6436,19 @@ var MessagingCoordinator = class {
6361
6436
  const r = await this.resolve();
6362
6437
  await r.source.markRead(group, upToServerSeq);
6363
6438
  }
6439
+ // ── Server-metadata cluster: notify scope (mute) + unread ──
6440
+ async setNotifyScope(group, scope) {
6441
+ const r = await this.resolve();
6442
+ return r.source.setNotifyScope(group, scope);
6443
+ }
6444
+ async getNotifyScope(group) {
6445
+ const r = await this.resolve();
6446
+ return r.source.getNotifyScope(group);
6447
+ }
6448
+ async unread(group) {
6449
+ const r = await this.resolve();
6450
+ return r.source.unread(group);
6451
+ }
6364
6452
  subscribeLive(group, chat) {
6365
6453
  let offMsg = null;
6366
6454
  let offConv = null;
@@ -7419,7 +7507,7 @@ function localStorageSessionStorage(key = DEFAULT_KEY) {
7419
7507
  }
7420
7508
 
7421
7509
  // src/version.ts
7422
- var VERSION = "1.6.2";
7510
+ var VERSION = "1.7.0";
7423
7511
 
7424
7512
  // src/internal.ts
7425
7513
  function getRuntime() {