@codingfactory/messenger-client 0.1.3 → 0.1.5

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