@codingfactory/messenger-client 0.1.1 → 0.1.3
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.js +122 -113
- package/dist/services/mediaApi.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ref as Q, getCurrentInstance as Me, computed as J, onUnmounted as we, toValue as Oe, watch as de } from "vue";
|
|
2
2
|
import { defineStore as Ge, storeToRefs as ke } from "pinia";
|
|
3
3
|
import Ve, { isAxiosError as Be } from "axios";
|
|
4
|
-
import { isAxiosError as
|
|
4
|
+
import { isAxiosError as Zt } from "axios";
|
|
5
5
|
import { useRoute as He } from "vue-router";
|
|
6
6
|
const Re = () => () => {
|
|
7
7
|
}, Ae = () => {
|
|
@@ -17,7 +17,7 @@ const Re = () => () => {
|
|
|
17
17
|
unsubscribeFromPresenceStatus: Ee,
|
|
18
18
|
subscribeToConversation: Te,
|
|
19
19
|
unsubscribeFromConversation: Fe
|
|
20
|
-
}, le = () => _.ECHO_INITIALIZED_EVENT, O = () => _.getEcho(), xe = (e) => _.onConnectionStatusChange(e),
|
|
20
|
+
}, le = () => _.ECHO_INITIALIZED_EVENT, O = () => _.getEcho(), xe = (e) => _.onConnectionStatusChange(e), je = (e) => _.subscribeToPresenceStatus(e), Ye = () => _.unsubscribeFromPresenceStatus(), We = (e, t) => _.subscribeToConversation(e, t), Ze = (e) => _.unsubscribeFromConversation(e);
|
|
21
21
|
function Xe(e) {
|
|
22
22
|
e.initializedEvent && (_.ECHO_INITIALIZED_EVENT = e.initializedEvent), e.getEcho && (_.getEcho = e.getEcho), e.onConnectionStatusChange && (_.onConnectionStatusChange = e.onConnectionStatusChange), e.subscribeToPresenceStatus && (_.subscribeToPresenceStatus = e.subscribeToPresenceStatus), e.unsubscribeFromPresenceStatus && (_.unsubscribeFromPresenceStatus = e.unsubscribeFromPresenceStatus), e.subscribeToConversation && (_.subscribeToConversation = e.subscribeToConversation), e.unsubscribeFromConversation && (_.unsubscribeFromConversation = e.unsubscribeFromConversation);
|
|
23
23
|
}
|
|
@@ -61,10 +61,10 @@ function m(e) {
|
|
|
61
61
|
}
|
|
62
62
|
return e instanceof Error ? e.message : typeof e == "string" ? e : typeof e == "object" && e !== null && "message" in e && typeof e.message == "string" ? e.message : "An unexpected error occurred";
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function Gt(e) {
|
|
65
65
|
return e instanceof Error;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function kt(e) {
|
|
68
68
|
return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
|
|
69
69
|
}
|
|
70
70
|
const Le = {
|
|
@@ -73,19 +73,22 @@ const Le = {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
let ie = Le;
|
|
76
|
-
function it(
|
|
76
|
+
function it() {
|
|
77
|
+
return ie;
|
|
78
|
+
}
|
|
79
|
+
function ot(e) {
|
|
77
80
|
ie = e;
|
|
78
81
|
}
|
|
79
|
-
function
|
|
82
|
+
function at() {
|
|
80
83
|
ie = Le;
|
|
81
84
|
}
|
|
82
|
-
function
|
|
85
|
+
function ct(e) {
|
|
83
86
|
return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
|
|
84
87
|
}
|
|
85
88
|
function Ne(e) {
|
|
86
89
|
return typeof e == "object" && e !== null;
|
|
87
90
|
}
|
|
88
|
-
function
|
|
91
|
+
function I(e) {
|
|
89
92
|
return !Ne(e) || !("data" in e) ? e : e.data;
|
|
90
93
|
}
|
|
91
94
|
function B(e, t) {
|
|
@@ -128,28 +131,28 @@ function ne(e) {
|
|
|
128
131
|
updated_at: B(e, "updated_at")
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
|
-
function
|
|
134
|
+
function ut(e) {
|
|
132
135
|
if (!Array.isArray(e))
|
|
133
136
|
throw new Error("Invalid messaging folder payload: expected array");
|
|
134
137
|
return e.map((t) => ne(t));
|
|
135
138
|
}
|
|
136
139
|
function he(e) {
|
|
137
|
-
if (!
|
|
140
|
+
if (!ct(e))
|
|
138
141
|
throw new Error("Invalid conversation payload from folder assignment endpoint");
|
|
139
142
|
return e;
|
|
140
143
|
}
|
|
141
144
|
const P = {
|
|
142
145
|
async fetchFolders() {
|
|
143
146
|
const e = await l.get("/v1/messaging/folders");
|
|
144
|
-
return
|
|
147
|
+
return ut(I(e.data));
|
|
145
148
|
},
|
|
146
149
|
async createFolder(e) {
|
|
147
150
|
const t = await l.post("/v1/messaging/folders", e);
|
|
148
|
-
return ne(
|
|
151
|
+
return ne(I(t.data));
|
|
149
152
|
},
|
|
150
153
|
async updateFolder(e, t) {
|
|
151
154
|
const s = await l.patch(`/v1/messaging/folders/${e}`, t);
|
|
152
|
-
return ne(
|
|
155
|
+
return ne(I(s.data));
|
|
153
156
|
},
|
|
154
157
|
async deleteFolder(e) {
|
|
155
158
|
await l.delete(`/v1/messaging/folders/${e}`);
|
|
@@ -161,16 +164,16 @@ const P = {
|
|
|
161
164
|
const s = await l.patch(`/v1/messaging/conversations/${e}/folder`, {
|
|
162
165
|
folder_id: t
|
|
163
166
|
});
|
|
164
|
-
return he(
|
|
167
|
+
return he(I(s.data));
|
|
165
168
|
},
|
|
166
169
|
async acceptRequest(e) {
|
|
167
170
|
const t = await l.post(`/v1/messaging/conversations/${e}/accept`);
|
|
168
|
-
return he(
|
|
171
|
+
return he(I(t.data));
|
|
169
172
|
},
|
|
170
173
|
async declineRequest(e) {
|
|
171
174
|
await l.post(`/v1/messaging/conversations/${e}/decline`);
|
|
172
175
|
}
|
|
173
|
-
}, ge = 1e3, oe = 4e3,
|
|
176
|
+
}, ge = 1e3, oe = 4e3, dt = 12e4, lt = 300, ft = 1, ht = 1600, ae = (e) => {
|
|
174
177
|
if (typeof e == "number" && Number.isFinite(e))
|
|
175
178
|
return e;
|
|
176
179
|
if (typeof e == "string") {
|
|
@@ -190,17 +193,17 @@ const P = {
|
|
|
190
193
|
return Math.max(ge, t * 1e3);
|
|
191
194
|
}
|
|
192
195
|
return oe;
|
|
193
|
-
}, ht = (e) => {
|
|
194
|
-
const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = oe * s;
|
|
195
|
-
return Math.min(ut, n);
|
|
196
196
|
}, gt = (e) => {
|
|
197
|
+
const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = oe * s;
|
|
198
|
+
return Math.min(dt, n);
|
|
199
|
+
}, mt = (e) => {
|
|
197
200
|
const t = e;
|
|
198
|
-
return ae(t.response?.status) === 429 ? ze(t.response?.headers?.["retry-after"]) :
|
|
201
|
+
return ae(t.response?.status) === 429 ? ze(t.response?.headers?.["retry-after"]) : lt;
|
|
199
202
|
}, pe = async (e) => {
|
|
200
203
|
await new Promise((t) => {
|
|
201
204
|
setTimeout(t, e);
|
|
202
205
|
});
|
|
203
|
-
},
|
|
206
|
+
}, pt = (e) => {
|
|
204
207
|
if (!M(e))
|
|
205
208
|
return !1;
|
|
206
209
|
const s = (M(e.data) ? e.data : e).throttled;
|
|
@@ -214,7 +217,7 @@ const P = {
|
|
|
214
217
|
}
|
|
215
218
|
return !1;
|
|
216
219
|
};
|
|
217
|
-
function
|
|
220
|
+
function vt(e, t, s) {
|
|
218
221
|
const n = typeof e == "string" && e.trim().length > 0 ? e.trim().toLowerCase() : void 0;
|
|
219
222
|
if (n)
|
|
220
223
|
return n;
|
|
@@ -224,17 +227,17 @@ function pt(e, t, s) {
|
|
|
224
227
|
const i = typeof s == "string" && s.trim().length > 0 ? s.trim().toLowerCase() : void 0;
|
|
225
228
|
return i ? i === "image" ? "image/*" : i === "video" ? "video/*" : i === "audio" ? "audio/*" : i : "application/octet-stream";
|
|
226
229
|
}
|
|
227
|
-
function
|
|
230
|
+
function _t(e) {
|
|
228
231
|
const t = e.url || "", s = e.thumbnail_url ?? e.thumbnail, n = {
|
|
229
232
|
id: e.media_id ?? e.id ?? "",
|
|
230
|
-
name: e.name ??
|
|
233
|
+
name: e.name ?? yt(t),
|
|
231
234
|
url: t,
|
|
232
|
-
type:
|
|
235
|
+
type: vt(e.mime, e.mime_type, e.type),
|
|
233
236
|
size: e.size ?? 0
|
|
234
237
|
};
|
|
235
238
|
return s !== void 0 && (n.thumbnail = s), n;
|
|
236
239
|
}
|
|
237
|
-
function
|
|
240
|
+
function yt(e) {
|
|
238
241
|
if (!e) return "attachment";
|
|
239
242
|
try {
|
|
240
243
|
const s = new URL(e).pathname.split("/");
|
|
@@ -243,8 +246,8 @@ function _t(e) {
|
|
|
243
246
|
return "attachment";
|
|
244
247
|
}
|
|
245
248
|
}
|
|
246
|
-
function
|
|
247
|
-
return !Array.isArray(e) || e.length === 0 ? [] : e.map(
|
|
249
|
+
function bt(e) {
|
|
250
|
+
return !Array.isArray(e) || e.length === 0 ? [] : e.map(_t);
|
|
248
251
|
}
|
|
249
252
|
function X(e) {
|
|
250
253
|
if (typeof e != "string")
|
|
@@ -253,7 +256,7 @@ function X(e) {
|
|
|
253
256
|
if (t.length !== 0)
|
|
254
257
|
return t;
|
|
255
258
|
}
|
|
256
|
-
function
|
|
259
|
+
function Ct(e) {
|
|
257
260
|
if (!e)
|
|
258
261
|
return;
|
|
259
262
|
const t = X(e.avatar) ?? X(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
|
|
@@ -264,7 +267,7 @@ function bt(e) {
|
|
|
264
267
|
...s ? { handle: s } : {}
|
|
265
268
|
};
|
|
266
269
|
}
|
|
267
|
-
function
|
|
270
|
+
function Y(e) {
|
|
268
271
|
const t = e.shared_post, s = e.author, n = t && typeof t == "object" ? {
|
|
269
272
|
id: t.id ?? "",
|
|
270
273
|
title: t.title ?? "",
|
|
@@ -280,12 +283,12 @@ function j(e) {
|
|
|
280
283
|
} : null;
|
|
281
284
|
return {
|
|
282
285
|
...e,
|
|
283
|
-
...s ? { author:
|
|
286
|
+
...s ? { author: Ct(s) } : {},
|
|
284
287
|
shared_post: n,
|
|
285
|
-
attachments:
|
|
288
|
+
attachments: bt(e.attachments)
|
|
286
289
|
};
|
|
287
290
|
}
|
|
288
|
-
function
|
|
291
|
+
function St(e) {
|
|
289
292
|
return typeof e != "string" || e.length === 0 ? null : e;
|
|
290
293
|
}
|
|
291
294
|
function ve(e) {
|
|
@@ -295,39 +298,45 @@ function ve(e) {
|
|
|
295
298
|
function re(e) {
|
|
296
299
|
return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
|
|
297
300
|
}
|
|
298
|
-
function
|
|
301
|
+
function Mt(e, t = []) {
|
|
299
302
|
const s = /* @__PURE__ */ new Map();
|
|
300
303
|
for (const n of t) {
|
|
301
304
|
const r = ve(n.last_read_message_id);
|
|
302
305
|
r && s.set(n.user_id, r);
|
|
303
306
|
}
|
|
304
307
|
return e.map((n) => {
|
|
305
|
-
const r = X(n.user?.avatar) ?? X(n.user?.avatar_url),
|
|
308
|
+
const r = Object.prototype.hasOwnProperty.call(n, "last_read_message_id"), i = X(n.user?.avatar) ?? X(n.user?.avatar_url), o = n.user ? {
|
|
306
309
|
id: n.user.id,
|
|
307
310
|
name: n.user.name,
|
|
308
|
-
...
|
|
311
|
+
...i ? { avatar: i } : {},
|
|
309
312
|
...n.user.handle ? { handle: n.user.handle } : {}
|
|
310
|
-
} : void 0,
|
|
311
|
-
if (
|
|
313
|
+
} : void 0, a = ve(n.last_read_message_id);
|
|
314
|
+
if (a)
|
|
312
315
|
return {
|
|
313
316
|
...n,
|
|
314
|
-
...
|
|
315
|
-
last_read_message_id:
|
|
317
|
+
...o ? { user: o } : {},
|
|
318
|
+
last_read_message_id: a
|
|
316
319
|
};
|
|
317
|
-
|
|
318
|
-
|
|
320
|
+
if (r)
|
|
321
|
+
return {
|
|
322
|
+
...n,
|
|
323
|
+
...o ? { user: o } : {},
|
|
324
|
+
last_read_message_id: ""
|
|
325
|
+
};
|
|
326
|
+
const u = s.get(n.user_id);
|
|
327
|
+
return u ? {
|
|
319
328
|
...n,
|
|
320
|
-
...
|
|
321
|
-
last_read_message_id:
|
|
329
|
+
...o ? { user: o } : {},
|
|
330
|
+
last_read_message_id: u
|
|
322
331
|
} : {
|
|
323
332
|
...n,
|
|
324
|
-
...
|
|
333
|
+
...o ? { user: o } : {},
|
|
325
334
|
last_read_message_id: ""
|
|
326
335
|
};
|
|
327
336
|
});
|
|
328
337
|
}
|
|
329
|
-
function
|
|
330
|
-
const s =
|
|
338
|
+
function D(e, t) {
|
|
339
|
+
const s = St(e.muted_until), n = e.is_muted ?? s !== null, r = e.last_message ? Y(e.last_message) : t?.last_message, i = e.last_message_at ?? t?.last_message_at, o = (() => {
|
|
331
340
|
if (!t || t.unread_count !== 0 || e.unread_count <= 0)
|
|
332
341
|
return !1;
|
|
333
342
|
const a = t.last_message?.id, u = e.last_message?.id;
|
|
@@ -336,18 +345,18 @@ function I(e, t) {
|
|
|
336
345
|
return {
|
|
337
346
|
...e,
|
|
338
347
|
unread_count: n || o ? 0 : e.unread_count,
|
|
339
|
-
participants:
|
|
348
|
+
participants: Mt(e.participants, t?.participants),
|
|
340
349
|
is_muted: n,
|
|
341
350
|
muted_until: s,
|
|
342
351
|
...r ? { last_message: r } : {},
|
|
343
352
|
...i ? { last_message_at: i } : {}
|
|
344
353
|
};
|
|
345
354
|
}
|
|
346
|
-
function
|
|
355
|
+
function wt(e) {
|
|
347
356
|
return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
348
357
|
}
|
|
349
358
|
function ee(e) {
|
|
350
|
-
return
|
|
359
|
+
return wt(e) ? 0 : e.unread_count || 0;
|
|
351
360
|
}
|
|
352
361
|
function _e(e, t) {
|
|
353
362
|
const s = t[e.id];
|
|
@@ -362,7 +371,7 @@ function _e(e, t) {
|
|
|
362
371
|
function M(e) {
|
|
363
372
|
return typeof e == "object" && e !== null;
|
|
364
373
|
}
|
|
365
|
-
function
|
|
374
|
+
function Rt(e) {
|
|
366
375
|
return M(e) ? (M(e.response) ? e.response : null)?.status === 401 : !1;
|
|
367
376
|
}
|
|
368
377
|
function ye(e) {
|
|
@@ -386,7 +395,7 @@ function ye(e) {
|
|
|
386
395
|
}
|
|
387
396
|
return t;
|
|
388
397
|
}
|
|
389
|
-
function
|
|
398
|
+
function At(e, t) {
|
|
390
399
|
const s = M(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
|
|
391
400
|
if (!(typeof n != "string" || n.length === 0))
|
|
392
401
|
return n;
|
|
@@ -396,7 +405,7 @@ function H(e, t) {
|
|
|
396
405
|
let r = [];
|
|
397
406
|
return Array.isArray(n) ? r = n : M(n) && (Array.isArray(n.items) ? r = n.items : Array.isArray(n[t]) ? r = n[t] : Array.isArray(n.data) && (r = n.data)), {
|
|
398
407
|
items: r,
|
|
399
|
-
nextCursor:
|
|
408
|
+
nextCursor: At(s, n)
|
|
400
409
|
};
|
|
401
410
|
}
|
|
402
411
|
function be(e) {
|
|
@@ -411,18 +420,18 @@ function W(e, t) {
|
|
|
411
420
|
const s = e.last_message_at ?? e.created_at, r = (t.last_message_at ?? t.created_at).localeCompare(s);
|
|
412
421
|
return r !== 0 ? r : e.id.localeCompare(t.id);
|
|
413
422
|
}
|
|
414
|
-
function
|
|
423
|
+
function j(e, t) {
|
|
415
424
|
return [t, ...e.filter((s) => s.id !== t.id)];
|
|
416
425
|
}
|
|
417
426
|
function $(e) {
|
|
418
427
|
return [...e].sort((t, s) => t.sort_order !== s.sort_order ? t.sort_order - s.sort_order : t.name.localeCompare(s.name));
|
|
419
428
|
}
|
|
420
|
-
function
|
|
429
|
+
function Et(e, t) {
|
|
421
430
|
return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
|
|
422
431
|
}
|
|
423
432
|
function Se(e, t) {
|
|
424
433
|
return e.map((s) => {
|
|
425
|
-
const n =
|
|
434
|
+
const n = Et(s.folder_id, t);
|
|
426
435
|
return (s.folder_id ?? null) === n ? s : {
|
|
427
436
|
...s,
|
|
428
437
|
folder_id: n
|
|
@@ -437,7 +446,7 @@ function te(e) {
|
|
|
437
446
|
s.is_request === !0 && t.set(s.id, s);
|
|
438
447
|
return Array.from(t.values()).sort(W);
|
|
439
448
|
}
|
|
440
|
-
const
|
|
449
|
+
const Ie = Ge("messaging", {
|
|
441
450
|
state: () => ({
|
|
442
451
|
conversations: [],
|
|
443
452
|
requests: [],
|
|
@@ -568,7 +577,7 @@ const De = Ge("messaging", {
|
|
|
568
577
|
const p = this.conversations.find(
|
|
569
578
|
(F) => F.id === d.id
|
|
570
579
|
);
|
|
571
|
-
return
|
|
580
|
+
return D(d, p);
|
|
572
581
|
});
|
|
573
582
|
e ? this.conversations.push(...f) : this.conversations = f, this.normalizeFolderAssignmentsState(), this.lastFetch = Date.now();
|
|
574
583
|
const y = {
|
|
@@ -592,7 +601,7 @@ const De = Ge("messaging", {
|
|
|
592
601
|
}), this.backgroundPollRetryAfterUntil = 0, this.backgroundPollTransientFailureCount = 0, !0;
|
|
593
602
|
} catch (e) {
|
|
594
603
|
const t = e, s = ae(t.response?.status);
|
|
595
|
-
return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + ze(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || Ue(s) ? (this.backgroundPollRetryAfterUntil = Date.now() +
|
|
604
|
+
return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + ze(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || Ue(s) ? (this.backgroundPollRetryAfterUntil = Date.now() + gt(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + oe, !1));
|
|
596
605
|
}
|
|
597
606
|
},
|
|
598
607
|
async fetchConversation(e) {
|
|
@@ -600,7 +609,7 @@ const De = Ge("messaging", {
|
|
|
600
609
|
try {
|
|
601
610
|
const t = await l.get(`/v1/messaging/conversations/${e}`, {
|
|
602
611
|
params: { include_presence: 1 }
|
|
603
|
-
}), s = this.conversations.find((o) => o.id === e), n =
|
|
612
|
+
}), s = this.conversations.find((o) => o.id === e), n = D(t.data.data || t.data, s), r = this.conversations.findIndex((o) => o.id === e);
|
|
604
613
|
r >= 0 ? this.conversations[r] = n : this.conversations.push(n);
|
|
605
614
|
const i = this.requests.findIndex((o) => o.id === e);
|
|
606
615
|
return i >= 0 && (this.requests[i] = n), this.normalizeFolderAssignmentsState(), n;
|
|
@@ -623,7 +632,7 @@ const De = Ge("messaging", {
|
|
|
623
632
|
"conversations"
|
|
624
633
|
), i = n.map((a) => {
|
|
625
634
|
const u = this.requests.find((f) => f.id === a.id);
|
|
626
|
-
return
|
|
635
|
+
return D(a, u);
|
|
627
636
|
});
|
|
628
637
|
e ? this.requests.push(...i) : this.requests = i, this.normalizeFolderAssignmentsState();
|
|
629
638
|
const o = {
|
|
@@ -647,14 +656,14 @@ const De = Ge("messaging", {
|
|
|
647
656
|
r = await l.get(`/v1/messaging/conversations/${e}/messages`, { params: s });
|
|
648
657
|
break;
|
|
649
658
|
} catch (d) {
|
|
650
|
-
if (!(n <
|
|
659
|
+
if (!(n < ft && me(d)))
|
|
651
660
|
throw d;
|
|
652
|
-
n += 1, await pe(
|
|
661
|
+
n += 1, await pe(mt(d));
|
|
653
662
|
}
|
|
654
663
|
const { items: i, nextCursor: o } = H(
|
|
655
664
|
r.data,
|
|
656
665
|
"messages"
|
|
657
|
-
), a = i.map(
|
|
666
|
+
), a = i.map(Y), u = [...a].reverse();
|
|
658
667
|
if (t ? this.messages[e] = [...u, ...this.messages[e] || []] : this.messages[e] = u, (() => {
|
|
659
668
|
const d = this.conversations.find((p) => p.id === e) ?? this.requests.find((p) => p.id === e);
|
|
660
669
|
return d ? !d.last_message || !d.last_message_at : !1;
|
|
@@ -702,7 +711,7 @@ const De = Ge("messaging", {
|
|
|
702
711
|
if (s && s.length > 0) {
|
|
703
712
|
const v = await Promise.all(
|
|
704
713
|
s.map(async (E) => {
|
|
705
|
-
const b = await
|
|
714
|
+
const b = await it().uploadImage(E);
|
|
706
715
|
return {
|
|
707
716
|
media_id: b.id,
|
|
708
717
|
mime: b.mime_type,
|
|
@@ -719,7 +728,7 @@ const De = Ge("messaging", {
|
|
|
719
728
|
...p,
|
|
720
729
|
type: "text"
|
|
721
730
|
});
|
|
722
|
-
const F = d.data.data || d.data, N = { ...y, ...F, attachments: F.attachments ?? y.attachments }, A =
|
|
731
|
+
const F = d.data.data || d.data, N = { ...y, ...F, attachments: F.attachments ?? y.attachments }, A = Y(N), T = this.messages[e], x = T.findIndex((v) => v.id === a);
|
|
723
732
|
x >= 0 && (T[x] = A), this._pendingSendIds.delete(a);
|
|
724
733
|
const U = A.id;
|
|
725
734
|
let h = 0;
|
|
@@ -824,9 +833,9 @@ const De = Ge("messaging", {
|
|
|
824
833
|
async sendTyping(e, t = "start") {
|
|
825
834
|
try {
|
|
826
835
|
const s = await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
827
|
-
if (t !== "start" || !
|
|
836
|
+
if (t !== "start" || !pt(s.data))
|
|
828
837
|
return;
|
|
829
|
-
await pe(
|
|
838
|
+
await pe(ht), await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
830
839
|
} catch (s) {
|
|
831
840
|
console.warn("Failed to send typing indicator:", s);
|
|
832
841
|
}
|
|
@@ -894,8 +903,8 @@ const De = Ge("messaging", {
|
|
|
894
903
|
const n = await l.post("/v1/messaging/conversations/dm", s), r = n.data.data || n.data;
|
|
895
904
|
if (!be(r))
|
|
896
905
|
throw new Error("Invalid conversation payload from DM create endpoint.");
|
|
897
|
-
const i = Ce(r) ?
|
|
898
|
-
return i.is_request === !0 ? (this.requests =
|
|
906
|
+
const i = Ce(r) ? D(r) : await this.fetchConversation(r.id);
|
|
907
|
+
return i.is_request === !0 ? (this.requests = j(this.requests, i), this.conversations = this.conversations.filter((o) => o.id !== i.id), i) : (this.conversations = j(this.conversations, i), this.requests = this.requests.filter((o) => o.id !== i.id), i);
|
|
899
908
|
} catch (s) {
|
|
900
909
|
throw this.error = m(s), s;
|
|
901
910
|
}
|
|
@@ -909,7 +918,7 @@ const De = Ge("messaging", {
|
|
|
909
918
|
if (!be(n))
|
|
910
919
|
throw new Error("Invalid conversation payload from group create endpoint.");
|
|
911
920
|
const r = Ce(n) ? n : await this.fetchConversation(n.id);
|
|
912
|
-
return this.conversations =
|
|
921
|
+
return this.conversations = j(this.conversations, r), r;
|
|
913
922
|
} catch (s) {
|
|
914
923
|
throw this.error = m(s), s;
|
|
915
924
|
}
|
|
@@ -945,7 +954,7 @@ const De = Ge("messaging", {
|
|
|
945
954
|
if (!t)
|
|
946
955
|
return;
|
|
947
956
|
this.messages[t] || (this.messages[t] = []);
|
|
948
|
-
const s =
|
|
957
|
+
const s = Y({ ...e, attachments: e.attachments ?? [] }), n = this.messages[t];
|
|
949
958
|
if (n.find((u) => u.id === s.id))
|
|
950
959
|
return;
|
|
951
960
|
const i = L();
|
|
@@ -1004,7 +1013,7 @@ const De = Ge("messaging", {
|
|
|
1004
1013
|
try {
|
|
1005
1014
|
a = await l.post(n, r);
|
|
1006
1015
|
} catch (d) {
|
|
1007
|
-
if (!
|
|
1016
|
+
if (!Rt(d))
|
|
1008
1017
|
throw d;
|
|
1009
1018
|
a = await l.post(n, r);
|
|
1010
1019
|
}
|
|
@@ -1056,13 +1065,13 @@ const De = Ge("messaging", {
|
|
|
1056
1065
|
try {
|
|
1057
1066
|
const t = await P.acceptRequest(e);
|
|
1058
1067
|
this.requests = this.requests.filter((n) => n.id !== e);
|
|
1059
|
-
const s =
|
|
1068
|
+
const s = D({
|
|
1060
1069
|
...t,
|
|
1061
1070
|
is_pinned: t.is_pinned ?? !1,
|
|
1062
1071
|
is_archived: t.is_archived ?? !1,
|
|
1063
1072
|
is_muted: t.is_muted ?? !1
|
|
1064
1073
|
});
|
|
1065
|
-
this.conversations =
|
|
1074
|
+
this.conversations = j(this.conversations, s);
|
|
1066
1075
|
} catch (t) {
|
|
1067
1076
|
throw this.error = m(t), t;
|
|
1068
1077
|
}
|
|
@@ -1140,8 +1149,8 @@ const De = Ge("messaging", {
|
|
|
1140
1149
|
}
|
|
1141
1150
|
}
|
|
1142
1151
|
});
|
|
1143
|
-
function
|
|
1144
|
-
const t =
|
|
1152
|
+
function Vt(e) {
|
|
1153
|
+
const t = Ie(), s = L(), n = Q(!1), r = Q(null), i = Q(null), o = Me(), a = o !== null, u = 20, f = 250;
|
|
1145
1154
|
let y = 0, d = null, p = null;
|
|
1146
1155
|
const F = J(() => s.currentUser?.id), N = () => Oe(e)?.trim() ?? "", A = () => {
|
|
1147
1156
|
d && (clearTimeout(d), d = null), y = 0;
|
|
@@ -1241,16 +1250,16 @@ function kt(e) {
|
|
|
1241
1250
|
unsubscribe: v
|
|
1242
1251
|
};
|
|
1243
1252
|
}
|
|
1244
|
-
const
|
|
1253
|
+
const De = () => {
|
|
1245
1254
|
};
|
|
1246
|
-
let ce =
|
|
1247
|
-
function
|
|
1255
|
+
let ce = De;
|
|
1256
|
+
function Ft(e) {
|
|
1248
1257
|
ce = e;
|
|
1249
1258
|
}
|
|
1250
|
-
function
|
|
1251
|
-
ce =
|
|
1259
|
+
function Tt() {
|
|
1260
|
+
ce = De;
|
|
1252
1261
|
}
|
|
1253
|
-
const
|
|
1262
|
+
const xt = {
|
|
1254
1263
|
debug: () => {
|
|
1255
1264
|
},
|
|
1256
1265
|
info: () => {
|
|
@@ -1259,17 +1268,17 @@ const Tt = {
|
|
|
1259
1268
|
},
|
|
1260
1269
|
error: () => {
|
|
1261
1270
|
}
|
|
1262
|
-
}, $e = () =>
|
|
1271
|
+
}, $e = () => xt;
|
|
1263
1272
|
let ue = $e;
|
|
1264
|
-
function
|
|
1273
|
+
function qt(e) {
|
|
1265
1274
|
ue = e;
|
|
1266
1275
|
}
|
|
1267
|
-
function
|
|
1276
|
+
function Pt() {
|
|
1268
1277
|
ue = $e;
|
|
1269
1278
|
}
|
|
1270
|
-
const se = ue("GlobalMessaging"),
|
|
1271
|
-
function
|
|
1272
|
-
const e =
|
|
1279
|
+
const se = ue("GlobalMessaging"), Lt = 3, Nt = (e) => e.replace(/\/+$/, ""), Ut = (e) => Nt(window.location.pathname) === `/messages/${e}`, zt = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
1280
|
+
function Bt() {
|
|
1281
|
+
const e = Ie(), t = L(), s = He(), n = Me(), { conversations: r } = ke(e), i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
|
|
1273
1282
|
let a = !1;
|
|
1274
1283
|
function u(h) {
|
|
1275
1284
|
const v = o.get(h);
|
|
@@ -1308,7 +1317,7 @@ function Vt() {
|
|
|
1308
1317
|
const c = C, g = t.currentUser?.id;
|
|
1309
1318
|
if (!g || c.message.author_id === g) return;
|
|
1310
1319
|
e.addMessage(c.message);
|
|
1311
|
-
const w = e.hasDetailSubscription(c.conversation_id), R =
|
|
1320
|
+
const w = e.hasDetailSubscription(c.conversation_id), R = Ut(c.conversation_id);
|
|
1312
1321
|
if (w || R) {
|
|
1313
1322
|
const q = e.getConversationById(c.conversation_id);
|
|
1314
1323
|
q && (q.unread_count = 0), e.markAsRead(c.conversation_id).catch(() => {
|
|
@@ -1317,7 +1326,7 @@ function Vt() {
|
|
|
1317
1326
|
}
|
|
1318
1327
|
const S = e.getConversationById(c.conversation_id);
|
|
1319
1328
|
if (S) {
|
|
1320
|
-
const q =
|
|
1329
|
+
const q = zt(S);
|
|
1321
1330
|
q || S.unread_count++, ce(q);
|
|
1322
1331
|
}
|
|
1323
1332
|
}, k = (C) => {
|
|
@@ -1364,7 +1373,7 @@ function Vt() {
|
|
|
1364
1373
|
function p() {
|
|
1365
1374
|
const h = O();
|
|
1366
1375
|
if (!h) return;
|
|
1367
|
-
const v = e.conversations.slice(0,
|
|
1376
|
+
const v = e.conversations.slice(0, Lt), E = new Set(v.map((b) => b.id));
|
|
1368
1377
|
for (const b of i)
|
|
1369
1378
|
if (!E.has(b) && !e.hasDetailSubscription(b)) {
|
|
1370
1379
|
try {
|
|
@@ -1380,10 +1389,10 @@ function Vt() {
|
|
|
1380
1389
|
e.updatePresenceForUser(h.user_id, h.status);
|
|
1381
1390
|
}
|
|
1382
1391
|
function N() {
|
|
1383
|
-
!O() || a || (
|
|
1392
|
+
!O() || a || (je(F), a = !0);
|
|
1384
1393
|
}
|
|
1385
1394
|
function A() {
|
|
1386
|
-
a && (
|
|
1395
|
+
a && (Ye(), a = !1);
|
|
1387
1396
|
}
|
|
1388
1397
|
const T = de(
|
|
1389
1398
|
r,
|
|
@@ -1403,45 +1412,45 @@ function Vt() {
|
|
|
1403
1412
|
T(), x(), U(), d(), A();
|
|
1404
1413
|
});
|
|
1405
1414
|
}
|
|
1406
|
-
function
|
|
1407
|
-
e.apiClient && tt(e.apiClient), e.authStore && nt(e.authStore), e.mediaApi &&
|
|
1415
|
+
function Ht(e) {
|
|
1416
|
+
e.apiClient && tt(e.apiClient), e.authStore && nt(e.authStore), e.mediaApi && ot(e.mediaApi), e.createLogger && qt(e.createLogger), e.playMessageNotification && Ft(e.playMessageNotification), e.echo && Xe(e.echo);
|
|
1408
1417
|
}
|
|
1409
|
-
function
|
|
1410
|
-
st(), rt(),
|
|
1418
|
+
function jt() {
|
|
1419
|
+
st(), rt(), at(), Pt(), Tt(), Qe();
|
|
1411
1420
|
}
|
|
1412
1421
|
export {
|
|
1413
1422
|
l as api,
|
|
1414
|
-
|
|
1423
|
+
Ht as configureMessengerClient,
|
|
1415
1424
|
ue as createLogger,
|
|
1416
1425
|
O as getEcho,
|
|
1417
1426
|
le as getEchoInitializedEvent,
|
|
1418
1427
|
m as getErrorMessage,
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1428
|
+
it as getMediaApi,
|
|
1429
|
+
kt as hasResponse,
|
|
1430
|
+
Zt as isAxiosError,
|
|
1431
|
+
Gt as isError,
|
|
1422
1432
|
Ke as isValidMessageReadEvent,
|
|
1423
1433
|
Je as isValidMessageSentEvent,
|
|
1424
1434
|
et as isValidRequestAcceptedEvent,
|
|
1425
|
-
ie as mediaApi,
|
|
1426
1435
|
P as messagingApi,
|
|
1427
1436
|
xe as onConnectionStatusChange,
|
|
1428
1437
|
Qe as resetEchoRuntimeConfig,
|
|
1429
|
-
|
|
1438
|
+
Pt as resetLoggerFactory,
|
|
1430
1439
|
st as resetMessagingApiClient,
|
|
1431
1440
|
rt as resetMessagingAuthStoreResolver,
|
|
1432
|
-
|
|
1433
|
-
|
|
1441
|
+
at as resetMessagingMediaApi,
|
|
1442
|
+
jt as resetMessengerClientConfig,
|
|
1434
1443
|
Xe as setEchoRuntimeConfig,
|
|
1435
|
-
|
|
1444
|
+
qt as setLoggerFactory,
|
|
1436
1445
|
tt as setMessagingApiClient,
|
|
1437
1446
|
nt as setMessagingAuthStoreResolver,
|
|
1438
|
-
|
|
1447
|
+
ot as setMessagingMediaApi,
|
|
1439
1448
|
We as subscribeToConversation,
|
|
1440
|
-
|
|
1449
|
+
je as subscribeToPresenceStatus,
|
|
1441
1450
|
Ze as unsubscribeFromConversation,
|
|
1442
|
-
|
|
1451
|
+
Ye as unsubscribeFromPresenceStatus,
|
|
1443
1452
|
L as useAuthStore,
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1453
|
+
Vt as useConversationChannel,
|
|
1454
|
+
Bt as useGlobalMessaging,
|
|
1455
|
+
Ie as useMessagingStore
|
|
1447
1456
|
};
|
|
@@ -6,6 +6,6 @@ export interface UploadedMedia {
|
|
|
6
6
|
export interface MessagingMediaApi {
|
|
7
7
|
uploadImage(file: File): Promise<UploadedMedia>;
|
|
8
8
|
}
|
|
9
|
-
export declare
|
|
9
|
+
export declare function getMediaApi(): MessagingMediaApi;
|
|
10
10
|
export declare function setMessagingMediaApi(client: MessagingMediaApi): void;
|
|
11
11
|
export declare function resetMessagingMediaApi(): void;
|