@codingfactory/messenger-client 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,84 +1,94 @@
1
- import { ref as J, getCurrentInstance as Fe, computed as K, onUnmounted as Ee, toValue as Be, watch as me } from "vue";
2
- import { defineStore as Ve, storeToRefs as He } from "pinia";
3
- import Ye, { isAxiosError as je } from "axios";
4
- import { isAxiosError as jt } from "axios";
5
- import { useRoute as We } from "vue-router";
6
- const Te = () => () => {
7
- }, xe = () => {
8
- }, qe = () => {
9
- }, Pe = () => {
10
- }, Le = () => {
1
+ import { ref as Q, getCurrentInstance as Me, computed as J, onUnmounted as we, toValue as Oe, watch as de } from "vue";
2
+ import { defineStore as Ge, storeToRefs as ke } from "pinia";
3
+ import Ve, { isAxiosError as Be } from "axios";
4
+ import { isAxiosError as Zt } from "axios";
5
+ import { useRoute as He } from "vue-router";
6
+ const Re = () => () => {
7
+ }, Ae = () => {
8
+ }, Ee = () => {
9
+ }, Fe = () => {
10
+ }, Te = () => {
11
11
  throw new Error("messenger-client subscribeToConversation is not configured");
12
- };
13
- let W = "messenger-client:echo-initialized", P = () => null, Z = Te, oe = xe, ae = qe, ce = Le, ue = Pe;
12
+ }, _ = {
13
+ ECHO_INITIALIZED_EVENT: "messenger-client:echo-initialized",
14
+ getEcho: () => null,
15
+ onConnectionStatusChange: Re,
16
+ subscribeToPresenceStatus: Ae,
17
+ unsubscribeFromPresenceStatus: Ee,
18
+ subscribeToConversation: Te,
19
+ unsubscribeFromConversation: Fe
20
+ }, le = () => _.ECHO_INITIALIZED_EVENT, O = () => _.getEcho(), xe = (e) => _.onConnectionStatusChange(e), je = (e) => _.subscribeToPresenceStatus(e), Ye = () => _.unsubscribeFromPresenceStatus(), We = (e, t) => _.subscribeToConversation(e, t), Ze = (e) => _.unsubscribeFromConversation(e);
14
21
  function Xe(e) {
15
- e.initializedEvent && (W = e.initializedEvent), e.getEcho && (P = e.getEcho), e.onConnectionStatusChange && (Z = e.onConnectionStatusChange), e.subscribeToPresenceStatus && (oe = e.subscribeToPresenceStatus), e.unsubscribeFromPresenceStatus && (ae = e.unsubscribeFromPresenceStatus), e.subscribeToConversation && (ce = e.subscribeToConversation), e.unsubscribeFromConversation && (ue = e.unsubscribeFromConversation);
22
+ e.initializedEvent && (_.ECHO_INITIALIZED_EVENT = e.initializedEvent), e.getEcho && (_.getEcho = e.getEcho), e.onConnectionStatusChange && (_.onConnectionStatusChange = e.onConnectionStatusChange), e.subscribeToPresenceStatus && (_.subscribeToPresenceStatus = e.subscribeToPresenceStatus), e.unsubscribeFromPresenceStatus && (_.unsubscribeFromPresenceStatus = e.unsubscribeFromPresenceStatus), e.subscribeToConversation && (_.subscribeToConversation = e.subscribeToConversation), e.unsubscribeFromConversation && (_.unsubscribeFromConversation = e.unsubscribeFromConversation);
16
23
  }
17
24
  function Qe() {
18
- W = "messenger-client:echo-initialized", P = () => null, Z = Te, oe = xe, ae = qe, ce = Le, ue = Pe;
25
+ _.ECHO_INITIALIZED_EVENT = "messenger-client:echo-initialized", _.getEcho = () => null, _.onConnectionStatusChange = Re, _.subscribeToPresenceStatus = Ae, _.unsubscribeFromPresenceStatus = Ee, _.subscribeToConversation = Te, _.unsubscribeFromConversation = Fe;
19
26
  }
