@dittolive/ditto-chat-core 0.1.0 → 0.1.2
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 +238 -236
- package/dist/index.umd.js +3 -3
- package/dist/src/slices/useMessages.d.ts +2 -3
- package/dist/src/useChat.d.ts +3 -2
- package/package.json +9 -9
- package/src/index.ts +0 -9
package/dist/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ const ze = {
|
|
|
7
7
|
canRemoveOwnReaction: !0,
|
|
8
8
|
canMentionUsers: !0,
|
|
9
9
|
canSubscribeToRoom: !0
|
|
10
|
-
},
|
|
10
|
+
}, Le = (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
|
|
28
|
-
return
|
|
27
|
+
const c = t().rbacConfig[s];
|
|
28
|
+
return c !== void 0 ? c : ze[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 = Symbol.for("immer-nothing"), ye = Symbol.for("immer-draftable"), O = Symbol.for("immer-state"),
|
|
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" ? [
|
|
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.`;
|
|
@@ -82,7 +82,7 @@ var Ae = Symbol.for("immer-nothing"), ye = Symbol.for("immer-draftable"), O = Sy
|
|
|
82
82
|
] : [];
|
|
83
83
|
function T(e, ...t) {
|
|
84
84
|
if (process.env.NODE_ENV !== "production") {
|
|
85
|
-
const r =
|
|
85
|
+
const r = He[e], n = typeof r == "function" ? r.apply(null, t) : r;
|
|
86
86
|
throw new Error(`[Immer] ${n}`);
|
|
87
87
|
}
|
|
88
88
|
throw new Error(
|
|
@@ -94,7 +94,7 @@ function N(e) {
|
|
|
94
94
|
return !!e && !!e[O];
|
|
95
95
|
}
|
|
96
96
|
function U(e) {
|
|
97
|
-
return e ? ve(e) || Array.isArray(e) || !!e[ye] || !!e.constructor?.[ye] ||
|
|
97
|
+
return e ? ve(e) || Array.isArray(e) || !!e[ye] || !!e.constructor?.[ye] || L(e) || X(e) : !1;
|
|
98
98
|
}
|
|
99
99
|
var $e = Object.prototype.constructor.toString(), ge = /* @__PURE__ */ new WeakMap();
|
|
100
100
|
function ve(e) {
|
|
@@ -118,7 +118,7 @@ function q(e, t, r = !0) {
|
|
|
118
118
|
}
|
|
119
119
|
function V(e) {
|
|
120
120
|
const t = e[O];
|
|
121
|
-
return t ? t.type_ : Array.isArray(e) ? 1 :
|
|
121
|
+
return t ? t.type_ : Array.isArray(e) ? 1 : L(e) ? 2 : X(e) ? 3 : 0;
|
|
122
122
|
}
|
|
123
123
|
function oe(e, t) {
|
|
124
124
|
return V(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
|
|
@@ -130,7 +130,7 @@ function Me(e, t, r) {
|
|
|
130
130
|
function je(e, t) {
|
|
131
131
|
return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function L(e) {
|
|
134
134
|
return e instanceof Map;
|
|
135
135
|
}
|
|
136
136
|
function X(e) {
|
|
@@ -140,7 +140,7 @@ function M(e) {
|
|
|
140
140
|
return e.copy_ || e.base_;
|
|
141
141
|
}
|
|
142
142
|
function ie(e, t) {
|
|
143
|
-
if (
|
|
143
|
+
if (L(e))
|
|
144
144
|
return new Map(e);
|
|
145
145
|
if (X(e))
|
|
146
146
|
return new Set(e);
|
|
@@ -152,13 +152,13 @@ function ie(e, t) {
|
|
|
152
152
|
delete n[O];
|
|
153
153
|
let s = Reflect.ownKeys(n);
|
|
154
154
|
for (let o = 0; o < s.length; o++) {
|
|
155
|
-
const
|
|
156
|
-
|
|
155
|
+
const c = s[o], a = n[c];
|
|
156
|
+
a.writable === !1 && (a.writable = !0, a.configurable = !0), (a.get || a.set) && (n[c] = {
|
|
157
157
|
configurable: !0,
|
|
158
158
|
writable: !0,
|
|
159
159
|
// could live with !!desc.set as well here...
|
|
160
|
-
enumerable:
|
|
161
|
-
value: e[
|
|
160
|
+
enumerable: a.enumerable,
|
|
161
|
+
value: e[c]
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
return Object.create(B(e), n);
|
|
@@ -171,7 +171,7 @@ function ie(e, t) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
function fe(e, t = !1) {
|
|
174
|
-
return
|
|
174
|
+
return J(e) || N(e) || !U(e) || (V(e) > 1 && Object.defineProperties(e, {
|
|
175
175
|
set: W,
|
|
176
176
|
add: W,
|
|
177
177
|
clear: W,
|
|
@@ -184,7 +184,7 @@ function We() {
|
|
|
184
184
|
var W = {
|
|
185
185
|
value: We
|
|
186
186
|
};
|
|
187
|
-
function
|
|
187
|
+
function J(e) {
|
|
188
188
|
return e === null || typeof e != "object" ? !0 : Object.isFrozen(e);
|
|
189
189
|
}
|
|
190
190
|
var Ge = {};
|
|
@@ -210,10 +210,10 @@ function qe(e, t) {
|
|
|
210
210
|
function he(e, t) {
|
|
211
211
|
t && (P("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
|
|
212
212
|
}
|
|
213
|
-
function ae(e) {
|
|
214
|
-
ce(e), e.drafts_.forEach(Qe), e.drafts_ = null;
|
|
215
|
-
}
|
|
216
213
|
function ce(e) {
|
|
214
|
+
ae(e), e.drafts_.forEach(Qe), e.drafts_ = null;
|
|
215
|
+
}
|
|
216
|
+
function ae(e) {
|
|
217
217
|
e === F && (F = e.parent_);
|
|
218
218
|
}
|
|
219
219
|
function be(e) {
|
|
@@ -226,21 +226,21 @@ function Qe(e) {
|
|
|
226
226
|
function _e(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_ && (
|
|
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
230
|
r[O].base_,
|
|
231
231
|
e,
|
|
232
232
|
t.patches_,
|
|
233
233
|
t.inversePatches_
|
|
234
|
-
)) : e = Q(t, r, []),
|
|
234
|
+
)) : e = Q(t, r, []), ce(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== Ae ? e : void 0;
|
|
235
235
|
}
|
|
236
236
|
function Q(e, t, r) {
|
|
237
|
-
if (
|
|
237
|
+
if (J(t))
|
|
238
238
|
return t;
|
|
239
239
|
const n = e.immer_.shouldUseStrictIteration(), s = t[O];
|
|
240
240
|
if (!s)
|
|
241
241
|
return q(
|
|
242
242
|
t,
|
|
243
|
-
(o,
|
|
243
|
+
(o, c) => we(e, s, t, o, c, r),
|
|
244
244
|
n
|
|
245
245
|
), t;
|
|
246
246
|
if (s.scope_ !== e)
|
|
@@ -250,17 +250,17 @@ function Q(e, t, r) {
|
|
|
250
250
|
if (!s.finalized_) {
|
|
251
251
|
s.finalized_ = !0, s.scope_.unfinalizedDrafts_--;
|
|
252
252
|
const o = s.copy_;
|
|
253
|
-
let
|
|
254
|
-
s.type_ === 3 && (
|
|
255
|
-
|
|
256
|
-
(
|
|
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(
|
|
257
257
|
e,
|
|
258
258
|
s,
|
|
259
259
|
o,
|
|
260
|
-
d,
|
|
261
260
|
y,
|
|
261
|
+
g,
|
|
262
262
|
r,
|
|
263
|
-
|
|
263
|
+
a
|
|
264
264
|
),
|
|
265
265
|
n
|
|
266
266
|
), Y(e, o, !1), r && e.patches_ && P("Patches").generatePatches_(
|
|
@@ -272,23 +272,23 @@ function Q(e, t, r) {
|
|
|
272
272
|
}
|
|
273
273
|
return s.copy_;
|
|
274
274
|
}
|
|
275
|
-
function we(e, t, r, n, s, o,
|
|
276
|
-
if (s == null || typeof s != "object" && !
|
|
275
|
+
function we(e, t, r, n, s, o, c) {
|
|
276
|
+
if (s == null || typeof s != "object" && !c)
|
|
277
277
|
return;
|
|
278
|
-
const
|
|
279
|
-
if (!(
|
|
278
|
+
const a = J(s);
|
|
279
|
+
if (!(a && !c)) {
|
|
280
280
|
if (process.env.NODE_ENV !== "production" && s === r && T(5), N(s)) {
|
|
281
|
-
const
|
|
282
|
-
!oe(t.assigned_, n) ? o.concat(n) : void 0,
|
|
283
|
-
if (Me(r, n,
|
|
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))
|
|
284
284
|
e.canAutoFreeze_ = !1;
|
|
285
285
|
else
|
|
286
286
|
return;
|
|
287
|
-
} else
|
|
288
|
-
if (U(s) && !
|
|
289
|
-
if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1 || t && t.base_ && t.base_[n] === s &&
|
|
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)
|
|
290
290
|
return;
|
|
291
|
-
Q(e, s), (!t || !t.scope_.parent_) && typeof n != "symbol" && (
|
|
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);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
}
|
|
@@ -321,8 +321,8 @@ function Ye(e, t) {
|
|
|
321
321
|
};
|
|
322
322
|
let s = n, o = me;
|
|
323
323
|
r && (s = [n], o = z);
|
|
324
|
-
const { revoke:
|
|
325
|
-
return n.draft_ =
|
|
324
|
+
const { revoke: c, proxy: a } = Proxy.revocable(s, o);
|
|
325
|
+
return n.draft_ = a, n.revoke_ = c, a;
|
|
326
326
|
}
|
|
327
327
|
var me = {
|
|
328
328
|
get(e, t) {
|
|
@@ -429,43 +429,43 @@ var Xe = class {
|
|
|
429
429
|
if (typeof t == "function" && typeof r != "function") {
|
|
430
430
|
const o = r;
|
|
431
431
|
r = t;
|
|
432
|
-
const
|
|
433
|
-
return function(
|
|
434
|
-
return
|
|
432
|
+
const c = this;
|
|
433
|
+
return function(y = o, ...g) {
|
|
434
|
+
return c.produce(y, (p) => r.call(this, p, ...g));
|
|
435
435
|
};
|
|
436
436
|
}
|
|
437
437
|
typeof r != "function" && T(6), n !== void 0 && typeof n != "function" && T(7);
|
|
438
438
|
let s;
|
|
439
439
|
if (U(t)) {
|
|
440
|
-
const o = be(this),
|
|
441
|
-
let
|
|
440
|
+
const o = be(this), c = le(t, void 0);
|
|
441
|
+
let a = !0;
|
|
442
442
|
try {
|
|
443
|
-
s = r(
|
|
443
|
+
s = r(c), a = !1;
|
|
444
444
|
} finally {
|
|
445
|
-
|
|
445
|
+
a ? ce(o) : ae(o);
|
|
446
446
|
}
|
|
447
447
|
return he(o, n), _e(s, o);
|
|
448
448
|
} else if (!t || typeof t != "object") {
|
|
449
449
|
if (s = r(t), s === void 0 && (s = t), s === Ae && (s = void 0), this.autoFreeze_ && fe(s, !0), n) {
|
|
450
|
-
const o = [],
|
|
451
|
-
P("Patches").generateReplacementPatches_(t, s, o,
|
|
450
|
+
const o = [], c = [];
|
|
451
|
+
P("Patches").generateReplacementPatches_(t, s, o, c), n(o, c);
|
|
452
452
|
}
|
|
453
453
|
return s;
|
|
454
454
|
} else
|
|
455
455
|
T(1, t);
|
|
456
456
|
}, this.produceWithPatches = (t, r) => {
|
|
457
457
|
if (typeof t == "function")
|
|
458
|
-
return (
|
|
458
|
+
return (c, ...a) => this.produceWithPatches(c, (y) => t(y, ...a));
|
|
459
459
|
let n, s;
|
|
460
|
-
return [this.produce(t, r, (
|
|
461
|
-
n =
|
|
460
|
+
return [this.produce(t, r, (c, a) => {
|
|
461
|
+
n = c, s = a;
|
|
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 =
|
|
466
|
+
U(e) || T(8), N(e) && (e = Je(e));
|
|
467
467
|
const t = be(this), r = le(e, void 0);
|
|
468
|
-
return r[O].isManual_ = !0,
|
|
468
|
+
return r[O].isManual_ = !0, ae(t), r;
|
|
469
469
|
}
|
|
470
470
|
finishDraft(e, t) {
|
|
471
471
|
const r = e && e[O];
|
|
@@ -519,14 +519,14 @@ var Xe = class {
|
|
|
519
519
|
}
|
|
520
520
|
};
|
|
521
521
|
function le(e, t) {
|
|
522
|
-
const r =
|
|
522
|
+
const r = L(e) ? P("MapSet").proxyMap_(e, t) : X(e) ? P("MapSet").proxySet_(e, t) : Ye(e, t);
|
|
523
523
|
return (t ? t.scope_ : Ce()).drafts_.push(r), r;
|
|
524
524
|
}
|
|
525
|
-
function
|
|
525
|
+
function Je(e) {
|
|
526
526
|
return N(e) || T(10, e), Pe(e);
|
|
527
527
|
}
|
|
528
528
|
function Pe(e) {
|
|
529
|
-
if (!U(e) ||
|
|
529
|
+
if (!U(e) || J(e))
|
|
530
530
|
return e;
|
|
531
531
|
const t = e[O];
|
|
532
532
|
let r, n = !0;
|
|
@@ -544,7 +544,7 @@ function Pe(e) {
|
|
|
544
544
|
n
|
|
545
545
|
), t && (t.finalized_ = !1), r;
|
|
546
546
|
}
|
|
547
|
-
var
|
|
547
|
+
var Ze = new Xe(), C = 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));
|
|
@@ -580,10 +580,10 @@ function Ee(e, t, r) {
|
|
|
580
580
|
return o(s.value), s.value;
|
|
581
581
|
});
|
|
582
582
|
e((s) => C(s, (o) => {
|
|
583
|
-
const
|
|
584
|
-
(
|
|
583
|
+
const c = s.rooms.filter(
|
|
584
|
+
(a) => a.collectionId !== n[0].collectionId
|
|
585
585
|
);
|
|
586
|
-
return o.rooms =
|
|
586
|
+
return o.rooms = c.concat(n), o.roomsLoading = !1, o;
|
|
587
587
|
}));
|
|
588
588
|
}
|
|
589
589
|
async function ne({
|
|
@@ -593,26 +593,26 @@ async function ne({
|
|
|
593
593
|
collectionId: n,
|
|
594
594
|
messagesId: s,
|
|
595
595
|
participants: o = [],
|
|
596
|
-
retentionDays:
|
|
597
|
-
isGenerated:
|
|
598
|
-
id:
|
|
596
|
+
retentionDays: c,
|
|
597
|
+
isGenerated: a = !1,
|
|
598
|
+
id: y
|
|
599
599
|
}) {
|
|
600
600
|
if (e)
|
|
601
601
|
try {
|
|
602
602
|
const p = {
|
|
603
|
-
_id:
|
|
603
|
+
_id: y || Ne(),
|
|
604
604
|
name: r,
|
|
605
605
|
messagesId: s,
|
|
606
606
|
collectionId: n,
|
|
607
|
-
isGenerated:
|
|
607
|
+
isGenerated: a,
|
|
608
608
|
createdBy: t,
|
|
609
609
|
createdOn: (/* @__PURE__ */ new Date()).toISOString(),
|
|
610
610
|
participants: o || void 0,
|
|
611
|
-
...
|
|
611
|
+
...c !== void 0 && { retentionDays: c }
|
|
612
612
|
}, S = `INSERT INTO \`${n}\` DOCUMENTS (:newDoc) ON ID CONFLICT DO UPDATE`;
|
|
613
613
|
return await e.store.execute(S, { newDoc: p }), p;
|
|
614
|
-
} catch (
|
|
615
|
-
console.error(`Error creating ${n}:`,
|
|
614
|
+
} catch (g) {
|
|
615
|
+
console.error(`Error creating ${n}:`, g);
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
618
|
const st = (e, t, { ditto: r, userId: n }) => {
|
|
@@ -658,18 +658,18 @@ const st = (e, t, { ditto: r, userId: n }) => {
|
|
|
658
658
|
* @param options.isGenerated - Optional flag to mark room as generated (hidden from main list)
|
|
659
659
|
* @returns Promise resolving to the created Room object, or undefined if permission denied
|
|
660
660
|
*/
|
|
661
|
-
createRoom(o,
|
|
661
|
+
createRoom(o, c) {
|
|
662
662
|
if (!t().canPerformAction("canCreateRoom"))
|
|
663
663
|
return console.warn("Permission denied: canCreateRoom is false"), Promise.resolve(void 0);
|
|
664
|
-
const
|
|
664
|
+
const a = t().currentUser;
|
|
665
665
|
return ne({
|
|
666
666
|
ditto: r,
|
|
667
|
-
currentUserId:
|
|
667
|
+
currentUserId: a?._id || n,
|
|
668
668
|
name: o,
|
|
669
669
|
collectionId: "rooms",
|
|
670
670
|
messagesId: "messages",
|
|
671
|
-
retentionDays:
|
|
672
|
-
isGenerated:
|
|
671
|
+
retentionDays: c?.retentionDays,
|
|
672
|
+
isGenerated: c?.isGenerated ?? !1
|
|
673
673
|
});
|
|
674
674
|
},
|
|
675
675
|
/**
|
|
@@ -704,16 +704,16 @@ const st = (e, t, { ditto: r, userId: n }) => {
|
|
|
704
704
|
* @throws Error if either user ID is invalid or missing
|
|
705
705
|
*/
|
|
706
706
|
createDMRoom(o) {
|
|
707
|
-
const
|
|
708
|
-
if (!
|
|
707
|
+
const c = t().currentUser;
|
|
708
|
+
if (!c?._id || !o?._id)
|
|
709
709
|
throw Error("Invalid users");
|
|
710
710
|
return ne({
|
|
711
711
|
ditto: r,
|
|
712
|
-
currentUserId:
|
|
713
|
-
name: `${
|
|
712
|
+
currentUserId: c?._id || n,
|
|
713
|
+
name: `${c?.name} & ${o.name}`,
|
|
714
714
|
collectionId: "dm_rooms",
|
|
715
715
|
messagesId: "dm_messages",
|
|
716
|
-
participants: [
|
|
716
|
+
participants: [c?._id, o._id]
|
|
717
717
|
});
|
|
718
718
|
},
|
|
719
719
|
/**
|
|
@@ -727,20 +727,20 @@ const st = (e, t, { ditto: r, userId: n }) => {
|
|
|
727
727
|
* @param name - Display name for the room
|
|
728
728
|
* @returns Promise resolving to the created Room object
|
|
729
729
|
*/
|
|
730
|
-
async createGeneratedRoom(o,
|
|
731
|
-
const
|
|
730
|
+
async createGeneratedRoom(o, c) {
|
|
731
|
+
const a = t().currentUser, y = await ne({
|
|
732
732
|
ditto: r,
|
|
733
|
-
currentUserId:
|
|
734
|
-
name:
|
|
733
|
+
currentUserId: a?._id || n,
|
|
734
|
+
name: c,
|
|
735
735
|
collectionId: "rooms",
|
|
736
736
|
messagesId: "messages",
|
|
737
737
|
isGenerated: !0,
|
|
738
738
|
id: o
|
|
739
739
|
});
|
|
740
|
-
return
|
|
741
|
-
...
|
|
742
|
-
generatedRooms: [...
|
|
743
|
-
}),
|
|
740
|
+
return y && e((g) => g.generatedRooms.some((S) => S._id === y._id) ? g : {
|
|
741
|
+
...g,
|
|
742
|
+
generatedRooms: [...g.generatedRooms, y]
|
|
743
|
+
}), y;
|
|
744
744
|
},
|
|
745
745
|
/**
|
|
746
746
|
* Returns all public rooms, filtering out generated rooms.
|
|
@@ -755,18 +755,18 @@ const st = (e, t, { ditto: r, userId: n }) => {
|
|
|
755
755
|
}
|
|
756
756
|
};
|
|
757
757
|
if (r) {
|
|
758
|
-
const o = "SELECT * from rooms WHERE isGenerated = false OR isGenerated IS NULL",
|
|
759
|
-
s.roomsSubscription = r.sync.registerSubscription(o), s.dmRoomsSubscription = r.sync.registerSubscription(
|
|
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
760
|
userId: n
|
|
761
761
|
}), s.roomsObserver = r.store.registerObserver(
|
|
762
762
|
o,
|
|
763
|
-
(
|
|
764
|
-
Ee(e, t,
|
|
763
|
+
(a) => {
|
|
764
|
+
Ee(e, t, a);
|
|
765
765
|
}
|
|
766
766
|
), s.dmRoomsObserver = r.store.registerObserver(
|
|
767
|
-
|
|
768
|
-
(
|
|
769
|
-
Ee(e, t,
|
|
767
|
+
c,
|
|
768
|
+
(a) => {
|
|
769
|
+
Ee(e, t, a);
|
|
770
770
|
},
|
|
771
771
|
{
|
|
772
772
|
userId: n
|
|
@@ -776,14 +776,14 @@ const st = (e, t, { ditto: r, userId: n }) => {
|
|
|
776
776
|
return s;
|
|
777
777
|
}, Te = (e) => {
|
|
778
778
|
let t;
|
|
779
|
-
const r = /* @__PURE__ */ new Set(), n = (
|
|
780
|
-
const S = typeof
|
|
779
|
+
const r = /* @__PURE__ */ new Set(), n = (g, p) => {
|
|
780
|
+
const S = typeof g == "function" ? g(t) : g;
|
|
781
781
|
if (!Object.is(S, t)) {
|
|
782
782
|
const x = t;
|
|
783
|
-
t = p ?? (typeof S != "object" || S === null) ? S : Object.assign({}, t, S), r.forEach((
|
|
783
|
+
t = p ?? (typeof S != "object" || S === null) ? S : Object.assign({}, t, S), r.forEach((H) => H(t, x));
|
|
784
784
|
}
|
|
785
|
-
}, s = () => t,
|
|
786
|
-
return
|
|
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
787
|
}, ot = ((e) => e ? Te(e) : Te), it = (e) => e;
|
|
788
788
|
function xe(e, t = it) {
|
|
789
789
|
const r = k.useSyncExternalStore(
|
|
@@ -804,7 +804,7 @@ const Se = (e) => Symbol.iterator in e, Oe = (e) => (
|
|
|
804
804
|
if (!n.has(s) || !Object.is(o, n.get(s)))
|
|
805
805
|
return !1;
|
|
806
806
|
return !0;
|
|
807
|
-
},
|
|
807
|
+
}, ct = (e, t) => {
|
|
808
808
|
const r = e[Symbol.iterator](), n = t[Symbol.iterator]();
|
|
809
809
|
let s = r.next(), o = n.next();
|
|
810
810
|
for (; !s.done && !o.done; ) {
|
|
@@ -814,8 +814,8 @@ const Se = (e) => Symbol.iterator in e, Oe = (e) => (
|
|
|
814
814
|
}
|
|
815
815
|
return !!s.done && !!o.done;
|
|
816
816
|
};
|
|
817
|
-
function
|
|
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) :
|
|
817
|
+
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(
|
|
819
819
|
{ entries: () => Object.entries(e) },
|
|
820
820
|
{ entries: () => Object.entries(t) }
|
|
821
821
|
);
|
|
@@ -824,7 +824,7 @@ function ut(e) {
|
|
|
824
824
|
const t = k.useRef(void 0);
|
|
825
825
|
return (r) => {
|
|
826
826
|
const n = e(r);
|
|
827
|
-
return
|
|
827
|
+
return at(t.current, n) ? t.current : t.current = n;
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
830
|
const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
@@ -849,15 +849,15 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
849
849
|
*
|
|
850
850
|
* @param user - User object (with optional _id for upsert)
|
|
851
851
|
*/
|
|
852
|
-
async addUser(
|
|
852
|
+
async addUser(c) {
|
|
853
853
|
if (r)
|
|
854
854
|
try {
|
|
855
855
|
await r.store.execute(
|
|
856
856
|
`INSERT INTO ${s} DOCUMENTS (:newUser) ON ID CONFLICT DO UPDATE`,
|
|
857
|
-
{ newUser:
|
|
857
|
+
{ newUser: c }
|
|
858
858
|
);
|
|
859
|
-
} catch (
|
|
860
|
-
console.error("Error in addUser:",
|
|
859
|
+
} catch (a) {
|
|
860
|
+
console.error("Error in addUser:", a);
|
|
861
861
|
}
|
|
862
862
|
},
|
|
863
863
|
/**
|
|
@@ -874,19 +874,19 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
874
874
|
*
|
|
875
875
|
* @param params - Object with _id and fields to update
|
|
876
876
|
*/
|
|
877
|
-
async updateUser({ _id:
|
|
878
|
-
if (r &&
|
|
877
|
+
async updateUser({ _id: c, ...a }) {
|
|
878
|
+
if (r && c)
|
|
879
879
|
try {
|
|
880
|
-
const
|
|
881
|
-
if (!
|
|
880
|
+
const y = await t().findUserById(c);
|
|
881
|
+
if (!y)
|
|
882
882
|
return;
|
|
883
|
-
const
|
|
883
|
+
const g = { ...y, ...a };
|
|
884
884
|
await r.store.execute(
|
|
885
885
|
`INSERT INTO ${s} DOCUMENTS (:newUser) ON ID CONFLICT DO UPDATE`,
|
|
886
|
-
{ newUser:
|
|
886
|
+
{ newUser: g }
|
|
887
887
|
);
|
|
888
|
-
} catch (
|
|
889
|
-
console.error("Error in updateUser:",
|
|
888
|
+
} catch (y) {
|
|
889
|
+
console.error("Error in updateUser:", y);
|
|
890
890
|
}
|
|
891
891
|
},
|
|
892
892
|
/**
|
|
@@ -902,16 +902,16 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
902
902
|
* @param userId - The unique identifier of the user
|
|
903
903
|
* @returns Promise resolving to ChatUser or null
|
|
904
904
|
*/
|
|
905
|
-
async findUserById(
|
|
905
|
+
async findUserById(c) {
|
|
906
906
|
if (!r)
|
|
907
907
|
return null;
|
|
908
908
|
try {
|
|
909
909
|
return (await r.store.execute(
|
|
910
910
|
`SELECT * FROM ${s} WHERE _id = :id`,
|
|
911
|
-
{ id:
|
|
911
|
+
{ id: c }
|
|
912
912
|
)).items?.[0]?.value;
|
|
913
|
-
} catch (
|
|
914
|
-
return console.error("Error in findUserById:",
|
|
913
|
+
} catch (a) {
|
|
914
|
+
return console.error("Error in findUserById:", a), null;
|
|
915
915
|
}
|
|
916
916
|
},
|
|
917
917
|
/**
|
|
@@ -929,21 +929,21 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
929
929
|
*
|
|
930
930
|
* @param roomId - ID of the room to mark as read
|
|
931
931
|
*/
|
|
932
|
-
async markRoomAsRead(
|
|
932
|
+
async markRoomAsRead(c) {
|
|
933
933
|
if (!(!r || !n))
|
|
934
934
|
try {
|
|
935
|
-
let
|
|
936
|
-
const
|
|
937
|
-
if (!
|
|
935
|
+
let a = !1;
|
|
936
|
+
const y = await t().findUserById(n);
|
|
937
|
+
if (!y)
|
|
938
938
|
return;
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
939
|
+
const g = y.subscriptions || {}, p = y.mentions || {};
|
|
940
|
+
if (g[c]) {
|
|
941
941
|
const S = (/* @__PURE__ */ new Date()).toISOString();
|
|
942
|
-
|
|
942
|
+
g[c] = S, a = !0;
|
|
943
943
|
}
|
|
944
|
-
p[
|
|
945
|
-
} catch (
|
|
946
|
-
console.error("Error in markRoomAsRead:",
|
|
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);
|
|
947
947
|
}
|
|
948
948
|
},
|
|
949
949
|
/**
|
|
@@ -960,49 +960,49 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
960
960
|
*
|
|
961
961
|
* @param roomId - ID of the room to toggle subscription for
|
|
962
962
|
*/
|
|
963
|
-
async toggleRoomSubscription(
|
|
963
|
+
async toggleRoomSubscription(c) {
|
|
964
964
|
if (!(!r || !n)) {
|
|
965
965
|
if (!t().canPerformAction("canSubscribeToRoom")) {
|
|
966
966
|
console.warn("Permission denied: canSubscribeToRoom is false");
|
|
967
967
|
return;
|
|
968
968
|
}
|
|
969
969
|
try {
|
|
970
|
-
const
|
|
971
|
-
if (!
|
|
970
|
+
const a = await t().findUserById(n);
|
|
971
|
+
if (!a)
|
|
972
972
|
return;
|
|
973
|
-
const
|
|
974
|
-
if (
|
|
975
|
-
|
|
973
|
+
const y = { ...a.subscriptions };
|
|
974
|
+
if (c in y && y[c] !== null)
|
|
975
|
+
y[c] = null;
|
|
976
976
|
else {
|
|
977
|
-
const
|
|
978
|
-
|
|
977
|
+
const g = (/* @__PURE__ */ new Date()).toISOString();
|
|
978
|
+
y[c] = g;
|
|
979
979
|
}
|
|
980
980
|
await t().updateUser({
|
|
981
981
|
_id: n,
|
|
982
|
-
subscriptions:
|
|
982
|
+
subscriptions: y
|
|
983
983
|
});
|
|
984
|
-
} catch (
|
|
985
|
-
console.error("Error in toggleRoomSubscription:",
|
|
984
|
+
} catch (a) {
|
|
985
|
+
console.error("Error in toggleRoomSubscription:", a);
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
988
|
}
|
|
989
989
|
};
|
|
990
990
|
if (r) {
|
|
991
|
-
const
|
|
991
|
+
const c = `SELECT * FROM ${s} WHERE _id = :id`, a = `SELECT * FROM ${s}`, y = { id: n };
|
|
992
992
|
o.userSubscription = r.sync.registerSubscription(
|
|
993
|
-
|
|
994
|
-
|
|
993
|
+
c,
|
|
994
|
+
y
|
|
995
995
|
), o.userObserver = r.store.registerObserver(
|
|
996
|
-
a,
|
|
997
|
-
(y) => {
|
|
998
|
-
e({ currentUser: y.items?.[0]?.value });
|
|
999
|
-
},
|
|
1000
|
-
d
|
|
1001
|
-
), o.allUsersSubscription = r.sync.registerSubscription(c), o.allUsersObserver = r.store.registerObserver(
|
|
1002
996
|
c,
|
|
1003
|
-
(
|
|
997
|
+
(g) => {
|
|
998
|
+
e({ currentUser: g.items?.[0]?.value });
|
|
999
|
+
},
|
|
1000
|
+
y
|
|
1001
|
+
), o.allUsersSubscription = r.sync.registerSubscription(a), o.allUsersObserver = r.store.registerObserver(
|
|
1002
|
+
a,
|
|
1003
|
+
(g) => {
|
|
1004
1004
|
e({
|
|
1005
|
-
allUsers:
|
|
1005
|
+
allUsers: g.items.map((p) => p.value),
|
|
1006
1006
|
usersLoading: !1
|
|
1007
1007
|
});
|
|
1008
1008
|
}
|
|
@@ -1014,9 +1014,9 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1014
1014
|
userId: n,
|
|
1015
1015
|
userCollectionKey: s,
|
|
1016
1016
|
retentionDays: o,
|
|
1017
|
-
notificationHandler:
|
|
1017
|
+
notificationHandler: c
|
|
1018
1018
|
}) => {
|
|
1019
|
-
const
|
|
1019
|
+
const a = async (i) => {
|
|
1020
1020
|
if (!r)
|
|
1021
1021
|
throw new Error("Ditto not initialized");
|
|
1022
1022
|
const u = await r.store.execute(
|
|
@@ -1026,7 +1026,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1026
1026
|
if (u.items.length === 0)
|
|
1027
1027
|
throw new Error("Room not found");
|
|
1028
1028
|
return u.items[0].value;
|
|
1029
|
-
},
|
|
1029
|
+
}, y = async () => {
|
|
1030
1030
|
if (!r || !n)
|
|
1031
1031
|
throw new Error("Ditto not initialized or user not found");
|
|
1032
1032
|
const u = (await r.store.execute(
|
|
@@ -1037,43 +1037,43 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1037
1037
|
id: n,
|
|
1038
1038
|
name: u?.name ?? n
|
|
1039
1039
|
};
|
|
1040
|
-
},
|
|
1040
|
+
}, g = () => {
|
|
1041
1041
|
e((i) => C(i, (u) => {
|
|
1042
1042
|
u.messagesLoading = !u.rooms.every(
|
|
1043
1043
|
(l) => l._id in u.messagesByRoom
|
|
1044
1044
|
);
|
|
1045
1045
|
}));
|
|
1046
1046
|
}, p = (i, u, l, f) => {
|
|
1047
|
-
const
|
|
1047
|
+
const d = {
|
|
1048
1048
|
message: l,
|
|
1049
1049
|
user: f,
|
|
1050
1050
|
id: l._id
|
|
1051
|
-
},
|
|
1052
|
-
...
|
|
1053
|
-
message:
|
|
1054
|
-
user:
|
|
1051
|
+
}, m = {
|
|
1052
|
+
...d,
|
|
1053
|
+
message: d.message,
|
|
1054
|
+
user: d.user
|
|
1055
1055
|
}, b = i.findIndex((h) => h.id === l._id);
|
|
1056
|
-
if (b === -1 && !l.archivedMessage && S(l, u) &&
|
|
1056
|
+
if (b === -1 && !l.archivedMessage && S(l, u) && c && t().activeRoomId !== u._id) {
|
|
1057
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
|
-
|
|
1058
|
+
c(D, A);
|
|
1059
1059
|
}
|
|
1060
1060
|
if (l.archivedMessage) {
|
|
1061
1061
|
const h = i.findIndex(
|
|
1062
1062
|
(_) => _.id === l.archivedMessage
|
|
1063
1063
|
);
|
|
1064
|
-
h !== -1 ? i[h] =
|
|
1064
|
+
h !== -1 ? i[h] = m : b === -1 ? i.push(m) : i[b] = m;
|
|
1065
1065
|
} else
|
|
1066
|
-
b === -1 ? i.push(
|
|
1066
|
+
b === -1 ? i.push(m) : i[b] = m;
|
|
1067
1067
|
}, S = (i, u) => {
|
|
1068
|
-
const f = t().currentUser,
|
|
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
1069
|
(w) => w.userId === f?._id
|
|
1070
1070
|
), _ = u.collectionId === "dm_rooms";
|
|
1071
|
-
return !
|
|
1071
|
+
return !d && m && (b || _ || h);
|
|
1072
1072
|
}, x = async (i, u, l = "") => {
|
|
1073
1073
|
if (!r || !n)
|
|
1074
1074
|
throw new Error("Ditto not initialized or user not found");
|
|
1075
|
-
const f = await
|
|
1076
|
-
_id:
|
|
1075
|
+
const f = await a(i), d = u._id || Ne(), m = {
|
|
1076
|
+
_id: d,
|
|
1077
1077
|
roomId: i._id,
|
|
1078
1078
|
userId: n,
|
|
1079
1079
|
createdOn: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1090,7 +1090,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1090
1090
|
}, b = l ? `COLLECTION ${f.messagesId} ${l}` : f.messagesId;
|
|
1091
1091
|
if (await r.store.execute(
|
|
1092
1092
|
`INSERT INTO ${b} DOCUMENTS (:newDoc) ON ID CONFLICT DO UPDATE`,
|
|
1093
|
-
{ newDoc:
|
|
1093
|
+
{ newDoc: m }
|
|
1094
1094
|
), u.mentions && u.mentions.length > 0) {
|
|
1095
1095
|
const h = t().allUsers;
|
|
1096
1096
|
await Promise.all(
|
|
@@ -1100,7 +1100,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1100
1100
|
return;
|
|
1101
1101
|
const R = {
|
|
1102
1102
|
...w.mentions || {},
|
|
1103
|
-
[i._id]: [...w.mentions?.[i._id] || [],
|
|
1103
|
+
[i._id]: [...w.mentions?.[i._id] || [], d]
|
|
1104
1104
|
};
|
|
1105
1105
|
return r.store.execute(
|
|
1106
1106
|
"UPDATE users SET mentions = :mentions WHERE _id = :id",
|
|
@@ -1109,8 +1109,8 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1109
1109
|
})
|
|
1110
1110
|
);
|
|
1111
1111
|
}
|
|
1112
|
-
return
|
|
1113
|
-
},
|
|
1112
|
+
return m;
|
|
1113
|
+
}, H = async (i, u, l) => {
|
|
1114
1114
|
if (!r)
|
|
1115
1115
|
throw new Error("Ditto not initialized");
|
|
1116
1116
|
return await r.store.execute(
|
|
@@ -1125,27 +1125,27 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1125
1125
|
}, de = async (i, u, l, f) => {
|
|
1126
1126
|
if (!r || !n)
|
|
1127
1127
|
throw new Error("Ditto not initialized or user not found");
|
|
1128
|
-
const
|
|
1128
|
+
const d = await y(), m = {
|
|
1129
1129
|
thumbnailImageToken: null,
|
|
1130
1130
|
largeImageToken: null,
|
|
1131
1131
|
fileAttachmentToken: null
|
|
1132
1132
|
};
|
|
1133
1133
|
if (f === "image") {
|
|
1134
1134
|
const h = await dt(u), _ = await De(h), w = new Uint8Array(await _.arrayBuffer());
|
|
1135
|
-
|
|
1135
|
+
m.thumbnailImageToken = await r.store.newAttachment(
|
|
1136
1136
|
w,
|
|
1137
|
-
se(
|
|
1137
|
+
se(d.id, d.name, "thumbnail", u)
|
|
1138
1138
|
);
|
|
1139
1139
|
const R = await De(await ke(u)), D = new Uint8Array(await R.arrayBuffer());
|
|
1140
|
-
|
|
1140
|
+
m.largeImageToken = await r.store.newAttachment(
|
|
1141
1141
|
D,
|
|
1142
|
-
se(
|
|
1142
|
+
se(d.id, d.name, "large", u)
|
|
1143
1143
|
);
|
|
1144
1144
|
} else {
|
|
1145
1145
|
const h = new Uint8Array(await u.arrayBuffer());
|
|
1146
|
-
|
|
1146
|
+
m.fileAttachmentToken = await r.store.newAttachment(
|
|
1147
1147
|
h,
|
|
1148
|
-
se(
|
|
1148
|
+
se(d.id, d.name, "file", u)
|
|
1149
1149
|
);
|
|
1150
1150
|
}
|
|
1151
1151
|
const b = f === "image" ? "(thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT)" : "(fileAttachmentToken ATTACHMENT)";
|
|
@@ -1153,7 +1153,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1153
1153
|
i,
|
|
1154
1154
|
{
|
|
1155
1155
|
text: l || (f === "file" ? u.name : ""),
|
|
1156
|
-
...
|
|
1156
|
+
...m
|
|
1157
1157
|
},
|
|
1158
1158
|
b
|
|
1159
1159
|
);
|
|
@@ -1199,27 +1199,27 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1199
1199
|
const l = i._id;
|
|
1200
1200
|
if (t().messageSubscriptionsByRoom[l])
|
|
1201
1201
|
return;
|
|
1202
|
-
const f = u ?? i.retentionDays ?? o ?? Ie,
|
|
1202
|
+
const f = u ?? i.retentionDays ?? o ?? Ie, d = new Date(
|
|
1203
1203
|
Date.now() - f * 24 * 60 * 60 * 1e3
|
|
1204
|
-
),
|
|
1204
|
+
), m = `SELECT * FROM COLLECTION ${i.messagesId} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
|
|
1205
1205
|
WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
|
|
1206
1206
|
ORDER BY createdOn ASC`, b = {
|
|
1207
1207
|
roomId: i._id,
|
|
1208
|
-
date:
|
|
1208
|
+
date: d.toISOString()
|
|
1209
1209
|
};
|
|
1210
1210
|
try {
|
|
1211
|
-
const h = r.sync.registerSubscription(
|
|
1212
|
-
|
|
1211
|
+
const h = r.sync.registerSubscription(m, b), _ = t().allUsers, w = r.store.registerObserver(
|
|
1212
|
+
m,
|
|
1213
1213
|
async (R) => {
|
|
1214
1214
|
e((D) => C(D, (A) => {
|
|
1215
1215
|
if (A.messagesByRoom[i._id] || (A.messagesByRoom[i._id] = []), R.items.length === 0)
|
|
1216
1216
|
return A;
|
|
1217
1217
|
for (const v of R.items) {
|
|
1218
|
-
const $ = v.value, j = A.messagesByRoom[i._id],
|
|
1219
|
-
p(j, i, $,
|
|
1218
|
+
const $ = v.value, j = A.messagesByRoom[i._id], Z = _.find((K) => K._id === $.userId);
|
|
1219
|
+
p(j, i, $, Z);
|
|
1220
1220
|
}
|
|
1221
1221
|
return A;
|
|
1222
|
-
})),
|
|
1222
|
+
})), g();
|
|
1223
1223
|
},
|
|
1224
1224
|
b
|
|
1225
1225
|
);
|
|
@@ -1259,17 +1259,17 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1259
1259
|
async subscribeToRoomMessages(i, u, l) {
|
|
1260
1260
|
if (!r || t().messageSubscriptionsByRoom[i])
|
|
1261
1261
|
return;
|
|
1262
|
-
const f = l ?? o ?? Ie,
|
|
1262
|
+
const f = l ?? o ?? Ie, d = new Date(
|
|
1263
1263
|
Date.now() - f * 24 * 60 * 60 * 1e3
|
|
1264
|
-
),
|
|
1264
|
+
), m = `SELECT * FROM COLLECTION ${u} (thumbnailImageToken ATTACHMENT, largeImageToken ATTACHMENT, fileAttachmentToken ATTACHMENT)
|
|
1265
1265
|
WHERE roomId = :roomId AND createdOn >= :date AND isArchived = false
|
|
1266
1266
|
ORDER BY createdOn ASC`, b = {
|
|
1267
1267
|
roomId: i,
|
|
1268
|
-
date:
|
|
1268
|
+
date: d.toISOString()
|
|
1269
1269
|
};
|
|
1270
1270
|
try {
|
|
1271
|
-
const h = r.sync.registerSubscription(
|
|
1272
|
-
|
|
1271
|
+
const h = r.sync.registerSubscription(m, b), _ = t().allUsers, w = r.store.registerObserver(
|
|
1272
|
+
m,
|
|
1273
1273
|
async (R) => {
|
|
1274
1274
|
const D = {
|
|
1275
1275
|
_id: i,
|
|
@@ -1284,11 +1284,11 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1284
1284
|
if (v.messagesByRoom[i] || (v.messagesByRoom[i] = []), R.items.length === 0)
|
|
1285
1285
|
return v;
|
|
1286
1286
|
for (const $ of R.items) {
|
|
1287
|
-
const j = $.value,
|
|
1288
|
-
p(
|
|
1287
|
+
const j = $.value, Z = v.messagesByRoom[i], K = _.find((Be) => Be._id === j.userId);
|
|
1288
|
+
p(Z, D, j, K);
|
|
1289
1289
|
}
|
|
1290
1290
|
return v;
|
|
1291
|
-
})),
|
|
1291
|
+
})), g();
|
|
1292
1292
|
},
|
|
1293
1293
|
b
|
|
1294
1294
|
);
|
|
@@ -1325,7 +1325,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1325
1325
|
*/
|
|
1326
1326
|
unsubscribeFromRoomMessages(i) {
|
|
1327
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, (
|
|
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)));
|
|
1329
1329
|
},
|
|
1330
1330
|
/**
|
|
1331
1331
|
* Create a new text message in a room.
|
|
@@ -1346,15 +1346,15 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1346
1346
|
async createMessage(i, u, l = []) {
|
|
1347
1347
|
if (!r || !n)
|
|
1348
1348
|
return;
|
|
1349
|
-
const f = t().canPerformAction("canMentionUsers"),
|
|
1349
|
+
const f = t().canPerformAction("canMentionUsers"), d = l.length > 0 && !f ? [] : l;
|
|
1350
1350
|
l.length > 0 && !f && console.warn("Permission denied: canMentionUsers is false");
|
|
1351
1351
|
try {
|
|
1352
1352
|
await x(i, {
|
|
1353
1353
|
text: u,
|
|
1354
|
-
mentions:
|
|
1354
|
+
mentions: d
|
|
1355
1355
|
});
|
|
1356
|
-
} catch (
|
|
1357
|
-
console.error("Error in createMessage:",
|
|
1356
|
+
} catch (m) {
|
|
1357
|
+
console.error("Error in createMessage:", m);
|
|
1358
1358
|
}
|
|
1359
1359
|
},
|
|
1360
1360
|
/**
|
|
@@ -1378,7 +1378,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1378
1378
|
return;
|
|
1379
1379
|
}
|
|
1380
1380
|
try {
|
|
1381
|
-
await
|
|
1381
|
+
await H(i, u, {
|
|
1382
1382
|
text: i.text,
|
|
1383
1383
|
largeImageToken: i.largeImageToken || null,
|
|
1384
1384
|
thumbnailImageToken: i.thumbnailImageToken || null,
|
|
@@ -1419,7 +1419,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1419
1419
|
file: "[deleted file]"
|
|
1420
1420
|
}[l];
|
|
1421
1421
|
try {
|
|
1422
|
-
await
|
|
1422
|
+
await H(i, u, {
|
|
1423
1423
|
text: f,
|
|
1424
1424
|
createdOn: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1425
1425
|
largeImageToken: null,
|
|
@@ -1429,8 +1429,8 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1429
1429
|
isDeleted: !0,
|
|
1430
1430
|
mentions: []
|
|
1431
1431
|
});
|
|
1432
|
-
} catch (
|
|
1433
|
-
console.error("Error in saveDeletedMessage:",
|
|
1432
|
+
} catch (d) {
|
|
1433
|
+
console.error("Error in saveDeletedMessage:", d);
|
|
1434
1434
|
}
|
|
1435
1435
|
},
|
|
1436
1436
|
/**
|
|
@@ -1493,6 +1493,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1493
1493
|
* @param token - Attachment token from message
|
|
1494
1494
|
* @param onProgress - Callback receiving progress (0-1)
|
|
1495
1495
|
* @param onComplete - Callback receiving AttachmentResult
|
|
1496
|
+
* @returns The fetcher object from the SDK for cleanup
|
|
1496
1497
|
*/
|
|
1497
1498
|
fetchAttachment(i, u, l) {
|
|
1498
1499
|
if (!r) {
|
|
@@ -1510,30 +1511,31 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1510
1511
|
return;
|
|
1511
1512
|
}
|
|
1512
1513
|
try {
|
|
1513
|
-
|
|
1514
|
-
|
|
1514
|
+
const f = i.id || JSON.stringify(i);
|
|
1515
|
+
return r.store.fetchAttachment(i, async (m) => {
|
|
1516
|
+
switch (m.type) {
|
|
1515
1517
|
case "Progress": {
|
|
1516
|
-
const
|
|
1517
|
-
u(
|
|
1518
|
+
const b = Number(m.downloadedBytes) / (Number(m.totalBytes) || 1);
|
|
1519
|
+
u(b);
|
|
1518
1520
|
break;
|
|
1519
1521
|
}
|
|
1520
1522
|
case "Completed":
|
|
1521
1523
|
try {
|
|
1522
|
-
const
|
|
1524
|
+
const b = m.attachment.getData(), h = b instanceof Promise ? await b : b;
|
|
1523
1525
|
l({
|
|
1524
1526
|
success: !0,
|
|
1525
|
-
data:
|
|
1526
|
-
metadata:
|
|
1527
|
+
data: h,
|
|
1528
|
+
metadata: m.attachment.metadata || {}
|
|
1527
1529
|
});
|
|
1528
|
-
} catch (
|
|
1530
|
+
} catch (b) {
|
|
1529
1531
|
l({
|
|
1530
1532
|
success: !1,
|
|
1531
|
-
error:
|
|
1533
|
+
error: b instanceof Error ? b : new Error("Unknown error getting attachment data")
|
|
1532
1534
|
});
|
|
1533
1535
|
}
|
|
1534
1536
|
break;
|
|
1535
1537
|
case "Deleted":
|
|
1536
|
-
l({
|
|
1538
|
+
console.warn(`[useMessages] Attachment reported as DELETED: ${f}`), l({
|
|
1537
1539
|
success: !1,
|
|
1538
1540
|
error: new Error("Attachment was deleted")
|
|
1539
1541
|
});
|
|
@@ -1541,10 +1543,10 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1541
1543
|
}
|
|
1542
1544
|
});
|
|
1543
1545
|
} catch (f) {
|
|
1544
|
-
l({
|
|
1546
|
+
return l({
|
|
1545
1547
|
success: !1,
|
|
1546
1548
|
error: f instanceof Error ? f : new Error("Failed to fetch attachment")
|
|
1547
|
-
});
|
|
1549
|
+
}), null;
|
|
1548
1550
|
}
|
|
1549
1551
|
},
|
|
1550
1552
|
/**
|
|
@@ -1576,13 +1578,13 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1576
1578
|
async updateMessageReactions(i, u, l) {
|
|
1577
1579
|
if (!r || !n)
|
|
1578
1580
|
return;
|
|
1579
|
-
const f = u._id,
|
|
1580
|
-
if (
|
|
1581
|
+
const f = u._id, d = t().messagesByRoom[f] || [], m = d.findIndex((_) => _.id === i._id);
|
|
1582
|
+
if (m === -1)
|
|
1581
1583
|
throw new Error("Message not found");
|
|
1582
|
-
const b = m
|
|
1584
|
+
const b = d[m].message, h = b.reactions || [];
|
|
1583
1585
|
e(
|
|
1584
1586
|
(_) => C(_, (w) => {
|
|
1585
|
-
w.messagesByRoom[f][
|
|
1587
|
+
w.messagesByRoom[f][m].message.reactions = l;
|
|
1586
1588
|
})
|
|
1587
1589
|
), setTimeout(async () => {
|
|
1588
1590
|
try {
|
|
@@ -1593,7 +1595,7 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1593
1595
|
} catch (_) {
|
|
1594
1596
|
console.error("Error updating reactions, rolling back:", _), e(
|
|
1595
1597
|
(w) => C(w, (R) => {
|
|
1596
|
-
R.messagesByRoom[f][
|
|
1598
|
+
R.messagesByRoom[f][m].message.reactions = h;
|
|
1597
1599
|
})
|
|
1598
1600
|
);
|
|
1599
1601
|
}
|
|
@@ -1622,11 +1624,11 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1622
1624
|
console.warn("Permission denied: canAddReaction is false");
|
|
1623
1625
|
return;
|
|
1624
1626
|
}
|
|
1625
|
-
const f = t().messagesByRoom[u._id],
|
|
1626
|
-
if (
|
|
1627
|
+
const f = t().messagesByRoom[u._id], d = f.findIndex((h) => h.id === i._id);
|
|
1628
|
+
if (d === -1)
|
|
1627
1629
|
throw new Error("Message not found");
|
|
1628
|
-
const
|
|
1629
|
-
await t().updateMessageReactions(
|
|
1630
|
+
const m = f[d].message, b = [...m.reactions || [], l];
|
|
1631
|
+
await t().updateMessageReactions(m, u, b);
|
|
1630
1632
|
},
|
|
1631
1633
|
/**
|
|
1632
1634
|
* Remove a reaction from a message.
|
|
@@ -1651,13 +1653,13 @@ const lt = (e, t, { ditto: r, userId: n, userCollectionKey: s }) => {
|
|
|
1651
1653
|
console.warn("Permission denied: canRemoveOwnReaction is false");
|
|
1652
1654
|
return;
|
|
1653
1655
|
}
|
|
1654
|
-
const f = t().messagesByRoom[u._id],
|
|
1655
|
-
if (
|
|
1656
|
+
const f = t().messagesByRoom[u._id], d = f.findIndex((h) => h.id === i._id);
|
|
1657
|
+
if (d === -1)
|
|
1656
1658
|
throw new Error("Message not found");
|
|
1657
|
-
const
|
|
1659
|
+
const m = f[d].message, b = (m.reactions || []).filter(
|
|
1658
1660
|
(h) => !(h.emoji === l.emoji && h.userId === l.userId)
|
|
1659
1661
|
);
|
|
1660
|
-
await t().updateMessageReactions(
|
|
1662
|
+
await t().updateMessageReactions(m, u, b);
|
|
1661
1663
|
}
|
|
1662
1664
|
};
|
|
1663
1665
|
};
|
|
@@ -1701,12 +1703,12 @@ async function De(e) {
|
|
|
1701
1703
|
});
|
|
1702
1704
|
}
|
|
1703
1705
|
function se(e, t, r, n) {
|
|
1704
|
-
const s = (/* @__PURE__ */ new Date()).toISOString(), o = t.replace(/\s/g, "-"),
|
|
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";
|
|
1705
1707
|
return {
|
|
1706
|
-
filename: `${o}_${r}_${
|
|
1708
|
+
filename: `${o}_${r}_${c}.${a}`,
|
|
1707
1709
|
userId: e,
|
|
1708
1710
|
username: t,
|
|
1709
|
-
fileformat: `.${
|
|
1711
|
+
fileformat: `.${a}`,
|
|
1710
1712
|
filesize: n.size.toString(),
|
|
1711
1713
|
timestamp: s,
|
|
1712
1714
|
originalName: n.name
|
|
@@ -1721,7 +1723,7 @@ function ht(e) {
|
|
|
1721
1723
|
...st(r, n, e),
|
|
1722
1724
|
...lt(r, n, e),
|
|
1723
1725
|
...mt(r, n, e),
|
|
1724
|
-
...
|
|
1726
|
+
...Le(r, n, e),
|
|
1725
1727
|
activeRoomId: null,
|
|
1726
1728
|
setActiveRoomId: (s) => r({ activeRoomId: s }),
|
|
1727
1729
|
chatLogout: () => {
|
|
@@ -1755,7 +1757,7 @@ function wt() {
|
|
|
1755
1757
|
export {
|
|
1756
1758
|
ze as DEFAULT_PERMISSIONS,
|
|
1757
1759
|
I as cancelSubscriptionOrObserver,
|
|
1758
|
-
|
|
1760
|
+
Le as createRBACSlice,
|
|
1759
1761
|
st as createRoomSlice,
|
|
1760
1762
|
_t as getChatStore,
|
|
1761
1763
|
wt as resetChatStore,
|