@dittolive/ditto-chat-core 0.1.2 → 0.1.4

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.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import k, { useMemo as Fe } from "react";
2
- const ze = {
1
+ import x, { useMemo as Be } from "react";
2
+ const Fe = {
3
3
  canCreateRoom: !0,
4
4
  canEditOwnMessage: !0,
5
5
  canDeleteOwnMessage: !0,
@@ -7,7 +7,7 @@ const ze = {
7
7
  canRemoveOwnReaction: !0,
8
8
  canMentionUsers: !0,
9
9
  canSubscribeToRoom: !0
10
- }, Le = (e, t, { rbacConfig: r = {} }) => ({
10
+ }, ze = (e, t, { rbacConfig: r = {} }) => ({
11
11
  rbacConfig: r,
12
12
  /**
13
13
  * Check if a specific permission action is allowed.
@@ -24,8 +24,8 @@ const ze = {
24
24
  * @returns boolean indicating if action is allowed
25
25
  */
26
26
  canPerformAction: (s) => {
27
- const c = t().rbacConfig[s];
28
- return c !== void 0 ? c : ze[s];
27
+ const a = t().rbacConfig[s];
28
+ return a !== void 0 ? a : Fe[s];
29
29
  },
30
30
  /**
31
31
  * Update the RBAC permission configuration.
@@ -49,7 +49,7 @@ const ze = {
49
49
  }));
50
50
  }
51
51
  });
52
- var Ae = /* @__PURE__ */ Symbol.for("immer-nothing"), ye = /* @__PURE__ */ Symbol.for("immer-draftable"), O = /* @__PURE__ */ Symbol.for("immer-state"), He = process.env.NODE_ENV !== "production" ? [
52
+ var Ae = /* @__PURE__ */ Symbol.for("immer-nothing"), me = /* @__PURE__ */ Symbol.for("immer-draftable"), S = /* @__PURE__ */ Symbol.for("immer-state"), He = process.env.NODE_ENV !== "production" ? [
53
53
  // All error codes, starting by 0:
54
54
  function(e) {
55
55
  return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
@@ -80,7 +80,7 @@ var Ae = /* @__PURE__ */ Symbol.for("immer-nothing"), ye = /* @__PURE__ */ Symbo
80
80
  // Note: if more errors are added, the errorOffset in Patches.ts should be increased
81
81
  // See Patches.ts for additional errors
82
82
  ] : [];
83
- function T(e, ...t) {
83
+ function p(e, ...t) {
84
84
  if (process.env.NODE_ENV !== "production") {
85
85
  const r = He[e], n = typeof r == "function" ? r.apply(null, t) : r;
86
86
  throw new Error(`[Immer] ${n}`);
@@ -89,15 +89,15 @@ function T(e, ...t) {
89
89
  `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`
90
90
  );
91
91
  }
92
- var B = Object.getPrototypeOf;
93
- function N(e) {
94
- return !!e && !!e[O];
92
+ var k = Object.getPrototypeOf;
93
+ function P(e) {
94
+ return !!e && !!e[S];
95
95
  }
96
- function U(e) {
97
- return e ? ve(e) || Array.isArray(e) || !!e[ye] || !!e.constructor?.[ye] || L(e) || X(e) : !1;
96
+ function C(e) {
97
+ return e ? De(e) || Array.isArray(e) || !!e[me] || !!e.constructor?.[me] || z(e) || V(e) : !1;
98
98
  }
99
- var $e = Object.prototype.constructor.toString(), ge = /* @__PURE__ */ new WeakMap();
100
- function ve(e) {
99
+ var Le = Object.prototype.constructor.toString(), ye = /* @__PURE__ */ new WeakMap();
100
+ function De(e) {
101
101
  if (!e || typeof e != "object")
102
102
  return !1;
103
103
  const t = Object.getPrototypeOf(e);
@@ -108,95 +108,95 @@ function ve(e) {
108
108
  return !0;
109
109
  if (typeof r != "function")
110
110
  return !1;
111
- let n = ge.get(r);
112
- return n === void 0 && (n = Function.toString.call(r), ge.set(r, n)), n === $e;
111
+ let n = ye.get(r);
112
+ return n === void 0 && (n = Function.toString.call(r), ye.set(r, n)), n === Le;
113
113
  }
114
- function q(e, t, r = !0) {
115
- V(e) === 0 ? (r ? Reflect.ownKeys(e) : Object.keys(e)).forEach((s) => {
114
+ function G(e, t, r = !0) {
115
+ Q(e) === 0 ? (r ? Reflect.ownKeys(e) : Object.keys(e)).forEach((s) => {
116
116
  t(s, e[s], e);
117
117
  }) : e.forEach((n, s) => t(s, n, e));
118
118
  }
119
- function V(e) {
120
- const t = e[O];
121
- return t ? t.type_ : Array.isArray(e) ? 1 : L(e) ? 2 : X(e) ? 3 : 0;
119
+ function Q(e) {
120
+ const t = e[S];
121
+ return t ? t.type_ : Array.isArray(e) ? 1 : z(e) ? 2 : V(e) ? 3 : 0;
122
122
  }
123
- function oe(e, t) {
124
- return V(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
123
+ function se(e, t) {
124
+ return Q(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
125
125
  }
126
126
  function Me(e, t, r) {
127
- const n = V(e);
127
+ const n = Q(e);
128
128
  n === 2 ? e.set(t, r) : n === 3 ? e.add(r) : e[t] = r;
129
129
  }
130
- function je(e, t) {
130
+ function $e(e, t) {
131
131
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
132
132
  }
133
- function L(e) {
133
+ function z(e) {
134
134
  return e instanceof Map;
135
135
  }
136
- function X(e) {
136
+ function V(e) {
137
137
  return e instanceof Set;
138
138
  }
139
- function M(e) {
139
+ function v(e) {
140
140
  return e.copy_ || e.base_;
141
141
  }
142
- function ie(e, t) {
143
- if (L(e))
142
+ function oe(e, t) {
143
+ if (z(e))
144
144
  return new Map(e);
145
- if (X(e))
145
+ if (V(e))
146
146
  return new Set(e);
147
147
  if (Array.isArray(e))
148
148
  return Array.prototype.slice.call(e);
149
- const r = ve(e);
149
+ const r = De(e);
150
150
  if (t === !0 || t === "class_only" && !r) {
151
151
  const n = Object.getOwnPropertyDescriptors(e);
152
- delete n[O];
152
+ delete n[S];
153
153
  let s = Reflect.ownKeys(n);
154
154
  for (let o = 0; o < s.length; o++) {
155
- const c = s[o], a = n[c];
156
- a.writable === !1 && (a.writable = !0, a.configurable = !0), (a.get || a.set) && (n[c] = {
155
+ const a = s[o], u = n[a];
156
+ u.writable === !1 && (u.writable = !0, u.configurable = !0), (u.get || u.set) && (n[a] = {
157
157
  configurable: !0,
158
158
  writable: !0,
159
159
  // could live with !!desc.set as well here...
160
- enumerable: a.enumerable,
161
- value: e[c]
160
+ enumerable: u.enumerable,
161
+ value: e[a]
162
162
  });
163
163
  }
164
- return Object.create(B(e), n);
164
+ return Object.create(k(e), n);
165
165
  } else {
166
- const n = B(e);
166
+ const n = k(e);
167
167
  if (n !== null && r)
168
168
  return { ...e };
169
169
  const s = Object.create(n);
170
170
  return Object.assign(s, e);
171
171
  }
172
172
  }
173
- function fe(e, t = !1) {
174
- return J(e) || N(e) || !U(e) || (V(e) > 1 && Object.defineProperties(e, {
175
- set: W,
176
- add: W,
177
- clear: W,
178
- delete: W
179
- }), Object.freeze(e), t && Object.values(e).forEach((r) => fe(r, !0))), e;
173
+ function le(e, t = !1) {
174
+ return X(e) || P(e) || !C(e) || (Q(e) > 1 && Object.defineProperties(e, {
175
+ set: j,
176
+ add: j,
177
+ clear: j,
178
+ delete: j
179
+ }), Object.freeze(e), t && Object.values(e).forEach((r) => le(r, !0))), e;
180
180
  }
181
- function We() {
182
- T(2);
181
+ function je() {
182
+ p(2);
183
183
  }
184
- var W = {
185
- value: We
184
+ var j = {
185
+ value: je
186
186
  };
187
- function J(e) {
187
+ function X(e) {
188
188
  return e === null || typeof e != "object" ? !0 : Object.isFrozen(e);
189
189
  }
190
- var Ge = {};
191
- function P(e) {
192
- const t = Ge[e];
193
- return t || T(0, e), t;
190
+ var We = {};
191
+ function U(e) {
192
+ const t = We[e];
193
+ return t || p(0, e), t;
194
194
  }
195
- var F;
196
- function Ce() {
197
- return F;
195
+ var B;
196
+ function ve() {
197
+ return B;
198
198
  }
199
- function qe(e, t) {
199
+ function Ge(e, t) {
200
200
  return {
201
201
  drafts_: [],
202
202
  parent_: e,
@@ -207,63 +207,63 @@ function qe(e, t) {
207
207
  unfinalizedDrafts_: 0
208
208
  };
209
209
  }
210
- function he(e, t) {
211
- t && (P("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
210
+ function ge(e, t) {
211
+ t && (U("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
212
212
  }
213
- function ce(e) {
214
- ae(e), e.drafts_.forEach(Qe), e.drafts_ = null;
213
+ function ie(e) {
214
+ ae(e), e.drafts_.forEach(Ye), e.drafts_ = null;
215
215
  }
216
216
  function ae(e) {
217
- e === F && (F = e.parent_);
217
+ e === B && (B = e.parent_);
218
218
  }
219
- function be(e) {
220
- return F = qe(F, e);
219
+ function he(e) {
220
+ return B = Ge(B, e);
221
221
  }
222
- function Qe(e) {
223
- const t = e[O];
222
+ function Ye(e) {
223
+ const t = e[S];
224
224
  t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
225
225
  }
226
- function _e(e, t) {
226
+ function be(e, t) {
227
227
  t.unfinalizedDrafts_ = t.drafts_.length;
228
228
  const r = t.drafts_[0];
229
- return e !== void 0 && e !== r ? (r[O].modified_ && (ce(t), T(4)), U(e) && (e = Q(t, e), t.parent_ || Y(t, e)), t.patches_ && P("Patches").generateReplacementPatches_(
230
- r[O].base_,
229
+ return e !== void 0 && e !== r ? (r[S].modified_ && (ie(t), p(4)), C(e) && (e = Y(t, e), t.parent_ || q(t, e)), t.patches_ && U("Patches").generateReplacementPatches_(
230
+ r[S].base_,
231
231
  e,
232
232
  t.patches_,
233
233
  t.inversePatches_
234
- )) : e = Q(t, r, []), ce(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== Ae ? e : void 0;
234
+ )) : e = Y(t, r, []), ie(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== Ae ? e : void 0;
235
235
  }
236
- function Q(e, t, r) {
237
- if (J(t))
236
+ function Y(e, t, r) {
237
+ if (X(t))
238
238
  return t;
239
- const n = e.immer_.shouldUseStrictIteration(), s = t[O];
239
+ const n = e.immer_.shouldUseStrictIteration(), s = t[S];
240
240
  if (!s)
241
- return q(
241
+ return G(
242
242
  t,
243
- (o, c) => we(e, s, t, o, c, r),
243
+ (o, a) => _e(e, s, t, o, a, r),
244
244
  n
245
245
  ), t;
246
246
  if (s.scope_ !== e)
247
247
  return t;
248
248
  if (!s.modified_)
249
- return Y(e, s.base_, !0), s.base_;
249
+ return q(e, s.base_, !0), s.base_;
250
250
  if (!s.finalized_) {
251
251
  s.finalized_ = !0, s.scope_.unfinalizedDrafts_--;
252
252
  const o = s.copy_;
253
- let c = o, a = !1;
254
- s.type_ === 3 && (c = new Set(o), o.clear(), a = !0), q(
255
- c,
256
- (y, g) => we(
253
+ let a = o, u = !1;
254
+ s.type_ === 3 && (a = new Set(o), o.clear(), u = !0), G(
255
+ a,
256
+ (y, g) => _e(
257
257
  e,
258
258
  s,
259
259
  o,
260
260
  y,
261
261
  g,
262
262
  r,
263
- a
263
+ u
264
264
  ),
265
265
  n
266
- ), Y(e, o, !1), r && e.patches_ && P("Patches").generatePatches_(
266
+ ), q(e, o, !1), r && e.patches_ && U("Patches").generatePatches_(
267
267
  s,
268
268
  r,
269
269
  e.patches_,
@@ -272,34 +272,34 @@ function Q(e, t, r) {
272
272
  }
273
273
  return s.copy_;
274
274
  }
275
- function we(e, t, r, n, s, o, c) {
276
- if (s == null || typeof s != "object" && !c)
275
+ function _e(e, t, r, n, s, o, a) {
276
+ if (s == null || typeof s != "object" && !a)
277
277
  return;
278
- const a = J(s);
279
- if (!(a && !c)) {
280
- if (process.env.NODE_ENV !== "production" && s === r && T(5), N(s)) {
278
+ const u = X(s);
279
+ if (!(u && !a)) {
280
+ if (process.env.NODE_ENV !== "production" && s === r && p(5), P(s)) {
281
281
  const y = o && t && t.type_ !== 3 && // Set objects are atomic since they have no keys.
282
- !oe(t.assigned_, n) ? o.concat(n) : void 0, g = Q(e, s, y);
283
- if (Me(r, n, g), N(g))
282
+ !se(t.assigned_, n) ? o.concat(n) : void 0, g = Y(e, s, y);
283
+ if (Me(r, n, g), P(g))
284
284
  e.canAutoFreeze_ = !1;
285
285
  else
286
286
  return;
287
- } else c && r.add(s);
288
- if (U(s) && !a) {
289
- if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1 || t && t.base_ && t.base_[n] === s && a)
287
+ } else a && r.add(s);
288
+ if (C(s) && !u) {
289
+ if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1 || t && t.base_ && t.base_[n] === s && u)
290
290
  return;
291
- Q(e, s), (!t || !t.scope_.parent_) && typeof n != "symbol" && (L(r) ? r.has(n) : Object.prototype.propertyIsEnumerable.call(r, n)) && Y(e, s);
291
+ Y(e, s), (!t || !t.scope_.parent_) && typeof n != "symbol" && (z(r) ? r.has(n) : Object.prototype.propertyIsEnumerable.call(r, n)) && q(e, s);
292
292
  }
293
293
  }
294
294
  }
295
- function Y(e, t, r = !1) {
296
- !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && fe(t, r);
295
+ function q(e, t, r = !1) {
296
+ !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && le(t, r);
297
297
  }
298
- function Ye(e, t) {
298
+ function qe(e, t) {
299
299
  const r = Array.isArray(e), n = {
300
300
  type_: r ? 1 : 0,
301
301
  // Track which produce call this is associated with.
302
- scope_: t ? t.scope_ : Ce(),
302
+ scope_: t ? t.scope_ : ve(),
303
303
  // True for both shallow and deep changes.
304
304
  modified_: !1,
305
305
  // Used during finalization.
@@ -319,50 +319,50 @@ function Ye(e, t) {
319
319
  revoke_: null,
320
320
  isManual_: !1
321
321
  };
322
- let s = n, o = me;
323
- r && (s = [n], o = z);
324
- const { revoke: c, proxy: a } = Proxy.revocable(s, o);
325
- return n.draft_ = a, n.revoke_ = c, a;
322
+ let s = n, o = fe;
323
+ r && (s = [n], o = F);
324
+ const { revoke: a, proxy: u } = Proxy.revocable(s, o);
325
+ return n.draft_ = u, n.revoke_ = a, u;
326
326
  }
327
- var me = {
327
+ var fe = {
328
328
  get(e, t) {
329
- if (t === O)
329
+ if (t === S)
330
330
  return e;
331
- const r = M(e);
332
- if (!oe(r, t))
333
- return Ve(e, r, t);
331
+ const r = v(e);
332
+ if (!se(r, t))
333
+ return Qe(e, r, t);
334
334
  const n = r[t];
335
- return e.finalized_ || !U(n) ? n : n === ee(e.base_, t) ? (te(e), e.copy_[t] = le(n, e)) : n;
335
+ return e.finalized_ || !C(n) ? n : n === K(e.base_, t) ? (ee(e), e.copy_[t] = ue(n, e)) : n;
336
336
  },
337
337
  has(e, t) {
338
- return t in M(e);
338
+ return t in v(e);
339
339
  },
340
340
  ownKeys(e) {
341
- return Reflect.ownKeys(M(e));
341
+ return Reflect.ownKeys(v(e));
342
342
  },
343
343
  set(e, t, r) {
344
- const n = Ue(M(e), t);
344
+ const n = Ce(v(e), t);
345
345
  if (n?.set)
346
346
  return n.set.call(e.draft_, r), !0;
347
347
  if (!e.modified_) {
348
- const s = ee(M(e), t), o = s?.[O];
348
+ const s = K(v(e), t), o = s?.[S];
349
349
  if (o && o.base_ === r)
350
350
  return e.copy_[t] = r, e.assigned_[t] = !1, !0;
351
- if (je(r, s) && (r !== void 0 || oe(e.base_, t)))
351
+ if ($e(r, s) && (r !== void 0 || se(e.base_, t)))
352
352
  return !0;
353
- te(e), ue(e);
353
+ ee(e), ce(e);
354
354
  }
355
355
  return e.copy_[t] === r && // special case: handle new props with value 'undefined'
356
356
  (r !== void 0 || t in e.copy_) || // special case: NaN
357
357
  Number.isNaN(r) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = r, e.assigned_[t] = !0), !0;
358
358
  },
359
359
  deleteProperty(e, t) {
360
- return ee(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, te(e), ue(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0;
360
+ return K(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, ee(e), ce(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0;
361
361
  },
362
362
  // Note: We never coerce `desc.value` into an Immer draft, because we can't make
363
363
  // the same guarantee in ES5 mode.
364
364
  getOwnPropertyDescriptor(e, t) {
365
- const r = M(e), n = Reflect.getOwnPropertyDescriptor(r, t);
365
+ const r = v(e), n = Reflect.getOwnPropertyDescriptor(r, t);
366
366
  return n && {
367
367
  writable: !0,
368
368
  configurable: e.type_ !== 1 || t !== "length",
@@ -371,107 +371,107 @@ var me = {
371
371
  };
372
372
  },
373
373
  defineProperty() {
374
- T(11);
374
+ p(11);
375
375
  },
376
376
  getPrototypeOf(e) {
377
- return B(e.base_);
377
+ return k(e.base_);
378
378
  },
379
379
  setPrototypeOf() {
380
- T(12);
380
+ p(12);
381
381
  }
382
- }, z = {};
383
- q(me, (e, t) => {
384
- z[e] = function() {
382
+ }, F = {};
383
+ G(fe, (e, t) => {
384
+ F[e] = function() {
385
385
  return arguments[0] = arguments[0][0], t.apply(this, arguments);
386
386
  };
387
387
  });
388
- z.deleteProperty = function(e, t) {
389
- return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && T(13), z.set.call(this, e, t, void 0);
388
+ F.deleteProperty = function(e, t) {
389
+ return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && p(13), F.set.call(this, e, t, void 0);
390
390
  };
391
- z.set = function(e, t, r) {
392
- return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && T(14), me.set.call(this, e[0], t, r, e[0]);
391
+ F.set = function(e, t, r) {
392
+ return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && p(14), fe.set.call(this, e[0], t, r, e[0]);
393
393
  };
394
- function ee(e, t) {
395
- const r = e[O];
396
- return (r ? M(r) : e)[t];
394
+ function K(e, t) {
395
+ const r = e[S];
396
+ return (r ? v(r) : e)[t];
397
397
  }
398
- function Ve(e, t, r) {
399
- const n = Ue(t, r);
398
+ function Qe(e, t, r) {
399
+ const n = Ce(t, r);
400
400
  return n ? "value" in n ? n.value : (
401
401
  // This is a very special case, if the prop is a getter defined by the
402
402
  // prototype, we should invoke it with the draft as context!
403
403
  n.get?.call(e.draft_)
404
404
  ) : void 0;
405
405
  }
406
- function Ue(e, t) {
406
+ function Ce(e, t) {
407
407
  if (!(t in e))
408
408
  return;
409
- let r = B(e);
409
+ let r = k(e);
410
410
  for (; r; ) {
411
411
  const n = Object.getOwnPropertyDescriptor(r, t);
412
412
  if (n)
413
413
  return n;
414
- r = B(r);
414
+ r = k(r);
415
415
  }
416
416
  }
417
- function ue(e) {
418
- e.modified_ || (e.modified_ = !0, e.parent_ && ue(e.parent_));
417
+ function ce(e) {
418
+ e.modified_ || (e.modified_ = !0, e.parent_ && ce(e.parent_));
419
419
  }
420
- function te(e) {
421
- e.copy_ || (e.copy_ = ie(
420
+ function ee(e) {
421
+ e.copy_ || (e.copy_ = oe(
422
422
  e.base_,
423
423
  e.scope_.immer_.useStrictShallowCopy_
424
424
  ));
425
425
  }
426
- var Xe = class {
426
+ var Ve = class {
427
427
  constructor(e) {
428
428
  this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !0, this.produce = (t, r, n) => {
429
429
  if (typeof t == "function" && typeof r != "function") {
430
430
  const o = r;
431
431
  r = t;
432
- const c = this;
432
+ const a = this;
433
433
  return function(y = o, ...g) {
434
- return c.produce(y, (p) => r.call(this, p, ...g));
434
+ return a.produce(y, (w) => r.call(this, w, ...g));
435
435
  };
436
436
  }
437
- typeof r != "function" && T(6), n !== void 0 && typeof n != "function" && T(7);
437
+ typeof r != "function" && p(6), n !== void 0 && typeof n != "function" && p(7);
438
438
  let s;
439
- if (U(t)) {
440
- const o = be(this), c = le(t, void 0);
441
- let a = !0;
439
+ if (C(t)) {
440
+ const o = he(this), a = ue(t, void 0);
441
+ let u = !0;
442
442
  try {
443
- s = r(c), a = !1;
443
+ s = r(a), u = !1;
444
444
  } finally {
445
- a ? ce(o) : ae(o);
445
+ u ? ie(o) : ae(o);
446
446
  }
447
- return he(o, n), _e(s, o);
447
+ return ge(o, n), be(s, o);
448
448
  } else if (!t || typeof t != "object") {
449
- if (s = r(t), s === void 0 && (s = t), s === Ae && (s = void 0), this.autoFreeze_ && fe(s, !0), n) {
450
- const o = [], c = [];
451
- P("Patches").generateReplacementPatches_(t, s, o, c), n(o, c);
449
+ if (s = r(t), s === void 0 && (s = t), s === Ae && (s = void 0), this.autoFreeze_ && le(s, !0), n) {
450
+ const o = [], a = [];
451
+ U("Patches").generateReplacementPatches_(t, s, o, a), n(o, a);
452
452
  }
453
453
  return s;
454
454
  } else
455
- T(1, t);
455
+ p(1, t);
456
456
  }, this.produceWithPatches = (t, r) => {
457
457
  if (typeof t == "function")
458
- return (c, ...a) => this.produceWithPatches(c, (y) => t(y, ...a));
458
+ return (a, ...u) => this.produceWithPatches(a, (y) => t(y, ...u));
459
459
  let n, s;
460
- return [this.produce(t, r, (c, a) => {
461
- n = c, s = a;
460
+ return [this.produce(t, r, (a, u) => {
461
+ n = a, s = u;
462
462
  }), n, s];
463
463
  }, typeof e?.autoFreeze == "boolean" && this.setAutoFreeze(e.autoFreeze), typeof e?.useStrictShallowCopy == "boolean" && this.setUseStrictShallowCopy(e.useStrictShallowCopy), typeof e?.useStrictIteration == "boolean" && this.setUseStrictIteration(e.useStrictIteration);
464
464
  }
465
465
  createDraft(e) {
466
- U(e) || T(8), N(e) && (e = Je(e));
467
- const t = be(this), r = le(e, void 0);
468
- return r[O].isManual_ = !0, ae(t), r;
466
+ C(e) || p(8), P(e) && (e = Xe(e));
467
+ const t = he(this), r = ue(e, void 0);
468
+ return r[S].isManual_ = !0, ae(t), r;
469
469
  }
470
470
  finishDraft(e, t) {
471
- const r = e && e[O];
472
- (!r || !r.isManual_) && T(9);
471
+ const r = e && e[S];
472
+ (!r || !r.isManual_) && p(9);
473
473
  const { scope_: n } = r;
474
- return he(n, t), _e(void 0, n);
474
+ return ge(n, t), be(void 0, n);
475
475
  }
476
476
  /**
477
477
  * Pass true to automatically freeze all copies created by Immer.
@@ -511,111 +511,113 @@ var Xe = class {
511
511
  }
512
512
  }
513
513
  r > -1 && (t = t.slice(r + 1));
514
- const n = P("Patches").applyPatches_;
515
- return N(e) ? n(e, t) : this.produce(
514
+ const n = U("Patches").applyPatches_;
515
+ return P(e) ? n(e, t) : this.produce(
516
516
  e,
517
517
  (s) => n(s, t)
518
518
  );
519
519
  }
520
520
  };
521
- function le(e, t) {
522
- const r = L(e) ? P("MapSet").proxyMap_(e, t) : X(e) ? P("MapSet").proxySet_(e, t) : Ye(e, t);
523
- return (t ? t.scope_ : Ce()).drafts_.push(r), r;
521
+ function ue(e, t) {
522
+ const r = z(e) ? U("MapSet").proxyMap_(e, t) : V(e) ? U("MapSet").proxySet_(e, t) : qe(e, t);
523
+ return (t ? t.scope_ : ve()).drafts_.push(r), r;
524
524
  }
525
- function Je(e) {
526
- return N(e) || T(10, e), Pe(e);
525
+ function Xe(e) {
526
+ return P(e) || p(10, e), Ue(e);
527
527
  }
528
- function Pe(e) {
529
- if (!U(e) || J(e))
528
+ function Ue(e) {
529
+ if (!C(e) || X(e))
530
530
  return e;
531
- const t = e[O];
531
+ const t = e[S];
532
532
  let r, n = !0;
533
533
  if (t) {
534
534
  if (!t.modified_)
535
535
  return t.base_;
536
- t.finalized_ = !0, r = ie(e, t.scope_.immer_.useStrictShallowCopy_), n = t.scope_.immer_.shouldUseStrictIteration();
536
+ t.finalized_ = !0, r = oe(e, t.scope_.immer_.useStrictShallowCopy_), n = t.scope_.immer_.shouldUseStrictIteration();
537
537
  } else
538
- r = ie(e, !0);
539
- return q(
538
+ r = oe(e, !0);
539
+ return G(
540
540
  r,
541
541
  (s, o) => {
542
- Me(r, s, Pe(o));
542
+ Me(r, s, Ue(o));
543
543
  },
544
544
  n
545
545
  ), t && (t.finalized_ = !1), r;
546
546
  }
547
- var Ze = new Xe(), C = Ze.produce;
547
+ var Ze = new Ve(), M = Ze.produce;
548
548
  const E = [];
549
549
  for (let e = 0; e < 256; ++e)
550
550
  E.push((e + 256).toString(16).slice(1));
551
- function Ke(e, t = 0) {
551
+ function Je(e, t = 0) {
552
552
  return (E[e[t + 0]] + E[e[t + 1]] + E[e[t + 2]] + E[e[t + 3]] + "-" + E[e[t + 4]] + E[e[t + 5]] + "-" + E[e[t + 6]] + E[e[t + 7]] + "-" + E[e[t + 8]] + E[e[t + 9]] + "-" + E[e[t + 10]] + E[e[t + 11]] + E[e[t + 12]] + E[e[t + 13]] + E[e[t + 14]] + E[e[t + 15]]).toLowerCase();
553
553
  }
554
- let re;
555
- const et = new Uint8Array(16);
556
- function tt() {
557
- if (!re) {
554
+ let te;
555
+ const Ke = new Uint8Array(16);
556
+ function et() {
557
+ if (!te) {
558
558
  if (typeof crypto > "u" || !crypto.getRandomValues)
559
559
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
560
- re = crypto.getRandomValues.bind(crypto);
560
+ te = crypto.getRandomValues.bind(crypto);
561
561
  }
562
- return re(et);
562
+ return te(Ke);
563
563
  }
564
- const rt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), pe = { randomUUID: rt };
565
- function nt(e, t, r) {
564
+ const tt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Te = { randomUUID: tt };
565
+ function rt(e, t, r) {
566
566
  e = e || {};
567
- const n = e.random ?? e.rng?.() ?? tt();
567
+ const n = e.random ?? e.rng?.() ?? et();
568
568
  if (n.length < 16)
569
569
  throw new Error("Random bytes length must be >= 16");
570
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Ke(n);
570
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Je(n);
571
571
  }
572
- function Ne(e, t, r) {
573
- return pe.randomUUID && !e ? pe.randomUUID() : nt(e);
572
+ function Pe(e, t, r) {
573
+ return Te.randomUUID && !e ? Te.randomUUID() : rt(e);
574
574
  }
575
- function Ee(e, t, r) {
576
- if (r.items.length === 0)
575
+ function we(e, t, r) {
576
+ if (r.items.length === 0) {
577
+ e((s) => M(s, (o) => (o.roomsLoading = !1, o.messagesLoading = !1, o)));
577
578
  return;
579
+ }
578
580
  const n = r.items.map((s) => {
579
581
  const o = t().messagesPublisher;
580
582
  return o(s.value), s.value;
581
583
  });
582
- e((s) => C(s, (o) => {
583
- const c = s.rooms.filter(
584
- (a) => a.collectionId !== n[0].collectionId
584
+ e((s) => M(s, (o) => {
585
+ const a = s.rooms.filter(
586
+ (u) => u.collectionId !== n[0].collectionId
585
587
  );
586
- return o.rooms = c.concat(n), o.roomsLoading = !1, o;
588
+ return o.rooms = a.concat(n), o.roomsLoading = !1, o;
587
589
  }));
588
590
  }
589
- async function ne({
591
+ async function re({
590
592
  ditto: e,
591
593
  currentUserId: t,
592
594
  name: r,
593
595
  collectionId: n,
594
596
  messagesId: s,
595
597
  participants: o = [],
596
- retentionDays: c,
597
- isGenerated: a = !1,
598
+ retention: a,
599
+ isGenerated: u = !1,
598
600
  id: y
599
601
  }) {
600
602
  if (e)
601
603
  try {
602
- const p = {
603
- _id: y || Ne(),
604
+ const w = {
605
+ _id: y || Pe(),
604
606
  name: r,
605
607
  messagesId: s,
606
608
  collectionId: n,
607
- isGenerated: a,
609
+ isGenerated: u,
608
610
  createdBy: t,
609
611
  createdOn: (/* @__PURE__ */ new Date()).toISOString(),
610
612
  participants: o || void 0,
611
- ...c !== void 0 && { retentionDays: c }
612
- }, S = `INSERT INTO \`${n}\` DOCUMENTS (:newDoc) ON ID CONFLICT DO UPDATE`;
613
- return await e.store.execute(S, { newDoc: p }), p;
613
+ ...a !== void 0 && { retention: a }
614
+ }, O = `INSERT INTO \`${n}\` DOCUMENTS (:newDoc) ON ID CONFLICT DO UPDATE`;
615
+ return await e.store.execute(O, { newDoc: w }), w;
614
616
  } catch (g) {
615
617
  console.error(`Error creating ${n}:`, g);
616
618
  }
617
619
  }
618
- const st = (e, t, { ditto: r, userId: n }) => {
620
+ const nt = (e, t, { ditto: r, userId: n }) => {
619
621
  const s = {
620
622
  rooms: [],
621
623
  dmRooms: [],
@@ -645,7 +647,7 @@ const st = (e, t, { ditto: r, userId: n }) => {
645
647
  * - Delegates to createRoomBase with appropriate parameters
646
648
  * - Sets collectionId to "rooms" for regular rooms
647
649
  * - Sets messagesId to "messages" collection
648
- * - Passes through optional retentionDays parameter
650
+ * - Passes through optional retention configuration
649
651
  *
650
652
  * This approach ensures:
651
653
  * - RBAC integration prevents unauthorized room creation
@@ -654,22 +656,22 @@ const st = (e, t, { ditto: r, userId: n }) => {
654
656
  *
655
657
  * @param name - Display name for the new room
656
658
  * @param options - Optional configuration for the room
657
- * @param options.retentionDays - Optional custom message retention period (overrides global default)
659
+ * @param options.retention - Optional custom message retention configuration (overrides global default)
658
660
  * @param options.isGenerated - Optional flag to mark room as generated (hidden from main list)
659
661
  * @returns Promise resolving to the created Room object, or undefined if permission denied
660
662
  */
661
- createRoom(o, c) {
663
+ createRoom(o, a) {
662
664
  if (!t().canPerformAction("canCreateRoom"))
663
665
  return console.warn("Permission denied: canCreateRoom is false"), Promise.resolve(void 0);
664
- const a = t().currentUser;
665
- return ne({
666
+ const u = t().currentUser;
667
+ return re({
666
668
  ditto: r,
667
- currentUserId: a?._id || n,
669
+ currentUserId: u?._id || n,
668
670
  name: o,
669
671
  collectionId: "rooms",
670
672
  messagesId: "messages",
671
- retentionDays: c?.retentionDays,
672
- isGenerated: c?.isGenerated ?? !1
673
+ retention: a?.retention,
674
+ isGenerated: a?.isGenerated ?? !1
673
675
  });
674
676
  },
675
677
  /**
@@ -704,16 +706,16 @@ const st = (e, t, { ditto: r, userId: n }) => {
704
706
  * @throws Error if either user ID is invalid or missing
705
707
  */
706
708
  createDMRoom(o) {
707
- const c = t().currentUser;
708
- if (!c?._id || !o?._id)
709
+ const a = t().currentUser;
710
+ if (!a?._id || !o?._id)
709
711
  throw Error("Invalid users");
710
- return ne({
712
+ return re({
711
713
  ditto: r,
712
- currentUserId: c?._id || n,
713
- name: `${c?.name} & ${o.name}`,
714
+ currentUserId: a?._id || n,
715
+ name: `${a?.name} & ${o.name}`,
714
716
  collectionId: "dm_rooms",
715
717
  messagesId: "dm_messages",
716
- participants: [c?._id, o._id]
718
+ participants: [a?._id, o._id]
717
719
  });
718
720
  },
719
721
  /**
@@ -727,17 +729,17 @@ const st = (e, t, { ditto: r, userId: n }) => {
727
729
  * @param name - Display name for the room
728
730
  * @returns Promise resolving to the created Room object
729
731
  */
730
- async createGeneratedRoom(o, c) {
731
- const a = t().currentUser, y = await ne({
732
+ async createGeneratedRoom(o, a) {
733
+ const u = t().currentUser, y = await re({
732
734
  ditto: r,
733
- currentUserId: a?._id || n,
734
- name: c,
735
+ currentUserId: u?._id || n,
736
+ name: a,
735
737
  collectionId: "rooms",
736
738
  messagesId: "messages",
737
739
  isGenerated: !0,
738
740
  id: o
739
741
  });
740
- return y && e((g) => g.generatedRooms.some((S) => S._id === y._id) ? g : {
742
+ return y && e((g) => g.generatedRooms.some((O) => O._id === y._id) ? g : {
741
743
  ...g,
742
744
  generatedRooms: [...g.generatedRooms, y]
743
745
  }), y;
@@ -755,18 +757,18 @@ const st = (e, t, { ditto: r, userId: n }) => {
755
757
  }
756
758
  };
757
759
  if (r) {
758
- const o = "SELECT * from rooms WHERE isGenerated = false OR isGenerated IS NULL", c = "SELECT * from dm_rooms where (array_contains(participants, :userId))";
759
- s.roomsSubscription = r.sync.registerSubscription(o), s.dmRoomsSubscription = r.sync.registerSubscription(c, {
760
+ const o = "SELECT * from rooms WHERE isGenerated = false OR isGenerated IS NULL", a = "SELECT * from dm_rooms where (array_contains(participants, :userId))";
761
+ s.roomsSubscription = r.sync.registerSubscription(o), s.dmRoomsSubscription = r.sync.registerSubscription(a, {
760
762
  userId: n
761
763
  }), s.roomsObserver = r.store.registerObserver(
762
764
  o,
763
- (a) => {
764
- Ee(e, t, a);
765
+ (u) => {
766
+ we(e, t, u);
765
767
  }
766
768
  ), s.dmRoomsObserver = r.store.registerObserver(
767
- c,
768
- (a) => {
769
- Ee(e, t, a);
769
+ a,
770
+ (u) => {
771
+ we(e, t, u);
770
772
  },
771
773
  {
772
774
  userId: n
@@ -774,26 +776,26 @@ const st = (e, t, { ditto: r, userId: n }) => {
774
776
  );
775
777
  }
776
778
  return s;
777
- }, Te = (e) => {
779
+ }, Ee = (e) => {
778
780
  let t;
779
- const r = /* @__PURE__ */ new Set(), n = (g, p) => {
780
- const S = typeof g == "function" ? g(t) : g;
781
- if (!Object.is(S, t)) {
782
- const x = t;
783
- t = p ?? (typeof S != "object" || S === null) ? S : Object.assign({}, t, S), r.forEach((H) => H(t, x));
781
+ const r = /* @__PURE__ */ new Set(), n = (g, w) => {
782
+ const O = typeof g == "function" ? g(t) : g;
783
+ if (!Object.is(O, t)) {
784
+ const N = t;
785
+ t = w ?? (typeof O != "object" || O === null) ? O : Object.assign({}, t, O), r.forEach((H) => H(t, N));
784
786
  }
785
- }, s = () => t, a = { setState: n, getState: s, getInitialState: () => y, subscribe: (g) => (r.add(g), () => r.delete(g)) }, y = t = e(n, s, a);
786
- return a;
787
- }, ot = ((e) => e ? Te(e) : Te), it = (e) => e;
788
- function xe(e, t = it) {
789
- const r = k.useSyncExternalStore(
787
+ }, s = () => t, u = { setState: n, getState: s, getInitialState: () => y, subscribe: (g) => (r.add(g), () => r.delete(g)) }, y = t = e(n, s, u);
788
+ return u;
789
+ }, st = ((e) => e ? Ee(e) : Ee), ot = (e) => e;
790
+ function Ne(e, t = ot) {
791
+ const r = x.useSyncExternalStore(
790
792
  e.subscribe,
791
- k.useCallback(() => t(e.getState()), [e, t]),
792
- k.useCallback(() => t(e.getInitialState()), [e, t])
793
+ x.useCallback(() => t(e.getState()), [e, t]),
794
+ x.useCallback(() => t(e.getInitialState()), [e, t])
793
795
  );
794
- return k.useDebugValue(r), r;
796
+ return x.useDebugValue(r), r;
795
797
  }
796
- const Se = (e) => Symbol.iterator in e, Oe = (e) => (
798
+ const pe = (e) => Symbol.iterator in e, Oe = (e) => (
797
799
  // HACK: avoid checking entries type
798
800
  "entries" in e
799
801
  ), Re = (e, t) => {
@@ -804,7 +806,7 @@ const Se = (e) => Symbol.iterator in e, Oe = (e) => (
804
806
  if (!n.has(s) || !Object.is(o, n.get(s)))
805
807
  return !1;
806
808
  return !0;
807
- }, ct = (e, t) => {
809
+ }, it = (e, t) => {
808
810
  const r = e[Symbol.iterator](), n = t[Symbol.iterator]();
809
811
  let s = r.next(), o = n.next();
810
812
  for (; !s.done && !o.done; ) {
@@ -815,19 +817,19 @@ const Se = (e) => Symbol.iterator in e, Oe = (e) => (
815
817
  return !!s.done && !!o.done;
816
818
  };
817
819
  function at(e, t) {
818
- return Object.is(e, t) ? !0 : typeof e != "object" || e === null || typeof t != "object" || t === null || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : Se(e) && Se(t) ? Oe(e) && Oe(t) ? Re(e, t) : ct(e, t) : Re(
820
+ return Object.is(e, t) ? !0 : typeof e != "object" || e === null || typeof t != "object" || t === null || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : pe(e) && pe(t) ? Oe(e) && Oe(t) ? Re(e, t) : it(e, t) : Re(
819
821
  { entries: () => Object.entries(e) },
820
822
  { entries: () => Object.entries(t) }
821
823
  );
822
824
  }
823
- function ut(e) {
824
- const t = k.useRef(void 0);
825
+ function ct(e) {
826
+ const t = x.useRef(void 0);
825
827
  return (r) => {
826
828
  const n = e(r);
827
829
  return at(t.current, n) ? t.current : t.current = n;
828
830
  };
829
831
  }
830
- const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
832
+ const ut = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
831
833
  const o = {
832
834
  usersLoading: !0,
833
835
  currentUser: null,
@@ -849,15 +851,15 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
849
851
  *
850
852
  * @param user - User object (with optional _id for upsert)
851
853
  */
852
- async addUser(c) {
854
+ async addUser(a) {
853
855
  if (r)
854
856
  try {
855
857
  await r.store.execute(
856
858
  `INSERT INTO ${s} DOCUMENTS (:newUser) ON ID CONFLICT DO UPDATE`,
857
- { newUser: c }
859
+ { newUser: a }
858
860
  );
859
- } catch (a) {
860
- console.error("Error in addUser:", a);
861
+ } catch (u) {
862
+ console.error("Error in addUser:", u);
861
863
  }
862
864
  },
863
865
  /**
@@ -874,13 +876,13 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
874
876
  *
875
877
  * @param params - Object with _id and fields to update
876
878
  */
877
- async updateUser({ _id: c, ...a }) {
878
- if (r && c)
879
+ async updateUser({ _id: a, ...u }) {
880
+ if (r && a)
879
881
  try {
880
- const y = await t().findUserById(c);
882
+ const y = await t().findUserById(a);
881
883
  if (!y)
882
884
  return;
883
- const g = { ...y, ...a };
885
+ const g = { ...y, ...u };
884
886
  await r.store.execute(
885
887
  `INSERT INTO ${s} DOCUMENTS (:newUser) ON ID CONFLICT DO UPDATE`,
886
888
  { newUser: g }
@@ -902,16 +904,16 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
902
904
  * @param userId - The unique identifier of the user
903
905
  * @returns Promise resolving to ChatUser or null
904
906
  */
905
- async findUserById(c) {
907
+ async findUserById(a) {
906
908
  if (!r)
907
909
  return null;
908
910
  try {
909
911
  return (await r.store.execute(
910
912
  `SELECT * FROM ${s} WHERE _id = :id`,
911
- { id: c }
913
+ { id: a }
912
914
  )).items?.[0]?.value;
913
- } catch (a) {
914
- return console.error("Error in findUserById:", a), null;
915
+ } catch (u) {
916
+ return console.error("Error in findUserById:", u), null;
915
917
  }
916
918
  },
917
919
  /**
@@ -929,21 +931,21 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
929
931
  *
930
932
  * @param roomId - ID of the room to mark as read
931
933
  */
932
- async markRoomAsRead(c) {
934
+ async markRoomAsRead(a) {
933
935
  if (!(!r || !n))
934
936
  try {
935
- let a = !1;
937
+ let u = !1;
936
938
  const y = await t().findUserById(n);
937
939
  if (!y)
938
940
  return;
939
- const g = y.subscriptions || {}, p = y.mentions || {};
940
- if (g[c]) {
941
- const S = (/* @__PURE__ */ new Date()).toISOString();
942
- g[c] = S, a = !0;
941
+ const g = y.subscriptions || {}, w = y.mentions || {};
942
+ if (g[a]) {
943
+ const O = (/* @__PURE__ */ new Date()).toISOString();
944
+ g[a] = O, u = !0;
943
945
  }
944
- p[c] && (p[c] = [], a = !0), a && await t().updateUser({ _id: n, subscriptions: g, mentions: p });
945
- } catch (a) {
946
- console.error("Error in markRoomAsRead:", a);
946
+ w[a] && (w[a] = [], u = !0), u && await t().updateUser({ _id: n, subscriptions: g, mentions: w });
947
+ } catch (u) {
948
+ console.error("Error in markRoomAsRead:", u);
947
949
  }
948
950
  },
949
951
  /**
@@ -960,120 +962,120 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
960
962
  *
961
963
  * @param roomId - ID of the room to toggle subscription for
962
964
  */
963
- async toggleRoomSubscription(c) {
965
+ async toggleRoomSubscription(a) {
964
966
  if (!(!r || !n)) {
965
967
  if (!t().canPerformAction("canSubscribeToRoom")) {
966
968
  console.warn("Permission denied: canSubscribeToRoom is false");
967
969
  return;
968
970
  }
969
971
  try {
970
- const a = await t().findUserById(n);
971
- if (!a)
972
+ const u = await t().findUserById(n);
973
+ if (!u)
972
974
  return;
973
- const y = { ...a.subscriptions };
974
- if (c in y && y[c] !== null)
975
- y[c] = null;
975
+ const y = { ...u.subscriptions };
976
+ if (a in y && y[a] !== null)
977
+ y[a] = null;
976
978
  else {
977
979
  const g = (/* @__PURE__ */ new Date()).toISOString();
978
- y[c] = g;
980
+ y[a] = g;
979
981
  }
980
982
  await t().updateUser({
981
983
  _id: n,
982
984
  subscriptions: y
983
985
  });
984
- } catch (a) {
985
- console.error("Error in toggleRoomSubscription:", a);
986
+ } catch (u) {
987
+ console.error("Error in toggleRoomSubscription:", u);
986
988
  }
987
989
  }
988
990
  }
989
991
  };
990
992
  if (r) {
991
- const c = `SELECT * FROM ${s} WHERE _id = :id`, a = `SELECT * FROM ${s}`, y = { id: n };
993
+ const a = `SELECT * FROM ${s} WHERE _id = :id`, u = `SELECT * FROM ${s}`, y = { id: n };
992
994
  o.userSubscription = r.sync.registerSubscription(
993
- c,
995
+ a,
994
996
  y
995
997
  ), o.userObserver = r.store.registerObserver(
996
- c,
998
+ a,
997
999
  (g) => {
998
1000
  e({ currentUser: g.items?.[0]?.value });
999
1001
  },
1000
1002
  y
1001
- ), o.allUsersSubscription = r.sync.registerSubscription(a), o.allUsersObserver = r.store.registerObserver(
1002
- a,
1003
+ ), o.allUsersSubscription = r.sync.registerSubscription(u), o.allUsersObserver = r.store.registerObserver(
1004
+ u,
1003
1005
  (g) => {
1004
1006
  e({
1005
- allUsers: g.items.map((p) => p.value),
1007
+ allUsers: g.items.map((w) => w.value),
1006
1008
  usersLoading: !1
1007
1009
  });
1008
1010
  }
1009
1011
  );
1010
1012
  }
1011
1013
  return o;
1012
- }, Ie = 30, ft = 1e4, G = 282, mt = (e, t, {
1014
+ }, Se = 30, lt = 1e4, W = 282, ft = (e, t, {
1013
1015
  ditto: r,
1014
1016
  userId: n,
1015
1017
  userCollectionKey: s,
1016
- retentionDays: o,
1017
- notificationHandler: c
1018
+ retention: o,
1019
+ notificationHandler: a
1018
1020
  }) => {
1019
- const a = async (i) => {
1021
+ const u = async (i) => {
1020
1022
  if (!r)
1021
1023
  throw new Error("Ditto not initialized");
1022
- const u = await r.store.execute(
1024
+ const c = await r.store.execute(
1023
1025
  `SELECT * FROM ${i.collectionId || "rooms"} WHERE _id = :id`,
1024
1026
  { id: i._id }
1025
1027
  );
1026
- if (u.items.length === 0)
1028
+ if (c.items.length === 0)
1027
1029
  throw new Error("Room not found");
1028
- return u.items[0].value;
1030
+ return c.items[0].value;
1029
1031
  }, y = async () => {
1030
1032
  if (!r || !n)
1031
1033
  throw new Error("Ditto not initialized or user not found");
1032
- const u = (await r.store.execute(
1034
+ const c = (await r.store.execute(
1033
1035
  `SELECT * FROM ${s} WHERE _id = :id`,
1034
1036
  { id: n }
1035
1037
  )).items?.[0]?.value;
1036
1038
  return {
1037
1039
  id: n,
1038
- name: u?.name ?? n
1040
+ name: c?.name ?? n
1039
1041
  };
1040
1042
  }, g = () => {
1041
- e((i) => C(i, (u) => {
1042
- u.messagesLoading = !u.rooms.every(
1043
- (l) => l._id in u.messagesByRoom
1043
+ e((i) => M(i, (c) => {
1044
+ c.messagesLoading = !c.rooms.every(
1045
+ (l) => l._id in c.messagesByRoom
1044
1046
  );
1045
1047
  }));
1046
- }, p = (i, u, l, f) => {
1047
- const d = {
1048
+ }, w = (i, c, l, m) => {
1049
+ const f = {
1048
1050
  message: l,
1049
- user: f,
1051
+ user: m,
1050
1052
  id: l._id
1051
- }, m = {
1052
- ...d,
1053
- message: d.message,
1054
- user: d.user
1053
+ }, d = {
1054
+ ...f,
1055
+ message: f.message,
1056
+ user: f.user
1055
1057
  }, b = i.findIndex((h) => h.id === l._id);
1056
- if (b === -1 && !l.archivedMessage && S(l, u) && c && t().activeRoomId !== u._id) {
1057
- const _ = f?.name || "Unknown User", w = u.name, D = u.collectionId === "dm_rooms" ? `New message from ${_}` : `#${w}: ${_}`, A = l.text ? l.text.substring(0, 30) + (l.text.length > 30 ? "..." : "") : "Sent an attachment";
1058
- c(D, A);
1058
+ if (b === -1 && !l.archivedMessage && O(l, c) && a && t().activeRoomId !== c._id) {
1059
+ const _ = m?.name || "Unknown User", T = c.name, R = c.collectionId === "dm_rooms" ? `New message from ${_}` : `#${T}: ${_}`, D = l.text ? l.text.substring(0, 30) + (l.text.length > 30 ? "..." : "") : "Sent an attachment";
1060
+ a(R, D);
1059
1061
  }
1060
1062
  if (l.archivedMessage) {
1061
1063
  const h = i.findIndex(
1062
1064
  (_) => _.id === l.archivedMessage
1063
1065
  );
1064
- h !== -1 ? i[h] = m : b === -1 ? i.push(m) : i[b] = m;
1066
+ h !== -1 ? i[h] = d : b === -1 ? i.push(d) : i[b] = d;
1065
1067
  } else
1066
- b === -1 ? i.push(m) : i[b] = m;
1067
- }, S = (i, u) => {
1068
- const f = t().currentUser, d = i.userId === f?._id, m = new Date(i.createdOn).getTime() > Date.now() - ft, b = f?.subscriptions?.[u._id], h = i.mentions?.some(
1069
- (w) => w.userId === f?._id
1070
- ), _ = u.collectionId === "dm_rooms";
1071
- return !d && m && (b || _ || h);
1072
- }, x = async (i, u, l = "") => {
1068
+ b === -1 ? i.push(d) : i[b] = d;
1069
+ }, O = (i, c) => {
1070
+ const m = t().currentUser, f = i.userId === m?._id, d = new Date(i.createdOn).getTime() > Date.now() - lt, b = m?.subscriptions?.[c._id], h = i.mentions?.some(
1071
+ (T) => T.userId === m?._id
1072
+ ), _ = c.collectionId === "dm_rooms";
1073
+ return !f && d && (b || _ || h);
1074
+ }, N = async (i, c, l = "") => {
1073
1075
  if (!r || !n)
1074
1076
  throw new Error("Ditto not initialized or user not found");
1075
- const f = await a(i), d = u._id || Ne(), m = {
1076
- _id: d,
1077
+ const m = await u(i), f = c._id || Pe(), d = {
1078
+ _id: f,
1077
1079
  roomId: i._id,
1078
1080
  userId: n,
1079
1081
  createdOn: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1084,76 +1086,76 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1084
1086
  fileAttachmentToken: null,
1085
1087
  isEdited: !1,
1086
1088
  isDeleted: !1,
1087
- ...u,
1088
- mentions: u.mentions?.map((h) => ({ ...h })) || [],
1089
- reactions: u.reactions?.map((h) => ({ ...h })) || []
1090
- }, b = l ? `COLLECTION ${f.messagesId} ${l}` : f.messagesId;
1089
+ ...c,
1090
+ mentions: c.mentions?.map((h) => ({ ...h })) || [],
1091
+ reactions: c.reactions?.map((h) => ({ ...h })) || []
1092
+ }, b = l ? `COLLECTION ${m.messagesId} ${l}` : m.messagesId;
1091
1093
  if (await r.store.execute(
1092
1094
  `INSERT INTO ${b} DOCUMENTS (:newDoc) ON ID CONFLICT DO UPDATE`,
1093
- { newDoc: m }
1094
- ), u.mentions && u.mentions.length > 0) {
1095
+ { newDoc: d }
1096
+ ), c.mentions && c.mentions.length > 0) {
1095
1097
  const h = t().allUsers;
1096
1098
  await Promise.all(
1097
- u.mentions.map((_) => {
1098
- const w = h.find((D) => D._id === _.userId);
1099
- if (!w)
1099
+ c.mentions.map((_) => {
1100
+ const T = h.find((R) => R._id === _.userId);
1101
+ if (!T)
1100
1102
  return;
1101
- const R = {
1102
- ...w.mentions || {},
1103
- [i._id]: [...w.mentions?.[i._id] || [], d]
1103
+ const I = {
1104
+ ...T.mentions || {},
1105
+ [i._id]: [...T.mentions?.[i._id] || [], f]
1104
1106
  };
1105
1107
  return r.store.execute(
1106
1108
  "UPDATE users SET mentions = :mentions WHERE _id = :id",
1107
- { id: w._id, mentions: R }
1109
+ { id: T._id, mentions: I }
1108
1110
  );
1109
1111
  })
1110
1112
  );
1111
1113
  }
1112
- return m;
1113
- }, H = async (i, u, l) => {
1114
+ return d;
1115
+ }, H = async (i, c, l) => {
1114
1116
  if (!r)
1115
1117
  throw new Error("Ditto not initialized");
1116
1118
  return await r.store.execute(
1117
- `UPDATE ${u.messagesId} SET isArchived = :isArchived WHERE _id = :id`,
1119
+ `UPDATE ${c.messagesId} SET isArchived = :isArchived WHERE _id = :id`,
1118
1120
  { id: i._id, isArchived: !0 }
1119
- ), x(u, {
1121
+ ), N(c, {
1120
1122
  text: "",
1121
1123
  createdOn: i.createdOn,
1122
1124
  archivedMessage: i._id,
1123
1125
  ...l
1124
1126
  });
1125
- }, de = async (i, u, l, f) => {
1127
+ }, de = async (i, c, l, m) => {
1126
1128
  if (!r || !n)
1127
1129
  throw new Error("Ditto not initialized or user not found");
1128
- const d = await y(), m = {
1130
+ const f = await y(), d = {
1129
1131
  thumbnailImageToken: null,
1130
1132
  largeImageToken: null,
1131
1133
  fileAttachmentToken: null
1132
1134
  };
1133
- if (f === "image") {
1134
- const h = await dt(u), _ = await De(h), w = new Uint8Array(await _.arrayBuffer());
1135
- m.thumbnailImageToken = await r.store.newAttachment(
1136
- w,
1137
- se(d.id, d.name, "thumbnail", u)
1135
+ if (m === "image") {
1136
+ const h = await dt(c), _ = await Ie(h), T = new Uint8Array(await _.arrayBuffer());
1137
+ d.thumbnailImageToken = await r.store.newAttachment(
1138
+ T,
1139
+ ne(f.id, f.name, "thumbnail", c)
1138
1140
  );
1139
- const R = await De(await ke(u)), D = new Uint8Array(await R.arrayBuffer());
1140
- m.largeImageToken = await r.store.newAttachment(
1141
- D,
1142
- se(d.id, d.name, "large", u)
1141
+ const I = await Ie(await xe(c)), R = new Uint8Array(await I.arrayBuffer());
1142
+ d.largeImageToken = await r.store.newAttachment(
1143
+ R,
1144
+ ne(f.id, f.name, "large", c)
1143
1145
  );
1144
1146
  } else {
1145
- const h = new Uint8Array(await u.arrayBuffer());
1146
- m.fileAttachmentToken = await r.store.newAttachment(
1147
+ const h = new Uint8Array(await c.arrayBuffer());
1148
+ d.fileAttachmentToken = await r.store.newAttachment(
1147
1149
  h,
1148
- se(d.id, d.name, "file", u)
1150
+ ne(f.id, f.name, "file", c)
1149
1151
  );
1150
1152
  }
1151
- const b = f === "image" ? "(thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT)" : "(fileAttachmentToken ATTACHMENT)";
1152
- await x(
1153
+ const b = m === "image" ? "(thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT)" : "(fileAttachmentToken ATTACHMENT)";
1154
+ await N(
1153
1155
  i,
1154
1156
  {
1155
- text: l || (f === "file" ? u.name : ""),
1156
- ...m
1157
+ text: l || (m === "file" ? c.name : ""),
1158
+ ...d
1157
1159
  },
1158
1160
  b
1159
1161
  );
@@ -1191,50 +1193,61 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1191
1193
  * 5. Triggers notifications for new messages from other users
1192
1194
  *
1193
1195
  * @param room - Room to subscribe to messages for
1194
- * @param retentionDays - Optional override for message retention period
1196
+ * @param retention - Optional override for message retention configuration
1195
1197
  */
1196
- async messagesPublisher(i, u) {
1198
+ async messagesPublisher(i, c) {
1197
1199
  if (!r)
1198
1200
  return;
1199
1201
  const l = i._id;
1200
1202
  if (t().messageSubscriptionsByRoom[l])
1201
1203
  return;
1202
- const f = u ?? i.retentionDays ?? o ?? Ie, d = new Date(
1203
- Date.now() - f * 24 * 60 * 60 * 1e3
1204
- ), m = `SELECT * FROM COLLECTION ${i.messagesId} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1205
- WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
1206
- ORDER BY createdOn ASC`, b = {
1207
- roomId: i._id,
1208
- date: d.toISOString()
1209
- };
1204
+ const m = c?.retainIndefinitely ?? i.retention?.retainIndefinitely ?? o?.retainIndefinitely ?? !1;
1205
+ let f, d;
1206
+ if (m)
1207
+ f = `SELECT * FROM COLLECTION ${i.messagesId} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1208
+ WHERE roomId = :roomId AND isArchived = false
1209
+ ORDER BY createdOn ASC`, d = {
1210
+ roomId: i._id
1211
+ };
1212
+ else {
1213
+ const b = c?.days ?? i.retention?.days ?? o?.days ?? Se, h = new Date(
1214
+ Date.now() - b * 24 * 60 * 60 * 1e3
1215
+ );
1216
+ f = `SELECT * FROM COLLECTION ${i.messagesId} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1217
+ WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
1218
+ ORDER BY createdOn ASC`, d = {
1219
+ roomId: i._id,
1220
+ date: h.toISOString()
1221
+ };
1222
+ }
1210
1223
  try {
1211
- const h = r.sync.registerSubscription(m, b), _ = t().allUsers, w = r.store.registerObserver(
1212
- m,
1213
- async (R) => {
1214
- e((D) => C(D, (A) => {
1215
- if (A.messagesByRoom[i._id] || (A.messagesByRoom[i._id] = []), R.items.length === 0)
1216
- return A;
1217
- for (const v of R.items) {
1218
- const $ = v.value, j = A.messagesByRoom[i._id], Z = _.find((K) => K._id === $.userId);
1219
- p(j, i, $, Z);
1224
+ const b = r.sync.registerSubscription(f, d), h = t().allUsers, _ = r.store.registerObserver(
1225
+ f,
1226
+ async (T) => {
1227
+ e((I) => M(I, (R) => {
1228
+ if (R.messagesByRoom[i._id] || (R.messagesByRoom[i._id] = []), T.items.length === 0)
1229
+ return R;
1230
+ for (const D of T.items) {
1231
+ const L = D.value, $ = R.messagesByRoom[i._id], Z = h.find((J) => J._id === L.userId);
1232
+ w($, i, L, Z);
1220
1233
  }
1221
- return A;
1234
+ return R;
1222
1235
  })), g();
1223
1236
  },
1224
- b
1237
+ d
1225
1238
  );
1226
1239
  e({
1227
1240
  messageSubscriptionsByRoom: {
1228
1241
  ...t().messageSubscriptionsByRoom,
1229
- [l]: h
1242
+ [l]: b
1230
1243
  },
1231
1244
  messageObserversByRoom: {
1232
1245
  ...t().messageObserversByRoom,
1233
- [l]: w
1246
+ [l]: _
1234
1247
  }
1235
1248
  });
1236
- } catch (h) {
1237
- console.error("Error in messagesPublisher:", h);
1249
+ } catch (b) {
1250
+ console.error("Error in messagesPublisher:", b);
1238
1251
  }
1239
1252
  },
1240
1253
  /**
@@ -1254,56 +1267,67 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1254
1267
  *
1255
1268
  * @param roomId - Room ID to subscribe to
1256
1269
  * @param messagesId - Collection ID for messages ("messages" or "dm_messages")
1257
- * @param retentionDays - Optional message retention override
1270
+ * @param retention - Optional message retention configuration override
1258
1271
  */
1259
- async subscribeToRoomMessages(i, u, l) {
1272
+ async subscribeToRoomMessages(i, c, l) {
1260
1273
  if (!r || t().messageSubscriptionsByRoom[i])
1261
1274
  return;
1262
- const f = l ?? o ?? Ie, d = new Date(
1263
- Date.now() - f * 24 * 60 * 60 * 1e3
1264
- ), m = `SELECT * FROM COLLECTION ${u} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1265
- WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
1266
- ORDER BY createdOn ASC`, b = {
1267
- roomId: i,
1268
- date: d.toISOString()
1269
- };
1275
+ const m = l?.retainIndefinitely ?? o?.retainIndefinitely ?? !1;
1276
+ let f, d;
1277
+ if (m)
1278
+ f = `SELECT * FROM COLLECTION ${c} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1279
+ WHERE roomId = :roomId AND isArchived = false
1280
+ ORDER BY createdOn ASC`, d = {
1281
+ roomId: i
1282
+ };
1283
+ else {
1284
+ const b = l?.days ?? o?.days ?? Se, h = new Date(
1285
+ Date.now() - b * 24 * 60 * 60 * 1e3
1286
+ );
1287
+ f = `SELECT * FROM COLLECTION ${c} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
1288
+ WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
1289
+ ORDER BY createdOn ASC`, d = {
1290
+ roomId: i,
1291
+ date: h.toISOString()
1292
+ };
1293
+ }
1270
1294
  try {
1271
- const h = r.sync.registerSubscription(m, b), _ = t().allUsers, w = r.store.registerObserver(
1272
- m,
1273
- async (R) => {
1274
- const D = {
1295
+ const b = r.sync.registerSubscription(f, d), h = t().allUsers, _ = r.store.registerObserver(
1296
+ f,
1297
+ async (T) => {
1298
+ const I = {
1275
1299
  _id: i,
1276
1300
  name: "",
1277
- messagesId: u,
1301
+ messagesId: c,
1278
1302
  collectionId: "rooms",
1279
1303
  createdBy: "",
1280
1304
  createdOn: "",
1281
1305
  isGenerated: !0
1282
1306
  };
1283
- e((A) => C(A, (v) => {
1284
- if (v.messagesByRoom[i] || (v.messagesByRoom[i] = []), R.items.length === 0)
1285
- return v;
1286
- for (const $ of R.items) {
1287
- const j = $.value, Z = v.messagesByRoom[i], K = _.find((Be) => Be._id === j.userId);
1288
- p(Z, D, j, K);
1307
+ e((R) => M(R, (D) => {
1308
+ if (D.messagesByRoom[i] || (D.messagesByRoom[i] = []), T.items.length === 0)
1309
+ return D;
1310
+ for (const L of T.items) {
1311
+ const $ = L.value, Z = D.messagesByRoom[i], J = h.find((ke) => ke._id === $.userId);
1312
+ w(Z, I, $, J);
1289
1313
  }
1290
- return v;
1314
+ return D;
1291
1315
  })), g();
1292
1316
  },
1293
- b
1317
+ d
1294
1318
  );
1295
1319
  e({
1296
1320
  messageSubscriptionsByRoom: {
1297
1321
  ...t().messageSubscriptionsByRoom,
1298
- [i]: h
1322
+ [i]: b
1299
1323
  },
1300
1324
  messageObserversByRoom: {
1301
1325
  ...t().messageObserversByRoom,
1302
- [i]: w
1326
+ [i]: _
1303
1327
  }
1304
1328
  });
1305
- } catch (h) {
1306
- console.error("Error in subscribeToRoomMessages:", h);
1329
+ } catch (b) {
1330
+ console.error("Error in subscribeToRoomMessages:", b);
1307
1331
  }
1308
1332
  },
1309
1333
  /**
@@ -1324,8 +1348,8 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1324
1348
  * @param roomId - Room ID to unsubscribe from
1325
1349
  */
1326
1350
  unsubscribeFromRoomMessages(i) {
1327
- const u = t().messageSubscriptionsByRoom[i], l = t().messageObserversByRoom[i];
1328
- u && !u.isCancelled && u.cancel(), l && !l.isCancelled && l.cancel(), e((f) => C(f, (d) => (delete d.messagesByRoom[i], delete d.messageSubscriptionsByRoom[i], delete d.messageObserversByRoom[i], d)));
1351
+ const c = t().messageSubscriptionsByRoom[i], l = t().messageObserversByRoom[i];
1352
+ c && !c.isCancelled && c.cancel(), l && !l.isCancelled && l.cancel(), e((m) => M(m, (f) => (delete f.messagesByRoom[i], delete f.messageSubscriptionsByRoom[i], delete f.messageObserversByRoom[i], f)));
1329
1353
  },
1330
1354
  /**
1331
1355
  * Create a new text message in a room.
@@ -1343,18 +1367,18 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1343
1367
  * @param text - Message text content
1344
1368
  * @param mentions - Optional array of user mentions
1345
1369
  */
1346
- async createMessage(i, u, l = []) {
1370
+ async createMessage(i, c, l = []) {
1347
1371
  if (!r || !n)
1348
1372
  return;
1349
- const f = t().canPerformAction("canMentionUsers"), d = l.length > 0 && !f ? [] : l;
1350
- l.length > 0 && !f && console.warn("Permission denied: canMentionUsers is false");
1373
+ const m = t().canPerformAction("canMentionUsers"), f = l.length > 0 && !m ? [] : l;
1374
+ l.length > 0 && !m && console.warn("Permission denied: canMentionUsers is false");
1351
1375
  try {
1352
- await x(i, {
1353
- text: u,
1354
- mentions: d
1376
+ await N(i, {
1377
+ text: c,
1378
+ mentions: f
1355
1379
  });
1356
- } catch (m) {
1357
- console.error("Error in createMessage:", m);
1380
+ } catch (d) {
1381
+ console.error("Error in createMessage:", d);
1358
1382
  }
1359
1383
  },
1360
1384
  /**
@@ -1372,13 +1396,13 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1372
1396
  * @param message - Message with updated text content
1373
1397
  * @param room - Room containing the message
1374
1398
  */
1375
- async saveEditedTextMessage(i, u) {
1399
+ async saveEditedTextMessage(i, c) {
1376
1400
  if (!t().canPerformAction("canEditOwnMessage")) {
1377
1401
  console.warn("Permission denied: canEditOwnMessage is false");
1378
1402
  return;
1379
1403
  }
1380
1404
  try {
1381
- await H(i, u, {
1405
+ await H(i, c, {
1382
1406
  text: i.text,
1383
1407
  largeImageToken: i.largeImageToken || null,
1384
1408
  thumbnailImageToken: i.thumbnailImageToken || null,
@@ -1408,19 +1432,19 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1408
1432
  * @param room - Room containing the message
1409
1433
  * @param type - Type of content: 'text', 'image', or 'file'
1410
1434
  */
1411
- async saveDeletedMessage(i, u, l = "text") {
1435
+ async saveDeletedMessage(i, c, l = "text") {
1412
1436
  if (!t().canPerformAction("canDeleteOwnMessage")) {
1413
1437
  console.warn("Permission denied: canDeleteOwnMessage is false");
1414
1438
  return;
1415
1439
  }
1416
- const f = {
1440
+ const m = {
1417
1441
  text: "[deleted message]",
1418
1442
  image: "[deleted image]",
1419
1443
  file: "[deleted file]"
1420
1444
  }[l];
1421
1445
  try {
1422
- await H(i, u, {
1423
- text: f,
1446
+ await H(i, c, {
1447
+ text: m,
1424
1448
  createdOn: (/* @__PURE__ */ new Date()).toISOString(),
1425
1449
  largeImageToken: null,
1426
1450
  thumbnailImageToken: null,
@@ -1429,8 +1453,8 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1429
1453
  isDeleted: !0,
1430
1454
  mentions: []
1431
1455
  });
1432
- } catch (d) {
1433
- console.error("Error in saveDeletedMessage:", d);
1456
+ } catch (f) {
1457
+ console.error("Error in saveDeletedMessage:", f);
1434
1458
  }
1435
1459
  },
1436
1460
  /**
@@ -1448,11 +1472,11 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1448
1472
  * @param imageFile - Image file to attach
1449
1473
  * @param text - Optional caption text
1450
1474
  */
1451
- async createImageMessage(i, u, l) {
1475
+ async createImageMessage(i, c, l) {
1452
1476
  try {
1453
- await de(i, u, l, "image");
1454
- } catch (f) {
1455
- console.error("Error in createImageMessage:", f);
1477
+ await de(i, c, l, "image");
1478
+ } catch (m) {
1479
+ console.error("Error in createImageMessage:", m);
1456
1480
  }
1457
1481
  },
1458
1482
  /**
@@ -1470,11 +1494,11 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1470
1494
  * @param file - File to attach
1471
1495
  * @param text - Optional text (defaults to filename)
1472
1496
  */
1473
- async createFileMessage(i, u, l) {
1497
+ async createFileMessage(i, c, l) {
1474
1498
  try {
1475
- await de(i, u, l, "file");
1476
- } catch (f) {
1477
- console.error("Error in createFileMessage:", f);
1499
+ await de(i, c, l, "file");
1500
+ } catch (m) {
1501
+ console.error("Error in createFileMessage:", m);
1478
1502
  }
1479
1503
  },
1480
1504
  /**
@@ -1495,7 +1519,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1495
1519
  * @param onComplete - Callback receiving AttachmentResult
1496
1520
  * @returns The fetcher object from the SDK for cleanup
1497
1521
  */
1498
- fetchAttachment(i, u, l) {
1522
+ fetchAttachment(i, c, l) {
1499
1523
  if (!r) {
1500
1524
  l({
1501
1525
  success: !1,
@@ -1511,41 +1535,40 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1511
1535
  return;
1512
1536
  }
1513
1537
  try {
1514
- const f = i.id || JSON.stringify(i);
1515
- return r.store.fetchAttachment(i, async (m) => {
1516
- switch (m.type) {
1538
+ return r.store.fetchAttachment(i, async (f) => {
1539
+ switch (f.type) {
1517
1540
  case "Progress": {
1518
- const b = Number(m.downloadedBytes) / (Number(m.totalBytes) || 1);
1519
- u(b);
1541
+ const d = Number(f.downloadedBytes) / (Number(f.totalBytes) || 1);
1542
+ c(d);
1520
1543
  break;
1521
1544
  }
1522
1545
  case "Completed":
1523
1546
  try {
1524
- const b = m.attachment.getData(), h = b instanceof Promise ? await b : b;
1547
+ const d = f.attachment.getData(), b = d instanceof Promise ? await d : d;
1525
1548
  l({
1526
1549
  success: !0,
1527
- data: h,
1528
- metadata: m.attachment.metadata || {}
1550
+ data: b,
1551
+ metadata: f.attachment.metadata || {}
1529
1552
  });
1530
- } catch (b) {
1553
+ } catch (d) {
1531
1554
  l({
1532
1555
  success: !1,
1533
- error: b instanceof Error ? b : new Error("Unknown error getting attachment data")
1556
+ error: d instanceof Error ? d : new Error("Unknown error getting attachment data")
1534
1557
  });
1535
1558
  }
1536
1559
  break;
1537
1560
  case "Deleted":
1538
- console.warn(`[useMessages] Attachment reported as DELETED: ${f}`), l({
1561
+ l({
1539
1562
  success: !1,
1540
1563
  error: new Error("Attachment was deleted")
1541
1564
  });
1542
1565
  break;
1543
1566
  }
1544
1567
  });
1545
- } catch (f) {
1568
+ } catch (m) {
1546
1569
  return l({
1547
1570
  success: !1,
1548
- error: f instanceof Error ? f : new Error("Failed to fetch attachment")
1571
+ error: m instanceof Error ? m : new Error("Failed to fetch attachment")
1549
1572
  }), null;
1550
1573
  }
1551
1574
  },
@@ -1575,27 +1598,27 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1575
1598
  * @param room - The room containing the message
1576
1599
  * @param reactions - The new array of reactions to apply
1577
1600
  */
1578
- async updateMessageReactions(i, u, l) {
1601
+ async updateMessageReactions(i, c, l) {
1579
1602
  if (!r || !n)
1580
1603
  return;
1581
- const f = u._id, d = t().messagesByRoom[f] || [], m = d.findIndex((_) => _.id === i._id);
1582
- if (m === -1)
1604
+ const m = c._id, f = t().messagesByRoom[m] || [], d = f.findIndex((_) => _.id === i._id);
1605
+ if (d === -1)
1583
1606
  throw new Error("Message not found");
1584
- const b = d[m].message, h = b.reactions || [];
1607
+ const b = f[d].message, h = b.reactions || [];
1585
1608
  e(
1586
- (_) => C(_, (w) => {
1587
- w.messagesByRoom[f][m].message.reactions = l;
1609
+ (_) => M(_, (T) => {
1610
+ T.messagesByRoom[m][d].message.reactions = l;
1588
1611
  })
1589
1612
  ), setTimeout(async () => {
1590
1613
  try {
1591
1614
  await r.store.execute(
1592
- `UPDATE ${u.messagesId} SET reactions = :reactions WHERE _id = :id`,
1615
+ `UPDATE ${c.messagesId} SET reactions = :reactions WHERE _id = :id`,
1593
1616
  { id: b._id, reactions: l }
1594
1617
  );
1595
1618
  } catch (_) {
1596
1619
  console.error("Error updating reactions, rolling back:", _), e(
1597
- (w) => C(w, (R) => {
1598
- R.messagesByRoom[f][m].message.reactions = h;
1620
+ (T) => M(T, (I) => {
1621
+ I.messagesByRoom[m][d].message.reactions = h;
1599
1622
  })
1600
1623
  );
1601
1624
  }
@@ -1617,18 +1640,18 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1617
1640
  * @param room - Room containing the message
1618
1641
  * @param reaction - Reaction object with emoji and userId
1619
1642
  */
1620
- async addReactionToMessage(i, u, l) {
1643
+ async addReactionToMessage(i, c, l) {
1621
1644
  if (!r || !n)
1622
1645
  return;
1623
1646
  if (!t().canPerformAction("canAddReaction")) {
1624
1647
  console.warn("Permission denied: canAddReaction is false");
1625
1648
  return;
1626
1649
  }
1627
- const f = t().messagesByRoom[u._id], d = f.findIndex((h) => h.id === i._id);
1628
- if (d === -1)
1650
+ const m = t().messagesByRoom[c._id], f = m.findIndex((h) => h.id === i._id);
1651
+ if (f === -1)
1629
1652
  throw new Error("Message not found");
1630
- const m = f[d].message, b = [...m.reactions || [], l];
1631
- await t().updateMessageReactions(m, u, b);
1653
+ const d = m[f].message, b = [...d.reactions || [], l];
1654
+ await t().updateMessageReactions(d, c, b);
1632
1655
  },
1633
1656
  /**
1634
1657
  * Remove a reaction from a message.
@@ -1646,31 +1669,31 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
1646
1669
  * @param room - Room containing the message
1647
1670
  * @param reaction - Reaction to remove (matched by emoji and userId)
1648
1671
  */
1649
- async removeReactionFromMessage(i, u, l) {
1672
+ async removeReactionFromMessage(i, c, l) {
1650
1673
  if (!r || !n)
1651
1674
  return;
1652
1675
  if (!t().canPerformAction("canRemoveOwnReaction")) {
1653
1676
  console.warn("Permission denied: canRemoveOwnReaction is false");
1654
1677
  return;
1655
1678
  }
1656
- const f = t().messagesByRoom[u._id], d = f.findIndex((h) => h.id === i._id);
1657
- if (d === -1)
1679
+ const m = t().messagesByRoom[c._id], f = m.findIndex((h) => h.id === i._id);
1680
+ if (f === -1)
1658
1681
  throw new Error("Message not found");
1659
- const m = f[d].message, b = (m.reactions || []).filter(
1682
+ const d = m[f].message, b = (d.reactions || []).filter(
1660
1683
  (h) => !(h.emoji === l.emoji && h.userId === l.userId)
1661
1684
  );
1662
- await t().updateMessageReactions(m, u, b);
1685
+ await t().updateMessageReactions(d, c, b);
1663
1686
  }
1664
1687
  };
1665
1688
  };
1666
1689
  async function dt(e) {
1667
- const t = await ke(e), r = document.createElement("canvas"), n = r.getContext("2d");
1690
+ const t = await xe(e), r = document.createElement("canvas"), n = r.getContext("2d");
1668
1691
  if (!n)
1669
1692
  throw new Error("Failed to get 2D context");
1670
1693
  let { width: s, height: o } = t;
1671
- return s > o ? (o = G / s * o, s = G) : (s = G / o * s, o = G), r.width = s, r.height = o, n.drawImage(t, 0, 0, s, o), r;
1694
+ return s > o ? (o = W / s * o, s = W) : (s = W / o * s, o = W), r.width = s, r.height = o, n.drawImage(t, 0, 0, s, o), r;
1672
1695
  }
1673
- function ke(e) {
1696
+ function xe(e) {
1674
1697
  return new Promise((t, r) => {
1675
1698
  const n = new FileReader();
1676
1699
  n.onload = (s) => {
@@ -1679,7 +1702,7 @@ function ke(e) {
1679
1702
  }, n.onerror = r, n.readAsDataURL(e);
1680
1703
  });
1681
1704
  }
1682
- async function De(e) {
1705
+ async function Ie(e) {
1683
1706
  return new Promise((t, r) => {
1684
1707
  const n = (s) => {
1685
1708
  s.toBlob(
@@ -1702,65 +1725,65 @@ async function De(e) {
1702
1725
  }
1703
1726
  });
1704
1727
  }
1705
- function se(e, t, r, n) {
1706
- const s = (/* @__PURE__ */ new Date()).toISOString(), o = t.replace(/\s/g, "-"), c = s.replace(/:/g, "-"), a = r === "file" ? n.name.split(".").pop() || "bin" : "jpg";
1728
+ function ne(e, t, r, n) {
1729
+ const s = (/* @__PURE__ */ new Date()).toISOString(), o = t.replace(/\s/g, "-"), a = s.replace(/:/g, "-"), u = r === "file" ? n.name.split(".").pop() || "bin" : "jpg";
1707
1730
  return {
1708
- filename: `${o}_${r}_${c}.${a}`,
1731
+ filename: `${o}_${r}_${a}.${u}`,
1709
1732
  userId: e,
1710
1733
  username: t,
1711
- fileformat: `.${a}`,
1734
+ fileformat: `.${u}`,
1712
1735
  filesize: n.size.toString(),
1713
1736
  timestamp: s,
1714
1737
  originalName: n.name
1715
1738
  };
1716
1739
  }
1717
- function I(e) {
1740
+ function A(e) {
1718
1741
  e && !e.isCancelled && e.cancel();
1719
1742
  }
1720
- function ht(e) {
1721
- const t = Fe(() => (globalThis.__DITTO_CHAT_STORE__ ? console.log("Reusing EXISTING global chatStore instance") : (console.log("Creating NEW global chatStore instance"), globalThis.__DITTO_CHAT_STORE__ = ot()(
1743
+ function gt(e) {
1744
+ const t = Be(() => (globalThis.__DITTO_CHAT_STORE__ || (globalThis.__DITTO_CHAT_STORE__ = st()(
1722
1745
  (r, n) => ({
1723
- ...st(r, n, e),
1724
- ...lt(r, n, e),
1725
- ...mt(r, n, e),
1726
- ...Le(r, n, e),
1746
+ ...nt(r, n, e),
1747
+ ...ut(r, n, e),
1748
+ ...ft(r, n, e),
1749
+ ...ze(r, n, e),
1727
1750
  activeRoomId: null,
1728
1751
  setActiveRoomId: (s) => r({ activeRoomId: s }),
1729
1752
  chatLogout: () => {
1730
1753
  const s = n();
1731
- I(s.roomsSubscription), I(s.roomsObserver), I(s.dmRoomsSubscription), I(s.dmRoomsObserver), Object.values(s.messageSubscriptionsByRoom || {}).map(
1732
- (o) => I(o)
1754
+ A(s.roomsSubscription), A(s.roomsObserver), A(s.dmRoomsSubscription), A(s.dmRoomsObserver), Object.values(s.messageSubscriptionsByRoom || {}).map(
1755
+ (o) => A(o)
1733
1756
  ), Object.values(s.messageObserversByRoom || {}).map(
1734
- (o) => I(o)
1735
- ), I(s.userObserver), I(s.userSubscription), I(s.allUsersObserver), I(s.allUsersSubscription);
1757
+ (o) => A(o)
1758
+ ), A(s.userObserver), A(s.userSubscription), A(s.allUsersObserver), A(s.allUsersSubscription);
1736
1759
  }
1737
1760
  })
1738
1761
  )), globalThis.__DITTO_CHAT_STORE__), [e]);
1739
- return xe(t);
1762
+ return Ne(t);
1740
1763
  }
1741
- function bt(e) {
1764
+ function ht(e) {
1742
1765
  if (!globalThis.__DITTO_CHAT_STORE__)
1743
1766
  throw new Error(
1744
1767
  "chatStore must be initialized before useDittoChatStore. use useDittoChat for initialization"
1745
1768
  );
1746
- const t = ut(
1769
+ const t = ct(
1747
1770
  e || ((n) => n)
1748
1771
  );
1749
- return xe(globalThis.__DITTO_CHAT_STORE__, t);
1772
+ return Ne(globalThis.__DITTO_CHAT_STORE__, t);
1750
1773
  }
1751
- function _t() {
1774
+ function bt() {
1752
1775
  return globalThis.__DITTO_CHAT_STORE__;
1753
1776
  }
1754
- function wt() {
1777
+ function _t() {
1755
1778
  globalThis.__DITTO_CHAT_STORE__ = void 0;
1756
1779
  }
1757
1780
  export {
1758
- ze as DEFAULT_PERMISSIONS,
1759
- I as cancelSubscriptionOrObserver,
1760
- Le as createRBACSlice,
1761
- st as createRoomSlice,
1762
- _t as getChatStore,
1763
- wt as resetChatStore,
1764
- ht as useDittoChat,
1765
- bt as useDittoChatStore
1781
+ Fe as DEFAULT_PERMISSIONS,
1782
+ A as cancelSubscriptionOrObserver,
1783
+ ze as createRBACSlice,
1784
+ nt as createRoomSlice,
1785
+ bt as getChatStore,
1786
+ _t as resetChatStore,
1787
+ gt as useDittoChat,
1788
+ ht as useDittoChatStore
1766
1789
  };