@codingfactory/messenger-client 0.1.3 → 0.1.5
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
|
|
2
|
-
import { defineStore as
|
|
3
|
-
import
|
|
4
|
-
import { isAxiosError as
|
|
5
|
-
import { useRoute as
|
|
6
|
-
const
|
|
7
|
-
}, Ae = () => {
|
|
8
|
-
}, Ee = () => {
|
|
9
|
-
}, Fe = () => {
|
|
1
|
+
import { ref as J, getCurrentInstance as Ae, computed as K, onUnmounted as Ee, toValue as Ve, watch as he } from "vue";
|
|
2
|
+
import { defineStore as Be, storeToRefs as He } from "pinia";
|
|
3
|
+
import je, { isAxiosError as Ye } from "axios";
|
|
4
|
+
import { isAxiosError as es } from "axios";
|
|
5
|
+
import { useRoute as We } from "vue-router";
|
|
6
|
+
const Fe = () => () => {
|
|
10
7
|
}, Te = () => {
|
|
8
|
+
}, xe = () => {
|
|
9
|
+
}, qe = () => {
|
|
10
|
+
}, Pe = () => {
|
|
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: Fe,
|
|
16
|
+
subscribeToPresenceStatus: Te,
|
|
17
|
+
unsubscribeFromPresenceStatus: xe,
|
|
18
|
+
subscribeToConversation: Pe,
|
|
19
|
+
unsubscribeFromConversation: qe
|
|
20
|
+
}, ge = () => y.ECHO_INITIALIZED_EVENT, G = () => y.getEcho(), Le = (e) => y.onConnectionStatusChange(e), Ze = (e) => y.subscribeToPresenceStatus(e), Xe = () => y.unsubscribeFromPresenceStatus(), Qe = (e, t) => y.subscribeToConversation(e, t), Je = (e) => y.unsubscribeFromConversation(e);
|
|
21
|
+
function Ke(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 et() {
|
|
25
|
+
y.ECHO_INITIALIZED_EVENT = "messenger-client:echo-initialized", y.getEcho = () => null, y.onConnectionStatusChange = Fe, y.subscribeToPresenceStatus = Te, y.unsubscribeFromPresenceStatus = xe, y.subscribeToConversation = Pe, y.unsubscribeFromConversation = qe;
|
|
26
26
|
}
|
|
27
27
|
function Z(e) {
|
|
28
28
|
return typeof e == "object" && e !== null;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function tt(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 st(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 nt(e) {
|
|
37
37
|
return Z(e) && typeof e.conversation_id == "string";
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
let
|
|
41
|
-
function
|
|
42
|
-
|
|
39
|
+
const Ne = je;
|
|
40
|
+
let oe = Ne;
|
|
41
|
+
function h() {
|
|
42
|
+
return oe;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
44
|
+
function rt(e) {
|
|
45
|
+
oe = e;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
function it() {
|
|
48
|
+
oe = Ne;
|
|
49
|
+
}
|
|
50
|
+
const Ue = {
|
|
48
51
|
currentUser: null
|
|
49
52
|
};
|
|
50
|
-
let
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
+
let ae = () => Ue;
|
|
54
|
+
function k() {
|
|
55
|
+
return ae;
|
|
53
56
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
57
|
+
function ot(e) {
|
|
58
|
+
ae = e;
|
|
59
|
+
}
|
|
60
|
+
function at() {
|
|
61
|
+
ae = () => Ue;
|
|
56
62
|
}
|
|
57
|
-
function
|
|
58
|
-
if (
|
|
63
|
+
function g(e) {
|
|
64
|
+
if (Ye(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 jt(e) {
|
|
65
71
|
return e instanceof Error;
|
|
66
72
|
}
|
|
67
|
-
function
|
|
73
|
+
function Yt(e) {
|
|
68
74
|
return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
|
|
69
75
|
}
|
|
70
|
-
const
|
|
76
|
+
const ze = {
|
|
71
77
|
async uploadImage() {
|
|
72
78
|
throw new Error("messenger-client mediaApi.uploadImage is not configured");
|
|
73
79
|
}
|
|
74
80
|
};
|
|
75
|
-
let
|
|
76
|
-
function
|
|
77
|
-
return
|
|
81
|
+
let ce = ze;
|
|
82
|
+
function ct() {
|
|
83
|
+
return ce;
|
|
78
84
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
85
|
+
function ut(e) {
|
|
86
|
+
ce = e;
|
|
81
87
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
88
|
+
function dt() {
|
|
89
|
+
ce = ze;
|
|
84
90
|
}
|
|
85
|
-
function
|
|
91
|
+
function lt(e) {
|
|
86
92
|
return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
|
|
87
93
|
}
|
|
88
|
-
function
|
|
94
|
+
function Ie(e) {
|
|
89
95
|
return typeof e == "object" && e !== null;
|
|
90
96
|
}
|
|
91
|
-
function
|
|
92
|
-
return !
|
|
97
|
+
function D(e) {
|
|
98
|
+
return !Ie(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 me(e, t) {
|
|
101
107
|
const s = e[t];
|
|
102
108
|
if (s == null)
|
|
103
109
|
return null;
|
|
@@ -105,7 +111,7 @@ function fe(e, t) {
|
|
|
105
111
|
throw new Error(`Invalid messaging folder payload: ${t} must be a string or null`);
|
|
106
112
|
return s;
|
|
107
113
|
}
|
|
108
|
-
function
|
|
114
|
+
function ee(e, t) {
|
|
109
115
|
const s = e[t];
|
|
110
116
|
if (typeof s == "number" && Number.isFinite(s))
|
|
111
117
|
return s;
|
|
@@ -116,64 +122,64 @@ function K(e, t) {
|
|
|
116
122
|
}
|
|
117
123
|
throw new Error(`Invalid messaging folder payload: missing numeric ${t}`);
|
|
118
124
|
}
|
|
119
|
-
function
|
|
120
|
-
if (!
|
|
125
|
+
function re(e) {
|
|
126
|
+
if (!Ie(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:
|
|
127
|
-
sort_order:
|
|
128
|
-
conversation_count:
|
|
129
|
-
unread_count:
|
|
131
|
+
color: me(e, "color"),
|
|
132
|
+
icon: me(e, "icon"),
|
|
133
|
+
sort_order: ee(e, "sort_order"),
|
|
134
|
+
conversation_count: ee(e, "conversation_count"),
|
|
135
|
+
unread_count: ee(e, "unread_count"),
|
|
130
136
|
created_at: B(e, "created_at"),
|
|
131
137
|
updated_at: B(e, "updated_at")
|
|
132
138
|
};
|
|
133
139
|
}
|
|
134
|
-
function
|
|
140
|
+
function ft(e) {
|
|
135
141
|
if (!Array.isArray(e))
|
|
136
142
|
throw new Error("Invalid messaging folder payload: expected array");
|
|
137
|
-
return e.map((t) =>
|
|
143
|
+
return e.map((t) => re(t));
|
|
138
144
|
}
|
|
139
|
-
function
|
|
140
|
-
if (!
|
|
145
|
+
function pe(e) {
|
|
146
|
+
if (!lt(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 ft(D(e.data));
|
|
148
154
|
},
|
|
149
155
|
async createFolder(e) {
|
|
150
|
-
const t = await
|
|
151
|
-
return
|
|
156
|
+
const t = await h().post("/v1/messaging/folders", e);
|
|
157
|
+
return re(D(t.data));
|
|
152
158
|
},
|
|
153
159
|
async updateFolder(e, t) {
|
|
154
|
-
const s = await
|
|
155
|
-
return
|
|
160
|
+
const s = await h().patch(`/v1/messaging/folders/${e}`, t);
|
|
161
|
+
return re(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 pe(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 pe(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
|
+
}, ve = 1e3, ue = 4e3, ht = 12e4, gt = 300, mt = 1, pt = 1600, de = (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
|
+
}, De = (e) => typeof e == "number" && e >= 500 && e < 600, _e = (e) => {
|
|
191
|
+
const s = de(e.response?.status);
|
|
192
|
+
return s === void 0 ? !0 : s === 429 || De(s);
|
|
193
|
+
}, $e = (e) => {
|
|
188
194
|
if (typeof e == "number" && Number.isFinite(e) && e > 0)
|
|
189
|
-
return Math.max(
|
|
195
|
+
return Math.max(ve, 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(ve, 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 ue;
|
|
202
|
+
}, vt = (e) => {
|
|
203
|
+
const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = ue * s;
|
|
204
|
+
return Math.min(ht, n);
|
|
205
|
+
}, _t = (e) => {
|
|
200
206
|
const t = e;
|
|
201
|
-
return
|
|
202
|
-
},
|
|
207
|
+
return de(t.response?.status) === 429 ? $e(t.response?.headers?.["retry-after"]) : gt;
|
|
208
|
+
}, ye = async (e) => {
|
|
203
209
|
await new Promise((t) => {
|
|
204
210
|
setTimeout(t, e);
|
|
205
211
|
});
|
|
206
|
-
},
|
|
207
|
-
if (!
|
|
212
|
+
}, yt = (e) => {
|
|
213
|
+
if (!C(e))
|
|
208
214
|
return !1;
|
|
209
|
-
const s = (
|
|
215
|
+
const s = (C(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 bt(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 Ct(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 ?? St(t),
|
|
234
240
|
url: t,
|
|
235
|
-
type:
|
|
241
|
+
type: bt(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 St(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 Mt(e) {
|
|
256
|
+
return !Array.isArray(e) || e.length === 0 ? [] : e.map(Ct);
|
|
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 Rt(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: Rt(s) } : {},
|
|
287
293
|
shared_post: n,
|
|
288
|
-
attachments:
|
|
294
|
+
attachments: Mt(e.attachments)
|
|
289
295
|
};
|
|
290
296
|
}
|
|
291
|
-
function
|
|
297
|
+
function wt(e) {
|
|
292
298
|
return typeof e != "string" || e.length === 0 ? null : e;
|
|
293
299
|
}
|
|
294
|
-
function
|
|
300
|
+
function be(e) {
|
|
295
301
|
if (!(typeof e != "string" || e.length === 0))
|
|
296
302
|
return e;
|
|
297
303
|
}
|
|
298
|
-
function
|
|
304
|
+
function ie(e) {
|
|
299
305
|
return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
|
|
300
306
|
}
|
|
301
|
-
function
|
|
307
|
+
function At(e, t = []) {
|
|
302
308
|
const s = /* @__PURE__ */ new Map();
|
|
303
309
|
for (const n of t) {
|
|
304
|
-
const r =
|
|
310
|
+
const r = be(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 = be(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,53 +341,53 @@ function Mt(e, t = []) {
|
|
|
335
341
|
};
|
|
336
342
|
});
|
|
337
343
|
}
|
|
338
|
-
function
|
|
339
|
-
const s =
|
|
344
|
+
function $(e, t) {
|
|
345
|
+
const s = wt(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: At(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 Et(e) {
|
|
356
362
|
return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
357
363
|
}
|
|
358
|
-
function
|
|
359
|
-
return
|
|
364
|
+
function te(e) {
|
|
365
|
+
return Et(e) ? 0 : e.unread_count || 0;
|
|
360
366
|
}
|
|
361
|
-
function
|
|
367
|
+
function Ce(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) {
|
|
365
371
|
const r = s[n]?.id;
|
|
366
|
-
if (
|
|
372
|
+
if (ie(r))
|
|
367
373
|
return r;
|
|
368
374
|
}
|
|
369
|
-
return
|
|
375
|
+
return ie(e.last_message?.id) ? e.last_message.id : null;
|
|
370
376
|
}
|
|
371
|
-
function
|
|
377
|
+
function C(e) {
|
|
372
378
|
return typeof e == "object" && e !== null;
|
|
373
379
|
}
|
|
374
|
-
function
|
|
375
|
-
return
|
|
380
|
+
function Ft(e) {
|
|
381
|
+
return C(e) ? (C(e.response) ? e.response : null)?.status === 401 : !1;
|
|
376
382
|
}
|
|
377
|
-
function
|
|
383
|
+
function Se(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 (!C(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) => C(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 Tt(e, t) {
|
|
405
|
+
const s = C(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 = C(e) ? e : {}, n = s.data ?? e;
|
|
405
411
|
let r = [];
|
|
406
|
-
return Array.isArray(n) ? r = n :
|
|
412
|
+
return Array.isArray(n) ? r = n : C(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: Tt(s, n)
|
|
409
415
|
};
|
|
410
416
|
}
|
|
411
|
-
function
|
|
412
|
-
return
|
|
417
|
+
function Me(e) {
|
|
418
|
+
return C(e) && typeof e.id == "string" && e.id.length > 0;
|
|
413
419
|
}
|
|
414
|
-
function
|
|
415
|
-
return
|
|
420
|
+
function Re(e) {
|
|
421
|
+
return C(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,22 +429,22 @@ 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 xt(e, t) {
|
|
430
436
|
return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
|
|
431
437
|
}
|
|
432
|
-
function
|
|
438
|
+
function we(e, t) {
|
|
433
439
|
return e.map((s) => {
|
|
434
|
-
const n =
|
|
440
|
+
const n = xt(s.folder_id, t);
|
|
435
441
|
return (s.folder_id ?? null) === n ? s : {
|
|
436
442
|
...s,
|
|
437
443
|
folder_id: n
|
|
438
444
|
};
|
|
439
445
|
});
|
|
440
446
|
}
|
|
441
|
-
function
|
|
447
|
+
function se(e) {
|
|
442
448
|
const t = /* @__PURE__ */ new Map();
|
|
443
449
|
for (const s of e.requests)
|
|
444
450
|
s.is_request === !0 && t.set(s.id, s);
|
|
@@ -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 Oe = Be("messaging", {
|
|
450
456
|
state: () => ({
|
|
451
457
|
conversations: [],
|
|
452
458
|
requests: [],
|
|
@@ -473,62 +479,62 @@ const Ie = Ge("messaging", {
|
|
|
473
479
|
getConversationById: (e) => (t) => e.conversations.find((s) => s.id === t),
|
|
474
480
|
getMessagesByConversationId: (e) => (t) => e.messages[t] || [],
|
|
475
481
|
getTypingUsers: (e) => (t) => e.typingUsers[t] || [],
|
|
476
|
-
unreadConversationsCount: (e) => e.conversations.filter((t) =>
|
|
477
|
-
unreadCount: (e) => e.conversations.reduce((t, s) => t +
|
|
478
|
-
totalUnreadCount: (e) => e.conversations.reduce((t, s) => t +
|
|
479
|
-
sortedFolders: (e) =>
|
|
482
|
+
unreadConversationsCount: (e) => e.conversations.filter((t) => te(t) > 0).length,
|
|
483
|
+
unreadCount: (e) => e.conversations.reduce((t, s) => t + te(s), 0),
|
|
484
|
+
totalUnreadCount: (e) => e.conversations.reduce((t, s) => t + te(s), 0),
|
|
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,
|
|
483
489
|
isLoadingMessages: (e) => (t) => e.loadingMessages[t] ?? !1,
|
|
484
490
|
// Message request getters
|
|
485
|
-
requestConversations: (e) =>
|
|
486
|
-
requestCount: (e) =>
|
|
487
|
-
unreadRequestCount: (e) =>
|
|
491
|
+
requestConversations: (e) => se(e),
|
|
492
|
+
requestCount: (e) => se(e).length,
|
|
493
|
+
unreadRequestCount: (e) => se(e).filter((t) => t.unread_count > 0).length
|
|
488
494
|
},
|
|
489
495
|
actions: {
|
|
490
496
|
normalizeFolderAssignmentsState() {
|
|
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 = we(this.conversations, e), this.requests = we(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
|
+
(S) => S.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 p = {
|
|
584
590
|
data: f,
|
|
585
|
-
has_more: !!
|
|
591
|
+
has_more: !!c
|
|
586
592
|
};
|
|
587
|
-
return
|
|
593
|
+
return c !== void 0 && (p.next_cursor = c), p;
|
|
588
594
|
} catch (r) {
|
|
589
|
-
throw n?.background &&
|
|
595
|
+
throw n?.background && _e(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 = de(t.response?.status);
|
|
610
|
+
return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + $e(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || De(s) ? (this.backgroundPollRetryAfterUntil = Date.now() + vt(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + ue, !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 < mt && _e(d)))
|
|
660
666
|
throw d;
|
|
661
|
-
n += 1, await
|
|
667
|
+
n += 1, await ye(_t(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 p = {
|
|
676
682
|
data: a,
|
|
677
683
|
has_more: !!o
|
|
678
684
|
};
|
|
679
|
-
return o !== void 0 && (
|
|
685
|
+
return o !== void 0 && (p.next_cursor = o), p;
|
|
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, p = {
|
|
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 && (p.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 && (p.reply_to_id = n), r != null && (p.reply_to = r), this.messages[e] || (this.messages[e] = []), this.messages[e].push(p), 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 (v) => {
|
|
720
|
+
const A = await ct().uploadImage(v);
|
|
715
721
|
return {
|
|
716
|
-
media_id:
|
|
717
|
-
mime:
|
|
718
|
-
size:
|
|
722
|
+
media_id: A.id,
|
|
723
|
+
mime: A.mime_type,
|
|
724
|
+
size: A.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 S = d.data.data || d.data, U = { ...p, ...S, attachments: S.attachments ?? p.attachments }, w = Y(U), E = this.messages[e], L = E.findIndex((l) => l.id === a);
|
|
738
|
+
L >= 0 && (E[L] = w), this._pendingSendIds.delete(a);
|
|
739
|
+
const z = w.id;
|
|
740
|
+
let N = 0;
|
|
741
|
+
for (let l = E.length - 1; l >= 0; l--) {
|
|
742
|
+
const v = E[l];
|
|
743
|
+
v && v.id === z && (N++, N > 1 && E.splice(l, 1));
|
|
738
744
|
}
|
|
739
|
-
return this.updateConversationLastMessage(e,
|
|
745
|
+
return this.updateConversationLastMessage(e, w), w;
|
|
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) {
|
|
@@ -778,14 +784,14 @@ const Ie = Ge("messaging", {
|
|
|
778
784
|
return null;
|
|
779
785
|
for (let i = r.length - 1; i >= 0; i -= 1) {
|
|
780
786
|
const o = r[i]?.id;
|
|
781
|
-
if (
|
|
787
|
+
if (ie(o))
|
|
782
788
|
return o;
|
|
783
789
|
}
|
|
784
790
|
return null;
|
|
785
|
-
})(), n = t ?
|
|
791
|
+
})(), n = t ? Ce(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 = Ce(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" || !yt(s.data))
|
|
837
843
|
return;
|
|
838
|
-
await
|
|
844
|
+
await ye(pt), 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 (!Me(r))
|
|
905
911
|
throw new Error("Invalid conversation payload from DM create endpoint.");
|
|
906
|
-
const i =
|
|
912
|
+
const i = Re(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 (!Me(n))
|
|
919
925
|
throw new Error("Invalid conversation payload from group create endpoint.");
|
|
920
|
-
const r =
|
|
926
|
+
const r = Re(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 (!Ft(d))
|
|
1017
1035
|
throw d;
|
|
1018
|
-
a = await
|
|
1036
|
+
a = await h().post(n, r);
|
|
1019
1037
|
}
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1038
|
+
const c = C(a.data) && "data" in a.data ? a.data.data : a.data, f = Se(
|
|
1039
|
+
C(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 = C(d.data) && "data" in d.data ? d.data.data : d.data, S = Se(
|
|
1044
|
+
C(m) ? m.reactions : void 0
|
|
1027
1045
|
);
|
|
1028
|
-
this.updateMessageReactions(e, t,
|
|
1046
|
+
this.updateMessageReactions(e, t, S);
|
|
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,114 @@ const Ie = Ge("messaging", {
|
|
|
1149
1167
|
}
|
|
1150
1168
|
}
|
|
1151
1169
|
});
|
|
1152
|
-
function
|
|
1153
|
-
const t =
|
|
1154
|
-
let
|
|
1155
|
-
const
|
|
1156
|
-
d && (clearTimeout(d), d = null),
|
|
1157
|
-
},
|
|
1158
|
-
!a || n.value || d ||
|
|
1159
|
-
d = null,
|
|
1170
|
+
function Wt(e) {
|
|
1171
|
+
const t = Oe(), s = k()(), n = J(!1), r = J(null), i = J(null), o = Ae(), a = o !== null, c = 20, f = 250;
|
|
1172
|
+
let p = 0, d = null, m = null;
|
|
1173
|
+
const S = K(() => s.currentUser?.id), U = () => Ve(e)?.trim() ?? "", w = () => {
|
|
1174
|
+
d && (clearTimeout(d), d = null), p = 0;
|
|
1175
|
+
}, E = () => {
|
|
1176
|
+
!a || n.value || d || p >= c || (d = setTimeout(() => {
|
|
1177
|
+
d = null, p += 1, q();
|
|
1160
1178
|
}, f));
|
|
1161
|
-
},
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1179
|
+
}, L = (u) => {
|
|
1180
|
+
if (t.addMessage(u.message), u.message.author_id !== S.value) {
|
|
1181
|
+
const _ = t.getConversationById(u.conversation_id);
|
|
1182
|
+
_ && (_.unread_count = 0), t.markAsRead(u.conversation_id).catch(() => {
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
}, z = (u) => {
|
|
1186
|
+
t.applyParticipantReadState(u);
|
|
1187
|
+
}, N = (u) => {
|
|
1188
|
+
const _ = t.getMessagesByConversationId(u.conversation_id), P = _.findIndex((T) => T.id === u.message.id);
|
|
1189
|
+
if (P >= 0) {
|
|
1190
|
+
const T = _[P];
|
|
1191
|
+
if (!T) return;
|
|
1192
|
+
const F = { ...T };
|
|
1193
|
+
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] = F;
|
|
1194
|
+
const Q = t.getConversationById(u.conversation_id);
|
|
1195
|
+
Q && Q.last_message?.id === u.message.id && (Q.last_message = F);
|
|
1196
|
+
}
|
|
1197
|
+
}, l = (u) => {
|
|
1198
|
+
t.removeMessage(u.conversation_id, u.message_id);
|
|
1199
|
+
}, v = (u) => {
|
|
1200
|
+
t.updateMessageReactions(
|
|
1201
|
+
u.conversation_id,
|
|
1202
|
+
u.message_id,
|
|
1203
|
+
u.reactions
|
|
1204
|
+
);
|
|
1205
|
+
}, A = (u) => {
|
|
1206
|
+
const _ = t.getConversationById(u.conversation_id);
|
|
1207
|
+
_ && (_.is_request = !1), t.requests = t.requests.filter(
|
|
1208
|
+
(P) => P.id !== u.conversation_id
|
|
1209
|
+
);
|
|
1210
|
+
};
|
|
1211
|
+
let b = null;
|
|
1212
|
+
const V = (u) => {
|
|
1213
|
+
u.removed_user_id === S.value && (b?.(), t.deleteConversation(u.conversation_id).catch(() => {
|
|
1214
|
+
}));
|
|
1215
|
+
}, q = () => {
|
|
1216
|
+
const u = U();
|
|
1217
|
+
if (!(n.value || !u)) {
|
|
1218
|
+
if (!G()) {
|
|
1219
|
+
E();
|
|
1166
1220
|
return;
|
|
1167
1221
|
}
|
|
1168
1222
|
r.value = null;
|
|
1169
1223
|
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 =
|
|
1224
|
+
m = Qe(u, {
|
|
1225
|
+
onMessageSent: L,
|
|
1226
|
+
onMessageRead: z,
|
|
1227
|
+
onMessageEdited: N,
|
|
1228
|
+
onMessageDeleted: l,
|
|
1229
|
+
onReactionToggled: v,
|
|
1230
|
+
onRequestAccepted: A,
|
|
1231
|
+
onParticipantRemoved: V
|
|
1232
|
+
}), n.value = !0, i.value = u, t.registerDetailSubscription(u), w();
|
|
1233
|
+
} catch (_) {
|
|
1234
|
+
r.value = _ instanceof Error ? _.message : "Failed to subscribe to conversation", console.error("ConversationChannel: Subscribe error", _);
|
|
1181
1235
|
}
|
|
1182
1236
|
}
|
|
1183
|
-
},
|
|
1184
|
-
n.value ||
|
|
1237
|
+
}, I = () => {
|
|
1238
|
+
n.value || q();
|
|
1185
1239
|
};
|
|
1186
|
-
typeof window < "u" && window.addEventListener(
|
|
1187
|
-
const
|
|
1188
|
-
if (
|
|
1189
|
-
n.value ||
|
|
1240
|
+
typeof window < "u" && window.addEventListener(ge(), I);
|
|
1241
|
+
const R = Le((u) => {
|
|
1242
|
+
if (u === "connected") {
|
|
1243
|
+
n.value || q();
|
|
1190
1244
|
return;
|
|
1191
1245
|
}
|
|
1192
|
-
(
|
|
1193
|
-
}),
|
|
1194
|
-
const
|
|
1195
|
-
if (
|
|
1246
|
+
(u === "disconnected" || u === "error") && (w(), m && (m(), m = null), i.value && (t.unregisterDetailSubscription(i.value), i.value = null), n.value = !1);
|
|
1247
|
+
}), M = () => {
|
|
1248
|
+
const u = i.value;
|
|
1249
|
+
if (w(), !(!n.value || !u))
|
|
1196
1250
|
try {
|
|
1197
|
-
|
|
1198
|
-
} catch (
|
|
1199
|
-
r.value =
|
|
1251
|
+
m && (m(), m = null), t.hasGlobalConversationSubscription(u) || Je(u), n.value = !1, t.unregisterDetailSubscription(u), i.value = null, r.value = null;
|
|
1252
|
+
} catch (_) {
|
|
1253
|
+
r.value = _ instanceof Error ? _.message : "Failed to unsubscribe from conversation", console.error("ConversationChannel: Unsubscribe error", _);
|
|
1200
1254
|
}
|
|
1201
|
-
}, E = (c) => {
|
|
1202
|
-
if (t.addMessage(c.message), c.message.author_id !== F.value) {
|
|
1203
|
-
const g = t.getConversationById(c.conversation_id);
|
|
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
1255
|
};
|
|
1244
|
-
return o !== null &&
|
|
1245
|
-
|
|
1256
|
+
return b = M, o !== null && Ee(() => {
|
|
1257
|
+
w(), R(), M(), typeof window < "u" && window.removeEventListener(ge(), I);
|
|
1246
1258
|
}), {
|
|
1247
|
-
isSubscribed:
|
|
1248
|
-
error:
|
|
1249
|
-
subscribe:
|
|
1250
|
-
unsubscribe:
|
|
1259
|
+
isSubscribed: K(() => n.value),
|
|
1260
|
+
error: K(() => r.value),
|
|
1261
|
+
subscribe: q,
|
|
1262
|
+
unsubscribe: M
|
|
1251
1263
|
};
|
|
1252
1264
|
}
|
|
1253
|
-
const
|
|
1265
|
+
const Ge = () => {
|
|
1254
1266
|
};
|
|
1255
|
-
let
|
|
1256
|
-
function
|
|
1257
|
-
|
|
1267
|
+
let le = Ge;
|
|
1268
|
+
function qt() {
|
|
1269
|
+
return le;
|
|
1258
1270
|
}
|
|
1259
|
-
function
|
|
1260
|
-
|
|
1271
|
+
function Pt(e) {
|
|
1272
|
+
le = e;
|
|
1261
1273
|
}
|
|
1262
|
-
|
|
1274
|
+
function Lt() {
|
|
1275
|
+
le = Ge;
|
|
1276
|
+
}
|
|
1277
|
+
const Nt = {
|
|
1263
1278
|
debug: () => {
|
|
1264
1279
|
},
|
|
1265
1280
|
info: () => {
|
|
@@ -1268,189 +1283,182 @@ const xt = {
|
|
|
1268
1283
|
},
|
|
1269
1284
|
error: () => {
|
|
1270
1285
|
}
|
|
1271
|
-
},
|
|
1272
|
-
let
|
|
1273
|
-
function
|
|
1274
|
-
|
|
1275
|
-
}
|
|
1276
|
-
function
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1286
|
+
}, ke = () => Nt;
|
|
1287
|
+
let fe = ke;
|
|
1288
|
+
function Ut() {
|
|
1289
|
+
return fe;
|
|
1290
|
+
}
|
|
1291
|
+
function zt(e) {
|
|
1292
|
+
fe = e;
|
|
1293
|
+
}
|
|
1294
|
+
function It() {
|
|
1295
|
+
fe = ke;
|
|
1296
|
+
}
|
|
1297
|
+
const ne = Ut()("GlobalMessaging"), Dt = 3, $t = (e) => e.replace(/\/+$/, ""), Ot = (e) => $t(window.location.pathname) === `/messages/${e}`, Gt = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
1298
|
+
function Zt() {
|
|
1299
|
+
const e = Oe(), t = k()(), s = qt(), n = We(), r = Ae(), { conversations: i } = He(e), o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
|
|
1300
|
+
let c = !1;
|
|
1301
|
+
function f(l) {
|
|
1302
|
+
const v = a.get(l);
|
|
1303
|
+
if (v && (a.delete(l), typeof v.channel.stopListening == "function"))
|
|
1304
|
+
for (const A of v.bindings)
|
|
1287
1305
|
try {
|
|
1288
|
-
v.channel.stopListening(
|
|
1306
|
+
v.channel.stopListening(A.event, A.handler);
|
|
1289
1307
|
} catch {
|
|
1290
1308
|
}
|
|
1291
1309
|
}
|
|
1292
|
-
function
|
|
1293
|
-
for (const
|
|
1294
|
-
|
|
1295
|
-
|
|
1310
|
+
function p() {
|
|
1311
|
+
for (const l of o)
|
|
1312
|
+
f(l), e.unregisterGlobalConversationSubscription(l);
|
|
1313
|
+
o.clear();
|
|
1296
1314
|
}
|
|
1297
|
-
function
|
|
1298
|
-
const v =
|
|
1299
|
-
if (!v ||
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
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)) {
|
|
1314
|
-
se.warn("Dropping malformed ConversationMessageSent event", C);
|
|
1315
|
+
function d(l) {
|
|
1316
|
+
const v = G();
|
|
1317
|
+
if (!v || o.has(l)) return;
|
|
1318
|
+
const A = `conversation.${l}`;
|
|
1319
|
+
f(l);
|
|
1320
|
+
const b = v.private(A), V = (R) => {
|
|
1321
|
+
if (!tt(R)) {
|
|
1322
|
+
ne.warn("Dropping malformed ConversationMessageSent event", R);
|
|
1315
1323
|
return;
|
|
1316
1324
|
}
|
|
1317
|
-
const
|
|
1318
|
-
if (!
|
|
1319
|
-
e.addMessage(
|
|
1320
|
-
const
|
|
1321
|
-
if (
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1325
|
+
const M = R, u = t.currentUser?.id;
|
|
1326
|
+
if (!u || M.message.author_id === u) return;
|
|
1327
|
+
e.addMessage(M.message);
|
|
1328
|
+
const _ = e.hasDetailSubscription(M.conversation_id), P = Ot(M.conversation_id);
|
|
1329
|
+
if (_ || P) {
|
|
1330
|
+
const F = e.getConversationById(M.conversation_id);
|
|
1331
|
+
F && (F.unread_count = 0), e.markAsRead(M.conversation_id).catch(() => {
|
|
1324
1332
|
});
|
|
1325
1333
|
return;
|
|
1326
1334
|
}
|
|
1327
|
-
const
|
|
1328
|
-
if (
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1335
|
+
const T = e.getConversationById(M.conversation_id);
|
|
1336
|
+
if (T) {
|
|
1337
|
+
const F = Gt(T);
|
|
1338
|
+
F || T.unread_count++, s(F);
|
|
1331
1339
|
}
|
|
1332
|
-
},
|
|
1333
|
-
if (!
|
|
1334
|
-
|
|
1340
|
+
}, q = (R) => {
|
|
1341
|
+
if (!st(R)) {
|
|
1342
|
+
ne.warn("Dropping malformed ConversationMessageRead event", R);
|
|
1335
1343
|
return;
|
|
1336
1344
|
}
|
|
1337
|
-
|
|
1338
|
-
},
|
|
1339
|
-
if (!
|
|
1340
|
-
|
|
1345
|
+
e.applyParticipantReadState(R);
|
|
1346
|
+
}, I = (R) => {
|
|
1347
|
+
if (!nt(R)) {
|
|
1348
|
+
ne.warn("Dropping malformed ConversationRequestAccepted event", R);
|
|
1341
1349
|
return;
|
|
1342
1350
|
}
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
(
|
|
1351
|
+
const M = R, u = e.getConversationById(M.conversation_id);
|
|
1352
|
+
u && (u.is_request = !1), e.requests = e.requests.filter(
|
|
1353
|
+
(_) => _.id !== M.conversation_id
|
|
1346
1354
|
);
|
|
1347
1355
|
};
|
|
1348
|
-
|
|
1349
|
-
channel:
|
|
1356
|
+
b.listen(".ConversationMessageSent", V), b.listen(".ConversationMessageRead", q), b.listen(".ConversationRequestAccepted", I), a.set(l, {
|
|
1357
|
+
channel: b,
|
|
1350
1358
|
bindings: [
|
|
1351
|
-
{ event: ".ConversationMessageSent", handler:
|
|
1352
|
-
{ event: ".ConversationMessageRead", handler:
|
|
1353
|
-
{ event: ".ConversationRequestAccepted", handler:
|
|
1359
|
+
{ event: ".ConversationMessageSent", handler: V },
|
|
1360
|
+
{ event: ".ConversationMessageRead", handler: q },
|
|
1361
|
+
{ event: ".ConversationRequestAccepted", handler: I }
|
|
1354
1362
|
]
|
|
1355
|
-
}),
|
|
1363
|
+
}), o.add(l), e.registerGlobalConversationSubscription(l);
|
|
1356
1364
|
}
|
|
1357
|
-
function
|
|
1358
|
-
const
|
|
1359
|
-
if (!
|
|
1360
|
-
|
|
1365
|
+
function m() {
|
|
1366
|
+
const l = G();
|
|
1367
|
+
if (!l) {
|
|
1368
|
+
p();
|
|
1361
1369
|
return;
|
|
1362
1370
|
}
|
|
1363
|
-
for (const v of
|
|
1364
|
-
|
|
1371
|
+
for (const v of o) {
|
|
1372
|
+
f(v);
|
|
1365
1373
|
try {
|
|
1366
|
-
|
|
1374
|
+
l.leave(`conversation.${v}`);
|
|
1367
1375
|
} catch {
|
|
1368
1376
|
}
|
|
1369
1377
|
e.unregisterGlobalConversationSubscription(v);
|
|
1370
1378
|
}
|
|
1371
|
-
|
|
1379
|
+
o.clear();
|
|
1372
1380
|
}
|
|
1373
|
-
function
|
|
1374
|
-
const
|
|
1375
|
-
if (!
|
|
1376
|
-
const v = e.conversations.slice(0,
|
|
1377
|
-
for (const b of
|
|
1378
|
-
if (!
|
|
1381
|
+
function S() {
|
|
1382
|
+
const l = G();
|
|
1383
|
+
if (!l) return;
|
|
1384
|
+
const v = e.conversations.slice(0, Dt), A = new Set(v.map((b) => b.id));
|
|
1385
|
+
for (const b of o)
|
|
1386
|
+
if (!A.has(b) && !e.hasDetailSubscription(b)) {
|
|
1379
1387
|
try {
|
|
1380
|
-
|
|
1388
|
+
f(b), l.leave(`conversation.${b}`);
|
|
1381
1389
|
} catch {
|
|
1382
1390
|
}
|
|
1383
|
-
|
|
1391
|
+
o.delete(b), e.unregisterGlobalConversationSubscription(b);
|
|
1384
1392
|
}
|
|
1385
1393
|
for (const b of v)
|
|
1386
|
-
|
|
1394
|
+
d(b.id);
|
|
1387
1395
|
}
|
|
1388
|
-
function
|
|
1389
|
-
e.updatePresenceForUser(
|
|
1396
|
+
function U(l) {
|
|
1397
|
+
e.updatePresenceForUser(l.user_id, l.status);
|
|
1390
1398
|
}
|
|
1391
|
-
function
|
|
1392
|
-
!
|
|
1399
|
+
function w() {
|
|
1400
|
+
!G() || c || (Ze(U), c = !0);
|
|
1393
1401
|
}
|
|
1394
|
-
function
|
|
1395
|
-
|
|
1402
|
+
function E() {
|
|
1403
|
+
c && (Xe(), c = !1);
|
|
1396
1404
|
}
|
|
1397
|
-
const
|
|
1398
|
-
|
|
1405
|
+
const L = he(
|
|
1406
|
+
i,
|
|
1399
1407
|
() => {
|
|
1400
|
-
|
|
1408
|
+
S();
|
|
1401
1409
|
},
|
|
1402
1410
|
{ deep: !1, immediate: !0 }
|
|
1403
|
-
),
|
|
1404
|
-
() =>
|
|
1411
|
+
), z = he(
|
|
1412
|
+
() => n.fullPath,
|
|
1405
1413
|
() => {
|
|
1406
|
-
|
|
1414
|
+
S();
|
|
1407
1415
|
}
|
|
1408
|
-
),
|
|
1409
|
-
|
|
1416
|
+
), N = Le((l) => {
|
|
1417
|
+
l === "connected" ? (p(), S(), E(), w()) : (l === "disconnected" || l === "error") && (p(), E());
|
|
1410
1418
|
});
|
|
1411
|
-
|
|
1412
|
-
|
|
1419
|
+
S(), w(), r !== null && Ee(() => {
|
|
1420
|
+
L(), z(), N(), m(), E();
|
|
1413
1421
|
});
|
|
1414
1422
|
}
|
|
1415
|
-
function
|
|
1416
|
-
e.apiClient &&
|
|
1423
|
+
function Xt(e) {
|
|
1424
|
+
e.apiClient && rt(e.apiClient), e.authStore && ot(e.authStore), e.mediaApi && ut(e.mediaApi), e.createLogger && zt(e.createLogger), e.playMessageNotification && Pt(e.playMessageNotification), e.echo && Ke(e.echo);
|
|
1417
1425
|
}
|
|
1418
|
-
function
|
|
1419
|
-
|
|
1426
|
+
function Qt() {
|
|
1427
|
+
it(), at(), dt(), It(), Lt(), et();
|
|
1420
1428
|
}
|
|
1421
1429
|
export {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
at as
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
ot as
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
Ze as
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1430
|
+
Xt as configureMessengerClient,
|
|
1431
|
+
h as getApi,
|
|
1432
|
+
k as getAuthStore,
|
|
1433
|
+
G as getEcho,
|
|
1434
|
+
ge as getEchoInitializedEvent,
|
|
1435
|
+
g as getErrorMessage,
|
|
1436
|
+
Ut as getLoggerFactory,
|
|
1437
|
+
ct as getMediaApi,
|
|
1438
|
+
Yt as hasResponse,
|
|
1439
|
+
es as isAxiosError,
|
|
1440
|
+
jt as isError,
|
|
1441
|
+
st as isValidMessageReadEvent,
|
|
1442
|
+
tt as isValidMessageSentEvent,
|
|
1443
|
+
nt as isValidRequestAcceptedEvent,
|
|
1444
|
+
x as messagingApi,
|
|
1445
|
+
Le as onConnectionStatusChange,
|
|
1446
|
+
et as resetEchoRuntimeConfig,
|
|
1447
|
+
It as resetLoggerFactory,
|
|
1448
|
+
it as resetMessagingApiClient,
|
|
1449
|
+
at as resetMessagingAuthStoreResolver,
|
|
1450
|
+
dt as resetMessagingMediaApi,
|
|
1451
|
+
Qt as resetMessengerClientConfig,
|
|
1452
|
+
Ke as setEchoRuntimeConfig,
|
|
1453
|
+
zt as setLoggerFactory,
|
|
1454
|
+
rt as setMessagingApiClient,
|
|
1455
|
+
ot as setMessagingAuthStoreResolver,
|
|
1456
|
+
ut as setMessagingMediaApi,
|
|
1457
|
+
Qe as subscribeToConversation,
|
|
1458
|
+
Ze as subscribeToPresenceStatus,
|
|
1459
|
+
Je as unsubscribeFromConversation,
|
|
1460
|
+
Xe as unsubscribeFromPresenceStatus,
|
|
1461
|
+
Wt as useConversationChannel,
|
|
1462
|
+
Zt as useGlobalMessaging,
|
|
1463
|
+
Oe as useMessagingStore
|
|
1456
1464
|
};
|