@codingfactory/messenger-client 0.1.5 → 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 +352 -342
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import { defineStore as
|
|
3
|
-
import
|
|
4
|
-
import { isAxiosError as
|
|
5
|
-
import { useRoute as
|
|
6
|
-
const
|
|
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 = () => () => {
|
|
7
|
+
}, Fe = () => {
|
|
7
8
|
}, Te = () => {
|
|
8
9
|
}, xe = () => {
|
|
9
10
|
}, 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
|
|
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
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
23
|
}
|
|
24
|
-
function
|
|
25
|
-
y.ECHO_INITIALIZED_EVENT = "messenger-client:echo-initialized", y.getEcho = () => null, y.onConnectionStatusChange =
|
|
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
|
|
39
|
+
const Le = He;
|
|
40
|
+
let ie = Le;
|
|
41
41
|
function h() {
|
|
42
|
-
return
|
|
42
|
+
return ie;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
44
|
+
function nt(e) {
|
|
45
|
+
ie = e;
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
47
|
+
function rt() {
|
|
48
|
+
ie = Le;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
50
|
+
const Ne = {
|
|
51
51
|
currentUser: null
|
|
52
52
|
};
|
|
53
|
-
let
|
|
53
|
+
let oe = () => Ne;
|
|
54
54
|
function k() {
|
|
55
|
-
return
|
|
55
|
+
return oe;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
57
|
+
function it(e) {
|
|
58
|
+
oe = e;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
60
|
+
function ot() {
|
|
61
|
+
oe = () => Ne;
|
|
62
62
|
}
|
|
63
63
|
function g(e) {
|
|
64
|
-
if (
|
|
64
|
+
if (je(e)) {
|
|
65
65
|
const t = e.response?.data?.message || e.message || "An error occurred";
|
|
66
66
|
return t.includes("SQLSTATE") || t.includes("Connection:") || t.includes("\\Illuminate\\") ? "Something went wrong. Please try again later." : t;
|
|
67
67
|
}
|
|
68
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";
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function Ht(e) {
|
|
71
71
|
return e instanceof Error;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function jt(e) {
|
|
74
74
|
return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const Ue = {
|
|
77
77
|
async uploadImage() {
|
|
78
78
|
throw new Error("messenger-client mediaApi.uploadImage is not configured");
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
let
|
|
82
|
-
function
|
|
83
|
-
return
|
|
81
|
+
let ae = Ue;
|
|
82
|
+
function at() {
|
|
83
|
+
return ae;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
85
|
+
function ct(e) {
|
|
86
|
+
ae = e;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
88
|
+
function ut() {
|
|
89
|
+
ae = Ue;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function dt(e) {
|
|
92
92
|
return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function ze(e) {
|
|
95
95
|
return typeof e == "object" && e !== null;
|
|
96
96
|
}
|
|
97
97
|
function D(e) {
|
|
98
|
-
return !
|
|
98
|
+
return !ze(e) || !("data" in e) ? e : e.data;
|
|
99
99
|
}
|
|
100
100
|
function B(e, t) {
|
|
101
101
|
const s = e[t];
|
|
@@ -103,7 +103,7 @@ function B(e, t) {
|
|
|
103
103
|
throw new Error(`Invalid messaging folder payload: missing string ${t}`);
|
|
104
104
|
return s;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function ge(e, t) {
|
|
107
107
|
const s = e[t];
|
|
108
108
|
if (s == null)
|
|
109
109
|
return null;
|
|
@@ -111,7 +111,7 @@ function me(e, t) {
|
|
|
111
111
|
throw new Error(`Invalid messaging folder payload: ${t} must be a string or null`);
|
|
112
112
|
return s;
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function K(e, t) {
|
|
115
115
|
const s = e[t];
|
|
116
116
|
if (typeof s == "number" && Number.isFinite(s))
|
|
117
117
|
return s;
|
|
@@ -122,43 +122,43 @@ function ee(e, t) {
|
|
|
122
122
|
}
|
|
123
123
|
throw new Error(`Invalid messaging folder payload: missing numeric ${t}`);
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
if (!
|
|
125
|
+
function ne(e) {
|
|
126
|
+
if (!ze(e))
|
|
127
127
|
throw new Error("Invalid messaging folder payload: expected object");
|
|
128
128
|
return {
|
|
129
129
|
id: B(e, "id"),
|
|
130
130
|
name: B(e, "name"),
|
|
131
|
-
color:
|
|
132
|
-
icon:
|
|
133
|
-
sort_order:
|
|
134
|
-
conversation_count:
|
|
135
|
-
unread_count:
|
|
131
|
+
color: ge(e, "color"),
|
|
132
|
+
icon: ge(e, "icon"),
|
|
133
|
+
sort_order: K(e, "sort_order"),
|
|
134
|
+
conversation_count: K(e, "conversation_count"),
|
|
135
|
+
unread_count: K(e, "unread_count"),
|
|
136
136
|
created_at: B(e, "created_at"),
|
|
137
137
|
updated_at: B(e, "updated_at")
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function lt(e) {
|
|
141
141
|
if (!Array.isArray(e))
|
|
142
142
|
throw new Error("Invalid messaging folder payload: expected array");
|
|
143
|
-
return e.map((t) =>
|
|
143
|
+
return e.map((t) => ne(t));
|
|
144
144
|
}
|
|
145
|
-
function
|
|
146
|
-
if (!
|
|
145
|
+
function me(e) {
|
|
146
|
+
if (!dt(e))
|
|
147
147
|
throw new Error("Invalid conversation payload from folder assignment endpoint");
|
|
148
148
|
return e;
|
|
149
149
|
}
|
|
150
150
|
const x = {
|
|
151
151
|
async fetchFolders() {
|
|
152
152
|
const e = await h().get("/v1/messaging/folders");
|
|
153
|
-
return
|
|
153
|
+
return lt(D(e.data));
|
|
154
154
|
},
|
|
155
155
|
async createFolder(e) {
|
|
156
156
|
const t = await h().post("/v1/messaging/folders", e);
|
|
157
|
-
return
|
|
157
|
+
return ne(D(t.data));
|
|
158
158
|
},
|
|
159
159
|
async updateFolder(e, t) {
|
|
160
160
|
const s = await h().patch(`/v1/messaging/folders/${e}`, t);
|
|
161
|
-
return
|
|
161
|
+
return ne(D(s.data));
|
|
162
162
|
},
|
|
163
163
|
async deleteFolder(e) {
|
|
164
164
|
await h().delete(`/v1/messaging/folders/${e}`);
|
|
@@ -170,16 +170,16 @@ const x = {
|
|
|
170
170
|
const s = await h().patch(`/v1/messaging/conversations/${e}/folder`, {
|
|
171
171
|
folder_id: t
|
|
172
172
|
});
|
|
173
|
-
return
|
|
173
|
+
return me(D(s.data));
|
|
174
174
|
},
|
|
175
175
|
async acceptRequest(e) {
|
|
176
176
|
const t = await h().post(`/v1/messaging/conversations/${e}/accept`);
|
|
177
|
-
return
|
|
177
|
+
return me(D(t.data));
|
|
178
178
|
},
|
|
179
179
|
async declineRequest(e) {
|
|
180
180
|
await h().post(`/v1/messaging/conversations/${e}/decline`);
|
|
181
181
|
}
|
|
182
|
-
},
|
|
182
|
+
}, pe = 1e3, ce = 4e3, ft = 12e4, ht = 300, gt = 1, mt = 1600, ue = (e) => {
|
|
183
183
|
if (typeof e == "number" && Number.isFinite(e))
|
|
184
184
|
return e;
|
|
185
185
|
if (typeof e == "string") {
|
|
@@ -187,32 +187,32 @@ const x = {
|
|
|
187
187
|
if (Number.isFinite(t))
|
|
188
188
|
return t;
|
|
189
189
|
}
|
|
190
|
-
},
|
|
191
|
-
const s =
|
|
192
|
-
return s === void 0 ? !0 : s === 429 ||
|
|
193
|
-
},
|
|
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) => {
|
|
194
194
|
if (typeof e == "number" && Number.isFinite(e) && e > 0)
|
|
195
|
-
return Math.max(
|
|
195
|
+
return Math.max(pe, e * 1e3);
|
|
196
196
|
if (typeof e == "string") {
|
|
197
197
|
const t = Number.parseInt(e, 10);
|
|
198
198
|
if (Number.isFinite(t) && t > 0)
|
|
199
|
-
return Math.max(
|
|
199
|
+
return Math.max(pe, t * 1e3);
|
|
200
200
|
}
|
|
201
|
-
return
|
|
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);
|
|
202
205
|
}, 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) => {
|
|
206
206
|
const t = e;
|
|
207
|
-
return
|
|
208
|
-
},
|
|
207
|
+
return ue(t.response?.status) === 429 ? De(t.response?.headers?.["retry-after"]) : ht;
|
|
208
|
+
}, _e = async (e) => {
|
|
209
209
|
await new Promise((t) => {
|
|
210
210
|
setTimeout(t, e);
|
|
211
211
|
});
|
|
212
|
-
},
|
|
213
|
-
if (!
|
|
212
|
+
}, _t = (e) => {
|
|
213
|
+
if (!S(e))
|
|
214
214
|
return !1;
|
|
215
|
-
const s = (
|
|
215
|
+
const s = (S(e.data) ? e.data : e).throttled;
|
|
216
216
|
if (typeof s == "boolean")
|
|
217
217
|
return s;
|
|
218
218
|
if (typeof s == "number")
|
|
@@ -223,7 +223,7 @@ const x = {
|
|
|
223
223
|
}
|
|
224
224
|
return !1;
|
|
225
225
|
};
|
|
226
|
-
function
|
|
226
|
+
function yt(e, t, s) {
|
|
227
227
|
const n = typeof e == "string" && e.trim().length > 0 ? e.trim().toLowerCase() : void 0;
|
|
228
228
|
if (n)
|
|
229
229
|
return n;
|
|
@@ -233,17 +233,17 @@ function bt(e, t, s) {
|
|
|
233
233
|
const i = typeof s == "string" && s.trim().length > 0 ? s.trim().toLowerCase() : void 0;
|
|
234
234
|
return i ? i === "image" ? "image/*" : i === "video" ? "video/*" : i === "audio" ? "audio/*" : i : "application/octet-stream";
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function bt(e) {
|
|
237
237
|
const t = e.url || "", s = e.thumbnail_url ?? e.thumbnail, n = {
|
|
238
238
|
id: e.media_id ?? e.id ?? "",
|
|
239
|
-
name: e.name ??
|
|
239
|
+
name: e.name ?? Ct(t),
|
|
240
240
|
url: t,
|
|
241
|
-
type:
|
|
241
|
+
type: yt(e.mime, e.mime_type, e.type),
|
|
242
242
|
size: e.size ?? 0
|
|
243
243
|
};
|
|
244
244
|
return s !== void 0 && (n.thumbnail = s), n;
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function Ct(e) {
|
|
247
247
|
if (!e) return "attachment";
|
|
248
248
|
try {
|
|
249
249
|
const s = new URL(e).pathname.split("/");
|
|
@@ -252,8 +252,8 @@ function St(e) {
|
|
|
252
252
|
return "attachment";
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
function
|
|
256
|
-
return !Array.isArray(e) || e.length === 0 ? [] : e.map(
|
|
255
|
+
function St(e) {
|
|
256
|
+
return !Array.isArray(e) || e.length === 0 ? [] : e.map(bt);
|
|
257
257
|
}
|
|
258
258
|
function X(e) {
|
|
259
259
|
if (typeof e != "string")
|
|
@@ -262,7 +262,7 @@ function X(e) {
|
|
|
262
262
|
if (t.length !== 0)
|
|
263
263
|
return t;
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function Mt(e) {
|
|
266
266
|
if (!e)
|
|
267
267
|
return;
|
|
268
268
|
const t = X(e.avatar) ?? X(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
|
|
@@ -289,25 +289,25 @@ function Y(e) {
|
|
|
289
289
|
} : null;
|
|
290
290
|
return {
|
|
291
291
|
...e,
|
|
292
|
-
...s ? { author:
|
|
292
|
+
...s ? { author: Mt(s) } : {},
|
|
293
293
|
shared_post: n,
|
|
294
|
-
attachments:
|
|
294
|
+
attachments: St(e.attachments)
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function Rt(e) {
|
|
298
298
|
return typeof e != "string" || e.length === 0 ? null : e;
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function ye(e) {
|
|
301
301
|
if (!(typeof e != "string" || e.length === 0))
|
|
302
302
|
return e;
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function re(e) {
|
|
305
305
|
return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function wt(e, t = []) {
|
|
308
308
|
const s = /* @__PURE__ */ new Map();
|
|
309
309
|
for (const n of t) {
|
|
310
|
-
const r =
|
|
310
|
+
const r = ye(n.last_read_message_id);
|
|
311
311
|
r && s.set(n.user_id, r);
|
|
312
312
|
}
|
|
313
313
|
return e.map((n) => {
|
|
@@ -316,7 +316,7 @@ function At(e, t = []) {
|
|
|
316
316
|
name: n.user.name,
|
|
317
317
|
...i ? { avatar: i } : {},
|
|
318
318
|
...n.user.handle ? { handle: n.user.handle } : {}
|
|
319
|
-
} : void 0, a =
|
|
319
|
+
} : void 0, a = ye(n.last_read_message_id);
|
|
320
320
|
if (a)
|
|
321
321
|
return {
|
|
322
322
|
...n,
|
|
@@ -342,7 +342,7 @@ function At(e, t = []) {
|
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
344
|
function $(e, t) {
|
|
345
|
-
const s =
|
|
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 = (() => {
|
|
346
346
|
if (!t || t.unread_count !== 0 || e.unread_count <= 0)
|
|
347
347
|
return !1;
|
|
348
348
|
const a = t.last_message?.id, c = e.last_message?.id;
|
|
@@ -351,43 +351,43 @@ function $(e, t) {
|
|
|
351
351
|
return {
|
|
352
352
|
...e,
|
|
353
353
|
unread_count: n || o ? 0 : e.unread_count,
|
|
354
|
-
participants:
|
|
354
|
+
participants: wt(e.participants, t?.participants),
|
|
355
355
|
is_muted: n,
|
|
356
356
|
muted_until: s,
|
|
357
357
|
...r ? { last_message: r } : {},
|
|
358
358
|
...i ? { last_message_at: i } : {}
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function At(e) {
|
|
362
362
|
return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
|
|
363
363
|
}
|
|
364
|
-
function
|
|
365
|
-
return
|
|
364
|
+
function ee(e) {
|
|
365
|
+
return At(e) ? 0 : e.unread_count || 0;
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function be(e, t) {
|
|
368
368
|
const s = t[e.id];
|
|
369
369
|
if (Array.isArray(s))
|
|
370
370
|
for (let n = s.length - 1; n >= 0; n -= 1) {
|
|
371
371
|
const r = s[n]?.id;
|
|
372
|
-
if (
|
|
372
|
+
if (re(r))
|
|
373
373
|
return r;
|
|
374
374
|
}
|
|
375
|
-
return
|
|
375
|
+
return re(e.last_message?.id) ? e.last_message.id : null;
|
|
376
376
|
}
|
|
377
|
-
function
|
|
377
|
+
function S(e) {
|
|
378
378
|
return typeof e == "object" && e !== null;
|
|
379
379
|
}
|
|
380
|
-
function
|
|
381
|
-
return
|
|
380
|
+
function Et(e) {
|
|
381
|
+
return S(e) ? (S(e.response) ? e.response : null)?.status === 401 : !1;
|
|
382
382
|
}
|
|
383
|
-
function
|
|
383
|
+
function Ce(e) {
|
|
384
384
|
if (!Array.isArray(e))
|
|
385
385
|
return [];
|
|
386
386
|
const t = [];
|
|
387
387
|
for (const s of e) {
|
|
388
|
-
if (!
|
|
388
|
+
if (!S(s) || typeof s.reaction != "string" || typeof s.count != "number" || !Array.isArray(s.users))
|
|
389
389
|
continue;
|
|
390
|
-
const n = s.users.filter((r) =>
|
|
390
|
+
const n = s.users.filter((r) => S(r)).filter(
|
|
391
391
|
(r) => typeof r.id == "string" && typeof r.name == "string"
|
|
392
392
|
).map((r) => ({
|
|
393
393
|
id: r.id,
|
|
@@ -401,24 +401,24 @@ function Se(e) {
|
|
|
401
401
|
}
|
|
402
402
|
return t;
|
|
403
403
|
}
|
|
404
|
-
function
|
|
405
|
-
const s =
|
|
404
|
+
function Ft(e, t) {
|
|
405
|
+
const s = S(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
|
|
406
406
|
if (!(typeof n != "string" || n.length === 0))
|
|
407
407
|
return n;
|
|
408
408
|
}
|
|
409
409
|
function H(e, t) {
|
|
410
|
-
const s =
|
|
410
|
+
const s = S(e) ? e : {}, n = s.data ?? e;
|
|
411
411
|
let r = [];
|
|
412
|
-
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)), {
|
|
413
413
|
items: r,
|
|
414
|
-
nextCursor:
|
|
414
|
+
nextCursor: Ft(s, n)
|
|
415
415
|
};
|
|
416
416
|
}
|
|
417
|
-
function
|
|
418
|
-
return
|
|
417
|
+
function Se(e) {
|
|
418
|
+
return S(e) && typeof e.id == "string" && e.id.length > 0;
|
|
419
419
|
}
|
|
420
|
-
function
|
|
421
|
-
return
|
|
420
|
+
function Me(e) {
|
|
421
|
+
return S(e) ? typeof e.id == "string" && (e.type === "dm" || e.type === "group") && Array.isArray(e.participants) : !1;
|
|
422
422
|
}
|
|
423
423
|
function W(e, t) {
|
|
424
424
|
if (e.is_pinned !== t.is_pinned)
|
|
@@ -432,19 +432,19 @@ function j(e, t) {
|
|
|
432
432
|
function O(e) {
|
|
433
433
|
return [...e].sort((t, s) => t.sort_order !== s.sort_order ? t.sort_order - s.sort_order : t.name.localeCompare(s.name));
|
|
434
434
|
}
|
|
435
|
-
function
|
|
435
|
+
function Tt(e, t) {
|
|
436
436
|
return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
|
|
437
437
|
}
|
|
438
|
-
function
|
|
438
|
+
function Re(e, t) {
|
|
439
439
|
return e.map((s) => {
|
|
440
|
-
const n =
|
|
440
|
+
const n = Tt(s.folder_id, t);
|
|
441
441
|
return (s.folder_id ?? null) === n ? s : {
|
|
442
442
|
...s,
|
|
443
443
|
folder_id: n
|
|
444
444
|
};
|
|
445
445
|
});
|
|
446
446
|
}
|
|
447
|
-
function
|
|
447
|
+
function te(e) {
|
|
448
448
|
const t = /* @__PURE__ */ new Map();
|
|
449
449
|
for (const s of e.requests)
|
|
450
450
|
s.is_request === !0 && t.set(s.id, s);
|
|
@@ -452,7 +452,7 @@ function se(e) {
|
|
|
452
452
|
s.is_request === !0 && t.set(s.id, s);
|
|
453
453
|
return Array.from(t.values()).sort(W);
|
|
454
454
|
}
|
|
455
|
-
const
|
|
455
|
+
const $e = Ve("messaging", {
|
|
456
456
|
state: () => ({
|
|
457
457
|
conversations: [],
|
|
458
458
|
requests: [],
|
|
@@ -479,25 +479,25 @@ const Oe = Be("messaging", {
|
|
|
479
479
|
getConversationById: (e) => (t) => e.conversations.find((s) => s.id === t),
|
|
480
480
|
getMessagesByConversationId: (e) => (t) => e.messages[t] || [],
|
|
481
481
|
getTypingUsers: (e) => (t) => e.typingUsers[t] || [],
|
|
482
|
-
unreadConversationsCount: (e) => e.conversations.filter((t) =>
|
|
483
|
-
unreadCount: (e) => e.conversations.reduce((t, s) => t +
|
|
484
|
-
totalUnreadCount: (e) => e.conversations.reduce((t, s) => t +
|
|
482
|
+
unreadConversationsCount: (e) => e.conversations.filter((t) => ee(t) > 0).length,
|
|
483
|
+
unreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
|
|
484
|
+
totalUnreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
|
|
485
485
|
sortedFolders: (e) => O(e.folders),
|
|
486
486
|
folderById: (e) => (t) => e.folders.find((s) => s.id === t),
|
|
487
487
|
conversationsInFolder: (e) => (t) => e.conversations.filter((s) => s.folder_id === t),
|
|
488
488
|
hasMoreMessages: (e) => (t) => e.conversationHasMore[t] ?? !1,
|
|
489
489
|
isLoadingMessages: (e) => (t) => e.loadingMessages[t] ?? !1,
|
|
490
490
|
// Message request getters
|
|
491
|
-
requestConversations: (e) =>
|
|
492
|
-
requestCount: (e) =>
|
|
493
|
-
unreadRequestCount: (e) =>
|
|
491
|
+
requestConversations: (e) => te(e),
|
|
492
|
+
requestCount: (e) => te(e).length,
|
|
493
|
+
unreadRequestCount: (e) => te(e).filter((t) => t.unread_count > 0).length
|
|
494
494
|
},
|
|
495
495
|
actions: {
|
|
496
496
|
normalizeFolderAssignmentsState() {
|
|
497
497
|
if (!this.foldersLoaded)
|
|
498
498
|
return;
|
|
499
499
|
const e = new Set(this.folders.map((t) => t.id));
|
|
500
|
-
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);
|
|
501
501
|
},
|
|
502
502
|
async fetchFolders() {
|
|
503
503
|
try {
|
|
@@ -581,18 +581,18 @@ const Oe = Be("messaging", {
|
|
|
581
581
|
"conversations"
|
|
582
582
|
), f = a.map((d) => {
|
|
583
583
|
const m = this.conversations.find(
|
|
584
|
-
(
|
|
584
|
+
(M) => M.id === d.id
|
|
585
585
|
);
|
|
586
586
|
return $(d, m);
|
|
587
587
|
});
|
|
588
588
|
e ? this.conversations.push(...f) : this.conversations = f, this.normalizeFolderAssignmentsState(), this.lastFetch = Date.now();
|
|
589
|
-
const
|
|
589
|
+
const v = {
|
|
590
590
|
data: f,
|
|
591
591
|
has_more: !!c
|
|
592
592
|
};
|
|
593
|
-
return c !== void 0 && (
|
|
593
|
+
return c !== void 0 && (v.next_cursor = c), v;
|
|
594
594
|
} catch (r) {
|
|
595
|
-
throw n?.background &&
|
|
595
|
+
throw n?.background && ve(r) || (this.error = g(r)), r;
|
|
596
596
|
} finally {
|
|
597
597
|
this.loading = !1;
|
|
598
598
|
}
|
|
@@ -606,8 +606,8 @@ const Oe = Be("messaging", {
|
|
|
606
606
|
includePresence: !1
|
|
607
607
|
}), this.backgroundPollRetryAfterUntil = 0, this.backgroundPollTransientFailureCount = 0, !0;
|
|
608
608
|
} catch (e) {
|
|
609
|
-
const t = e, s =
|
|
610
|
-
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));
|
|
611
611
|
}
|
|
612
612
|
},
|
|
613
613
|
async fetchConversation(e) {
|
|
@@ -662,9 +662,9 @@ const Oe = Be("messaging", {
|
|
|
662
662
|
r = await h().get(`/v1/messaging/conversations/${e}/messages`, { params: s });
|
|
663
663
|
break;
|
|
664
664
|
} catch (d) {
|
|
665
|
-
if (!(n <
|
|
665
|
+
if (!(n < gt && ve(d)))
|
|
666
666
|
throw d;
|
|
667
|
-
n += 1, await
|
|
667
|
+
n += 1, await _e(vt(d));
|
|
668
668
|
}
|
|
669
669
|
const { items: i, nextCursor: o } = H(
|
|
670
670
|
r.data,
|
|
@@ -678,11 +678,11 @@ const Oe = Be("messaging", {
|
|
|
678
678
|
d && this.updateConversationLastMessage(e, d);
|
|
679
679
|
}
|
|
680
680
|
o ? (this.conversationCursors[e] = o, this.conversationHasMore[e] = !0) : (delete this.conversationCursors[e], this.conversationHasMore[e] = !1);
|
|
681
|
-
const
|
|
681
|
+
const v = {
|
|
682
682
|
data: a,
|
|
683
683
|
has_more: !!o
|
|
684
684
|
};
|
|
685
|
-
return o !== void 0 && (
|
|
685
|
+
return o !== void 0 && (v.next_cursor = o), v;
|
|
686
686
|
} catch (s) {
|
|
687
687
|
throw this.error = g(s), s;
|
|
688
688
|
} finally {
|
|
@@ -690,7 +690,7 @@ const Oe = Be("messaging", {
|
|
|
690
690
|
}
|
|
691
691
|
},
|
|
692
692
|
async sendMessage(e, t, s, n, r, i) {
|
|
693
|
-
const o = k()(), a = `temp-${Date.now()}-${Math.random()}`, c = typeof i == "string" && i.trim().length > 0 ? i.trim() : null, f = o.currentUser,
|
|
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 = {
|
|
694
694
|
id: a,
|
|
695
695
|
conversation_id: e,
|
|
696
696
|
author_id: f?.id || "",
|
|
@@ -701,12 +701,12 @@ const Oe = Be("messaging", {
|
|
|
701
701
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
702
702
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
703
703
|
};
|
|
704
|
-
f && (
|
|
704
|
+
f && (v.author = {
|
|
705
705
|
id: f.id,
|
|
706
706
|
name: f.name,
|
|
707
707
|
...f.avatar ? { avatar: f.avatar } : {},
|
|
708
708
|
...f.handle ? { handle: f.handle } : {}
|
|
709
|
-
}), 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);
|
|
710
710
|
try {
|
|
711
711
|
let d;
|
|
712
712
|
const m = {
|
|
@@ -716,12 +716,12 @@ const Oe = Be("messaging", {
|
|
|
716
716
|
};
|
|
717
717
|
if (s && s.length > 0) {
|
|
718
718
|
const l = await Promise.all(
|
|
719
|
-
s.map(async (
|
|
720
|
-
const
|
|
719
|
+
s.map(async (_) => {
|
|
720
|
+
const w = await at().uploadImage(_);
|
|
721
721
|
return {
|
|
722
|
-
media_id:
|
|
723
|
-
mime:
|
|
724
|
-
size:
|
|
722
|
+
media_id: w.id,
|
|
723
|
+
mime: w.mime_type,
|
|
724
|
+
size: w.size
|
|
725
725
|
};
|
|
726
726
|
})
|
|
727
727
|
);
|
|
@@ -734,15 +734,15 @@ const Oe = Be("messaging", {
|
|
|
734
734
|
...m,
|
|
735
735
|
type: "text"
|
|
736
736
|
});
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
const z =
|
|
740
|
-
let
|
|
741
|
-
for (let l =
|
|
742
|
-
const
|
|
743
|
-
|
|
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));
|
|
744
744
|
}
|
|
745
|
-
return this.updateConversationLastMessage(e,
|
|
745
|
+
return this.updateConversationLastMessage(e, R), R;
|
|
746
746
|
} catch (d) {
|
|
747
747
|
throw this._pendingSendIds.delete(a), this.messages[e] = this.messages[e].filter((m) => m.id !== a), this.error = g(d), d;
|
|
748
748
|
}
|
|
@@ -784,11 +784,11 @@ const Oe = Be("messaging", {
|
|
|
784
784
|
return null;
|
|
785
785
|
for (let i = r.length - 1; i >= 0; i -= 1) {
|
|
786
786
|
const o = r[i]?.id;
|
|
787
|
-
if (
|
|
787
|
+
if (re(o))
|
|
788
788
|
return o;
|
|
789
789
|
}
|
|
790
790
|
return null;
|
|
791
|
-
})(), n = t ?
|
|
791
|
+
})(), n = t ? be(t, this.messages) : s;
|
|
792
792
|
if (!n)
|
|
793
793
|
return;
|
|
794
794
|
await h().post(`/v1/messaging/conversations/${e}/read`, {
|
|
@@ -807,7 +807,7 @@ const Oe = Be("messaging", {
|
|
|
807
807
|
if (e.length === 0)
|
|
808
808
|
return;
|
|
809
809
|
const t = e.map((r) => {
|
|
810
|
-
const i =
|
|
810
|
+
const i = be(r, this.messages);
|
|
811
811
|
return i ? {
|
|
812
812
|
conversationId: r.id,
|
|
813
813
|
messageId: i
|
|
@@ -839,9 +839,9 @@ const Oe = Be("messaging", {
|
|
|
839
839
|
async sendTyping(e, t = "start") {
|
|
840
840
|
try {
|
|
841
841
|
const s = await h().post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
842
|
-
if (t !== "start" || !
|
|
842
|
+
if (t !== "start" || !_t(s.data))
|
|
843
843
|
return;
|
|
844
|
-
await
|
|
844
|
+
await _e(mt), await h().post(`/v1/messaging/conversations/${e}/typing`, { state: t });
|
|
845
845
|
} catch (s) {
|
|
846
846
|
console.warn("Failed to send typing indicator:", s);
|
|
847
847
|
}
|
|
@@ -907,9 +907,9 @@ const Oe = Be("messaging", {
|
|
|
907
907
|
};
|
|
908
908
|
t && (s.message = t);
|
|
909
909
|
const n = await h().post("/v1/messaging/conversations/dm", s), r = n.data.data || n.data;
|
|
910
|
-
if (!
|
|
910
|
+
if (!Se(r))
|
|
911
911
|
throw new Error("Invalid conversation payload from DM create endpoint.");
|
|
912
|
-
const i =
|
|
912
|
+
const i = Me(r) ? $(r) : await this.fetchConversation(r.id);
|
|
913
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);
|
|
914
914
|
} catch (s) {
|
|
915
915
|
throw this.error = g(s), s;
|
|
@@ -921,9 +921,9 @@ const Oe = Be("messaging", {
|
|
|
921
921
|
title: e,
|
|
922
922
|
participant_ids: t
|
|
923
923
|
}), n = s.data.data || s.data;
|
|
924
|
-
if (!
|
|
924
|
+
if (!Se(n))
|
|
925
925
|
throw new Error("Invalid conversation payload from group create endpoint.");
|
|
926
|
-
const r =
|
|
926
|
+
const r = Me(n) ? n : await this.fetchConversation(n.id);
|
|
927
927
|
return this.conversations = j(this.conversations, r), r;
|
|
928
928
|
} catch (s) {
|
|
929
929
|
throw this.error = g(s), s;
|
|
@@ -1031,19 +1031,19 @@ const Oe = Be("messaging", {
|
|
|
1031
1031
|
try {
|
|
1032
1032
|
a = await h().post(n, r);
|
|
1033
1033
|
} catch (d) {
|
|
1034
|
-
if (!
|
|
1034
|
+
if (!Et(d))
|
|
1035
1035
|
throw d;
|
|
1036
1036
|
a = await h().post(n, r);
|
|
1037
1037
|
}
|
|
1038
|
-
const c =
|
|
1039
|
-
|
|
1038
|
+
const c = S(a.data) && "data" in a.data ? a.data.data : a.data, f = Ce(
|
|
1039
|
+
S(c) ? c.reactions : void 0
|
|
1040
1040
|
);
|
|
1041
1041
|
(f.length > 0 || o.length === 0) && this.updateMessageReactions(e, t, f);
|
|
1042
1042
|
try {
|
|
1043
|
-
const d = await h().get(n), m =
|
|
1044
|
-
|
|
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
|
|
1045
1045
|
);
|
|
1046
|
-
this.updateMessageReactions(e, t,
|
|
1046
|
+
this.updateMessageReactions(e, t, M);
|
|
1047
1047
|
} catch {
|
|
1048
1048
|
}
|
|
1049
1049
|
} catch (a) {
|
|
@@ -1167,114 +1167,124 @@ const Oe = Be("messaging", {
|
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
1169
1169
|
});
|
|
1170
|
-
function
|
|
1171
|
-
const t =
|
|
1172
|
-
let
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
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();
|
|
1178
1180
|
}, f));
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
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(() => {
|
|
1183
1186
|
});
|
|
1184
1187
|
}
|
|
1185
|
-
}
|
|
1188
|
+
}
|
|
1189
|
+
function z(u) {
|
|
1186
1190
|
t.applyParticipantReadState(u);
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
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);
|
|
1196
1201
|
}
|
|
1197
|
-
}
|
|
1202
|
+
}
|
|
1203
|
+
function l(u) {
|
|
1198
1204
|
t.removeMessage(u.conversation_id, u.message_id);
|
|
1199
|
-
}
|
|
1205
|
+
}
|
|
1206
|
+
function _(u) {
|
|
1200
1207
|
t.updateMessageReactions(
|
|
1201
1208
|
u.conversation_id,
|
|
1202
1209
|
u.message_id,
|
|
1203
1210
|
u.reactions
|
|
1204
1211
|
);
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
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
|
|
1209
1217
|
);
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
u.removed_user_id === S.value && (b?.(), t.deleteConversation(u.conversation_id).catch(() => {
|
|
1218
|
+
}
|
|
1219
|
+
function b(u) {
|
|
1220
|
+
u.removed_user_id === M.value && (C(), t.deleteConversation(u.conversation_id).catch(() => {
|
|
1214
1221
|
}));
|
|
1215
|
-
}
|
|
1222
|
+
}
|
|
1223
|
+
function q() {
|
|
1216
1224
|
const u = U();
|
|
1217
1225
|
if (!(n.value || !u)) {
|
|
1218
1226
|
if (!G()) {
|
|
1219
|
-
|
|
1227
|
+
A();
|
|
1220
1228
|
return;
|
|
1221
1229
|
}
|
|
1222
1230
|
r.value = null;
|
|
1223
1231
|
try {
|
|
1224
|
-
m =
|
|
1225
|
-
onMessageSent:
|
|
1232
|
+
m = Xe(u, {
|
|
1233
|
+
onMessageSent: P,
|
|
1226
1234
|
onMessageRead: z,
|
|
1227
|
-
onMessageEdited:
|
|
1235
|
+
onMessageEdited: L,
|
|
1228
1236
|
onMessageDeleted: l,
|
|
1229
|
-
onReactionToggled:
|
|
1230
|
-
onRequestAccepted:
|
|
1231
|
-
onParticipantRemoved:
|
|
1232
|
-
}), n.value = !0, i.value = u, t.registerDetailSubscription(u),
|
|
1233
|
-
} catch (
|
|
1234
|
-
r.value =
|
|
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);
|
|
1235
1243
|
}
|
|
1236
1244
|
}
|
|
1237
|
-
}
|
|
1245
|
+
}
|
|
1246
|
+
function I() {
|
|
1238
1247
|
n.value || q();
|
|
1239
|
-
}
|
|
1240
|
-
typeof window < "u" && window.addEventListener(
|
|
1241
|
-
const
|
|
1248
|
+
}
|
|
1249
|
+
typeof window < "u" && window.addEventListener(he(), I);
|
|
1250
|
+
const V = Pe((u) => {
|
|
1242
1251
|
if (u === "connected") {
|
|
1243
1252
|
n.value || q();
|
|
1244
1253
|
return;
|
|
1245
1254
|
}
|
|
1246
|
-
(u === "disconnected" || u === "error") && (
|
|
1247
|
-
})
|
|
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() {
|
|
1248
1258
|
const u = i.value;
|
|
1249
|
-
if (
|
|
1259
|
+
if (R(), !(!n.value || !u))
|
|
1250
1260
|
try {
|
|
1251
|
-
m && (m(), m = null), t.hasGlobalConversationSubscription(u) ||
|
|
1252
|
-
} catch (
|
|
1253
|
-
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);
|
|
1254
1264
|
}
|
|
1255
|
-
}
|
|
1256
|
-
return
|
|
1257
|
-
|
|
1265
|
+
}
|
|
1266
|
+
return o !== null && Ae(() => {
|
|
1267
|
+
R(), V(), C(), typeof window < "u" && window.removeEventListener(he(), I);
|
|
1258
1268
|
}), {
|
|
1259
|
-
isSubscribed:
|
|
1260
|
-
error:
|
|
1269
|
+
isSubscribed: J(() => n.value),
|
|
1270
|
+
error: J(() => r.value),
|
|
1261
1271
|
subscribe: q,
|
|
1262
|
-
unsubscribe:
|
|
1272
|
+
unsubscribe: C
|
|
1263
1273
|
};
|
|
1264
1274
|
}
|
|
1265
|
-
const
|
|
1275
|
+
const Oe = () => {
|
|
1266
1276
|
};
|
|
1267
|
-
let
|
|
1268
|
-
function
|
|
1269
|
-
return
|
|
1277
|
+
let de = Oe;
|
|
1278
|
+
function xt() {
|
|
1279
|
+
return de;
|
|
1270
1280
|
}
|
|
1271
|
-
function
|
|
1272
|
-
|
|
1281
|
+
function qt(e) {
|
|
1282
|
+
de = e;
|
|
1273
1283
|
}
|
|
1274
|
-
function
|
|
1275
|
-
|
|
1284
|
+
function Pt() {
|
|
1285
|
+
de = Oe;
|
|
1276
1286
|
}
|
|
1277
|
-
const
|
|
1287
|
+
const Lt = {
|
|
1278
1288
|
debug: () => {
|
|
1279
1289
|
},
|
|
1280
1290
|
info: () => {
|
|
@@ -1283,182 +1293,182 @@ const Nt = {
|
|
|
1283
1293
|
},
|
|
1284
1294
|
error: () => {
|
|
1285
1295
|
}
|
|
1286
|
-
},
|
|
1287
|
-
let
|
|
1288
|
-
function
|
|
1289
|
-
return
|
|
1296
|
+
}, Ge = () => Lt;
|
|
1297
|
+
let le = Ge;
|
|
1298
|
+
function Nt() {
|
|
1299
|
+
return le;
|
|
1290
1300
|
}
|
|
1291
|
-
function
|
|
1292
|
-
|
|
1301
|
+
function Ut(e) {
|
|
1302
|
+
le = e;
|
|
1293
1303
|
}
|
|
1294
|
-
function
|
|
1295
|
-
|
|
1304
|
+
function zt() {
|
|
1305
|
+
le = Ge;
|
|
1296
1306
|
}
|
|
1297
|
-
const
|
|
1298
|
-
function
|
|
1299
|
-
const e =
|
|
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();
|
|
1300
1310
|
let c = !1;
|
|
1301
1311
|
function f(l) {
|
|
1302
|
-
const
|
|
1303
|
-
if (
|
|
1304
|
-
for (const
|
|
1312
|
+
const _ = a.get(l);
|
|
1313
|
+
if (_ && (a.delete(l), typeof _.channel.stopListening == "function"))
|
|
1314
|
+
for (const w of _.bindings)
|
|
1305
1315
|
try {
|
|
1306
|
-
|
|
1316
|
+
_.channel.stopListening(w.event, w.handler);
|
|
1307
1317
|
} catch {
|
|
1308
1318
|
}
|
|
1309
1319
|
}
|
|
1310
|
-
function
|
|
1320
|
+
function v() {
|
|
1311
1321
|
for (const l of o)
|
|
1312
1322
|
f(l), e.unregisterGlobalConversationSubscription(l);
|
|
1313
1323
|
o.clear();
|
|
1314
1324
|
}
|
|
1315
1325
|
function d(l) {
|
|
1316
|
-
const
|
|
1317
|
-
if (!
|
|
1318
|
-
const
|
|
1326
|
+
const _ = G();
|
|
1327
|
+
if (!_ || o.has(l)) return;
|
|
1328
|
+
const w = `conversation.${l}`;
|
|
1319
1329
|
f(l);
|
|
1320
|
-
const b =
|
|
1321
|
-
if (!
|
|
1322
|
-
|
|
1330
|
+
const b = _.private(w), q = (C) => {
|
|
1331
|
+
if (!et(C)) {
|
|
1332
|
+
se.warn("Dropping malformed ConversationMessageSent event", C);
|
|
1323
1333
|
return;
|
|
1324
1334
|
}
|
|
1325
|
-
const
|
|
1326
|
-
if (!
|
|
1327
|
-
e.addMessage(
|
|
1328
|
-
const
|
|
1329
|
-
if (
|
|
1330
|
-
const
|
|
1331
|
-
|
|
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(() => {
|
|
1332
1342
|
});
|
|
1333
1343
|
return;
|
|
1334
1344
|
}
|
|
1335
|
-
const
|
|
1336
|
-
if (
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1345
|
+
const F = e.getConversationById(u.conversation_id);
|
|
1346
|
+
if (F) {
|
|
1347
|
+
const T = Ot(F);
|
|
1348
|
+
T || F.unread_count++, s(T);
|
|
1339
1349
|
}
|
|
1340
|
-
},
|
|
1341
|
-
if (!
|
|
1342
|
-
|
|
1350
|
+
}, I = (C) => {
|
|
1351
|
+
if (!tt(C)) {
|
|
1352
|
+
se.warn("Dropping malformed ConversationMessageRead event", C);
|
|
1343
1353
|
return;
|
|
1344
1354
|
}
|
|
1345
|
-
e.applyParticipantReadState(
|
|
1346
|
-
},
|
|
1347
|
-
if (!
|
|
1348
|
-
|
|
1355
|
+
e.applyParticipantReadState(C);
|
|
1356
|
+
}, V = (C) => {
|
|
1357
|
+
if (!st(C)) {
|
|
1358
|
+
se.warn("Dropping malformed ConversationRequestAccepted event", C);
|
|
1349
1359
|
return;
|
|
1350
1360
|
}
|
|
1351
|
-
const
|
|
1352
|
-
|
|
1353
|
-
(
|
|
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
|
|
1354
1364
|
);
|
|
1355
1365
|
};
|
|
1356
|
-
b.listen(".ConversationMessageSent",
|
|
1366
|
+
b.listen(".ConversationMessageSent", q), b.listen(".ConversationMessageRead", I), b.listen(".ConversationRequestAccepted", V), a.set(l, {
|
|
1357
1367
|
channel: b,
|
|
1358
1368
|
bindings: [
|
|
1359
|
-
{ event: ".ConversationMessageSent", handler:
|
|
1360
|
-
{ event: ".ConversationMessageRead", handler:
|
|
1361
|
-
{ event: ".ConversationRequestAccepted", handler:
|
|
1369
|
+
{ event: ".ConversationMessageSent", handler: q },
|
|
1370
|
+
{ event: ".ConversationMessageRead", handler: I },
|
|
1371
|
+
{ event: ".ConversationRequestAccepted", handler: V }
|
|
1362
1372
|
]
|
|
1363
1373
|
}), o.add(l), e.registerGlobalConversationSubscription(l);
|
|
1364
1374
|
}
|
|
1365
1375
|
function m() {
|
|
1366
1376
|
const l = G();
|
|
1367
1377
|
if (!l) {
|
|
1368
|
-
|
|
1378
|
+
v();
|
|
1369
1379
|
return;
|
|
1370
1380
|
}
|
|
1371
|
-
for (const
|
|
1372
|
-
f(
|
|
1381
|
+
for (const _ of o) {
|
|
1382
|
+
f(_);
|
|
1373
1383
|
try {
|
|
1374
|
-
l.leave(`conversation.${
|
|
1384
|
+
l.leave(`conversation.${_}`);
|
|
1375
1385
|
} catch {
|
|
1376
1386
|
}
|
|
1377
|
-
e.unregisterGlobalConversationSubscription(
|
|
1387
|
+
e.unregisterGlobalConversationSubscription(_);
|
|
1378
1388
|
}
|
|
1379
1389
|
o.clear();
|
|
1380
1390
|
}
|
|
1381
|
-
function
|
|
1391
|
+
function M() {
|
|
1382
1392
|
const l = G();
|
|
1383
1393
|
if (!l) return;
|
|
1384
|
-
const
|
|
1394
|
+
const _ = e.conversations.slice(0, It), w = new Set(_.map((b) => b.id));
|
|
1385
1395
|
for (const b of o)
|
|
1386
|
-
if (!
|
|
1396
|
+
if (!w.has(b) && !e.hasDetailSubscription(b)) {
|
|
1387
1397
|
try {
|
|
1388
1398
|
f(b), l.leave(`conversation.${b}`);
|
|
1389
1399
|
} catch {
|
|
1390
1400
|
}
|
|
1391
1401
|
o.delete(b), e.unregisterGlobalConversationSubscription(b);
|
|
1392
1402
|
}
|
|
1393
|
-
for (const b of
|
|
1403
|
+
for (const b of _)
|
|
1394
1404
|
d(b.id);
|
|
1395
1405
|
}
|
|
1396
1406
|
function U(l) {
|
|
1397
1407
|
e.updatePresenceForUser(l.user_id, l.status);
|
|
1398
1408
|
}
|
|
1399
|
-
function
|
|
1400
|
-
!G() || c || (
|
|
1409
|
+
function R() {
|
|
1410
|
+
!G() || c || (We(U), c = !0);
|
|
1401
1411
|
}
|
|
1402
|
-
function
|
|
1403
|
-
c && (
|
|
1412
|
+
function A() {
|
|
1413
|
+
c && (Ze(), c = !1);
|
|
1404
1414
|
}
|
|
1405
|
-
const
|
|
1415
|
+
const P = fe(
|
|
1406
1416
|
i,
|
|
1407
1417
|
() => {
|
|
1408
|
-
|
|
1418
|
+
M();
|
|
1409
1419
|
},
|
|
1410
1420
|
{ deep: !1, immediate: !0 }
|
|
1411
|
-
), z =
|
|
1421
|
+
), z = fe(
|
|
1412
1422
|
() => n.fullPath,
|
|
1413
1423
|
() => {
|
|
1414
|
-
|
|
1424
|
+
M();
|
|
1415
1425
|
}
|
|
1416
|
-
),
|
|
1417
|
-
l === "connected" ? (
|
|
1426
|
+
), L = Pe((l) => {
|
|
1427
|
+
l === "connected" ? (v(), M(), A(), R()) : (l === "disconnected" || l === "error") && (v(), A());
|
|
1418
1428
|
});
|
|
1419
|
-
|
|
1420
|
-
|
|
1429
|
+
M(), R(), r !== null && Ae(() => {
|
|
1430
|
+
P(), z(), L(), m(), A();
|
|
1421
1431
|
});
|
|
1422
1432
|
}
|
|
1423
|
-
function
|
|
1424
|
-
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);
|
|
1425
1435
|
}
|
|
1426
|
-
function
|
|
1427
|
-
|
|
1436
|
+
function Xt() {
|
|
1437
|
+
rt(), ot(), ut(), zt(), Pt(), Ke();
|
|
1428
1438
|
}
|
|
1429
1439
|
export {
|
|
1430
|
-
|
|
1440
|
+
Zt as configureMessengerClient,
|
|
1431
1441
|
h as getApi,
|
|
1432
1442
|
k as getAuthStore,
|
|
1433
1443
|
G as getEcho,
|
|
1434
|
-
|
|
1444
|
+
he as getEchoInitializedEvent,
|
|
1435
1445
|
g as getErrorMessage,
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
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,
|
|
1444
1454
|
x as messagingApi,
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
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
|
|
1464
1474
|
};
|