@palbase/web 1.6.1 → 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.
@@ -7,7 +7,7 @@ import {
7
7
  __configure,
8
8
  endpointRefFromApiKey,
9
9
  getRuntime
10
- } from "../chunk-EQAHM3ZJ.js";
10
+ } from "../chunk-QRO632M7.js";
11
11
 
12
12
  // src/next/client.ts
13
13
  var SESSION_MAX_AGE_S = 2592e3;
@@ -2921,6 +2921,10 @@ var MessagingPaths = {
2921
2921
  groupMessages: (displayId) => `${GROUPS}/${seg(displayId)}/messages`,
2922
2922
  groupCommits: (displayId) => `${GROUPS}/${seg(displayId)}/commits`,
2923
2923
  groupRead: (displayId) => `${GROUPS}/${seg(displayId)}/read`,
2924
+ // Server-metadata cluster: the per-(user,group) notify scope (mute toggle, GET/PUT)
2925
+ // + the caller's own unread view (GET). {gid} is the grp_ display_id (M3 #7).
2926
+ groupNotify: (displayId) => `${GROUPS}/${seg(displayId)}/notify`,
2927
+ groupUnread: (displayId) => `${GROUPS}/${seg(displayId)}/unread`,
2924
2928
  deviceWelcomes: (deviceId) => `${DEVICES}/${seg(deviceId)}/welcomes`,
2925
2929
  deviceQueue: (deviceId) => `${DEVICES}/${seg(deviceId)}/queue`,
2926
2930
  deviceQueueAck: (deviceId) => `${DEVICES}/${seg(deviceId)}/queue/ack`,
@@ -4499,6 +4503,18 @@ var Chat = class {
4499
4503
  lastSeenAt: ts ? new Date(ts * 1e3) : null
4500
4504
  });
4501
4505
  this.emit();
4506
+ } else if (event === "delivered" || event === "read") {
4507
+ const seq = typeof payload.up_to_server_seq === "number" ? payload.up_to_server_seq : null;
4508
+ if (seq === null) return;
4509
+ let changed = false;
4510
+ this.messageList = this.messageList.map((m) => {
4511
+ if (m.direction !== "outgoing" || m.serverSeq > seq) return m;
4512
+ const cur = event === "delivered" ? m.deliveredUpTo ?? -1 : m.readUpTo ?? -1;
4513
+ if (seq <= cur) return m;
4514
+ changed = true;
4515
+ return event === "delivered" ? { ...m, deliveredUpTo: seq } : { ...m, readUpTo: seq };
4516
+ });
4517
+ if (changed) this.emit();
4502
4518
  }
4503
4519
  }
