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