@codingfactory/messenger-client 0.1.3 → 0.1.6
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
CHANGED
|
@@ -1,95 +1,101 @@
|
|
|
1
|
-
import { ref as Q, getCurrentInstance as
|
|
2
|
-
import { defineStore as
|
|
3
|
-
import
|
|
4
|
-
import { isAxiosError as
|
|
5
|
-
import { useRoute as
|
|
6
|
-
const
|
|
7
|
-
}, Ae = () => {
|
|
8
|
-
}, Ee = () => {
|
|
1
|
+
import { ref as Q, getCurrentInstance as we, computed as J, onUnmounted as Ae, toValue as ke, watch as fe } from "vue";
|
|
2
|
+
import { defineStore as Ve, storeToRefs as Be } from "pinia";
|
|
3
|
+
import He, { isAxiosError as je } from "axios";
|
|
4
|
+
import { isAxiosError as Kt } from "axios";
|
|
5
|
+
import { useRoute as Ye } from "vue-router";
|
|
6
|
+
const Ee = () => () => {
|
|
9
7
|
}, Fe = () => {
|
|
10
8
|
}, Te = () => {
|
|
9
|
+
}, xe = () => {
|
|
10
|
+
}, qe = () => {
|
|
11
11
|
throw new Error("messenger-client subscribeToConversation is not configured");
|
|
12
|
-
},
|
|
12
|
+
}, y = {
|
|
13
13
|
ECHO_INITIALIZED_EVENT: "messenger-client:echo-initialized",
|
|
14
14
|
getEcho: () => null,
|
|
15
|
-
onConnectionStatusChange:
|
|
16
|
-
subscribeToPresenceStatus:
|
|
17
|
-
unsubscribeFromPresenceStatus:
|
|
18
|
-
subscribeToConversation:
|
|
19
|
-
unsubscribeFromConversation:
|
|
20
|
-
},
|
|
21
|
-
function
|
|
22
|
-
e.initializedEvent && (
|
|
23
|
-
}
|
|
24
|
-
function
|
|
25
|
-
|
|
15
|
+
onConnectionStatusChange: Ee,
|
|
16
|
+
subscribeToPresenceStatus: Fe,
|
|
17
|
+
unsubscribeFromPresenceStatus: Te,
|
|
18
|
+
subscribeToConversation: qe,
|
|
19
|
+
unsubscribeFromConversation: xe
|
|
20
|
+
}, he = () => y.ECHO_INITIALIZED_EVENT, G = () => y.getEcho(), Pe = (e) => y.onConnectionStatusChange(e), We = (e) => y.subscribeToPresenceStatus(e), Ze = () => y.unsubscribeFromPresenceStatus(), Xe = (e, t) => y.subscribeToConversation(e, t), Qe = (e) => y.unsubscribeFromConversation(e);
|
|
21
|
+
function Je(e) {
|
|
22
|
+
e.initializedEvent && (y.ECHO_INITIALIZED_EVENT = e.initializedEvent), e.getEcho && (y.getEcho = e.getEcho), e.onConnectionStatusChange && (y.onConnectionStatusChange = e.onConnectionStatusChange), e.subscribeToPresenceStatus && (y.subscribeToPresenceStatus = e.subscribeToPresenceStatus), e.unsubscribeFromPresenceStatus && (y.unsubscribeFromPresenceStatus = e.unsubscribeFromPresenceStatus), e.subscribeToConversation && (y.subscribeToConversation = e.subscribeToConversation), e.unsubscribeFromConversation && (y.unsubscribeFromConversation = e.unsubscribeFromConversation);
|
|
23
|
+
}
|
|
24
|
+
function Ke() {
|
|
25
|
+
y.ECHO_INITIALIZED_EVENT = "messenger-client:echo-initialized", y.getEcho = () => null, y.onConnectionStatusChange = Ee, y.subscribeToPresenceStatus = Fe, y.unsubscribeFromPresenceStatus = Te, y.subscribeToConversation = qe, y.unsubscribeFromConversation = xe;
|
|
26
26
|
}
|
|
27
27
|
function Z(e) {
|
|
28
28
|
return typeof e == "object" && e !== null;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function et(e) {
|
|
31
31
|
return Z(e) && typeof e.conversation_id == "string" && Z(e.message) && typeof e.message.id == "string" && typeof e.message.conversation_id == "string" && typeof e.message.author_id == "string";
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function tt(e) {
|
|
34
34
|
return Z(e) && typeof e.conversation_id == "string" && typeof e.user_id == "string" && typeof e.message_id == "string";
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function st(e) {
|
|
37
37
|
return Z(e) && typeof e.conversation_id == "string";
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
let
|
|
41
|
-
function
|
|
42
|
-
|
|
39
|
+
const Le = He;
|
|
40
|
+
let ie = Le;
|
|
41
|
+
function h() {
|
|
42
|
+
return ie;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
44
|
+
function nt(e) {
|
|
45
|
+
ie = e;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
function rt() {
|
|
48
|
+
ie = Le;
|
|
49
|
+
}
|
|
50
|
+
const Ne = {
|
|
48
51
|
currentUser: null
|
|
49
52
|
};
|
|
50
|
-
let
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
+
let oe = () => Ne;
|
|
54
|
+
function k() {
|
|
55
|
+
return oe;
|
|
53
56
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
57
|
+
function it(e) {
|
|
58
|
+
oe = e;
|
|
59
|
+
}
|
|
60
|
+
function ot() {
|
|
61
|
+
oe = () => Ne;
|
|
56
62
|
}
|
|
57
|
-
function
|
|
58
|
-
if (
|
|
63
|
+
function g(e) {
|
|
64
|
+
if (je(e)) {
|
|
59
65
|
const t = e.response?.data?.message || e.message || "An error occurred";
|
|
60
66
|
return t.includes("SQLSTATE") || t.includes("Connection:") || t.includes("\\Illuminate\\") ? "Something went wrong. Please try again later." : t;
|
|
61
67
|
}
|
|
62
68
|
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
69
|
}
|
|
64
|
-
function
|
|
70
|
+
function Ht(e) {
|
|
65
71
|
return e instanceof Error;
|
|
66
72
|
}
|
|
67
|
-
function
|
|
73
|
+
function jt(e) {
|
|
68
74
|
return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
|
|
69
75
|
}
|
|
70
|
-
const
|
|
76
|
+
const Ue = {
|
|
71
77
|
async uploadImage() {
|
|
72
78
|
throw new Error("messenger-client mediaApi.uploadImage is not configured");
|
|
73
79
|
}
|
|
74
80
|
};
|
|
75
|
-
let
|
|
76
|
-
function it() {
|
|
77
|
-
return ie;
|
|
78
|
-
}
|
|
79
|
-
function ot(e) {
|
|
80
|
-
ie = e;
|
|
81
|
-
}
|
|
81
|
+
let ae = Ue;
|
|
82
82
|
function at() {
|
|
83
|
-
|
|
83
|
+
return ae;
|
|
84
84
|
}
|
|
85
85
|
function ct(e) {
|
|
86
|
+
ae = e;
|
|
87
|
+
}
|
|
88
|
+
function ut() {
|
|
89
|
+
ae = Ue;
|
|
90
|
+
}
|
|
91
|
+
function dt(e) {
|
|
86
92
|
return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
|
|
87
93
|
}
|
|
88
|
-
function
|
|
94
|
+
function ze(e) {
|
|
89
95
|
return typeof e == "object" && e !== null;
|
|
90
96
|
}
|
|
91
|
-
function
|
|
92
|
-
return !
|
|
97
|
+
function D(e) {
|
|
98
|
+
return !ze(e) || !("data" in e) ? e : e.data;
|
|
93
99
|
}
|
|
94
100
|
function B(e, t) {
|
|
95
101
|
const s = e[t];
|
|
@@ -97,7 +103,7 @@ function B(e, t) {
|
|
|
97
103
|
throw new Error(`Invalid messaging folder payload: missing string ${t}`);
|
|
98
104
|
return s;
|
|
99
105
|
}
|
|
100
|
-
function
|
|
106
|
+
function ge(e, t) {
|
|
101
107
|
const s = e[t];
|
|
102
108
|
if (s == null)
|
|
103
109
|
return null;
|
|
@@ -117,13 +123,13 @@ function K(e, t) {
|
|
|
117
123
|
throw new Error(`Invalid messaging folder payload: missing numeric ${t}`);
|
|
118
124
|
}
|
|
119
125
|
function ne(e) {
|
|
120
|
-
if (!
|
|
126
|
+
if (!ze(e))
|
|
121
127
|
throw new Error("Invalid messaging folder payload: expected object");
|
|
122
128
|
return {
|
|
123
129
|
id: B(e, "id"),
|
|
124
130
|
name: B(e, "name"),
|
|
125
|
-
color:
|
|
126
|
-
icon:
|
|
131
|
+
color: ge(e, "color"),
|
|
132
|
+
icon: ge(e, "icon"),
|
|
127
133
|
sort_order: K(e, "sort_order"),
|
|
128
134
|
conversation_count: K(e, "conversation_count"),
|
|
129
135
|
unread_count: K(e, "unread_count"),
|
|
@@ -131,49 +137,49 @@ function ne(e) {
|
|
|
131
137
|
updated_at: B(e, "updated_at")
|
|
132
138
|
};
|
|
133
139
|
}
|
|
134
|
-
function
|
|
140
|
+
function lt(e) {
|
|
135
141
|
if (!Array.isArray(e))
|
|
136
142
|
throw new Error("Invalid messaging folder payload: expected array");
|
|
137
143
|
return e.map((t) => ne(t));
|
|
138
144
|
}
|
|
139
|
-
function
|
|
140
|
-
if (!
|
|
145
|
+
function me(e) {
|
|
146
|
+
if (!dt(e))
|
|
141
147
|
throw new Error("Invalid conversation payload from folder assignment endpoint");
|
|
142
148
|
return e;
|
|
143
149
|
}
|
|
144
|
-
const
|
|
150
|
+
const x = {
|
|
145
151
|
async fetchFolders() {
|
|
146
|
-
const e = await
|
|
147
|
-
return
|
|
152
|
+
const e = await h().get("/v1/messaging/folders");
|
|
153
|
+
return lt(D(e.data));
|
|
148
154
|
},
|
|
149
155
|
async createFolder(e) {
|
|
150
|
-
const t = await
|
|
151
|
-
return ne(
|
|
156
|
+
const t = await h().post("/v1/messaging/folders", e);
|
|
157
|
+
return ne(D(t.data));
|
|
152
158
|
},
|
|
153
159
|
async updateFolder(e, t) {
|
|
154
|
-
const s = await
|
|
155
|
-
return ne(
|
|
160
|
+
const s = await h().patch(`/v1/messaging/folders/${e}`, t);
|
|
161
|
+
return ne(D(s.data));
|
|
156
162
|
},
|
|
157
163
|
async deleteFolder(e) {
|
|
158
|
-
await
|
|
164
|
+
await h().delete(`/v1/messaging/folders/${e}`);
|
|
159
165
|
},
|
|
160
166
|
async reorderFolders(e) {
|
|
161
|
-
await
|
|
167
|
+
await h().patch("/v1/messaging/folders/reorder", { order: e });
|
|
162
168
|
},
|
|
163
169
|
async assignFolder(e, t) {
|
|
164
|
-
const s = await
|
|
170
|
+
const s = await h().patch(`/v1/messaging/conversations/${e}/folder`, {
|
|
165
171
|
folder_id: t
|
|
166
172
|
});
|
|
167
|
-
return
|
|
173
|
+
return me(D(s.data));
|
|
168
174
|
},
|
|
169
175
|
async acceptRequest(e) {
|
|
170
|
-
const t = await
|
|
171
|
-
return
|
|
176
|
+
const t = await h().post(`/v1/messaging/conversations/${e}/accept`);
|
|
177
|
+
return me(D(t.data));
|
|
172
178
|
},
|
|
173
179
|
async declineRequest(e) {
|
|
174
|
-
await
|
|
180
|
+
await h().post(`/v1/messaging/conversations/${e}/decline`);
|
|
175
181
|
}
|
|
176
|
-
},
|
|
182
|
+
}, pe = 1e3, ce = 4e3, ft = 12e4, ht = 300, gt = 1, mt = 1600, ue = (e) => {
|
|
177
183
|
if (typeof e == "number" && Number.isFinite(e))
|
|
178
184
|
return e;
|
|
179
185
|
if (typeof e == "string") {
|
|
@@ -181,32 +187,32 @@ const P = {
|
|
|
181
187
|
if (Number.isFinite(t))
|
|
182
188
|
return t;
|
|
183
189
|
}
|
|
184
|
-
},
|
|
185
|
-
const s =
|
|
186
|
-
return s === void 0 ? !0 : s === 429 ||
|
|
187
|
-
},
|
|
190
|
+
}, Ie = (e) => typeof e == "number" && e >= 500 && e < 600, ve = (e) => {
|
|
191
|
+
const s = ue(e.response?.status);
|
|
192
|
+
return s === void 0 ? !0 : s === 429 || Ie(s);
|
|
193
|
+
}, De = (e) => {
|
|
188
194
|
if (typeof e == "number" && Number.isFinite(e) && e > 0)
|
|
189
|
-
return Math.max(
|
|
195
|
+
return Math.max(pe, e * 1e3);
|
|
190
196
|
if (typeof e == "string") {
|
|
191
197
|
const t = Number.parseInt(e, 10);
|
|
192
198
|
if (Number.isFinite(t) && t > 0)
|
|
193
|
-
return Math.max(
|
|
199
|
+
return Math.max(pe, t * 1e3);
|
|
194
200
|
}
|
|
195
|
-
return
|
|
196
|
-
},
|
|
197
|
-
const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n =
|
|
198
|
-
return Math.min(
|
|
199
|
-
},
|
|
201
|
+
return ce;
|
|
202
|
+
}, pt = (e) => {
|
|
203
|
+
const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = ce * s;
|
|
204
|
+
return Math.min(ft, n);
|
|
205
|
+
}, vt = (e) => {
|
|
200
206
|
const t = e;
|
|
201
|
-
return
|
|
202
|
-
},
|
|
207
|
+
return ue(t.response?.status) === 429 ? De(t.response?.headers?.["retry-after"]) : ht;
|
|
208
|
+
}, _e = async (e) => {
|
|
203
209
|
await new Promise((t) => {
|
|
204
210
|
setTimeout(t, e);
|
|
205
211
|
});
|
|
206
|
-
},
|
|
207
|
-
if (!
|
|
212
|
+
}, _t = (e) => {
|
|
213
|
+
if (!S(e))
|
|
208
214
|
return !1;
|
|
209
|
-
const s = (
|
|
215
|
+
const s = (S(e.data) ? e.data : e).throttled;
|
|
210
216
|
if (typeof s == "boolean")
|
|
211
217
|
return s;
|
|
212
218
|
if (typeof s == "number")
|
|
@@ -217,7 +223,7 @@ const P = {
|
|
|
217
223
|
}
|
|
218
224
|
return !1;
|
|
219
225
|
};
|
|
220
|
-
function
|
|
226
|
+
function yt(e, t, s) {
|
|
221
227
|
const n = typeof e == "string" && e.trim().length > 0 ? e.trim().toLowerCase() : void 0;
|
|
222
228
|
if (n)
|
|
223
229
|
return n;
|
|
@@ -227,17 +233,17 @@ function vt(e, t, s) {
|
|
|
227
233
|
const i = typeof s == "string" && s.trim().length > 0 ? s.trim().toLowerCase() : void 0;
|
|
228
234
|
return i ? i === "image" ? "image/*" : i === "video" ? "video/*" : i === "audio" ? "audio/*" : i : "application/octet-stream";
|
|
229
235
|
}
|
|
230
|
-
function
|
|
236
|
+
function bt(e) {
|
|
231
237
|
const t = e.url || "", s = e.thumbnail_url ?? e.thumbnail, n = {
|
|
232
238
|
id: e.media_id ?? e.id ?? "",
|
|
233
|
-
name: e.name ??
|
|
239
|
+
name: e.name ?? Ct(t),
|
|
234
240
|
url: t,
|
|
235
|
-
type:
|
|
241
|
+
type: yt(e.mime, e.mime_type, e.type),
|
|
236
242
|
size: e.size ?? 0
|
|
237
243
|
};
|
|
238
244
|
return s !== void 0 && (n.thumbnail = s), n;
|
|
239
245
|
}
|
|
240
|
-
function
|
|
246
|
+
function Ct(e) {
|
|
241
247
|
if (!e) return "attachment";
|
|
242
248
|
try {
|
|
243
249
|
const s = new URL(e).pathname.split("/");
|
|
@@ -246,8 +252,8 @@ function yt(e) {
|
|
|
246
252
|
return "attachment";
|
|
247
253
|
}
|
|
248
254
|
}
|
|
249
|
-
function
|
|
250
|
-
return !Array.isArray(e) || e.length === 0 ? [] : e.map(
|
|
255
|
+
function St(e) {
|
|
256
|
+
return !Array.isArray(e) || e.length === 0 ? [] : e.map(bt);
|
|
251
257
|
}
|
|
252
258
|
function X(e) {
|
|
253
259
|
if (typeof e != "string")
|
|
@@ -256,7 +262,7 @@ function X(e) {
|
|
|
256
262
|
if (t.length !== 0)
|
|
257
263
|
return t;
|
|
258
264
|
}
|
|
259
|
-
function
|
|
265
|
+
function Mt(e) {
|
|
260
266
|
if (!e)
|
|
261
267
|
return;
|
|
262
268
|
const t = X(e.avatar) ?? X(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
|
|
@@ -283,25 +289,25 @@ function Y(e) {
|
|
|
283
289
|
} : null;
|
|
284
290
|
return {
|
|
285
291
|
...e,
|
|
286
|
-
...s ? { author:
|
|
292
|
+
...s ? { author: Mt(s) } : {},
|
|
287
293
|
shared_post: n,
|
|
288
|
-
attachments:
|
|
294
|
+
attachments: St(e.attachments)
|
|
289
295
|
};
|
|
290
296
|
}
|
|
291
|
-
function
|
|
297
|
+
function Rt(e) {
|
|
292
298
|
return typeof e != "string" || e.length === 0 ? null : e;
|
|
293
299
|
}
|
|
294
|
-
function
|
|
300
|
+
function ye(e) {
|
|
295
301
|
if (!(typeof e != "string" || e.length === 0))
|
|
296
302
|
return e;
|
|
297
303
|
}
|
|
298
304
|
function re(e) {
|
|
299
305
|
return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
|
|
300
306
|
}
|
|
301
|
-
function
|
|
307
|
+
function wt(e, t = []) {
|
|
302
308
|
const s = /* @__PURE__ */ new Map();
|
|
303
309
|
for (const n of t) {
|
|
304
|
-
const r =
|
|
310
|
+
const r = ye(n.last_read_message_id);
|
|
305
311
|
r && s.set(n.user_id, r);
|
|
306
312
|
}
|
|
307
313
|
return e.map((n) => {
|
|
@@ -310,7 +316,7 @@ function Mt(e, t = []) {
|
|
|
310
316
|
name: n.user.name,
|
|
311
317
|
...i ? { avatar: i } : {},
|
|
312
318
|
...n.user.handle ? { handle: n.user.handle } : {}
|
|
313
|
-
} : void 0, a =
|
|
319
|
+
} : void 0, a = ye(n.last_read_message_id);
|
|
314
320
|
if (a)
|
|
315
321
|
return {
|
|
316
322
|
...n,
|
|
@@ -323,11 +329,11 @@ function Mt(e, t = []) {
|
|
|
323
329
|
...o ? { user: o } : {},
|
|
324
330
|
last_read_message_id: ""
|
|
325
331
|
};
|
|
326
|
-
const
|
|
327
|
-
return
|
|
332
|
+
const c = s.get(n.user_id);
|
|
333
|
+
return c ? {
|
|
328
334
|
...n,
|
|
329
335
|
...o ? { user: o } : {},
|
|
330
|
-
last_read_message_id:
|
|
336
|
+
last_read_message_id: c
|
|
331
337
|
} : {
|
|
332
338
|
...n,
|
|
333
339
|
...o ? { user: o } : {},
|
|
@@ -335,30 +341,30 @@ function Mt(e, t = []) {
|
|
|
335
341
|
};
|
|
336
342
|
});
|
|
337
343
|
}
|
|
338
|
-
function
|
|
339
|
-
const s =
|
|
344
|
+
function $(e, t) {
|
|
345
|
+
const s = Rt(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 = (() => {
|
|
340
346
|
if (!t || t.unread_count !== 0 || e.unread_count <= 0)
|
|
341
347
|
return !1;
|
|
342
|
-
const a = t.last_message?.id,
|
|
343
|
-
return !a || !
|
|
348
|
+
const a = t.last_message?.id, c = e.last_message?.id;
|
|
349
|
+
return !a || !c ? !1 : a === c;
|
|
344
350
|
})();
|
|
345
351
|
return {
|
|
346
352
|
...e,
|
|
347
353
|
unread_count: n || o ? 0 : e.unread_count,
|
|
348
|
-
participants:
|
|
354
|
+
participants: wt(e.participants, t?.participants),
|
|
349
355
|
is_muted: n,
|
|
350
356
|
muted_until: s,
|
|
351
357
|
...r ? { last_message: r } : {},
|
|
352
358
|
...i ? { last_message_at: i } : {}
|
|
353
359
|
};
|
|
354
360
|
}
|
|
355
|
-
function
|
|
361
|
+
function At(e) {
|
|
356
362
|
return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
357
363
|
}
|
|
358
364
|
function ee(e) {
|
|
359
|
-
return
|
|
365
|
+
return At(e) ? 0 : e.unread_count || 0;
|
|
360
366
|
}
|
|
361
|
-
function
|
|
367
|
+
function be(e, t) {
|
|
362
368
|
const s = t[e.id];
|
|
363
369
|
if (Array.isArray(s))
|
|
364
370
|
for (let n = s.length - 1; n >= 0; n -= 1) {
|
|
@@ -368,20 +374,20 @@ function _e(e, t) {
|
|
|
368
374
|
}
|
|
369
375
|
return re(e.last_message?.id) ? e.last_message.id : null;
|
|
370
376
|
}
|
|
371
|
-
function
|
|
377
|
+
function S(e) {
|
|
372
378
|
return typeof e == "object" && e !== null;
|
|
373
379
|
}
|
|
374
|
-
function
|
|
375
|
-
return
|
|
380
|
+
function Et(e) {
|
|
381
|
+
return S(e) ? (S(e.response) ? e.response : null)?.status === 401 : !1;
|
|
376
382
|
}
|
|
377
|
-
function
|
|
383
|
+
function Ce(e) {
|
|
378
384
|
if (!Array.isArray(e))
|
|
379
385
|
return [];
|
|
380
386
|
const t = [];
|
|
381
387
|
for (const s of e) {
|
|
382
|
-
if (!
|
|
388
|
+
if (!S(s) || typeof s.reaction != "string" || typeof s.count != "number" || !Array.isArray(s.users))
|
|
383
389
|
continue;
|
|
384
|
-
const n = s.users.filter((r) =>
|
|
390
|
+
const n = s.users.filter((r) => S(r)).filter(
|
|
385
391
|
(r) => typeof r.id == "string" && typeof r.name == "string"
|
|
386
392
|
).map((r) => ({
|
|
387
393
|
id: r.id,
|
|
@@ -395,24 +401,24 @@ function ye(e) {
|
|
|
395
401
|
}
|
|
396
402
|
return t;
|
|
397
403
|
}
|
|
398
|
-
function
|
|
399
|
-
const s =
|
|
404
|
+
function Ft(e, t) {
|
|
405
|
+
const s = S(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
|
|
400
406
|
if (!(typeof n != "string" || n.length === 0))
|
|
401
407
|
return n;
|
|
402
408
|
}
|
|
403
409
|
function H(e, t) {
|
|
404
|
-
const s =
|
|
410
|
+
const s = S(e) ? e : {}, n = s.data ?? e;
|
|
405
411
|
let r = [];
|
|
406
|
-
return Array.isArray(n) ? r = n :
|
|
412
|
+
return Array.isArray(n) ? r = n : S(n) && (Array.isArray(n.items) ? r = n.items : Array.isArray(n[t]) ? r = n[t] : Array.isArray(n.data) && (r = n.data)), {
|
|
407
413
|
items: r,
|
|
408
|
-
nextCursor:
|
|
414
|
+
nextCursor: Ft(s, n)
|
|
409
415
|
};
|
|
410
416
|
}
|
|
411
|
-
function
|
|
412
|
-
return
|
|
417
|
+
function Se(e) {
|
|
418
|
+
return S(e) && typeof e.id == "string" && e.id.length > 0;
|
|
413
419
|
}
|
|
414
|
-
function
|
|
415
|
-
return
|
|
420
|
+
function Me(e) {
|
|
421
|
+
return S(e) ? typeof e.id == "string" && (e.type === "dm" || e.type === "group") && Array.isArray(e.participants) : !1;
|
|
416
422
|
}
|
|
417
423
|
function W(e, t) {
|
|
418
424
|
if (e.is_pinned !== t.is_pinned)
|
|
@@ -423,15 +429,15 @@ function W(e, t) {
|
|
|
423
429
|
function j(e, t) {
|
|
424
430
|
return [t, ...e.filter((s) => s.id !== t.id)];
|
|
425
431
|
}
|
|
426
|
-
function
|
|
432
|
+
function O(e) {
|
|
427
433
|
return [...e].sort((t, s) => t.sort_order !== s.sort_order ? t.sort_order - s.sort_order : t.name.localeCompare(s.name));
|
|
428
434
|
}
|
|
429
|
-
function
|
|
435
|
+
function Tt(e, t) {
|
|
430
436
|
return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
|
|
431
437
|
}
|
|
432
|
-
function
|
|
438
|
+
function Re(e, t) {
|
|
433
439
|
return e.map((s) => {
|
|
434
|
-
const n =
|
|
440
|
+
const n = Tt(s.folder_id, t);
|
|
435
441
|
return (s.folder_id ?? null) === n ? s : {
|
|
436
442
|
...s,
|
|
437
443
|
folder_id: n
|
|
@@ -446,7 +452,7 @@ function te(e) {
|
|
|
446
452
|
s.is_request === !0 && t.set(s.id, s);
|
|
447
453
|
return Array.from(t.values()).sort(W);
|
|
448
454
|
}
|
|
449
|
-
const
|
|
455
|
+
const $e = Ve("messaging", {
|
|
450
456
|
state: () => ({
|
|
451
457
|
conversations: [],
|
|
452
458
|
requests: [],
|
|
@@ -476,7 +482,7 @@ const Ie = Ge("messaging", {
|
|
|
476
482
|
unreadConversationsCount: (e) => e.conversations.filter((t) => ee(t) > 0).length,
|
|
477
483
|
unreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
|
|
478
484
|
totalUnreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
|
|
479
|
-
sortedFolders: (e) =>
|
|
485
|
+
sortedFolders: (e) => O(e.folders),
|
|
480
486
|
folderById: (e) => (t) => e.folders.find((s) => s.id === t),
|
|
481
487
|
conversationsInFolder: (e) => (t) => e.conversations.filter((s) => s.folder_id === t),
|
|
482
488
|
hasMoreMessages: (e) => (t) => e.conversationHasMore[t] ?? !1,
|
|
@@ -491,44 +497,44 @@ const Ie = Ge("messaging", {
|
|
|
491
497
|
if (!this.foldersLoaded)
|
|
492
498
|
return;
|
|
493
499
|
const e = new Set(this.folders.map((t) => t.id));
|
|
494
|
-
this.conversations =
|
|
500
|
+
this.conversations = Re(this.conversations, e), this.requests = Re(this.requests, e), this.activeFolderId !== null && !e.has(this.activeFolderId) && (this.activeFolderId = null);
|
|
495
501
|
},
|
|
496
502
|
async fetchFolders() {
|
|
497
503
|
try {
|
|
498
|
-
const e = await
|
|
499
|
-
return this.folders =
|
|
504
|
+
const e = await x.fetchFolders();
|
|
505
|
+
return this.folders = O(e), this.foldersLoaded = !0, this.normalizeFolderAssignmentsState(), this.folders;
|
|
500
506
|
} catch (e) {
|
|
501
|
-
throw this.error =
|
|
507
|
+
throw this.error = g(e), e;
|
|
502
508
|
}
|
|
503
509
|
},
|
|
504
510
|
async createFolder(e) {
|
|
505
511
|
try {
|
|
506
|
-
const t = await
|
|
507
|
-
return this.folders =
|
|
512
|
+
const t = await x.createFolder(e);
|
|
513
|
+
return this.folders = O([...this.folders, t]), t;
|
|
508
514
|
} catch (t) {
|
|
509
|
-
throw this.error =
|
|
515
|
+
throw this.error = g(t), t;
|
|
510
516
|
}
|
|
511
517
|
},
|
|
512
518
|
async updateFolder(e, t) {
|
|
513
519
|
try {
|
|
514
|
-
const s = await
|
|
515
|
-
return this.folders =
|
|
520
|
+
const s = await x.updateFolder(e, t);
|
|
521
|
+
return this.folders = O(
|
|
516
522
|
this.folders.map((n) => n.id === e ? s : n)
|
|
517
523
|
), s;
|
|
518
524
|
} catch (s) {
|
|
519
|
-
throw this.error =
|
|
525
|
+
throw this.error = g(s), s;
|
|
520
526
|
}
|
|
521
527
|
},
|
|
522
528
|
async deleteFolder(e) {
|
|
523
529
|
try {
|
|
524
|
-
await
|
|
530
|
+
await x.deleteFolder(e), this.folders = this.folders.filter((t) => t.id !== e), this.foldersLoaded = !0, this.activeFolderId === e && (this.activeFolderId = null), this.normalizeFolderAssignmentsState();
|
|
525
531
|
} catch (t) {
|
|
526
|
-
throw this.error =
|
|
532
|
+
throw this.error = g(t), t;
|
|
527
533
|
}
|
|
528
534
|
},
|
|
529
535
|
async reorderFolders(e) {
|
|
530
536
|
try {
|
|
531
|
-
await
|
|
537
|
+
await x.reorderFolders(e);
|
|
532
538
|
const t = new Map(this.folders.map((r) => [r.id, r])), s = [];
|
|
533
539
|
for (const r of e) {
|
|
534
540
|
const i = t.get(r);
|
|
@@ -537,7 +543,7 @@ const Ie = Ge("messaging", {
|
|
|
537
543
|
sort_order: s.length + 1
|
|
538
544
|
}), t.delete(r));
|
|
539
545
|
}
|
|
540
|
-
const n =
|
|
546
|
+
const n = O(Array.from(t.values()));
|
|
541
547
|
for (const r of n)
|
|
542
548
|
s.push({
|
|
543
549
|
...r,
|
|
@@ -545,12 +551,12 @@ const Ie = Ge("messaging", {
|
|
|
545
551
|
});
|
|
546
552
|
this.folders = s;
|
|
547
553
|
} catch (t) {
|
|
548
|
-
throw this.error =
|
|
554
|
+
throw this.error = g(t), t;
|
|
549
555
|
}
|
|
550
556
|
},
|
|
551
557
|
async assignToFolder(e, t) {
|
|
552
558
|
try {
|
|
553
|
-
const s = await
|
|
559
|
+
const s = await x.assignFolder(e, t), n = this.conversations.findIndex((o) => o.id === e);
|
|
554
560
|
if (n < 0)
|
|
555
561
|
return;
|
|
556
562
|
const r = this.conversations[n];
|
|
@@ -562,7 +568,7 @@ const Ie = Ge("messaging", {
|
|
|
562
568
|
folder_id: i
|
|
563
569
|
};
|
|
564
570
|
} catch (s) {
|
|
565
|
-
throw this.error =
|
|
571
|
+
throw this.error = g(s), s;
|
|
566
572
|
}
|
|
567
573
|
},
|
|
568
574
|
async fetchConversations(e, t, s, n) {
|
|
@@ -570,23 +576,23 @@ const Ie = Ge("messaging", {
|
|
|
570
576
|
try {
|
|
571
577
|
const r = n?.includePresence ?? !0, i = {};
|
|
572
578
|
r && (i.include_presence = 1), e && (i.cursor = e), t && (i.filter = t), typeof s == "string" && s.length > 0 && (i.folder_id = s);
|
|
573
|
-
const o = await
|
|
579
|
+
const o = await h().get("/v1/messaging/conversations", { params: i }), { items: a, nextCursor: c } = H(
|
|
574
580
|
o.data,
|
|
575
581
|
"conversations"
|
|
576
582
|
), f = a.map((d) => {
|
|
577
|
-
const
|
|
578
|
-
(
|
|
583
|
+
const m = this.conversations.find(
|
|
584
|
+
(M) => M.id === d.id
|
|
579
585
|
);
|
|
580
|
-
return
|
|
586
|
+
return $(d, m);
|
|
581
587
|
});
|
|
582
588
|
e ? this.conversations.push(...f) : this.conversations = f, this.normalizeFolderAssignmentsState(), this.lastFetch = Date.now();
|
|
583
|
-
const
|
|
589
|
+
const v = {
|
|
584
590
|
data: f,
|
|
585
|
-
has_more: !!
|
|
591
|
+
has_more: !!c
|
|
586
592
|
};
|
|
587
|
-
return
|
|
593
|
+
return c !== void 0 && (v.next_cursor = c), v;
|
|
588
594
|
} catch (r) {
|
|
589
|
-
throw n?.background &&
|
|
595
|
+
throw n?.background && ve(r) || (this.error = g(r)), r;
|
|
590
596
|
} finally {
|
|
591
597
|
this.loading = !1;
|
|
592
598
|
}
|
|
@@ -600,21 +606,21 @@ const Ie = Ge("messaging", {
|
|
|
600
606
|
includePresence: !1
|
|
601
607
|
}), this.backgroundPollRetryAfterUntil = 0, this.backgroundPollTransientFailureCount = 0, !0;
|
|
602
608
|
} catch (e) {
|
|
603
|
-
const t = e, s =
|
|
604
|
-
return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() +
|
|
609
|
+
const t = e, s = ue(t.response?.status);
|
|
610
|
+
return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + De(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || Ie(s) ? (this.backgroundPollRetryAfterUntil = Date.now() + pt(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + ce, !1));
|
|
605
611
|
}
|
|
606
612
|
},
|
|
607
613
|
async fetchConversation(e) {
|
|
608
614
|
this.loading = !0, this.error = null;
|
|
609
615
|
try {
|
|
610
|
-
const t = await
|
|
616
|
+
const t = await h().get(`/v1/messaging/conversations/${e}`, {
|
|
611
617
|
params: { include_presence: 1 }
|
|
612
|
-
}), s = this.conversations.find((o) => o.id === e), n =
|
|
618
|
+
}), s = this.conversations.find((o) => o.id === e), n = $(t.data.data || t.data, s), r = this.conversations.findIndex((o) => o.id === e);
|
|
613
619
|
r >= 0 ? this.conversations[r] = n : this.conversations.push(n);
|
|
614
620
|
const i = this.requests.findIndex((o) => o.id === e);
|
|
615
621
|
return i >= 0 && (this.requests[i] = n), this.normalizeFolderAssignmentsState(), n;
|
|
616
622
|
} catch (t) {
|
|
617
|
-
throw this.error =
|
|
623
|
+
throw this.error = g(t), t;
|
|
618
624
|
} finally {
|
|
619
625
|
this.loading = !1;
|
|
620
626
|
}
|
|
@@ -627,12 +633,12 @@ const Ie = Ge("messaging", {
|
|
|
627
633
|
filter: "requests"
|
|
628
634
|
};
|
|
629
635
|
e && (t.cursor = e);
|
|
630
|
-
const s = await
|
|
636
|
+
const s = await h().get("/v1/messaging/conversations", { params: t }), { items: n, nextCursor: r } = H(
|
|
631
637
|
s.data,
|
|
632
638
|
"conversations"
|
|
633
639
|
), i = n.map((a) => {
|
|
634
|
-
const
|
|
635
|
-
return
|
|
640
|
+
const c = this.requests.find((f) => f.id === a.id);
|
|
641
|
+
return $(a, c);
|
|
636
642
|
});
|
|
637
643
|
e ? this.requests.push(...i) : this.requests = i, this.normalizeFolderAssignmentsState();
|
|
638
644
|
const o = {
|
|
@@ -641,7 +647,7 @@ const Ie = Ge("messaging", {
|
|
|
641
647
|
};
|
|
642
648
|
return r !== void 0 && (o.next_cursor = r), o;
|
|
643
649
|
} catch (t) {
|
|
644
|
-
throw this.error =
|
|
650
|
+
throw this.error = g(t), t;
|
|
645
651
|
} finally {
|
|
646
652
|
this.loading = !1;
|
|
647
653
|
}
|
|
@@ -653,111 +659,111 @@ const Ie = Ge("messaging", {
|
|
|
653
659
|
let n = 0, r;
|
|
654
660
|
for (; ; )
|
|
655
661
|
try {
|
|
656
|
-
r = await
|
|
662
|
+
r = await h().get(`/v1/messaging/conversations/${e}/messages`, { params: s });
|
|
657
663
|
break;
|
|
658
664
|
} catch (d) {
|
|
659
|
-
if (!(n <
|
|
665
|
+
if (!(n < gt && ve(d)))
|
|
660
666
|
throw d;
|
|
661
|
-
n += 1, await
|
|
667
|
+
n += 1, await _e(vt(d));
|
|
662
668
|
}
|
|
663
669
|
const { items: i, nextCursor: o } = H(
|
|
664
670
|
r.data,
|
|
665
671
|
"messages"
|
|
666
|
-
), a = i.map(Y),
|
|
667
|
-
if (t ? this.messages[e] = [...
|
|
668
|
-
const d = this.conversations.find((
|
|
672
|
+
), a = i.map(Y), c = [...a].reverse();
|
|
673
|
+
if (t ? this.messages[e] = [...c, ...this.messages[e] || []] : this.messages[e] = c, (() => {
|
|
674
|
+
const d = this.conversations.find((m) => m.id === e) ?? this.requests.find((m) => m.id === e);
|
|
669
675
|
return d ? !d.last_message || !d.last_message_at : !1;
|
|
670
676
|
})()) {
|
|
671
677
|
const d = this.messages[e]?.at(-1);
|
|
672
678
|
d && this.updateConversationLastMessage(e, d);
|
|
673
679
|
}
|
|
674
680
|
o ? (this.conversationCursors[e] = o, this.conversationHasMore[e] = !0) : (delete this.conversationCursors[e], this.conversationHasMore[e] = !1);
|
|
675
|
-
const
|
|
681
|
+
const v = {
|
|
676
682
|
data: a,
|
|
677
683
|
has_more: !!o
|
|
678
684
|
};
|
|
679
|
-
return o !== void 0 && (
|
|
685
|
+
return o !== void 0 && (v.next_cursor = o), v;
|
|
680
686
|
} catch (s) {
|
|
681
|
-
throw this.error =
|
|
687
|
+
throw this.error = g(s), s;
|
|
682
688
|
} finally {
|
|
683
689
|
this.loadingMessages[e] = !1, this.loading = !1;
|
|
684
690
|
}
|
|
685
691
|
},
|
|
686
692
|
async sendMessage(e, t, s, n, r, i) {
|
|
687
|
-
const o =
|
|
693
|
+
const o = k()(), a = `temp-${Date.now()}-${Math.random()}`, c = typeof i == "string" && i.trim().length > 0 ? i.trim() : null, f = o.currentUser, v = {
|
|
688
694
|
id: a,
|
|
689
695
|
conversation_id: e,
|
|
690
696
|
author_id: f?.id || "",
|
|
691
697
|
body: t || "",
|
|
692
698
|
attachments: [],
|
|
693
|
-
meta:
|
|
699
|
+
meta: c ? { shared_post_id: c } : {},
|
|
694
700
|
is_deleted: !1,
|
|
695
701
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
696
702
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
697
703
|
};
|
|
698
|
-
f && (
|
|
704
|
+
f && (v.author = {
|
|
699
705
|
id: f.id,
|
|
700
706
|
name: f.name,
|
|
701
707
|
...f.avatar ? { avatar: f.avatar } : {},
|
|
702
708
|
...f.handle ? { handle: f.handle } : {}
|
|
703
|
-
}), n != null && (
|
|
709
|
+
}), n != null && (v.reply_to_id = n), r != null && (v.reply_to = r), this.messages[e] || (this.messages[e] = []), this.messages[e].push(v), this._pendingSendIds.add(a);
|
|
704
710
|
try {
|
|
705
711
|
let d;
|
|
706
|
-
const
|
|
712
|
+
const m = {
|
|
707
713
|
body: t || "",
|
|
708
714
|
...n ? { reply_to_id: n } : {},
|
|
709
|
-
...
|
|
715
|
+
...c ? { shared_post_id: c } : {}
|
|
710
716
|
};
|
|
711
717
|
if (s && s.length > 0) {
|
|
712
|
-
const
|
|
713
|
-
s.map(async (
|
|
714
|
-
const
|
|
718
|
+
const l = await Promise.all(
|
|
719
|
+
s.map(async (_) => {
|
|
720
|
+
const w = await at().uploadImage(_);
|
|
715
721
|
return {
|
|
716
|
-
media_id:
|
|
717
|
-
mime:
|
|
718
|
-
size:
|
|
722
|
+
media_id: w.id,
|
|
723
|
+
mime: w.mime_type,
|
|
724
|
+
size: w.size
|
|
719
725
|
};
|
|
720
726
|
})
|
|
721
727
|
);
|
|
722
|
-
d = await
|
|
723
|
-
...
|
|
724
|
-
attachments:
|
|
728
|
+
d = await h().post(`/v1/messaging/conversations/${e}/messages`, {
|
|
729
|
+
...m,
|
|
730
|
+
attachments: l
|
|
725
731
|
});
|
|
726
732
|
} else
|
|
727
|
-
d = await
|
|
728
|
-
...
|
|
733
|
+
d = await h().post(`/v1/messaging/conversations/${e}/messages`, {
|
|
734
|
+
...m,
|
|
729
735
|
type: "text"
|
|
730
736
|
});
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
let
|
|
735
|
-
for (let
|
|
736
|
-
const
|
|
737
|
-
|
|
737
|
+
const M = d.data.data || d.data, U = { ...v, ...M, attachments: M.attachments ?? v.attachments }, R = Y(U), A = this.messages[e], P = A.findIndex((l) => l.id === a);
|
|
738
|
+
P >= 0 && (A[P] = R), this._pendingSendIds.delete(a);
|
|
739
|
+
const z = R.id;
|
|
740
|
+
let L = 0;
|
|
741
|
+
for (let l = A.length - 1; l >= 0; l--) {
|
|
742
|
+
const _ = A[l];
|
|
743
|
+
_ && _.id === z && (L++, L > 1 && A.splice(l, 1));
|
|
738
744
|
}
|
|
739
|
-
return this.updateConversationLastMessage(e,
|
|
745
|
+
return this.updateConversationLastMessage(e, R), R;
|
|
740
746
|
} catch (d) {
|
|
741
|
-
throw this._pendingSendIds.delete(a), this.messages[e] = this.messages[e].filter((
|
|
747
|
+
throw this._pendingSendIds.delete(a), this.messages[e] = this.messages[e].filter((m) => m.id !== a), this.error = g(d), d;
|
|
742
748
|
}
|
|
743
749
|
},
|
|
744
750
|
async editMessage(e, t, s) {
|
|
745
751
|
try {
|
|
746
|
-
const n = await
|
|
752
|
+
const n = await h().patch(`/v1/messaging/conversations/${e}/messages/${t}`, {
|
|
747
753
|
body: s
|
|
748
754
|
}), r = n.data.data || n.data, i = this.messages[e] || [], o = i.findIndex((a) => a.id === t);
|
|
749
755
|
if (o >= 0) {
|
|
750
|
-
const a = i[o],
|
|
751
|
-
return i[o] =
|
|
756
|
+
const a = i[o], c = r.id ? { ...a, ...r } : { ...a, body: s, edited_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
757
|
+
return i[o] = c, c;
|
|
752
758
|
}
|
|
753
759
|
return r;
|
|
754
760
|
} catch (n) {
|
|
755
|
-
throw this.error =
|
|
761
|
+
throw this.error = g(n), n;
|
|
756
762
|
}
|
|
757
763
|
},
|
|
758
764
|
async deleteMessage(e, t) {
|
|
759
765
|
try {
|
|
760
|
-
await
|
|
766
|
+
await h().delete(`/v1/messaging/conversations/${e}/messages/${t}`);
|
|
761
767
|
const s = this.messages[e] || [], n = s.findIndex((r) => r.id === t);
|
|
762
768
|
if (n >= 0) {
|
|
763
769
|
const r = s[n];
|
|
@@ -767,7 +773,7 @@ const Ie = Ge("messaging", {
|
|
|
767
773
|
delete i.body, s[n] = i;
|
|
768
774
|
}
|
|
769
775
|
} catch (s) {
|
|
770
|
-
throw this.error =
|
|
776
|
+
throw this.error = g(s), s;
|
|
771
777
|
}
|
|
772
778
|
},
|
|
773
779
|
async markAsRead(e) {
|
|
@@ -782,10 +788,10 @@ const Ie = Ge("messaging", {
|
|
|
782
788
|
return o;
|
|
783
789
|
}
|
|
784
790
|
return null;
|
|
785
|
-
})(), n = t ?
|
|
791
|
+
})(), n = t ? be(t, this.messages) : s;
|
|
786
792
|
if (!n)
|
|
787
793
|
return;
|
|
788
|
-
await
|
|
794
|
+
await h().post(`/v1/messaging/conversations/${e}/read`, {
|
|
789
795
|
message_id: n
|
|
790
796
|
}), this.conversations.forEach((r) => {
|
|
791
797
|
r.id === e && (r.unread_count = 0);
|
|
@@ -793,7 +799,7 @@ const Ie = Ge("messaging", {
|
|
|
793
799
|
r.id === e && (r.unread_count = 0);
|
|
794
800
|
});
|
|
795
801
|
} catch (t) {
|
|
796
|
-
throw this.error =
|
|
802
|
+
throw this.error = g(t), t;
|
|
797
803
|
}
|
|
798
804
|
},
|
|
799
805
|
async markAllAsRead() {
|
|
@@ -801,7 +807,7 @@ const Ie = Ge("messaging", {
|
|
|
801
807
|
if (e.length === 0)
|
|
802
808
|
return;
|
|
803
809
|
const t = e.map((r) => {
|
|
804
|
-
const i =
|
|
810
|
+
const i = be(r, this.messages);
|
|
805
811
|
return i ? {
|
|
806
812
|
conversationId: r.id,
|
|
807
813
|
messageId: i
|
|
@@ -811,7 +817,7 @@ const Ie = Ge("messaging", {
|
|
|
811
817
|
return;
|
|
812
818
|
const s = await Promise.allSettled(
|
|
813
819
|
t.map(
|
|
814
|
-
(r) =>
|
|
820
|
+
(r) => h().post(`/v1/messaging/conversations/${r.conversationId}/read`, {
|
|
815
821
|
message_id: r.messageId
|
|
816
822
|
})
|
|
817
823
|
)
|
|
@@ -821,46 +827,46 @@ const Ie = Ge("messaging", {
|
|
|
821
827
|
const o = t[i];
|
|
822
828
|
if (o) {
|
|
823
829
|
if (r.status === "fulfilled") {
|
|
824
|
-
const a = this.conversations.find((
|
|
830
|
+
const a = this.conversations.find((c) => c.id === o.conversationId);
|
|
825
831
|
a && (a.unread_count = 0);
|
|
826
832
|
return;
|
|
827
833
|
}
|
|
828
834
|
n === null && (n = r.reason);
|
|
829
835
|
}
|
|
830
836
|
}), n !== null)
|
|
831
|
-
throw this.error =
|
|
837
|
+
throw this.error = g(n), n;
|
|
832
838
|
},
|
|
833
839
|
async sendTyping(e, t = "start") {
|
|
834
840
|
try {
|
|
835
|
-
const s = await
|
|
836
|
-
if (t !== "start" || !
|
|
841
|
+
const s = await h().post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
842
|
+
if (t !== "start" || !_t(s.data))
|
|
837
843
|
return;
|
|
838
|
-
await
|
|
844
|
+
await _e(mt), await h().post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
839
845
|
} catch (s) {
|
|
840
846
|
console.warn("Failed to send typing indicator:", s);
|
|
841
847
|
}
|
|
842
848
|
},
|
|
843
849
|
async muteConversation(e, t) {
|
|
844
850
|
try {
|
|
845
|
-
const s = { minutes: t }, n = await
|
|
851
|
+
const s = { minutes: t }, n = await h().patch(`/v1/messaging/conversations/${e}/mute`, s), i = (n.data.data || n.data).muted_until || null, o = this.conversations.find((a) => a.id === e);
|
|
846
852
|
o && (o.is_muted = i !== null, o.muted_until = i);
|
|
847
853
|
} catch (s) {
|
|
848
|
-
throw this.error =
|
|
854
|
+
throw this.error = g(s), s;
|
|
849
855
|
}
|
|
850
856
|
},
|
|
851
857
|
async unmuteConversation(e) {
|
|
852
858
|
try {
|
|
853
|
-
const t = await
|
|
859
|
+
const t = await h().patch(`/v1/messaging/conversations/${e}/mute`, {
|
|
854
860
|
minutes: 0
|
|
855
861
|
}), n = (t.data.data || t.data).muted_until || null, r = this.conversations.find((i) => i.id === e);
|
|
856
862
|
r && (r.is_muted = n !== null, r.muted_until = n);
|
|
857
863
|
} catch (t) {
|
|
858
|
-
throw this.error =
|
|
864
|
+
throw this.error = g(t), t;
|
|
859
865
|
}
|
|
860
866
|
},
|
|
861
867
|
async updateConversationTitle(e, t) {
|
|
862
868
|
try {
|
|
863
|
-
const s = await
|
|
869
|
+
const s = await h().patch(`/v1/messaging/conversations/${e}`, {
|
|
864
870
|
title: t
|
|
865
871
|
}), n = s.data.data || s.data, r = typeof n?.title == "string" ? n.title : t, i = (o) => o.map((a) => a.id !== e ? a : {
|
|
866
872
|
...a,
|
|
@@ -868,30 +874,30 @@ const Ie = Ge("messaging", {
|
|
|
868
874
|
});
|
|
869
875
|
this.conversations = i(this.conversations), this.requests = i(this.requests);
|
|
870
876
|
} catch (s) {
|
|
871
|
-
throw this.error =
|
|
877
|
+
throw this.error = g(s), s;
|
|
872
878
|
}
|
|
873
879
|
},
|
|
874
880
|
async pinConversation(e, t) {
|
|
875
881
|
try {
|
|
876
|
-
await
|
|
882
|
+
await h().patch(`/v1/messaging/conversations/${e}/pin`, { pinned: t });
|
|
877
883
|
const s = this.conversations.find((n) => n.id === e);
|
|
878
884
|
s && (s.is_pinned = t), this.conversations.sort(W);
|
|
879
885
|
} catch (s) {
|
|
880
|
-
throw this.error =
|
|
886
|
+
throw this.error = g(s), s;
|
|
881
887
|
}
|
|
882
888
|
},
|
|
883
889
|
async archiveConversation(e, t) {
|
|
884
890
|
try {
|
|
885
|
-
await
|
|
891
|
+
await h().patch(`/v1/messaging/conversations/${e}/archive`, { archived: t }), this.conversations = this.conversations.filter((s) => s.id !== e);
|
|
886
892
|
} catch (s) {
|
|
887
|
-
throw this.error =
|
|
893
|
+
throw this.error = g(s), s;
|
|
888
894
|
}
|
|
889
895
|
},
|
|
890
896
|
async deleteConversation(e) {
|
|
891
897
|
try {
|
|
892
|
-
await
|
|
898
|
+
await h().delete(`/v1/messaging/conversations/${e}`), this.conversations = this.conversations.filter((t) => t.id !== e), delete this.messages[e], delete this.typingUsers[e], delete this.conversationCursors[e], delete this.conversationHasMore[e], delete this.loadingMessages[e];
|
|
893
899
|
} catch (t) {
|
|
894
|
-
throw this.error =
|
|
900
|
+
throw this.error = g(t), t;
|
|
895
901
|
}
|
|
896
902
|
},
|
|
897
903
|
async createDMConversation(e, t) {
|
|
@@ -900,52 +906,64 @@ const Ie = Ge("messaging", {
|
|
|
900
906
|
user_id: e
|
|
901
907
|
};
|
|
902
908
|
t && (s.message = t);
|
|
903
|
-
const n = await
|
|
904
|
-
if (!
|
|
909
|
+
const n = await h().post("/v1/messaging/conversations/dm", s), r = n.data.data || n.data;
|
|
910
|
+
if (!Se(r))
|
|
905
911
|
throw new Error("Invalid conversation payload from DM create endpoint.");
|
|
906
|
-
const i =
|
|
912
|
+
const i = Me(r) ? $(r) : await this.fetchConversation(r.id);
|
|
907
913
|
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);
|
|
908
914
|
} catch (s) {
|
|
909
|
-
throw this.error =
|
|
915
|
+
throw this.error = g(s), s;
|
|
910
916
|
}
|
|
911
917
|
},
|
|
912
918
|
async createGroupConversation(e, t) {
|
|
913
919
|
try {
|
|
914
|
-
const s = await
|
|
920
|
+
const s = await h().post("/v1/messaging/conversations/group", {
|
|
915
921
|
title: e,
|
|
916
922
|
participant_ids: t
|
|
917
923
|
}), n = s.data.data || s.data;
|
|
918
|
-
if (!
|
|
924
|
+
if (!Se(n))
|
|
919
925
|
throw new Error("Invalid conversation payload from group create endpoint.");
|
|
920
|
-
const r =
|
|
926
|
+
const r = Me(n) ? n : await this.fetchConversation(n.id);
|
|
921
927
|
return this.conversations = j(this.conversations, r), r;
|
|
922
928
|
} catch (s) {
|
|
923
|
-
throw this.error =
|
|
929
|
+
throw this.error = g(s), s;
|
|
924
930
|
}
|
|
925
931
|
},
|
|
926
932
|
async addParticipants(e, t) {
|
|
927
933
|
try {
|
|
928
|
-
await
|
|
934
|
+
await h().post(`/v1/messaging/conversations/${e}/participants`, {
|
|
929
935
|
user_ids: t
|
|
930
936
|
// Changed from participant_ids to user_ids to match backend
|
|
931
937
|
}), await this.fetchConversation(e);
|
|
932
938
|
} catch (s) {
|
|
933
|
-
throw this.error =
|
|
939
|
+
throw this.error = g(s), s;
|
|
934
940
|
}
|
|
935
941
|
},
|
|
936
942
|
async removeParticipant(e, t) {
|
|
937
943
|
try {
|
|
938
|
-
await
|
|
939
|
-
const s =
|
|
944
|
+
await h().delete(`/v1/messaging/conversations/${e}/participants/${t}`);
|
|
945
|
+
const s = k()();
|
|
940
946
|
if (t === s.currentUser?.id) {
|
|
941
947
|
this.conversations = this.conversations.filter((n) => n.id !== e), this.requests = this.requests.filter((n) => n.id !== e), delete this.messages[e], delete this.typingUsers[e], delete this.conversationCursors[e], delete this.conversationHasMore[e], delete this.loadingMessages[e];
|
|
942
948
|
return;
|
|
943
949
|
}
|
|
944
950
|
await this.fetchConversation(e);
|
|
945
951
|
} catch (s) {
|
|
946
|
-
throw this.error =
|
|
952
|
+
throw this.error = g(s), s;
|
|
947
953
|
}
|
|
948
954
|
},
|
|
955
|
+
applyParticipantReadState(e) {
|
|
956
|
+
const t = this.getConversationById(e.conversation_id);
|
|
957
|
+
if (!t)
|
|
958
|
+
return;
|
|
959
|
+
let s = !1;
|
|
960
|
+
const n = t.participants.map((o) => o.user_id !== e.user_id || o.last_read_message_id === e.message_id ? o : (s = !0, {
|
|
961
|
+
...o,
|
|
962
|
+
last_read_message_id: e.message_id
|
|
963
|
+
}));
|
|
964
|
+
s && (t.participants = n), !this.getMessagesByConversationId(e.conversation_id).some((o) => o.id === e.message_id) && this.fetchConversation(e.conversation_id).catch(() => {
|
|
965
|
+
});
|
|
966
|
+
},
|
|
949
967
|
// Real-time event handlers
|
|
950
968
|
// Accepts messages with any attachment shape — broadcast events use MessageAttachment[]
|
|
951
969
|
// while the store uses Attachment[]. normalizeMessage converts either format.
|
|
@@ -955,24 +973,24 @@ const Ie = Ge("messaging", {
|
|
|
955
973
|
return;
|
|
956
974
|
this.messages[t] || (this.messages[t] = []);
|
|
957
975
|
const s = Y({ ...e, attachments: e.attachments ?? [] }), n = this.messages[t];
|
|
958
|
-
if (n.find((
|
|
976
|
+
if (n.find((c) => c.id === s.id))
|
|
959
977
|
return;
|
|
960
|
-
const i =
|
|
978
|
+
const i = k()();
|
|
961
979
|
if (s.author_id === i.currentUser?.id) {
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
964
|
-
const f = n[
|
|
965
|
-
n[
|
|
980
|
+
const c = n.findIndex((f) => f.id.startsWith("temp-"));
|
|
981
|
+
if (c >= 0) {
|
|
982
|
+
const f = n[c]?.id ?? "";
|
|
983
|
+
n[c] = s, this._pendingSendIds.delete(f), this.updateConversationLastMessage(t, s);
|
|
966
984
|
return;
|
|
967
985
|
}
|
|
968
986
|
}
|
|
969
987
|
const o = s.created_at;
|
|
970
988
|
let a = n.length;
|
|
971
|
-
for (let
|
|
972
|
-
const f = n[
|
|
989
|
+
for (let c = n.length - 1; c >= 0; c--) {
|
|
990
|
+
const f = n[c];
|
|
973
991
|
if (f && f.created_at <= o)
|
|
974
992
|
break;
|
|
975
|
-
a =
|
|
993
|
+
a = c;
|
|
976
994
|
}
|
|
977
995
|
n.splice(a, 0, s), a === n.length - 1 && this.updateConversationLastMessage(t, s);
|
|
978
996
|
},
|
|
@@ -981,27 +999,27 @@ const Ie = Ge("messaging", {
|
|
|
981
999
|
s >= 0 && (t[s] = e);
|
|
982
1000
|
},
|
|
983
1001
|
removeMessage(e, t) {
|
|
984
|
-
const s = (
|
|
985
|
-
const f = { ...
|
|
1002
|
+
const s = (c) => {
|
|
1003
|
+
const f = { ...c, is_deleted: !0 };
|
|
986
1004
|
return delete f.body, f;
|
|
987
1005
|
};
|
|
988
1006
|
let n = null;
|
|
989
|
-
const r = this.conversations.find((
|
|
1007
|
+
const r = this.conversations.find((c) => c.id === e);
|
|
990
1008
|
r?.last_message?.id === t && (n = s(r.last_message), r.last_message = n);
|
|
991
|
-
const i = this.requests.find((
|
|
1009
|
+
const i = this.requests.find((c) => c.id === e);
|
|
992
1010
|
if (i?.last_message?.id === t) {
|
|
993
|
-
const
|
|
994
|
-
i.last_message =
|
|
1011
|
+
const c = s(i.last_message);
|
|
1012
|
+
i.last_message = c, n === null && (n = c);
|
|
995
1013
|
}
|
|
996
1014
|
const o = this.messages[e];
|
|
997
1015
|
if (!o) {
|
|
998
1016
|
n && this.addMessage(n);
|
|
999
1017
|
return;
|
|
1000
1018
|
}
|
|
1001
|
-
const a = o.findIndex((
|
|
1019
|
+
const a = o.findIndex((c) => c.id === t);
|
|
1002
1020
|
if (a >= 0) {
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1021
|
+
const c = o[a];
|
|
1022
|
+
c && (o[a] = s(c));
|
|
1005
1023
|
return;
|
|
1006
1024
|
}
|
|
1007
1025
|
n && this.addMessage(n);
|
|
@@ -1011,25 +1029,25 @@ const Ie = Ge("messaging", {
|
|
|
1011
1029
|
try {
|
|
1012
1030
|
let a;
|
|
1013
1031
|
try {
|
|
1014
|
-
a = await
|
|
1032
|
+
a = await h().post(n, r);
|
|
1015
1033
|
} catch (d) {
|
|
1016
|
-
if (!
|
|
1034
|
+
if (!Et(d))
|
|
1017
1035
|
throw d;
|
|
1018
|
-
a = await
|
|
1036
|
+
a = await h().post(n, r);
|
|
1019
1037
|
}
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1038
|
+
const c = S(a.data) && "data" in a.data ? a.data.data : a.data, f = Ce(
|
|
1039
|
+
S(c) ? c.reactions : void 0
|
|
1022
1040
|
);
|
|
1023
1041
|
(f.length > 0 || o.length === 0) && this.updateMessageReactions(e, t, f);
|
|
1024
1042
|
try {
|
|
1025
|
-
const d = await
|
|
1026
|
-
|
|
1043
|
+
const d = await h().get(n), m = S(d.data) && "data" in d.data ? d.data.data : d.data, M = Ce(
|
|
1044
|
+
S(m) ? m.reactions : void 0
|
|
1027
1045
|
);
|
|
1028
|
-
this.updateMessageReactions(e, t,
|
|
1046
|
+
this.updateMessageReactions(e, t, M);
|
|
1029
1047
|
} catch {
|
|
1030
1048
|
}
|
|
1031
1049
|
} catch (a) {
|
|
1032
|
-
throw this.error =
|
|
1050
|
+
throw this.error = g(a), a;
|
|
1033
1051
|
}
|
|
1034
1052
|
},
|
|
1035
1053
|
updateMessageReactions(e, t, s) {
|
|
@@ -1063,9 +1081,9 @@ const Ie = Ge("messaging", {
|
|
|
1063
1081
|
},
|
|
1064
1082
|
async acceptRequest(e) {
|
|
1065
1083
|
try {
|
|
1066
|
-
const t = await
|
|
1084
|
+
const t = await x.acceptRequest(e);
|
|
1067
1085
|
this.requests = this.requests.filter((n) => n.id !== e);
|
|
1068
|
-
const s =
|
|
1086
|
+
const s = $({
|
|
1069
1087
|
...t,
|
|
1070
1088
|
is_pinned: t.is_pinned ?? !1,
|
|
1071
1089
|
is_archived: t.is_archived ?? !1,
|
|
@@ -1073,14 +1091,14 @@ const Ie = Ge("messaging", {
|
|
|
1073
1091
|
});
|
|
1074
1092
|
this.conversations = j(this.conversations, s);
|
|
1075
1093
|
} catch (t) {
|
|
1076
|
-
throw this.error =
|
|
1094
|
+
throw this.error = g(t), t;
|
|
1077
1095
|
}
|
|
1078
1096
|
},
|
|
1079
1097
|
async declineRequest(e) {
|
|
1080
1098
|
try {
|
|
1081
|
-
await
|
|
1099
|
+
await x.declineRequest(e), this.requests = this.requests.filter((t) => t.id !== e);
|
|
1082
1100
|
} catch (t) {
|
|
1083
|
-
throw this.error =
|
|
1101
|
+
throw this.error = g(t), t;
|
|
1084
1102
|
}
|
|
1085
1103
|
},
|
|
1086
1104
|
async searchConversations(e, t, s) {
|
|
@@ -1088,7 +1106,7 @@ const Ie = Ge("messaging", {
|
|
|
1088
1106
|
try {
|
|
1089
1107
|
const n = { search: e, limit: 20 };
|
|
1090
1108
|
t && (n.filter = t), typeof s == "string" && s.length > 0 && (n.folder_id = s);
|
|
1091
|
-
const r = await
|
|
1109
|
+
const r = await h().get("/v1/messaging/conversations", {
|
|
1092
1110
|
params: n
|
|
1093
1111
|
}), { items: i } = H(
|
|
1094
1112
|
r.data,
|
|
@@ -1096,7 +1114,7 @@ const Ie = Ge("messaging", {
|
|
|
1096
1114
|
);
|
|
1097
1115
|
return i;
|
|
1098
1116
|
} catch (n) {
|
|
1099
|
-
return this.error =
|
|
1117
|
+
return this.error = g(n), [];
|
|
1100
1118
|
} finally {
|
|
1101
1119
|
this.searchLoading = !1;
|
|
1102
1120
|
}
|
|
@@ -1104,12 +1122,12 @@ const Ie = Ge("messaging", {
|
|
|
1104
1122
|
async searchMessages(e, t) {
|
|
1105
1123
|
this.searchLoading = !0;
|
|
1106
1124
|
try {
|
|
1107
|
-
const s = await
|
|
1125
|
+
const s = await h().get(`/v1/messaging/conversations/${e}/search`, {
|
|
1108
1126
|
params: { q: t }
|
|
1109
1127
|
}), n = s.data.data || s.data || [];
|
|
1110
1128
|
return this.searchResults = n, n;
|
|
1111
1129
|
} catch (s) {
|
|
1112
|
-
return this.error =
|
|
1130
|
+
return this.error = g(s), [];
|
|
1113
1131
|
} finally {
|
|
1114
1132
|
this.searchLoading = !1;
|
|
1115
1133
|
}
|
|
@@ -1149,117 +1167,124 @@ const Ie = Ge("messaging", {
|
|
|
1149
1167
|
}
|
|
1150
1168
|
}
|
|
1151
1169
|
});
|
|
1152
|
-
function
|
|
1153
|
-
const t =
|
|
1154
|
-
let
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1170
|
+
function Yt(e) {
|
|
1171
|
+
const t = $e(), s = k()(), n = Q(!1), r = Q(null), i = Q(null), o = we(), a = o !== null, c = 20, f = 250;
|
|
1172
|
+
let v = 0, d = null, m = null;
|
|
1173
|
+
const M = J(() => s.currentUser?.id), U = () => ke(e)?.trim() ?? "";
|
|
1174
|
+
function R() {
|
|
1175
|
+
d && (clearTimeout(d), d = null), v = 0;
|
|
1176
|
+
}
|
|
1177
|
+
function A() {
|
|
1178
|
+
!a || n.value || d || v >= c || (d = setTimeout(() => {
|
|
1179
|
+
d = null, v += 1, q();
|
|
1160
1180
|
}, f));
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
if (
|
|
1164
|
-
|
|
1165
|
-
|
|
1181
|
+
}
|
|
1182
|
+
function P(u) {
|
|
1183
|
+
if (t.addMessage(u.message), u.message.author_id !== M.value) {
|
|
1184
|
+
const p = t.getConversationById(u.conversation_id);
|
|
1185
|
+
p && (p.unread_count = 0), t.markAsRead(u.conversation_id).catch(() => {
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
function z(u) {
|
|
1190
|
+
t.applyParticipantReadState(u);
|
|
1191
|
+
}
|
|
1192
|
+
function L(u) {
|
|
1193
|
+
const p = t.getMessagesByConversationId(u.conversation_id), E = p.findIndex((N) => N.id === u.message.id);
|
|
1194
|
+
if (E >= 0) {
|
|
1195
|
+
const N = p[E];
|
|
1196
|
+
if (!N) return;
|
|
1197
|
+
const F = { ...N };
|
|
1198
|
+
u.message.body !== void 0 && (F.body = u.message.body), u.message.edited_at !== void 0 && (F.edited_at = u.message.edited_at), u.message.meta !== void 0 && (F.meta = u.message.meta), p[E] = F;
|
|
1199
|
+
const T = t.getConversationById(u.conversation_id);
|
|
1200
|
+
T && T.last_message?.id === u.message.id && (T.last_message = F);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
function l(u) {
|
|
1204
|
+
t.removeMessage(u.conversation_id, u.message_id);
|
|
1205
|
+
}
|
|
1206
|
+
function _(u) {
|
|
1207
|
+
t.updateMessageReactions(
|
|
1208
|
+
u.conversation_id,
|
|
1209
|
+
u.message_id,
|
|
1210
|
+
u.reactions
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
function w(u) {
|
|
1214
|
+
const p = t.getConversationById(u.conversation_id);
|
|
1215
|
+
p && (p.is_request = !1), t.requests = t.requests.filter(
|
|
1216
|
+
(E) => E.id !== u.conversation_id
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
function b(u) {
|
|
1220
|
+
u.removed_user_id === M.value && (C(), t.deleteConversation(u.conversation_id).catch(() => {
|
|
1221
|
+
}));
|
|
1222
|
+
}
|
|
1223
|
+
function q() {
|
|
1224
|
+
const u = U();
|
|
1225
|
+
if (!(n.value || !u)) {
|
|
1226
|
+
if (!G()) {
|
|
1227
|
+
A();
|
|
1166
1228
|
return;
|
|
1167
1229
|
}
|
|
1168
1230
|
r.value = null;
|
|
1169
1231
|
try {
|
|
1170
|
-
|
|
1171
|
-
onMessageSent:
|
|
1172
|
-
onMessageRead:
|
|
1173
|
-
onMessageEdited:
|
|
1174
|
-
onMessageDeleted:
|
|
1175
|
-
onReactionToggled:
|
|
1176
|
-
onRequestAccepted:
|
|
1177
|
-
onParticipantRemoved:
|
|
1178
|
-
}), n.value = !0, i.value =
|
|
1179
|
-
} catch (
|
|
1180
|
-
r.value =
|
|
1232
|
+
m = Xe(u, {
|
|
1233
|
+
onMessageSent: P,
|
|
1234
|
+
onMessageRead: z,
|
|
1235
|
+
onMessageEdited: L,
|
|
1236
|
+
onMessageDeleted: l,
|
|
1237
|
+
onReactionToggled: _,
|
|
1238
|
+
onRequestAccepted: w,
|
|
1239
|
+
onParticipantRemoved: b
|
|
1240
|
+
}), n.value = !0, i.value = u, t.registerDetailSubscription(u), R();
|
|
1241
|
+
} catch (p) {
|
|
1242
|
+
r.value = p instanceof Error ? p.message : "Failed to subscribe to conversation", console.error("ConversationChannel: Subscribe error", p);
|
|
1181
1243
|
}
|
|
1182
1244
|
}
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1245
|
+
}
|
|
1246
|
+
function I() {
|
|
1247
|
+
n.value || q();
|
|
1248
|
+
}
|
|
1249
|
+
typeof window < "u" && window.addEventListener(he(), I);
|
|
1250
|
+
const V = Pe((u) => {
|
|
1251
|
+
if (u === "connected") {
|
|
1252
|
+
n.value || q();
|
|
1190
1253
|
return;
|
|
1191
1254
|
}
|
|
1192
|
-
(
|
|
1193
|
-
})
|
|
1194
|
-
|
|
1195
|
-
|
|
1255
|
+
(u === "disconnected" || u === "error") && (R(), m && (m(), m = null), i.value && (t.unregisterDetailSubscription(i.value), i.value = null), n.value = !1);
|
|
1256
|
+
});
|
|
1257
|
+
function C() {
|
|
1258
|
+
const u = i.value;
|
|
1259
|
+
if (R(), !(!n.value || !u))
|
|
1196
1260
|
try {
|
|
1197
|
-
|
|
1198
|
-
} catch (
|
|
1199
|
-
r.value =
|
|
1261
|
+
m && (m(), m = null), t.hasGlobalConversationSubscription(u) || Qe(u), n.value = !1, t.unregisterDetailSubscription(u), i.value = null, r.value = null;
|
|
1262
|
+
} catch (p) {
|
|
1263
|
+
r.value = p instanceof Error ? p.message : "Failed to unsubscribe from conversation", console.error("ConversationChannel: Unsubscribe error", p);
|
|
1200
1264
|
}
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
g && (g.unread_count = 0), t.markAsRead(c.conversation_id).catch(() => {
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
}, b = (c) => {
|
|
1208
|
-
const g = t.getConversationById(c.conversation_id);
|
|
1209
|
-
if (g) {
|
|
1210
|
-
let w = !1;
|
|
1211
|
-
const R = g.participants.map((S) => S.user_id !== c.user_id || S.last_read_message_id === c.message_id ? S : (w = !0, {
|
|
1212
|
-
...S,
|
|
1213
|
-
last_read_message_id: c.message_id
|
|
1214
|
-
}));
|
|
1215
|
-
w && (g.participants = R);
|
|
1216
|
-
}
|
|
1217
|
-
}, z = (c) => {
|
|
1218
|
-
const g = t.getMessagesByConversationId(c.conversation_id), w = g.findIndex((R) => R.id === c.message.id);
|
|
1219
|
-
if (w >= 0) {
|
|
1220
|
-
const R = g[w];
|
|
1221
|
-
if (!R) return;
|
|
1222
|
-
const S = { ...R };
|
|
1223
|
-
c.message.body !== void 0 && (S.body = c.message.body), c.message.edited_at !== void 0 && (S.edited_at = c.message.edited_at), c.message.meta !== void 0 && (S.meta = c.message.meta), g[w] = S;
|
|
1224
|
-
const q = t.getConversationById(c.conversation_id);
|
|
1225
|
-
q && q.last_message?.id === c.message.id && (q.last_message = S);
|
|
1226
|
-
}
|
|
1227
|
-
}, G = (c) => {
|
|
1228
|
-
t.removeMessage(c.conversation_id, c.message_id);
|
|
1229
|
-
}, k = (c) => {
|
|
1230
|
-
t.updateMessageReactions(
|
|
1231
|
-
c.conversation_id,
|
|
1232
|
-
c.message_id,
|
|
1233
|
-
c.reactions
|
|
1234
|
-
);
|
|
1235
|
-
}, V = (c) => {
|
|
1236
|
-
const g = t.getConversationById(c.conversation_id);
|
|
1237
|
-
g && (g.is_request = !1), t.requests = t.requests.filter(
|
|
1238
|
-
(w) => w.id !== c.conversation_id
|
|
1239
|
-
);
|
|
1240
|
-
}, C = (c) => {
|
|
1241
|
-
c.removed_user_id === F.value && (v(), t.deleteConversation(c.conversation_id).catch(() => {
|
|
1242
|
-
}));
|
|
1243
|
-
};
|
|
1244
|
-
return o !== null && we(() => {
|
|
1245
|
-
A(), h(), v(), typeof window < "u" && window.removeEventListener(le(), U);
|
|
1265
|
+
}
|
|
1266
|
+
return o !== null && Ae(() => {
|
|
1267
|
+
R(), V(), C(), typeof window < "u" && window.removeEventListener(he(), I);
|
|
1246
1268
|
}), {
|
|
1247
1269
|
isSubscribed: J(() => n.value),
|
|
1248
1270
|
error: J(() => r.value),
|
|
1249
|
-
subscribe:
|
|
1250
|
-
unsubscribe:
|
|
1271
|
+
subscribe: q,
|
|
1272
|
+
unsubscribe: C
|
|
1251
1273
|
};
|
|
1252
1274
|
}
|
|
1253
|
-
const
|
|
1275
|
+
const Oe = () => {
|
|
1254
1276
|
};
|
|
1255
|
-
let
|
|
1256
|
-
function
|
|
1257
|
-
|
|
1277
|
+
let de = Oe;
|
|
1278
|
+
function xt() {
|
|
1279
|
+
return de;
|
|
1280
|
+
}
|
|
1281
|
+
function qt(e) {
|
|
1282
|
+
de = e;
|
|
1258
1283
|
}
|
|
1259
|
-
function
|
|
1260
|
-
|
|
1284
|
+
function Pt() {
|
|
1285
|
+
de = Oe;
|
|
1261
1286
|
}
|
|
1262
|
-
const
|
|
1287
|
+
const Lt = {
|
|
1263
1288
|
debug: () => {
|
|
1264
1289
|
},
|
|
1265
1290
|
info: () => {
|
|
@@ -1268,189 +1293,182 @@ const xt = {
|
|
|
1268
1293
|
},
|
|
1269
1294
|
error: () => {
|
|
1270
1295
|
}
|
|
1271
|
-
},
|
|
1272
|
-
let
|
|
1273
|
-
function
|
|
1274
|
-
|
|
1296
|
+
}, Ge = () => Lt;
|
|
1297
|
+
let le = Ge;
|
|
1298
|
+
function Nt() {
|
|
1299
|
+
return le;
|
|
1275
1300
|
}
|
|
1276
|
-
function
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1301
|
+
function Ut(e) {
|
|
1302
|
+
le = e;
|
|
1303
|
+
}
|
|
1304
|
+
function zt() {
|
|
1305
|
+
le = Ge;
|
|
1306
|
+
}
|
|
1307
|
+
const se = Nt()("GlobalMessaging"), It = 3, Dt = (e) => e.replace(/\/+$/, ""), $t = (e) => Dt(window.location.pathname) === `/messages/${e}`, Ot = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
1308
|
+
function Wt() {
|
|
1309
|
+
const e = $e(), t = k()(), s = xt(), n = Ye(), r = we(), { conversations: i } = Be(e), o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
|
|
1310
|
+
let c = !1;
|
|
1311
|
+
function f(l) {
|
|
1312
|
+
const _ = a.get(l);
|
|
1313
|
+
if (_ && (a.delete(l), typeof _.channel.stopListening == "function"))
|
|
1314
|
+
for (const w of _.bindings)
|
|
1287
1315
|
try {
|
|
1288
|
-
|
|
1316
|
+
_.channel.stopListening(w.event, w.handler);
|
|
1289
1317
|
} catch {
|
|
1290
1318
|
}
|
|
1291
1319
|
}
|
|
1292
|
-
function
|
|
1293
|
-
for (const
|
|
1294
|
-
|
|
1295
|
-
|
|
1320
|
+
function v() {
|
|
1321
|
+
for (const l of o)
|
|
1322
|
+
f(l), e.unregisterGlobalConversationSubscription(l);
|
|
1323
|
+
o.clear();
|
|
1296
1324
|
}
|
|
1297
|
-
function
|
|
1298
|
-
const
|
|
1299
|
-
if (!
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
let g = !1;
|
|
1305
|
-
const w = c.participants.map((R) => R.user_id !== C.user_id || R.last_read_message_id === C.message_id ? R : (g = !0, {
|
|
1306
|
-
...R,
|
|
1307
|
-
last_read_message_id: C.message_id
|
|
1308
|
-
}));
|
|
1309
|
-
g && (c.participants = w);
|
|
1310
|
-
}, b = `conversation.${h}`;
|
|
1311
|
-
u(h);
|
|
1312
|
-
const z = v.private(b), G = (C) => {
|
|
1313
|
-
if (!Je(C)) {
|
|
1325
|
+
function d(l) {
|
|
1326
|
+
const _ = G();
|
|
1327
|
+
if (!_ || o.has(l)) return;
|
|
1328
|
+
const w = `conversation.${l}`;
|
|
1329
|
+
f(l);
|
|
1330
|
+
const b = _.private(w), q = (C) => {
|
|
1331
|
+
if (!et(C)) {
|
|
1314
1332
|
se.warn("Dropping malformed ConversationMessageSent event", C);
|
|
1315
1333
|
return;
|
|
1316
1334
|
}
|
|
1317
|
-
const
|
|
1318
|
-
if (!
|
|
1319
|
-
e.addMessage(
|
|
1320
|
-
const
|
|
1321
|
-
if (
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1335
|
+
const u = C, p = t.currentUser?.id;
|
|
1336
|
+
if (!p || u.message.author_id === p) return;
|
|
1337
|
+
e.addMessage(u.message);
|
|
1338
|
+
const E = e.hasDetailSubscription(u.conversation_id), N = $t(u.conversation_id);
|
|
1339
|
+
if (E || N) {
|
|
1340
|
+
const T = e.getConversationById(u.conversation_id);
|
|
1341
|
+
T && (T.unread_count = 0), e.markAsRead(u.conversation_id).catch(() => {
|
|
1324
1342
|
});
|
|
1325
1343
|
return;
|
|
1326
1344
|
}
|
|
1327
|
-
const
|
|
1328
|
-
if (
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1345
|
+
const F = e.getConversationById(u.conversation_id);
|
|
1346
|
+
if (F) {
|
|
1347
|
+
const T = Ot(F);
|
|
1348
|
+
T || F.unread_count++, s(T);
|
|
1331
1349
|
}
|
|
1332
|
-
},
|
|
1333
|
-
if (!
|
|
1350
|
+
}, I = (C) => {
|
|
1351
|
+
if (!tt(C)) {
|
|
1334
1352
|
se.warn("Dropping malformed ConversationMessageRead event", C);
|
|
1335
1353
|
return;
|
|
1336
1354
|
}
|
|
1337
|
-
|
|
1355
|
+
e.applyParticipantReadState(C);
|
|
1338
1356
|
}, V = (C) => {
|
|
1339
|
-
if (!
|
|
1357
|
+
if (!st(C)) {
|
|
1340
1358
|
se.warn("Dropping malformed ConversationRequestAccepted event", C);
|
|
1341
1359
|
return;
|
|
1342
1360
|
}
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
(
|
|
1361
|
+
const u = C, p = e.getConversationById(u.conversation_id);
|
|
1362
|
+
p && (p.is_request = !1), e.requests = e.requests.filter(
|
|
1363
|
+
(E) => E.id !== u.conversation_id
|
|
1346
1364
|
);
|
|
1347
1365
|
};
|
|
1348
|
-
|
|
1349
|
-
channel:
|
|
1366
|
+
b.listen(".ConversationMessageSent", q), b.listen(".ConversationMessageRead", I), b.listen(".ConversationRequestAccepted", V), a.set(l, {
|
|
1367
|
+
channel: b,
|
|
1350
1368
|
bindings: [
|
|
1351
|
-
{ event: ".ConversationMessageSent", handler:
|
|
1352
|
-
{ event: ".ConversationMessageRead", handler:
|
|
1369
|
+
{ event: ".ConversationMessageSent", handler: q },
|
|
1370
|
+
{ event: ".ConversationMessageRead", handler: I },
|
|
1353
1371
|
{ event: ".ConversationRequestAccepted", handler: V }
|
|
1354
1372
|
]
|
|
1355
|
-
}),
|
|
1373
|
+
}), o.add(l), e.registerGlobalConversationSubscription(l);
|
|
1356
1374
|
}
|
|
1357
|
-
function
|
|
1358
|
-
const
|
|
1359
|
-
if (!
|
|
1360
|
-
|
|
1375
|
+
function m() {
|
|
1376
|
+
const l = G();
|
|
1377
|
+
if (!l) {
|
|
1378
|
+
v();
|
|
1361
1379
|
return;
|
|
1362
1380
|
}
|
|
1363
|
-
for (const
|
|
1364
|
-
|
|
1381
|
+
for (const _ of o) {
|
|
1382
|
+
f(_);
|
|
1365
1383
|
try {
|
|
1366
|
-
|
|
1384
|
+
l.leave(`conversation.${_}`);
|
|
1367
1385
|
} catch {
|
|
1368
1386
|
}
|
|
1369
|
-
e.unregisterGlobalConversationSubscription(
|
|
1387
|
+
e.unregisterGlobalConversationSubscription(_);
|
|
1370
1388
|
}
|
|
1371
|
-
|
|
1389
|
+
o.clear();
|
|
1372
1390
|
}
|
|
1373
|
-
function
|
|
1374
|
-
const
|
|
1375
|
-
if (!
|
|
1376
|
-
const
|
|
1377
|
-
for (const b of
|
|
1378
|
-
if (!
|
|
1391
|
+
function M() {
|
|
1392
|
+
const l = G();
|
|
1393
|
+
if (!l) return;
|
|
1394
|
+
const _ = e.conversations.slice(0, It), w = new Set(_.map((b) => b.id));
|
|
1395
|
+
for (const b of o)
|
|
1396
|
+
if (!w.has(b) && !e.hasDetailSubscription(b)) {
|
|
1379
1397
|
try {
|
|
1380
|
-
|
|
1398
|
+
f(b), l.leave(`conversation.${b}`);
|
|
1381
1399
|
} catch {
|
|
1382
1400
|
}
|
|
1383
|
-
|
|
1401
|
+
o.delete(b), e.unregisterGlobalConversationSubscription(b);
|
|
1384
1402
|
}
|
|
1385
|
-
for (const b of
|
|
1386
|
-
|
|
1403
|
+
for (const b of _)
|
|
1404
|
+
d(b.id);
|
|
1387
1405
|
}
|
|
1388
|
-
function
|
|
1389
|
-
e.updatePresenceForUser(
|
|
1406
|
+
function U(l) {
|
|
1407
|
+
e.updatePresenceForUser(l.user_id, l.status);
|
|
1390
1408
|
}
|
|
1391
|
-
function
|
|
1392
|
-
!
|
|
1409
|
+
function R() {
|
|
1410
|
+
!G() || c || (We(U), c = !0);
|
|
1393
1411
|
}
|
|
1394
1412
|
function A() {
|
|
1395
|
-
|
|
1413
|
+
c && (Ze(), c = !1);
|
|
1396
1414
|
}
|
|
1397
|
-
const
|
|
1398
|
-
|
|
1415
|
+
const P = fe(
|
|
1416
|
+
i,
|
|
1399
1417
|
() => {
|
|
1400
|
-
|
|
1418
|
+
M();
|
|
1401
1419
|
},
|
|
1402
1420
|
{ deep: !1, immediate: !0 }
|
|
1403
|
-
),
|
|
1404
|
-
() =>
|
|
1421
|
+
), z = fe(
|
|
1422
|
+
() => n.fullPath,
|
|
1405
1423
|
() => {
|
|
1406
|
-
|
|
1424
|
+
M();
|
|
1407
1425
|
}
|
|
1408
|
-
),
|
|
1409
|
-
|
|
1426
|
+
), L = Pe((l) => {
|
|
1427
|
+
l === "connected" ? (v(), M(), A(), R()) : (l === "disconnected" || l === "error") && (v(), A());
|
|
1410
1428
|
});
|
|
1411
|
-
|
|
1412
|
-
|
|
1429
|
+
M(), R(), r !== null && Ae(() => {
|
|
1430
|
+
P(), z(), L(), m(), A();
|
|
1413
1431
|
});
|
|
1414
1432
|
}
|
|
1415
|
-
function
|
|
1416
|
-
e.apiClient &&
|
|
1433
|
+
function Zt(e) {
|
|
1434
|
+
e.apiClient && nt(e.apiClient), e.authStore && it(e.authStore), e.mediaApi && ct(e.mediaApi), e.createLogger && Ut(e.createLogger), e.playMessageNotification && qt(e.playMessageNotification), e.echo && Je(e.echo);
|
|
1417
1435
|
}
|
|
1418
|
-
function
|
|
1419
|
-
|
|
1436
|
+
function Xt() {
|
|
1437
|
+
rt(), ot(), ut(), zt(), Pt(), Ke();
|
|
1420
1438
|
}
|
|
1421
1439
|
export {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
et as
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
rt as
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
nt as
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1440
|
+
Zt as configureMessengerClient,
|
|
1441
|
+
h as getApi,
|
|
1442
|
+
k as getAuthStore,
|
|
1443
|
+
G as getEcho,
|
|
1444
|
+
he as getEchoInitializedEvent,
|
|
1445
|
+
g as getErrorMessage,
|
|
1446
|
+
Nt as getLoggerFactory,
|
|
1447
|
+
at as getMediaApi,
|
|
1448
|
+
jt as hasResponse,
|
|
1449
|
+
Kt as isAxiosError,
|
|
1450
|
+
Ht as isError,
|
|
1451
|
+
tt as isValidMessageReadEvent,
|
|
1452
|
+
et as isValidMessageSentEvent,
|
|
1453
|
+
st as isValidRequestAcceptedEvent,
|
|
1454
|
+
x as messagingApi,
|
|
1455
|
+
Pe as onConnectionStatusChange,
|
|
1456
|
+
Ke as resetEchoRuntimeConfig,
|
|
1457
|
+
zt as resetLoggerFactory,
|
|
1458
|
+
rt as resetMessagingApiClient,
|
|
1459
|
+
ot as resetMessagingAuthStoreResolver,
|
|
1460
|
+
ut as resetMessagingMediaApi,
|
|
1461
|
+
Xt as resetMessengerClientConfig,
|
|
1462
|
+
Je as setEchoRuntimeConfig,
|
|
1463
|
+
Ut as setLoggerFactory,
|
|
1464
|
+
nt as setMessagingApiClient,
|
|
1465
|
+
it as setMessagingAuthStoreResolver,
|
|
1466
|
+
ct as setMessagingMediaApi,
|
|
1467
|
+
Xe as subscribeToConversation,
|
|
1468
|
+
We as subscribeToPresenceStatus,
|
|
1469
|
+
Qe as unsubscribeFromConversation,
|
|
1470
|
+
Ze as unsubscribeFromPresenceStatus,
|
|
1471
|
+
Yt as useConversationChannel,
|
|
1472
|
+
Wt as useGlobalMessaging,
|
|
1473
|
+
$e as useMessagingStore
|
|
1456
1474
|
};
|