4504
4520
  kindOf(incoming) {
@@ -4747,6 +4763,31 @@ var Chat = class {
4747
4763
  this.readWatermark = Math.max(this.readWatermark, message.serverSeq);
4748
4764
  this.emit();
4749
4765
  }
4766
+ // ── Server-metadata cluster: notify scope (mute) + server unread ──
4767
+ /** Set this chat's notify scope (the mute toggle). `'none'` mutes the push wake;
4768
+ * `'all'` unmutes (the default). Materializes a draft first (the scope is a
4769
+ * per-(user,group) server row), PUTs `/notify`, and returns the server-echoed scope.
4770
+ * Mirrors iOS `Chat.setNotifyScope`. */
4771
+ async setNotifyScope(scope) {
4772
+ const group = await this.materializeIfNeeded();
4773
+ return this.backend.setNotifyScope(group, scope);
4774
+ }
4775
+ /** Refresh + return this chat's notify scope from the server (fail-OPEN to `'all'`).
4776
+ * Returns `'all'` for a draft chat (no server row yet). */
4777
+ async getNotifyScope() {
4778
+ if (!this._group) return "all";
4779
+ return this.backend.getNotifyScope(this._group);
4780
+ }
4781
+ /** Fetch the caller's authoritative SERVER unread count (opaque server metadata).
4782
+ * Returns the clamped count (`max(0, …)`); `0` for a draft chat. The local computed
4783
+ * `unreadCount` getter stays the instant, offline best-effort badge — this is the
4784
+ * canonical count on demand. Named distinctly so it does not shadow the observable
4785
+ * `unreadCount` snapshot getter. Mirrors iOS `Chat.refreshUnread`. */
4786
+ async unreadCountFromServer() {
4787
+ if (!this._group) return 0;
4788
+ const v = await this.backend.unread(this._group);
4789
+ return Math.max(0, v.unreadCount);
4790
+ }
4750
4791
  // ── Reactions ──
4751
4792
  /** Add an emoji reaction to a message. No-op if the message isn't reactable
4752
4793
  * (empty clientMsgId — a legacy/system row). The reaction folds locally with
@@ -5185,7 +5226,7 @@ var MessageDeliverySource = class {
5185
5226
  if (this.observed.has(group.displayId)) return;
5186
5227
  try {
5187
5228
  const channel = this.rt.realtime.channel(`messaging:conv:${group.rfcGroupId}`);
5188
- const subs = ["presence", "typing", "read"].map(
5229
+ const subs = ["presence", "typing", "read", "delivered"].map(
5189
5230
  (ev) => channel.on(ev, (payload) => {
5190
5231
  this.hub.emitConv(group.displayId, { event: ev, payload });
5191
5232
  })
@@ -5225,6 +5266,40 @@ var MessageDeliverySource = class {
5225
5266
  body: { read_seq: upToServerSeq, read_epoch: group.currentEpoch, is_private: false }
5226
5267
  });
5227
5268
  }
5269
+ // ── Server-metadata cluster: notify scope (mute) + unread (HTTP) ──
5270
+ /** PUT `/v1/messaging/groups/{gid}/notify` — set the caller's per-(user,group) notify
5271
+ * scope (`'all'`|`'none'`). The server stores the opaque enum verbatim and stays blind.
5272
+ * Returns the server-echoed scope (fail-OPEN to `'all'` on an unknown value). */
5273
+ async setNotifyScope(group, scope) {
5274
+ const res = await palbeRequest(
5275
+ this.rt,
5276
+ "PUT",
5277
+ MessagingPaths.groupNotify(group.displayId),
5278
+ { body: { notify_scope: scope } }
5279
+ );
5280
+ return res.notify_scope === "none" ? "none" : "all";
5281
+ }
5282
+ /** GET `/v1/messaging/groups/{gid}/notify` — the caller's notify scope. An absent
5283
+ * server row / unknown value reads as `'all'` (fail-OPEN — never silently mutes). */
5284
+ async getNotifyScope(group) {
5285
+ const res = await palbeRequest(
5286
+ this.rt,
5287
+ "GET",
5288
+ MessagingPaths.groupNotify(group.displayId)
5289
+ );
5290
+ return res.notify_scope === "none" ? "none" : "all";
5291
+ }
5292
+ /** GET `/v1/messaging/groups/{gid}/unread` — the caller's OWN unread view (opaque
5293
+ * server metadata). Maps the snake_case wire → the camelCase `UnreadView`. */
5294
+ async unread(group) {
5295
+ const res = await palbeRequest(this.rt, "GET", MessagingPaths.groupUnread(group.displayId));
5296
+ return {
5297
+ groupMaxSeq: res.group_max_seq,
5298
+ lastReadSeq: res.last_read_seq,
5299
+ deliveredSeq: res.delivered_seq,
5300
+ unreadCount: res.unread_count
5301
+ };
5302
+ }
5228
5303
  };
5229
5304
  function isOwnEchoOrConsumed(e) {
5230
5305
  const msg = e instanceof Error ? e.message : String(e);
@@ -7279,9 +7354,9 @@ var MessagingCoordinator = class {
7279
7354
  });
7280
7355
  return group;
7281
7356
  }
7282
- async sendText(group, text, replyTo, bodyRanges) {
7357
+ async sendText(group, text, replyTo, bodyRanges, expiry) {
7283
7358
  const r = await this.resolve();
7284
- return r.groups.sendText(group, text, replyTo, bodyRanges);
7359
+ return r.groups.sendText(group, text, replyTo, bodyRanges, expiry);
7285
7360
  }
7286
7361
  async sendReaction(group, args) {
7287
7362
  const r = await this.resolve();
@@ -7382,6 +7457,19 @@ var MessagingCoordinator = class {
7382
7457
  const r = await this.resolve();
7383
7458
  await r.source.markRead(group, upToServerSeq);
7384
7459
  }
7460
+ // ── Server-metadata cluster: notify scope (mute) + unread ──
7461
+ async setNotifyScope(group, scope) {
7462
+ const r = await this.resolve();
7463
+ return r.source.setNotifyScope(group, scope);
7464
+ }
7465
+ async getNotifyScope(group) {
7466
+ const r = await this.resolve();
7467
+ return r.source.getNotifyScope(group);
7468
+ }
7469
+ async unread(group) {
7470
+ const r = await this.resolve();
7471
+ return r.source.unread(group);
7472
+ }
7385
7473
  subscribeLive(group, chat) {
7386
7474
  let offMsg = null;
7387
7475
  let offConv = null;
@@ -8321,7 +8409,7 @@ function defaultSessionStorage(key) {
8321
8409
  }
8322
8410
 
8323
8411
  // src/version.ts
8324
- var VERSION = "1.6.1";
8412
+ var VERSION = "1.7.0";
8325
8413
 
8326
8414
  // src/runtime.ts
8327
8415
  function buildRuntime(config) {