20
- function X(e) {
27
+ function Z(e) {
21
28
  return typeof e == "object" && e !== null;
22
29
  }
23
- function Ze(e) {
24
- return X(e) && typeof e.conversation_id == "string" && X(e.message) && typeof e.message.id == "string" && typeof e.message.conversation_id == "string" && typeof e.message.author_id == "string";
25
- }
26
30
  function Je(e) {
27
- return X(e) && typeof e.conversation_id == "string" && typeof e.user_id == "string" && typeof e.message_id == "string";
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";
28
32
  }
29
33
  function Ke(e) {
30
- return X(e) && typeof e.conversation_id == "string";
34
+ return Z(e) && typeof e.conversation_id == "string" && typeof e.user_id == "string" && typeof e.message_id == "string";
31
35
  }
32
- const Ue = Ye;
33
- let l = Ue;
34
36
  function et(e) {
37
+ return Z(e) && typeof e.conversation_id == "string";
38
+ }
39
+ const qe = Ve;
40
+ let l = qe;
41
+ function tt(e) {
35
42
  l = e;
36
43
  }
37
- function tt() {
38
- l = Ue;
44
+ function st() {
45
+ l = qe;
39
46
  }
40
- const ze = {
47
+ const Pe = {
41
48
  currentUser: null
42
49
  };
43
- let L = () => ze;
44
- function st(e) {
50
+ let L = () => Pe;
51
+ function nt(e) {
45
52
  L = e;
46
53
  }
47
- function nt() {
48
- L = () => ze;
54
+ function rt() {
55
+ L = () => Pe;
49
56
  }
50
57
  function m(e) {
51
- if (je(e)) {
58
+ if (Be(e)) {
52
59
  const t = e.response?.data?.message || e.message || "An error occurred";
53
60
  return t.includes("SQLSTATE") || t.includes("Connection:") || t.includes("\\Illuminate\\") ? "Something went wrong. Please try again later." : t;
54
61
  }
55
62
  return e instanceof Error ? e.message : typeof e == "string" ? e : typeof e == "object" && e !== null && "message" in e && typeof e.message == "string" ? e.message : "An unexpected error occurred";
56
63
  }
57
- function It(e) {
64
+ function Gt(e) {
58
65
  return e instanceof Error;
59
66
  }
60
- function Ot(e) {
67
+ function kt(e) {
61
68
  return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
62
69
  }
63
- const $e = {
70
+ const Le = {
64
71
  async uploadImage() {
65
72
  throw new Error("messenger-client mediaApi.uploadImage is not configured");
66
73
  }
67
74
  };
68
- let de = $e;
69
- function rt(e) {
70
- de = e;
71
- }
75
+ let ie = Le;
72
76
  function it() {
73
- de = $e;
77
+ return ie;
74
78
  }
75
79
  function ot(e) {
80
+ ie = e;
81
+ }
82
+ function at() {
83
+ ie = Le;
84
+ }
85
+ function ct(e) {
76
86
  return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
77
87
  }
78
88
  function Ne(e) {
79
89
  return typeof e == "object" && e !== null;
80
90
  }
81
- function N(e) {
91
+ function I(e) {
82
92
  return !Ne(e) || !("data" in e) ? e : e.data;
83
93
  }
84
94
  function B(e, t) {
@@ -87,7 +97,7 @@ function B(e, t) {
87
97
  throw new Error(`Invalid messaging folder payload: missing string ${t}`);
88
98
  return s;
89
99
  }
90
- function pe(e, t) {
100
+ function fe(e, t) {
91
101
  const s = e[t];
92
102
  if (s == null)
93
103
  return null;
@@ -95,7 +105,7 @@ function pe(e, t) {
95
105
  throw new Error(`Invalid messaging folder payload: ${t} must be a string or null`);
96
106
  return s;
97
107
  }
98
- function ee(e, t) {
108
+ function K(e, t) {
99
109
  const s = e[t];
100
110
  if (typeof s == "number" && Number.isFinite(s))
101
111
  return s;
@@ -106,43 +116,43 @@ function ee(e, t) {
106
116
  }
107
117
  throw new Error(`Invalid messaging folder payload: missing numeric ${t}`);
108
118
  }
109
- function re(e) {
119
+ function ne(e) {
110
120
  if (!Ne(e))
111
121
  throw new Error("Invalid messaging folder payload: expected object");
112
122
  return {
113
123
  id: B(e, "id"),
114
124
  name: B(e, "name"),
115
- color: pe(e, "color"),
116
- icon: pe(e, "icon"),
117
- sort_order: ee(e, "sort_order"),
118
- conversation_count: ee(e, "conversation_count"),
119
- unread_count: ee(e, "unread_count"),
125
+ color: fe(e, "color"),
126
+ icon: fe(e, "icon"),
127
+ sort_order: K(e, "sort_order"),
128
+ conversation_count: K(e, "conversation_count"),
129
+ unread_count: K(e, "unread_count"),
120
130
  created_at: B(e, "created_at"),
121
131
  updated_at: B(e, "updated_at")
122
132
  };
123
133
  }
124
- function at(e) {
134
+ function ut(e) {
125
135
  if (!Array.isArray(e))
126
136
  throw new Error("Invalid messaging folder payload: expected array");
127
- return e.map((t) => re(t));
137
+ return e.map((t) => ne(t));
128
138
  }
129
- function ve(e) {
130
- if (!ot(e))
139
+ function he(e) {
140
+ if (!ct(e))
131
141
  throw new Error("Invalid conversation payload from folder assignment endpoint");
132
142
  return e;
133
143
  }
134
- const q = {
144
+ const P = {
135
145
  async fetchFolders() {
136
146
  const e = await l.get("/v1/messaging/folders");
137
- return at(N(e.data));
147
+ return ut(I(e.data));
138
148
  },
139
149
  async createFolder(e) {
140
150
  const t = await l.post("/v1/messaging/folders", e);
141
- return re(N(t.data));
151
+ return ne(I(t.data));
142
152
  },
143
153
  async updateFolder(e, t) {
144
154
  const s = await l.patch(`/v1/messaging/folders/${e}`, t);
145
- return re(N(s.data));
155
+ return ne(I(s.data));
146
156
  },
147
157
  async deleteFolder(e) {
148
158
  await l.delete(`/v1/messaging/folders/${e}`);
@@ -154,16 +164,16 @@ const q = {
154
164
  const s = await l.patch(`/v1/messaging/conversations/${e}/folder`, {
155
165
  folder_id: t
156
166
  });
157
- return ve(N(s.data));
167
+ return he(I(s.data));
158
168
  },
159
169
  async acceptRequest(e) {
160
170
  const t = await l.post(`/v1/messaging/conversations/${e}/accept`);
161
- return ve(N(t.data));
171
+ return he(I(t.data));
162
172
  },
163
173
  async declineRequest(e) {
164
174
  await l.post(`/v1/messaging/conversations/${e}/decline`);
165
175
  }
166
- }, _e = 1e3, le = 4e3, ct = 12e4, ut = 300, dt = 1, lt = 1600, fe = (e) => {
176
+ }, ge = 1e3, oe = 4e3, dt = 12e4, lt = 300, ft = 1, ht = 1600, ae = (e) => {
167
177
  if (typeof e == "number" && Number.isFinite(e))
168
178
  return e;
169
179
  if (typeof e == "string") {
@@ -171,32 +181,32 @@ const q = {
171
181
  if (Number.isFinite(t))
172
182
  return t;
173
183
  }
174
- }, De = (e) => typeof e == "number" && e >= 500 && e < 600, ye = (e) => {
175
- const s = fe(e.response?.status);
176
- return s === void 0 ? !0 : s === 429 || De(s);
177
- }, Ie = (e) => {
184
+ }, Ue = (e) => typeof e == "number" && e >= 500 && e < 600, me = (e) => {
185
+ const s = ae(e.response?.status);
186
+ return s === void 0 ? !0 : s === 429 || Ue(s);
187
+ }, ze = (e) => {
178
188
  if (typeof e == "number" && Number.isFinite(e) && e > 0)
179
- return Math.max(_e, e * 1e3);
189
+ return Math.max(ge, e * 1e3);
180
190
  if (typeof e == "string") {
181
191
  const t = Number.parseInt(e, 10);
182
192
  if (Number.isFinite(t) && t > 0)
183
- return Math.max(_e, t * 1e3);
193
+ return Math.max(ge, t * 1e3);
184
194
  }
185
- return le;
186
- }, ft = (e) => {
187
- const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = le * s;
188
- return Math.min(ct, n);
189
- }, ht = (e) => {
195
+ return oe;
196
+ }, gt = (e) => {
197
+ const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = oe * s;
198
+ return Math.min(dt, n);
199
+ }, mt = (e) => {
190
200
  const t = e;
191
- return fe(t.response?.status) === 429 ? Ie(t.response?.headers?.["retry-after"]) : ut;
192
- }, be = async (e) => {
201
+ return ae(t.response?.status) === 429 ? ze(t.response?.headers?.["retry-after"]) : lt;
202
+ }, pe = async (e) => {
193
203
  await new Promise((t) => {
194
204
  setTimeout(t, e);
195
205
  });
196
- }, gt = (e) => {
197
- if (!S(e))
206
+ }, pt = (e) => {
207
+ if (!M(e))
198
208
  return !1;
199
- const s = (S(e.data) ? e.data : e).throttled;
209
+ const s = (M(e.data) ? e.data : e).throttled;
200
210
  if (typeof s == "boolean")
201
211
  return s;
202
212
  if (typeof s == "number")
@@ -207,7 +217,7 @@ const q = {
207
217
  }
208
218
  return !1;
209
219
  };
210
- function mt(e, t, s) {
220
+ function vt(e, t, s) {
211
221
  const n = typeof e == "string" && e.trim().length > 0 ? e.trim().toLowerCase() : void 0;
212
222
  if (n)
213
223
  return n;
@@ -217,17 +227,17 @@ function mt(e, t, s) {
217
227
  const i = typeof s == "string" && s.trim().length > 0 ? s.trim().toLowerCase() : void 0;
218
228
  return i ? i === "image" ? "image/*" : i === "video" ? "video/*" : i === "audio" ? "audio/*" : i : "application/octet-stream";
219
229
  }
220
- function pt(e) {
230
+ function _t(e) {
221
231
  const t = e.url || "", s = e.thumbnail_url ?? e.thumbnail, n = {
222
232
  id: e.media_id ?? e.id ?? "",
223
- name: e.name ?? vt(t),
233
+ name: e.name ?? yt(t),
224
234
  url: t,
225
- type: mt(e.mime, e.mime_type, e.type),
235
+ type: vt(e.mime, e.mime_type, e.type),
226
236
  size: e.size ?? 0
227
237
  };
228
238
  return s !== void 0 && (n.thumbnail = s), n;
229
239
  }
230
- function vt(e) {
240
+ function yt(e) {
231
241
  if (!e) return "attachment";
232
242
  try {
233
243
  const s = new URL(e).pathname.split("/");
@@ -236,20 +246,20 @@ function vt(e) {
236
246
  return "attachment";
237
247
  }
238
248
  }
239
- function _t(e) {
240
- return !Array.isArray(e) || e.length === 0 ? [] : e.map(pt);
249
+ function bt(e) {
250
+ return !Array.isArray(e) || e.length === 0 ? [] : e.map(_t);
241
251
  }
242
- function Q(e) {
252
+ function X(e) {
243
253
  if (typeof e != "string")
244
254
  return;
245
255
  const t = e.trim();
246
256
  if (t.length !== 0)
247
257
  return t;
248
258
  }
249
- function yt(e) {
259
+ function Ct(e) {
250
260
  if (!e)
251
261
  return;
252
- const t = Q(e.avatar) ?? Q(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
262
+ const t = X(e.avatar) ?? X(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
253
263
  return {
254
264
  id: e.id ?? "",
255
265
  name: e.name ?? "",
@@ -273,54 +283,60 @@ function Y(e) {
273
283
  } : null;
274
284
  return {
275
285
  ...e,
276
- ...s ? { author: yt(s) } : {},
286
+ ...s ? { author: Ct(s) } : {},
277
287
  shared_post: n,
278
- attachments: _t(e.attachments)
288
+ attachments: bt(e.attachments)
279
289
  };
280
290
  }
281
- function bt(e) {
291
+ function St(e) {
282
292
  return typeof e != "string" || e.length === 0 ? null : e;
283
293
  }
284
- function Ce(e) {
294
+ function ve(e) {
285
295
  if (!(typeof e != "string" || e.length === 0))
286
296
  return e;
287
297
  }
288
- function ie(e) {
298
+ function re(e) {
289
299
  return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
290
300
  }
291
- function Ct(e, t = []) {
301
+ function Mt(e, t = []) {
292
302
  const s = /* @__PURE__ */ new Map();
293
303
  for (const n of t) {
294
- const r = Ce(n.last_read_message_id);
304
+ const r = ve(n.last_read_message_id);
295
305
  r && s.set(n.user_id, r);
296
306
  }
297
307
  return e.map((n) => {
298
- const r = Q(n.user?.avatar) ?? Q(n.user?.avatar_url), i = n.user ? {
308
+ const r = Object.prototype.hasOwnProperty.call(n, "last_read_message_id"), i = X(n.user?.avatar) ?? X(n.user?.avatar_url), o = n.user ? {
299
309
  id: n.user.id,
300
310
  name: n.user.name,
301
- ...r ? { avatar: r } : {},
311
+ ...i ? { avatar: i } : {},
302
312
  ...n.user.handle ? { handle: n.user.handle } : {}
303
- } : void 0, o = Ce(n.last_read_message_id);
304
- if (o)
313
+ } : void 0, a = ve(n.last_read_message_id);
314
+ if (a)
305
315
  return {
306
316
  ...n,
307
- ...i ? { user: i } : {},
308
- last_read_message_id: o
317
+ ...o ? { user: o } : {},
318
+ last_read_message_id: a
309
319
  };
310
- const a = s.get(n.user_id);
311
- return a ? {
320
+ if (r)
321
+ return {
322
+ ...n,
323
+ ...o ? { user: o } : {},
324
+ last_read_message_id: ""
325
+ };
326
+ const u = s.get(n.user_id);
327
+ return u ? {
312
328
  ...n,
313
- ...i ? { user: i } : {},
314
- last_read_message_id: a
329
+ ...o ? { user: o } : {},
330
+ last_read_message_id: u
315
331
  } : {
316
332
  ...n,
317
- ...i ? { user: i } : {},
333
+ ...o ? { user: o } : {},
318
334
  last_read_message_id: ""
319
335
  };
320
336
  });
321
337
  }
322
338
  function D(e, t) {
323
- const s = bt(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 = (() => {
339
+ const s = St(e.muted_until), n = e.is_muted ?? s !== null, r = e.last_message ? Y(e.last_message) : t?.last_message, i = e.last_message_at ?? t?.last_message_at, o = (() => {
324
340
  if (!t || t.unread_count !== 0 || e.unread_count <= 0)
325
341
  return !1;
326
342
  const a = t.last_message?.id, u = e.last_message?.id;
@@ -329,43 +345,43 @@ function D(e, t) {
329
345
  return {
330
346
  ...e,
331
347
  unread_count: n || o ? 0 : e.unread_count,
332
- participants: Ct(e.participants, t?.participants),
348
+ participants: Mt(e.participants, t?.participants),
333
349
  is_muted: n,
334
350
  muted_until: s,
335
351
  ...r ? { last_message: r } : {},
336
352
  ...i ? { last_message_at: i } : {}
337
353
  };
338
354
  }
339
- function St(e) {
355
+ function wt(e) {
340
356
  return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
341
357
  }
342
- function te(e) {
343
- return St(e) ? 0 : e.unread_count || 0;
358
+ function ee(e) {
359
+ return wt(e) ? 0 : e.unread_count || 0;
344
360
  }
345
- function Se(e, t) {
361
+ function _e(e, t) {
346
362
  const s = t[e.id];
347
363
  if (Array.isArray(s))
348
364
  for (let n = s.length - 1; n >= 0; n -= 1) {
349
365
  const r = s[n]?.id;
350
- if (ie(r))
366
+ if (re(r))
351
367
  return r;
352
368
  }
353
- return ie(e.last_message?.id) ? e.last_message.id : null;
369
+ return re(e.last_message?.id) ? e.last_message.id : null;
354
370
  }
355
- function S(e) {
371
+ function M(e) {
356
372
  return typeof e == "object" && e !== null;
357
373
  }
358
- function Mt(e) {
359
- return S(e) ? (S(e.response) ? e.response : null)?.status === 401 : !1;
374
+ function Rt(e) {
375
+ return M(e) ? (M(e.response) ? e.response : null)?.status === 401 : !1;
360
376
  }
361
- function Me(e) {
377
+ function ye(e) {
362
378
  if (!Array.isArray(e))
363
379
  return [];
364
380
  const t = [];
365
381
  for (const s of e) {
366
- if (!S(s) || typeof s.reaction != "string" || typeof s.count != "number" || !Array.isArray(s.users))
382
+ if (!M(s) || typeof s.reaction != "string" || typeof s.count != "number" || !Array.isArray(s.users))
367
383
  continue;
368
- const n = s.users.filter((r) => S(r)).filter(
384
+ const n = s.users.filter((r) => M(r)).filter(
369
385
  (r) => typeof r.id == "string" && typeof r.name == "string"
370
386
  ).map((r) => ({
371
387
  id: r.id,
@@ -379,58 +395,58 @@ function Me(e) {
379
395
  }
380
396
  return t;
381
397
  }
382
- function wt(e, t) {
383
- const s = S(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
398
+ function At(e, t) {
399
+ const s = M(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
384
400
  if (!(typeof n != "string" || n.length === 0))
385
401
  return n;
386
402
  }
387
- function V(e, t) {
388
- const s = S(e) ? e : {}, n = s.data ?? e;
403
+ function H(e, t) {
404
+ const s = M(e) ? e : {}, n = s.data ?? e;
389
405
  let r = [];
390
- 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)), {
406
+ return Array.isArray(n) ? r = n : M(n) && (Array.isArray(n.items) ? r = n.items : Array.isArray(n[t]) ? r = n[t] : Array.isArray(n.data) && (r = n.data)), {
391
407
  items: r,
392
- nextCursor: wt(s, n)
408
+ nextCursor: At(s, n)
393
409
  };
394
410
  }
395
- function we(e) {
396
- return S(e) && typeof e.id == "string" && e.id.length > 0;
411
+ function be(e) {
412
+ return M(e) && typeof e.id == "string" && e.id.length > 0;
397
413
  }
398
- function Re(e) {
399
- return S(e) ? typeof e.id == "string" && (e.type === "dm" || e.type === "group") && Array.isArray(e.participants) : !1;
414
+ function Ce(e) {
415
+ return M(e) ? typeof e.id == "string" && (e.type === "dm" || e.type === "group") && Array.isArray(e.participants) : !1;
400
416
  }
401
- function j(e, t) {
417
+ function W(e, t) {
402
418
  if (e.is_pinned !== t.is_pinned)
403
419
  return e.is_pinned ? -1 : 1;
404
420
  const s = e.last_message_at ?? e.created_at, r = (t.last_message_at ?? t.created_at).localeCompare(s);
405
421
  return r !== 0 ? r : e.id.localeCompare(t.id);
406
422
  }
407
- function H(e, t) {
423
+ function j(e, t) {
408
424
  return [t, ...e.filter((s) => s.id !== t.id)];
409
425
  }
410
- function I(e) {
426
+ function $(e) {
411
427
  return [...e].sort((t, s) => t.sort_order !== s.sort_order ? t.sort_order - s.sort_order : t.name.localeCompare(s.name));
412
428
  }
413
- function Rt(e, t) {
429
+ function Et(e, t) {
414
430
  return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
415
431
  }
416
- function Ae(e, t) {
432
+ function Se(e, t) {
417
433
  return e.map((s) => {
418
- const n = Rt(s.folder_id, t);
434
+ const n = Et(s.folder_id, t);
419
435
  return (s.folder_id ?? null) === n ? s : {
420
436
  ...s,
421
437
  folder_id: n
422
438
  };
423
439
  });
424
440
  }
425
- function se(e) {
441
+ function te(e) {
426
442
  const t = /* @__PURE__ */ new Map();
427
443
  for (const s of e.requests)
428
444
  s.is_request === !0 && t.set(s.id, s);
429
445
  for (const s of e.conversations)
430
446
  s.is_request === !0 && t.set(s.id, s);
431
- return Array.from(t.values()).sort(j);
447
+ return Array.from(t.values()).sort(W);
432
448
  }
433
- const Oe = Ve("messaging", {
449
+ const Ie = Ge("messaging", {
434
450
  state: () => ({
435
451
  conversations: [],
436
452
  requests: [],
@@ -457,46 +473,46 @@ const Oe = Ve("messaging", {
457
473
  getConversationById: (e) => (t) => e.conversations.find((s) => s.id === t),
458
474
  getMessagesByConversationId: (e) => (t) => e.messages[t] || [],
459
475
  getTypingUsers: (e) => (t) => e.typingUsers[t] || [],
460
- unreadConversationsCount: (e) => e.conversations.filter((t) => te(t) > 0).length,
461
- unreadCount: (e) => e.conversations.reduce((t, s) => t + te(s), 0),
462
- totalUnreadCount: (e) => e.conversations.reduce((t, s) => t + te(s), 0),
463
- sortedFolders: (e) => I(e.folders),
476
+ unreadConversationsCount: (e) => e.conversations.filter((t) => ee(t) > 0).length,
477
+ unreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
478
+ totalUnreadCount: (e) => e.conversations.reduce((t, s) => t + ee(s), 0),
479
+ sortedFolders: (e) => $(e.folders),
464
480
  folderById: (e) => (t) => e.folders.find((s) => s.id === t),
465
481
  conversationsInFolder: (e) => (t) => e.conversations.filter((s) => s.folder_id === t),
466
482
  hasMoreMessages: (e) => (t) => e.conversationHasMore[t] ?? !1,
467
483
  isLoadingMessages: (e) => (t) => e.loadingMessages[t] ?? !1,
468
484
  // Message request getters
469
- requestConversations: (e) => se(e),
470
- requestCount: (e) => se(e).length,
471
- unreadRequestCount: (e) => se(e).filter((t) => t.unread_count > 0).length
485
+ requestConversations: (e) => te(e),
486
+ requestCount: (e) => te(e).length,
487
+ unreadRequestCount: (e) => te(e).filter((t) => t.unread_count > 0).length
472
488
  },
473
489
  actions: {
474
490
  normalizeFolderAssignmentsState() {
475
491
  if (!this.foldersLoaded)
476
492
  return;
477
493
  const e = new Set(this.folders.map((t) => t.id));
478
- this.conversations = Ae(this.conversations, e), this.requests = Ae(this.requests, e), this.activeFolderId !== null && !e.has(this.activeFolderId) && (this.activeFolderId = null);
494
+ this.conversations = Se(this.conversations, e), this.requests = Se(this.requests, e), this.activeFolderId !== null && !e.has(this.activeFolderId) && (this.activeFolderId = null);
479
495
  },
480
496
  async fetchFolders() {
481
497
  try {
482
- const e = await q.fetchFolders();
483
- return this.folders = I(e), this.foldersLoaded = !0, this.normalizeFolderAssignmentsState(), this.folders;
498
+ const e = await P.fetchFolders();
499
+ return this.folders = $(e), this.foldersLoaded = !0, this.normalizeFolderAssignmentsState(), this.folders;
484
500
  } catch (e) {
485
501
  throw this.error = m(e), e;
486
502
  }
487
503
  },
488
504
  async createFolder(e) {
489
505
  try {
490
- const t = await q.createFolder(e);
491
- return this.folders = I([...this.folders, t]), t;
506
+ const t = await P.createFolder(e);
507
+ return this.folders = $([...this.folders, t]), t;
492
508
  } catch (t) {
493
509
  throw this.error = m(t), t;
494
510
  }
495
511
  },
496
512
  async updateFolder(e, t) {
497
513
  try {
498
- const s = await q.updateFolder(e, t);
499
- return this.folders = I(
514
+ const s = await P.updateFolder(e, t);
515
+ return this.folders = $(
500
516
  this.folders.map((n) => n.id === e ? s : n)
501
517
  ), s;
502
518
  } catch (s) {
@@ -505,14 +521,14 @@ const Oe = Ve("messaging", {
505
521
  },
506
522
  async deleteFolder(e) {
507
523
  try {
508
- await q.deleteFolder(e), this.folders = this.folders.filter((t) => t.id !== e), this.foldersLoaded = !0, this.activeFolderId === e && (this.activeFolderId = null), this.normalizeFolderAssignmentsState();
524
+ await P.deleteFolder(e), this.folders = this.folders.filter((t) => t.id !== e), this.foldersLoaded = !0, this.activeFolderId === e && (this.activeFolderId = null), this.normalizeFolderAssignmentsState();
509
525
  } catch (t) {
510
526
  throw this.error = m(t), t;
511
527
  }
512
528
  },
513
529
  async reorderFolders(e) {
514
530
  try {
515
- await q.reorderFolders(e);
531
+ await P.reorderFolders(e);
516
532
  const t = new Map(this.folders.map((r) => [r.id, r])), s = [];
517
533
  for (const r of e) {
518
534
  const i = t.get(r);
@@ -521,7 +537,7 @@ const Oe = Ve("messaging", {
521
537
  sort_order: s.length + 1
522
538
  }), t.delete(r));
523
539
  }
524
- const n = I(Array.from(t.values()));
540
+ const n = $(Array.from(t.values()));
525
541
  for (const r of n)
526
542
  s.push({
527
543
  ...r,
@@ -534,7 +550,7 @@ const Oe = Ve("messaging", {
534
550
  },
535
551
  async assignToFolder(e, t) {
536
552
  try {
537
- const s = await q.assignFolder(e, t), n = this.conversations.findIndex((o) => o.id === e);
553
+ const s = await P.assignFolder(e, t), n = this.conversations.findIndex((o) => o.id === e);
538
554
  if (n < 0)
539
555
  return;
540
556
  const r = this.conversations[n];
@@ -554,7 +570,7 @@ const Oe = Ve("messaging", {
554
570
  try {
555
571
  const r = n?.includePresence ?? !0, i = {};
556
572
  r && (i.include_presence = 1), e && (i.cursor = e), t && (i.filter = t), typeof s == "string" && s.length > 0 && (i.folder_id = s);
557
- const o = await l.get("/v1/messaging/conversations", { params: i }), { items: a, nextCursor: u } = V(
573
+ const o = await l.get("/v1/messaging/conversations", { params: i }), { items: a, nextCursor: u } = H(
558
574
  o.data,
559
575
  "conversations"
560
576
  ), f = a.map((d) => {
@@ -564,13 +580,13 @@ const Oe = Ve("messaging", {
564
580
  return D(d, p);
565
581
  });
566
582
  e ? this.conversations.push(...f) : this.conversations = f, this.normalizeFolderAssignmentsState(), this.lastFetch = Date.now();
567
- const _ = {
583
+ const y = {
568
584
  data: f,
569
585
  has_more: !!u
570
586
  };
571
- return u !== void 0 && (_.next_cursor = u), _;
587
+ return u !== void 0 && (y.next_cursor = u), y;
572
588
  } catch (r) {
573
- throw n?.background && ye(r) || (this.error = m(r)), r;
589
+ throw n?.background && me(r) || (this.error = m(r)), r;
574
590
  } finally {
575
591
  this.loading = !1;
576
592
  }
@@ -584,8 +600,8 @@ const Oe = Ve("messaging", {
584
600
  includePresence: !1
585
601
  }), this.backgroundPollRetryAfterUntil = 0, this.backgroundPollTransientFailureCount = 0, !0;
586
602
  } catch (e) {
587
- const t = e, s = fe(t.response?.status);
588
- return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + Ie(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || De(s) ? (this.backgroundPollRetryAfterUntil = Date.now() + ft(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + le, !1));
603
+ const t = e, s = ae(t.response?.status);
604
+ return s === 429 ? (this.backgroundPollRetryAfterUntil = Date.now() + ze(t.response?.headers?.["retry-after"]), !1) : (this.backgroundPollTransientFailureCount += 1, s === void 0 || Ue(s) ? (this.backgroundPollRetryAfterUntil = Date.now() + gt(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + oe, !1));
589
605
  }
590
606
  },
591
607
  async fetchConversation(e) {
@@ -611,7 +627,7 @@ const Oe = Ve("messaging", {
611
627
  filter: "requests"
612
628
  };
613
629
  e && (t.cursor = e);
614
- const s = await l.get("/v1/messaging/conversations", { params: t }), { items: n, nextCursor: r } = V(
630
+ const s = await l.get("/v1/messaging/conversations", { params: t }), { items: n, nextCursor: r } = H(
615
631
  s.data,
616
632
  "conversations"
617
633
  ), i = n.map((a) => {
@@ -640,11 +656,11 @@ const Oe = Ve("messaging", {
640
656
  r = await l.get(`/v1/messaging/conversations/${e}/messages`, { params: s });
641
657
  break;
642
658
  } catch (d) {
643
- if (!(n < dt && ye(d)))
659
+ if (!(n < ft && me(d)))
644
660
  throw d;
645
- n += 1, await be(ht(d));
661
+ n += 1, await pe(mt(d));
646
662
  }
647
- const { items: i, nextCursor: o } = V(
663
+ const { items: i, nextCursor: o } = H(
648
664
  r.data,
649
665
  "messages"
650
666
  ), a = i.map(Y), u = [...a].reverse();
@@ -656,11 +672,11 @@ const Oe = Ve("messaging", {
656
672
  d && this.updateConversationLastMessage(e, d);
657
673
  }
658
674
  o ? (this.conversationCursors[e] = o, this.conversationHasMore[e] = !0) : (delete this.conversationCursors[e], this.conversationHasMore[e] = !1);
659
- const _ = {
675
+ const y = {
660
676
  data: a,
661
677
  has_more: !!o
662
678
  };
663
- return o !== void 0 && (_.next_cursor = o), _;
679
+ return o !== void 0 && (y.next_cursor = o), y;
664
680
  } catch (s) {
665
681
  throw this.error = m(s), s;
666
682
  } finally {
@@ -668,7 +684,7 @@ const Oe = Ve("messaging", {
668
684
  }
669
685
  },
670
686
  async sendMessage(e, t, s, n, r, i) {
671
- const o = L(), a = `temp-${Date.now()}-${Math.random()}`, u = typeof i == "string" && i.trim().length > 0 ? i.trim() : null, f = o.currentUser, _ = {
687
+ const o = L(), a = `temp-${Date.now()}-${Math.random()}`, u = typeof i == "string" && i.trim().length > 0 ? i.trim() : null, f = o.currentUser, y = {
672
688
  id: a,
673
689
  conversation_id: e,
674
690
  author_id: f?.id || "",
@@ -679,12 +695,12 @@ const Oe = Ve("messaging", {
679
695
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
680
696
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
681
697
  };
682
- f && (_.author = {
698
+ f && (y.author = {
683
699
  id: f.id,
684
700
  name: f.name,
685
701
  ...f.avatar ? { avatar: f.avatar } : {},
686
702
  ...f.handle ? { handle: f.handle } : {}
687
- }), n != null && (_.reply_to_id = n), r != null && (_.reply_to = r), this.messages[e] || (this.messages[e] = []), this.messages[e].push(_), this._pendingSendIds.add(a);
703
+ }), n != null && (y.reply_to_id = n), r != null && (y.reply_to = r), this.messages[e] || (this.messages[e] = []), this.messages[e].push(y), this._pendingSendIds.add(a);
688
704
  try {
689
705
  let d;
690
706
  const p = {
@@ -694,12 +710,12 @@ const Oe = Ve("messaging", {
694
710
  };
695
711
  if (s && s.length > 0) {
696
712
  const v = await Promise.all(
697
- s.map(async (A) => {
698
- const y = await de.uploadImage(A);
713
+ s.map(async (E) => {
714
+ const b = await it().uploadImage(E);
699
715
  return {
700
- media_id: y.id,
701
- mime: y.mime_type,
702
- size: y.size
716
+ media_id: b.id,
717
+ mime: b.mime_type,
718
+ size: b.size
703
719
  };
704
720
  })
705
721
  );
@@ -712,15 +728,15 @@ const Oe = Ve("messaging", {
712
728
  ...p,
713
729
  type: "text"
714
730
  });
715
- const F = d.data.data || d.data, U = { ..._, ...F, attachments: F.attachments ?? _.attachments }, R = Y(U), E = this.messages[e], T = E.findIndex((v) => v.id === a);
716
- T >= 0 && (E[T] = R), this._pendingSendIds.delete(a);
717
- const z = R.id;
731
+ const F = d.data.data || d.data, N = { ...y, ...F, attachments: F.attachments ?? y.attachments }, A = Y(N), T = this.messages[e], x = T.findIndex((v) => v.id === a);
732
+ x >= 0 && (T[x] = A), this._pendingSendIds.delete(a);
733
+ const U = A.id;
718
734
  let h = 0;
719
- for (let v = E.length - 1; v >= 0; v--) {
720
- const A = E[v];
721
- A && A.id === z && (h++, h > 1 && E.splice(v, 1));
735
+ for (let v = T.length - 1; v >= 0; v--) {
736
+ const E = T[v];
737
+ E && E.id === U && (h++, h > 1 && T.splice(v, 1));
722
738
  }
723
- return this.updateConversationLastMessage(e, R), R;
739
+ return this.updateConversationLastMessage(e, A), A;
724
740
  } catch (d) {
725
741
  throw this._pendingSendIds.delete(a), this.messages[e] = this.messages[e].filter((p) => p.id !== a), this.error = m(d), d;
726
742
  }
@@ -762,11 +778,11 @@ const Oe = Ve("messaging", {
762
778
  return null;
763
779
  for (let i = r.length - 1; i >= 0; i -= 1) {
764
780
  const o = r[i]?.id;
765
- if (ie(o))
781
+ if (re(o))
766
782
  return o;
767
783
  }
768
784
  return null;
769
- })(), n = t ? Se(t, this.messages) : s;
785
+ })(), n = t ? _e(t, this.messages) : s;
770
786
  if (!n)
771
787
  return;
772
788
  await l.post(`/v1/messaging/conversations/${e}/read`, {
@@ -785,7 +801,7 @@ const Oe = Ve("messaging", {
785
801
  if (e.length === 0)
786
802
  return;
787
803
  const t = e.map((r) => {
788
- const i = Se(r, this.messages);
804
+ const i = _e(r, this.messages);
789
805
  return i ? {
790
806
  conversationId: r.id,
791
807
  messageId: i
@@ -817,9 +833,9 @@ const Oe = Ve("messaging", {
817
833
  async sendTyping(e, t = "start") {
818
834
  try {
819
835
  const s = await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
820
- if (t !== "start" || !gt(s.data))
836
+ if (t !== "start" || !pt(s.data))
821
837
  return;
822
- await be(lt), await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
838
+ await pe(ht), await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
823
839
  } catch (s) {
824
840
  console.warn("Failed to send typing indicator:", s);
825
841
  }
@@ -859,7 +875,7 @@ const Oe = Ve("messaging", {
859
875
  try {
860
876
  await l.patch(`/v1/messaging/conversations/${e}/pin`, { pinned: t });
861
877
  const s = this.conversations.find((n) => n.id === e);
862
- s && (s.is_pinned = t), this.conversations.sort(j);
878
+ s && (s.is_pinned = t), this.conversations.sort(W);
863
879
  } catch (s) {
864
880
  throw this.error = m(s), s;
865
881
  }
@@ -885,10 +901,10 @@ const Oe = Ve("messaging", {
885
901
  };
886
902
  t && (s.message = t);
887
903
  const n = await l.post("/v1/messaging/conversations/dm", s), r = n.data.data || n.data;
888
- if (!we(r))
904
+ if (!be(r))
889
905
  throw new Error("Invalid conversation payload from DM create endpoint.");
890
- const i = Re(r) ? D(r) : await this.fetchConversation(r.id);
891
- return i.is_request === !0 ? (this.requests = H(this.requests, i), this.conversations = this.conversations.filter((o) => o.id !== i.id), i) : (this.conversations = H(this.conversations, i), this.requests = this.requests.filter((o) => o.id !== i.id), i);
906
+ const i = Ce(r) ? D(r) : await this.fetchConversation(r.id);
907
+ return i.is_request === !0 ? (this.requests = j(this.requests, i), this.conversations = this.conversations.filter((o) => o.id !== i.id), i) : (this.conversations = j(this.conversations, i), this.requests = this.requests.filter((o) => o.id !== i.id), i);
892
908
  } catch (s) {
893
909
  throw this.error = m(s), s;
894
910
  }
@@ -899,10 +915,10 @@ const Oe = Ve("messaging", {
899
915
  title: e,
900
916
  participant_ids: t
901
917
  }), n = s.data.data || s.data;
902
- if (!we(n))
918
+ if (!be(n))
903
919
  throw new Error("Invalid conversation payload from group create endpoint.");
904
- const r = Re(n) ? n : await this.fetchConversation(n.id);
905
- return this.conversations = H(this.conversations, r), r;
920
+ const r = Ce(n) ? n : await this.fetchConversation(n.id);
921
+ return this.conversations = j(this.conversations, r), r;
906
922
  } catch (s) {
907
923
  throw this.error = m(s), s;
908
924
  }
@@ -997,17 +1013,17 @@ const Oe = Ve("messaging", {
997
1013
  try {
998
1014
  a = await l.post(n, r);
999
1015
  } catch (d) {
1000
- if (!Mt(d))
1016
+ if (!Rt(d))
1001
1017
  throw d;
1002
1018
  a = await l.post(n, r);
1003
1019
  }
1004
- const u = S(a.data) && "data" in a.data ? a.data.data : a.data, f = Me(
1005
- S(u) ? u.reactions : void 0
1020
+ const u = M(a.data) && "data" in a.data ? a.data.data : a.data, f = ye(
1021
+ M(u) ? u.reactions : void 0
1006
1022
  );
1007
1023
  (f.length > 0 || o.length === 0) && this.updateMessageReactions(e, t, f);
1008
1024
  try {
1009
- const d = await l.get(n), p = S(d.data) && "data" in d.data ? d.data.data : d.data, F = Me(
1010
- S(p) ? p.reactions : void 0
1025
+ const d = await l.get(n), p = M(d.data) && "data" in d.data ? d.data.data : d.data, F = ye(
1026
+ M(p) ? p.reactions : void 0
1011
1027
  );
1012
1028
  this.updateMessageReactions(e, t, F);
1013
1029
  } catch {
@@ -1038,7 +1054,7 @@ const Oe = Ve("messaging", {
1038
1054
  const o = i.find((a) => a.id === e);
1039
1055
  return o ? (o.last_message = t, o.last_message_at = t.created_at, !0) : !1;
1040
1056
  }, n = s(this.conversations), r = s(this.requests);
1041
- n && this.conversations.sort(j), r && this.requests.sort(j);
1057
+ n && this.conversations.sort(W), r && this.requests.sort(W);
1042
1058
  },
1043
1059
  updatePresenceForUser(e, t) {
1044
1060
  const s = t === "online" || t === "idle" || t === "dnd";
@@ -1047,7 +1063,7 @@ const Oe = Ve("messaging", {
1047
1063
  },
1048
1064
  async acceptRequest(e) {
1049
1065
  try {
1050
- const t = await q.acceptRequest(e);
1066
+ const t = await P.acceptRequest(e);
1051
1067
  this.requests = this.requests.filter((n) => n.id !== e);
1052
1068
  const s = D({
1053
1069
  ...t,
@@ -1055,14 +1071,14 @@ const Oe = Ve("messaging", {
1055
1071
  is_archived: t.is_archived ?? !1,
1056
1072
  is_muted: t.is_muted ?? !1
1057
1073
  });
1058
- this.conversations = H(this.conversations, s);
1074
+ this.conversations = j(this.conversations, s);
1059
1075
  } catch (t) {
1060
1076
  throw this.error = m(t), t;
1061
1077
  }
1062
1078
  },
1063
1079
  async declineRequest(e) {
1064
1080
  try {
1065
- await q.declineRequest(e), this.requests = this.requests.filter((t) => t.id !== e);
1081
+ await P.declineRequest(e), this.requests = this.requests.filter((t) => t.id !== e);
1066
1082
  } catch (t) {
1067
1083
  throw this.error = m(t), t;
1068
1084
  }
@@ -1074,7 +1090,7 @@ const Oe = Ve("messaging", {
1074
1090
  t && (n.filter = t), typeof s == "string" && s.length > 0 && (n.folder_id = s);
1075
1091
  const r = await l.get("/v1/messaging/conversations", {
1076
1092
  params: n
1077
- }), { items: i } = V(
1093
+ }), { items: i } = H(
1078
1094
  r.data,
1079
1095
  "conversations"
1080
1096
  );
@@ -1133,117 +1149,117 @@ const Oe = Ve("messaging", {
1133
1149
  }
1134
1150
  }
1135
1151
  });
1136
- function Gt(e) {
1137
- const t = Oe(), s = L(), n = J(!1), r = J(null), i = J(null), o = Fe(), a = o !== null, u = 20, f = 250;
1138
- let _ = 0, d = null, p = null;
1139
- const F = K(() => s.currentUser?.id), U = () => Be(e)?.trim() ?? "", R = () => {
1140
- d && (clearTimeout(d), d = null), _ = 0;
1141
- }, E = () => {
1142
- !a || n.value || d || _ >= u || (d = setTimeout(() => {
1143
- d = null, _ += 1, T();
1144
- }, f));
1152
+ function Vt(e) {
1153
+ const t = Ie(), s = L(), n = Q(!1), r = Q(null), i = Q(null), o = Me(), a = o !== null, u = 20, f = 250;
1154
+ let y = 0, d = null, p = null;
1155
+ const F = J(() => s.currentUser?.id), N = () => Oe(e)?.trim() ?? "", A = () => {
1156
+ d && (clearTimeout(d), d = null), y = 0;
1145
1157
  }, T = () => {
1146
- const c = U();
1158
+ !a || n.value || d || y >= u || (d = setTimeout(() => {
1159
+ d = null, y += 1, x();
1160
+ }, f));
1161
+ }, x = () => {
1162
+ const c = N();
1147
1163
  if (!(n.value || !c)) {
1148
- if (!P()) {
1149
- E();
1164
+ if (!O()) {
1165
+ T();
1150
1166
  return;
1151
1167
  }
1152
1168
  r.value = null;
1153
1169
  try {
1154
- p = ce(c, {
1155
- onMessageSent: A,
1156
- onMessageRead: y,
1157
- onMessageEdited: $,
1158
- onMessageDeleted: O,
1159
- onReactionToggled: G,
1160
- onRequestAccepted: k,
1161
- onParticipantRemoved: b
1162
- }), n.value = !0, i.value = c, t.registerDetailSubscription(c), R();
1170
+ p = We(c, {
1171
+ onMessageSent: E,
1172
+ onMessageRead: b,
1173
+ onMessageEdited: z,
1174
+ onMessageDeleted: G,
1175
+ onReactionToggled: k,
1176
+ onRequestAccepted: V,
1177
+ onParticipantRemoved: C
1178
+ }), n.value = !0, i.value = c, t.registerDetailSubscription(c), A();
1163
1179
  } catch (g) {
1164
1180
  r.value = g instanceof Error ? g.message : "Failed to subscribe to conversation", console.error("ConversationChannel: Subscribe error", g);
1165
1181
  }
1166
1182
  }
1167
- }, z = () => {
1168
- n.value || T();
1183
+ }, U = () => {
1184
+ n.value || x();
1169
1185
  };
1170
- typeof window < "u" && window.addEventListener(W, z);
1171
- const h = Z((c) => {
1186
+ typeof window < "u" && window.addEventListener(le(), U);
1187
+ const h = xe((c) => {
1172
1188
  if (c === "connected") {
1173
- n.value || T();
1189
+ n.value || x();
1174
1190
  return;
1175
1191
  }
1176
- (c === "disconnected" || c === "error") && (R(), p && (p(), p = null), i.value && (t.unregisterDetailSubscription(i.value), i.value = null), n.value = !1);
1192
+ (c === "disconnected" || c === "error") && (A(), p && (p(), p = null), i.value && (t.unregisterDetailSubscription(i.value), i.value = null), n.value = !1);
1177
1193
  }), v = () => {
1178
1194
  const c = i.value;
1179
- if (R(), !(!n.value || !c))
1195
+ if (A(), !(!n.value || !c))
1180
1196
  try {
1181
- p && (p(), p = null), t.hasGlobalConversationSubscription(c) || ue(c), n.value = !1, t.unregisterDetailSubscription(c), i.value = null, r.value = null;
1197
+ p && (p(), p = null), t.hasGlobalConversationSubscription(c) || Ze(c), n.value = !1, t.unregisterDetailSubscription(c), i.value = null, r.value = null;
1182
1198
  } catch (g) {
1183
1199
  r.value = g instanceof Error ? g.message : "Failed to unsubscribe from conversation", console.error("ConversationChannel: Unsubscribe error", g);
1184
1200
  }
1185
- }, A = (c) => {
1201
+ }, E = (c) => {
1186
1202
  if (t.addMessage(c.message), c.message.author_id !== F.value) {
1187
1203
  const g = t.getConversationById(c.conversation_id);
1188
1204
  g && (g.unread_count = 0), t.markAsRead(c.conversation_id).catch(() => {
1189
1205
  });
1190
1206
  }
1191
- }, y = (c) => {
1207
+ }, b = (c) => {
1192
1208
  const g = t.getConversationById(c.conversation_id);
1193
1209
  if (g) {
1194
- let M = !1;
1195
- const w = g.participants.map((C) => C.user_id !== c.user_id || C.last_read_message_id === c.message_id ? C : (M = !0, {
1196
- ...C,
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,
1197
1213
  last_read_message_id: c.message_id
1198
1214
  }));
1199
- M && (g.participants = w);
1215
+ w && (g.participants = R);
1200
1216
  }
1201
- }, $ = (c) => {
1202
- const g = t.getMessagesByConversationId(c.conversation_id), M = g.findIndex((w) => w.id === c.message.id);
1203
- if (M >= 0) {
1204
- const w = g[M];
1205
- if (!w) return;
1206
- const C = { ...w };
1207
- c.message.body !== void 0 && (C.body = c.message.body), c.message.edited_at !== void 0 && (C.edited_at = c.message.edited_at), c.message.meta !== void 0 && (C.meta = c.message.meta), g[M] = C;
1208
- const x = t.getConversationById(c.conversation_id);
1209
- x && x.last_message?.id === c.message.id && (x.last_message = C);
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);
1210
1226
  }
1211
- }, O = (c) => {
1212
- t.removeMessage(c.conversation_id, c.message_id);
1213
1227
  }, G = (c) => {
1228
+ t.removeMessage(c.conversation_id, c.message_id);
1229
+ }, k = (c) => {
1214
1230
  t.updateMessageReactions(
1215
1231
  c.conversation_id,
1216
1232
  c.message_id,
1217
1233
  c.reactions
1218
1234
  );
1219
- }, k = (c) => {
1235
+ }, V = (c) => {
1220
1236
  const g = t.getConversationById(c.conversation_id);
1221
1237
  g && (g.is_request = !1), t.requests = t.requests.filter(
1222
- (M) => M.id !== c.conversation_id
1238
+ (w) => w.id !== c.conversation_id
1223
1239
  );
1224
- }, b = (c) => {
1240
+ }, C = (c) => {
1225
1241
  c.removed_user_id === F.value && (v(), t.deleteConversation(c.conversation_id).catch(() => {
1226
1242
  }));
1227
1243
  };
1228
- return o !== null && Ee(() => {
1229
- R(), h(), v(), typeof window < "u" && window.removeEventListener(W, z);
1244
+ return o !== null && we(() => {
1245
+ A(), h(), v(), typeof window < "u" && window.removeEventListener(le(), U);
1230
1246
  }), {
1231
- isSubscribed: K(() => n.value),
1232
- error: K(() => r.value),
1233
- subscribe: T,
1247
+ isSubscribed: J(() => n.value),
1248
+ error: J(() => r.value),
1249
+ subscribe: x,
1234
1250
  unsubscribe: v
1235
1251
  };
1236
1252
  }
1237
- const Ge = () => {
1253
+ const De = () => {
1238
1254
  };
1239
- let he = Ge;
1240
- function At(e) {
1241
- he = e;
1255
+ let ce = De;
1256
+ function Ft(e) {
1257
+ ce = e;
1242
1258
  }
1243
- function Ft() {
1244
- he = Ge;
1259
+ function Tt() {
1260
+ ce = De;
1245
1261
  }
1246
- const Et = {
1262
+ const xt = {
1247
1263
  debug: () => {
1248
1264
  },
1249
1265
  info: () => {
@@ -1252,24 +1268,24 @@ const Et = {
1252
1268
  },
1253
1269
  error: () => {
1254
1270
  }
1255
- }, ke = () => Et;
1256
- let ge = ke;
1257
- function Tt(e) {
1258
- ge = e;
1271
+ }, $e = () => xt;
1272
+ let ue = $e;
1273
+ function qt(e) {
1274
+ ue = e;
1259
1275
  }
1260
- function xt() {
1261
- ge = ke;
1276
+ function Pt() {
1277
+ ue = $e;
1262
1278
  }
1263
- const ne = ge("GlobalMessaging"), qt = 3, Pt = (e) => e.replace(/\/+$/, ""), Lt = (e) => Pt(window.location.pathname) === `/messages/${e}`, Ut = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
1264
- function kt() {
1265
- const e = Oe(), t = L(), s = We(), n = Fe(), { conversations: r } = He(e), i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
1279
+ const se = ue("GlobalMessaging"), Lt = 3, Nt = (e) => e.replace(/\/+$/, ""), Ut = (e) => Nt(window.location.pathname) === `/messages/${e}`, zt = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
1280
+ function Bt() {
1281
+ const e = Ie(), t = L(), s = He(), n = Me(), { conversations: r } = ke(e), i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
1266
1282
  let a = !1;
1267
1283
  function u(h) {
1268
1284
  const v = o.get(h);
1269
1285
  if (v && (o.delete(h), typeof v.channel.stopListening == "function"))
1270
- for (const A of v.bindings)
1286
+ for (const E of v.bindings)
1271
1287
  try {
1272
- v.channel.stopListening(A.event, A.handler);
1288
+ v.channel.stopListening(E.event, E.handler);
1273
1289
  } catch {
1274
1290
  }
1275
1291
  }
@@ -1278,68 +1294,68 @@ function kt() {
1278
1294
  u(h), e.unregisterGlobalConversationSubscription(h);
1279
1295
  i.clear();
1280
1296
  }
1281
- function _(h) {
1282
- const v = P();
1297
+ function y(h) {
1298
+ const v = O();
1283
1299
  if (!v || i.has(h)) return;
1284
- const A = (b) => {
1285
- const c = e.getConversationById(b.conversation_id);
1300
+ const E = (C) => {
1301
+ const c = e.getConversationById(C.conversation_id);
1286
1302
  if (!c)
1287
1303
  return;
1288
1304
  let g = !1;
1289
- const M = c.participants.map((w) => w.user_id !== b.user_id || w.last_read_message_id === b.message_id ? w : (g = !0, {
1290
- ...w,
1291
- last_read_message_id: b.message_id
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
1292
1308
  }));
1293
- g && (c.participants = M);
1294
- }, y = `conversation.${h}`;
1309
+ g && (c.participants = w);
1310
+ }, b = `conversation.${h}`;
1295
1311
  u(h);
1296
- const $ = v.private(y), O = (b) => {
1297
- if (!Ze(b)) {
1298
- ne.warn("Dropping malformed ConversationMessageSent event", b);
1312
+ const z = v.private(b), G = (C) => {
1313
+ if (!Je(C)) {
1314
+ se.warn("Dropping malformed ConversationMessageSent event", C);
1299
1315
  return;
1300
1316
  }
1301
- const c = b, g = t.currentUser?.id;
1317
+ const c = C, g = t.currentUser?.id;
1302
1318
  if (!g || c.message.author_id === g) return;
1303
1319
  e.addMessage(c.message);
1304
- const M = e.hasDetailSubscription(c.conversation_id), w = Lt(c.conversation_id);
1305
- if (M || w) {
1306
- const x = e.getConversationById(c.conversation_id);
1307
- x && (x.unread_count = 0), e.markAsRead(c.conversation_id).catch(() => {
1320
+ const w = e.hasDetailSubscription(c.conversation_id), R = Ut(c.conversation_id);
1321
+ if (w || R) {
1322
+ const q = e.getConversationById(c.conversation_id);
1323
+ q && (q.unread_count = 0), e.markAsRead(c.conversation_id).catch(() => {
1308
1324
  });
1309
1325
  return;
1310
1326
  }
1311
- const C = e.getConversationById(c.conversation_id);
1312
- if (C) {
1313
- const x = Ut(C);
1314
- x || C.unread_count++, he(x);
1327
+ const S = e.getConversationById(c.conversation_id);
1328
+ if (S) {
1329
+ const q = zt(S);
1330
+ q || S.unread_count++, ce(q);
1315
1331
  }
1316
- }, G = (b) => {
1317
- if (!Je(b)) {
1318
- ne.warn("Dropping malformed ConversationMessageRead event", b);
1332
+ }, k = (C) => {
1333
+ if (!Ke(C)) {
1334
+ se.warn("Dropping malformed ConversationMessageRead event", C);
1319
1335
  return;
1320
1336
  }
1321
- A(b);
1322
- }, k = (b) => {
1323
- if (!Ke(b)) {
1324
- ne.warn("Dropping malformed ConversationRequestAccepted event", b);
1337
+ E(C);
1338
+ }, V = (C) => {
1339
+ if (!et(C)) {
1340
+ se.warn("Dropping malformed ConversationRequestAccepted event", C);
1325
1341
  return;
1326
1342
  }
1327
- const c = b, g = e.getConversationById(c.conversation_id);
1343
+ const c = C, g = e.getConversationById(c.conversation_id);
1328
1344
  g && (g.is_request = !1), e.requests = e.requests.filter(
1329
- (M) => M.id !== c.conversation_id
1345
+ (w) => w.id !== c.conversation_id
1330
1346
  );
1331
1347
  };
1332
- $.listen(".ConversationMessageSent", O), $.listen(".ConversationMessageRead", G), $.listen(".ConversationRequestAccepted", k), o.set(h, {
1333
- channel: $,
1348
+ z.listen(".ConversationMessageSent", G), z.listen(".ConversationMessageRead", k), z.listen(".ConversationRequestAccepted", V), o.set(h, {
1349
+ channel: z,
1334
1350
  bindings: [
1335
- { event: ".ConversationMessageSent", handler: O },
1336
- { event: ".ConversationMessageRead", handler: G },
1337
- { event: ".ConversationRequestAccepted", handler: k }
1351
+ { event: ".ConversationMessageSent", handler: G },
1352
+ { event: ".ConversationMessageRead", handler: k },
1353
+ { event: ".ConversationRequestAccepted", handler: V }
1338
1354
  ]
1339
1355
  }), i.add(h), e.registerGlobalConversationSubscription(h);
1340
1356
  }
1341
1357
  function d() {
1342
- const h = P();
1358
+ const h = O();
1343
1359
  if (!h) {
1344
1360
  f();
1345
1361
  return;
@@ -1355,86 +1371,86 @@ function kt() {
1355
1371
  i.clear();
1356
1372
  }
1357
1373
  function p() {
1358
- const h = P();
1374
+ const h = O();
1359
1375
  if (!h) return;
1360
- const v = e.conversations.slice(0, qt), A = new Set(v.map((y) => y.id));
1361
- for (const y of i)
1362
- if (!A.has(y) && !e.hasDetailSubscription(y)) {
1376
+ const v = e.conversations.slice(0, Lt), E = new Set(v.map((b) => b.id));
1377
+ for (const b of i)
1378
+ if (!E.has(b) && !e.hasDetailSubscription(b)) {
1363
1379
  try {
1364
- u(y), h.leave(`conversation.${y}`);
1380
+ u(b), h.leave(`conversation.${b}`);
1365
1381
  } catch {
1366
1382
  }
1367
- i.delete(y), e.unregisterGlobalConversationSubscription(y);
1383
+ i.delete(b), e.unregisterGlobalConversationSubscription(b);
1368
1384
  }
1369
- for (const y of v)
1370
- _(y.id);
1385
+ for (const b of v)
1386
+ y(b.id);
1371
1387
  }
1372
1388
  function F(h) {
1373
1389
  e.updatePresenceForUser(h.user_id, h.status);
1374
1390
  }
1375
- function U() {
1376
- !P() || a || (oe(F), a = !0);
1391
+ function N() {
1392
+ !O() || a || (je(F), a = !0);
1377
1393
  }
1378
- function R() {
1379
- a && (ae(), a = !1);
1394
+ function A() {
1395
+ a && (Ye(), a = !1);
1380
1396
  }
1381
- const E = me(
1397
+ const T = de(
1382
1398
  r,
1383
1399
  () => {
1384
1400
  p();
1385
1401
  },
1386
1402
  { deep: !1, immediate: !0 }
1387
- ), T = me(
1403
+ ), x = de(
1388
1404
  () => s.fullPath,
1389
1405
  () => {
1390
1406
  p();
1391
1407
  }
1392
- ), z = Z((h) => {
1393
- h === "connected" ? (f(), p(), R(), U()) : (h === "disconnected" || h === "error") && (f(), R());
1408
+ ), U = xe((h) => {
1409
+ h === "connected" ? (f(), p(), A(), N()) : (h === "disconnected" || h === "error") && (f(), A());
1394
1410
  });
1395
- p(), U(), n !== null && Ee(() => {
1396
- E(), T(), z(), d(), R();
1411
+ p(), N(), n !== null && we(() => {
1412
+ T(), x(), U(), d(), A();
1397
1413
  });
1398
1414
  }
1399
- function Bt(e) {
1400
- e.apiClient && et(e.apiClient), e.authStore && st(e.authStore), e.mediaApi && rt(e.mediaApi), e.createLogger && Tt(e.createLogger), e.playMessageNotification && At(e.playMessageNotification), e.echo && Xe(e.echo);
1415
+ function Ht(e) {
1416
+ e.apiClient && tt(e.apiClient), e.authStore && nt(e.authStore), e.mediaApi && ot(e.mediaApi), e.createLogger && qt(e.createLogger), e.playMessageNotification && Ft(e.playMessageNotification), e.echo && Xe(e.echo);
1401
1417
  }
1402
- function Vt() {
1403
- tt(), nt(), it(), xt(), Ft(), Qe();
1418
+ function jt() {
1419
+ st(), rt(), at(), Pt(), Tt(), Qe();
1404
1420
  }
1405
1421
  export {
1406
- W as ECHO_INITIALIZED_EVENT,
1407
1422
  l as api,
1408
- Bt as configureMessengerClient,
1409
- ge as createLogger,
1410
- P as getEcho,
1423
+ Ht as configureMessengerClient,
1424
+ ue as createLogger,
1425
+ O as getEcho,
1426
+ le as getEchoInitializedEvent,
1411
1427
  m as getErrorMessage,
1412
- Ot as hasResponse,
1413
- jt as isAxiosError,
1414
- It as isError,
1415
- Je as isValidMessageReadEvent,
1416
- Ze as isValidMessageSentEvent,
1417
- Ke as isValidRequestAcceptedEvent,
1418
- de as mediaApi,
1419
- q as messagingApi,
1420
- Z as onConnectionStatusChange,
1428
+ it as getMediaApi,
1429
+ kt as hasResponse,
1430
+ Zt as isAxiosError,
1431
+ Gt as isError,
1432
+ Ke as isValidMessageReadEvent,
1433
+ Je as isValidMessageSentEvent,
1434
+ et as isValidRequestAcceptedEvent,
1435
+ P as messagingApi,
1436
+ xe as onConnectionStatusChange,
1421
1437
  Qe as resetEchoRuntimeConfig,
1422
- xt as resetLoggerFactory,
1423
- tt as resetMessagingApiClient,
1424
- nt as resetMessagingAuthStoreResolver,
1425
- it as resetMessagingMediaApi,
1426
- Vt as resetMessengerClientConfig,
1438
+ Pt as resetLoggerFactory,
1439
+ st as resetMessagingApiClient,
1440
+ rt as resetMessagingAuthStoreResolver,
1441
+ at as resetMessagingMediaApi,
1442
+ jt as resetMessengerClientConfig,
1427
1443
  Xe as setEchoRuntimeConfig,
1428
- Tt as setLoggerFactory,
1429
- et as setMessagingApiClient,
1430
- st as setMessagingAuthStoreResolver,
1431
- rt as setMessagingMediaApi,
1432
- ce as subscribeToConversation,
1433
- oe as subscribeToPresenceStatus,
1434
- ue as unsubscribeFromConversation,
1435
- ae as unsubscribeFromPresenceStatus,
1444
+ qt as setLoggerFactory,
1445
+ tt as setMessagingApiClient,
1446
+ nt as setMessagingAuthStoreResolver,
1447
+ ot as setMessagingMediaApi,
1448
+ We as subscribeToConversation,
1449
+ je as subscribeToPresenceStatus,
1450
+ Ze as unsubscribeFromConversation,
1451
+ Ye as unsubscribeFromPresenceStatus,
1436
1452
  L as useAuthStore,
1437
- Gt as useConversationChannel,
1438
- kt as useGlobalMessaging,
1439
- Oe as useMessagingStore
1453
+ Vt as useConversationChannel,
1454
+ Bt as useGlobalMessaging,
1455
+ Ie as useMessagingStore
1440
1456
  };