@codingfactory/messenger-client 0.1.1 → 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,7 +1,7 @@
1
1
  import { ref as Q, getCurrentInstance as Me, computed as J, onUnmounted as we, toValue as Oe, watch as de } from "vue";
2
2
  import { defineStore as Ge, storeToRefs as ke } from "pinia";
3
3
  import Ve, { isAxiosError as Be } from "axios";
4
- import { isAxiosError as Wt } from "axios";
4
+ import { isAxiosError as Zt } from "axios";
5
5
  import { useRoute as He } from "vue-router";
6
6
  const Re = () => () => {
7
7
  }, Ae = () => {
@@ -17,7 +17,7 @@ const Re = () => () => {
17
17
  unsubscribeFromPresenceStatus: Ee,
18
18
  subscribeToConversation: Te,
19
19
  unsubscribeFromConversation: Fe
20
- }, le = () => _.ECHO_INITIALIZED_EVENT, O = () => _.getEcho(), xe = (e) => _.onConnectionStatusChange(e), Ye = (e) => _.subscribeToPresenceStatus(e), je = () => _.unsubscribeFromPresenceStatus(), We = (e, t) => _.subscribeToConversation(e, t), Ze = (e) => _.unsubscribeFromConversation(e);
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
21
  function Xe(e) {
22
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
23
  }
@@ -61,10 +61,10 @@ function m(e) {
61
61
  }
62
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";
63
63
  }
64
- function Ot(e) {
64
+ function Gt(e) {
65
65
  return e instanceof Error;
66
66
  }
67
- function Gt(e) {
67
+ function kt(e) {
68
68
  return typeof e == "object" && e !== null && "response" in e && typeof e.response == "object";
69
69
  }
70
70
  const Le = {
@@ -73,19 +73,22 @@ const Le = {
73
73
  }
74
74
  };
75
75
  let ie = Le;
76
- function it(e) {
76
+ function it() {
77
+ return ie;
78
+ }
79
+ function ot(e) {
77
80
  ie = e;
78
81
  }
79
- function ot() {
82
+ function at() {
80
83
  ie = Le;
81
84
  }
82
- function at(e) {
85
+ function ct(e) {
83
86
  return e !== null && typeof e == "object" && "id" in e && "type" in e && "participants" in e;
84
87
  }
85
88
  function Ne(e) {
86
89
  return typeof e == "object" && e !== null;
87
90
  }
88
- function D(e) {
91
+ function I(e) {
89
92
  return !Ne(e) || !("data" in e) ? e : e.data;
90
93
  }
91
94
  function B(e, t) {
@@ -128,28 +131,28 @@ function ne(e) {
128
131
  updated_at: B(e, "updated_at")
129
132
  };
130
133
  }
131
- function ct(e) {
134
+ function ut(e) {
132
135
  if (!Array.isArray(e))
133
136
  throw new Error("Invalid messaging folder payload: expected array");
134
137
  return e.map((t) => ne(t));
135
138
  }
136
139
  function he(e) {
137
- if (!at(e))
140
+ if (!ct(e))
138
141
  throw new Error("Invalid conversation payload from folder assignment endpoint");
139
142
  return e;
140
143
  }
141
144
  const P = {
142
145
  async fetchFolders() {
143
146
  const e = await l.get("/v1/messaging/folders");
144
- return ct(D(e.data));
147
+ return ut(I(e.data));
145
148
  },
146
149
  async createFolder(e) {
147
150
  const t = await l.post("/v1/messaging/folders", e);
148
- return ne(D(t.data));
151
+ return ne(I(t.data));
149
152
  },
150
153
  async updateFolder(e, t) {
151
154
  const s = await l.patch(`/v1/messaging/folders/${e}`, t);
152
- return ne(D(s.data));
155
+ return ne(I(s.data));
153
156
  },
154
157
  async deleteFolder(e) {
155
158
  await l.delete(`/v1/messaging/folders/${e}`);
@@ -161,16 +164,16 @@ const P = {
161
164
  const s = await l.patch(`/v1/messaging/conversations/${e}/folder`, {
162
165
  folder_id: t
163
166
  });
164
- return he(D(s.data));
167
+ return he(I(s.data));
165
168
  },
166
169
  async acceptRequest(e) {
167
170
  const t = await l.post(`/v1/messaging/conversations/${e}/accept`);
168
- return he(D(t.data));
171
+ return he(I(t.data));
169
172
  },
170
173
  async declineRequest(e) {
171
174
  await l.post(`/v1/messaging/conversations/${e}/decline`);
172
175
  }
173
- }, ge = 1e3, oe = 4e3, ut = 12e4, dt = 300, lt = 1, ft = 1600, ae = (e) => {
176
+ }, ge = 1e3, oe = 4e3, dt = 12e4, lt = 300, ft = 1, ht = 1600, ae = (e) => {
174
177
  if (typeof e == "number" && Number.isFinite(e))
175
178
  return e;
176
179
  if (typeof e == "string") {
@@ -190,17 +193,17 @@ const P = {
190
193
  return Math.max(ge, t * 1e3);
191
194
  }
192
195
  return oe;
193
- }, ht = (e) => {
194
- const t = Math.max(0, e), s = 2 ** Math.min(t, 6), n = oe * s;
195
- return Math.min(ut, n);
196
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) => {
197
200
  const t = e;
198
- return ae(t.response?.status) === 429 ? ze(t.response?.headers?.["retry-after"]) : dt;
201
+ return ae(t.response?.status) === 429 ? ze(t.response?.headers?.["retry-after"]) : lt;
199
202
  }, pe = async (e) => {
200
203
  await new Promise((t) => {
201
204
  setTimeout(t, e);
202
205
  });
203
- }, mt = (e) => {
206
+ }, pt = (e) => {
204
207
  if (!M(e))
205
208
  return !1;
206
209
  const s = (M(e.data) ? e.data : e).throttled;
@@ -214,7 +217,7 @@ const P = {
214
217
  }
215
218
  return !1;
216
219
  };
217
- function pt(e, t, s) {
220
+ function vt(e, t, s) {
218
221
  const n = typeof e == "string" && e.trim().length > 0 ? e.trim().toLowerCase() : void 0;
219
222
  if (n)
220
223
  return n;
@@ -224,17 +227,17 @@ function pt(e, t, s) {
224
227
  const i = typeof s == "string" && s.trim().length > 0 ? s.trim().toLowerCase() : void 0;
225
228
  return i ? i === "image" ? "image/*" : i === "video" ? "video/*" : i === "audio" ? "audio/*" : i : "application/octet-stream";
226
229
  }
227
- function vt(e) {
230
+ function _t(e) {
228
231
  const t = e.url || "", s = e.thumbnail_url ?? e.thumbnail, n = {
229
232
  id: e.media_id ?? e.id ?? "",
230
- name: e.name ?? _t(t),
233
+ name: e.name ?? yt(t),
231
234
  url: t,
232
- type: pt(e.mime, e.mime_type, e.type),
235
+ type: vt(e.mime, e.mime_type, e.type),
233
236
  size: e.size ?? 0
234
237
  };
235
238
  return s !== void 0 && (n.thumbnail = s), n;
236
239
  }
237
- function _t(e) {
240
+ function yt(e) {
238
241
  if (!e) return "attachment";
239
242
  try {
240
243
  const s = new URL(e).pathname.split("/");
@@ -243,8 +246,8 @@ function _t(e) {
243
246
  return "attachment";
244
247
  }
245
248
  }
246
- function yt(e) {
247
- return !Array.isArray(e) || e.length === 0 ? [] : e.map(vt);
249
+ function bt(e) {
250
+ return !Array.isArray(e) || e.length === 0 ? [] : e.map(_t);
248
251
  }
249
252
  function X(e) {
250
253
  if (typeof e != "string")
@@ -253,7 +256,7 @@ function X(e) {
253
256
  if (t.length !== 0)
254
257
  return t;
255
258
  }
256
- function bt(e) {
259
+ function Ct(e) {
257
260
  if (!e)
258
261
  return;
259
262
  const t = X(e.avatar) ?? X(e.avatar_url), s = typeof e.handle == "string" && e.handle.length > 0 ? e.handle : void 0;
@@ -264,7 +267,7 @@ function bt(e) {
264
267
  ...s ? { handle: s } : {}
265
268
  };
266
269
  }
267
- function j(e) {
270
+ function Y(e) {
268
271
  const t = e.shared_post, s = e.author, n = t && typeof t == "object" ? {
269
272
  id: t.id ?? "",
270
273
  title: t.title ?? "",
@@ -280,12 +283,12 @@ function j(e) {
280
283
  } : null;
281
284
  return {
282
285
  ...e,
283
- ...s ? { author: bt(s) } : {},
286
+ ...s ? { author: Ct(s) } : {},
284
287
  shared_post: n,
285
- attachments: yt(e.attachments)
288
+ attachments: bt(e.attachments)
286
289
  };
287
290
  }
288
- function Ct(e) {
291
+ function St(e) {
289
292
  return typeof e != "string" || e.length === 0 ? null : e;
290
293
  }
291
294
  function ve(e) {
@@ -295,39 +298,45 @@ function ve(e) {
295
298
  function re(e) {
296
299
  return typeof e == "string" && e.length > 0 && !e.startsWith("temp-");
297
300
  }
298
- function St(e, t = []) {
301
+ function Mt(e, t = []) {
299
302
  const s = /* @__PURE__ */ new Map();
300
303
  for (const n of t) {
301
304
  const r = ve(n.last_read_message_id);
302
305
  r && s.set(n.user_id, r);
303
306
  }
304
307
  return e.map((n) => {
305
- const r = X(n.user?.avatar) ?? X(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 ? {
306
309
  id: n.user.id,
307
310
  name: n.user.name,
308
- ...r ? { avatar: r } : {},
311
+ ...i ? { avatar: i } : {},
309
312
  ...n.user.handle ? { handle: n.user.handle } : {}
310
- } : void 0, o = ve(n.last_read_message_id);
311
- if (o)
313
+ } : void 0, a = ve(n.last_read_message_id);
314
+ if (a)
312
315
  return {
313
316
  ...n,
314
- ...i ? { user: i } : {},
315
- last_read_message_id: o
317
+ ...o ? { user: o } : {},
318
+ last_read_message_id: a
316
319
  };
317
- const a = s.get(n.user_id);
318
- 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 ? {
319
328
  ...n,
320
- ...i ? { user: i } : {},
321
- last_read_message_id: a
329
+ ...o ? { user: o } : {},
330
+ last_read_message_id: u
322
331
  } : {
323
332
  ...n,
324
- ...i ? { user: i } : {},
333
+ ...o ? { user: o } : {},
325
334
  last_read_message_id: ""
326
335
  };
327
336
  });
328
337
  }
329
- function I(e, t) {
330
- const s = Ct(e.muted_until), n = e.is_muted ?? s !== null, r = e.last_message ? j(e.last_message) : t?.last_message, i = e.last_message_at ?? t?.last_message_at, o = (() => {
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 = (() => {
331
340
  if (!t || t.unread_count !== 0 || e.unread_count <= 0)
332
341
  return !1;
333
342
  const a = t.last_message?.id, u = e.last_message?.id;
@@ -336,18 +345,18 @@ function I(e, t) {
336
345
  return {
337
346
  ...e,
338
347
  unread_count: n || o ? 0 : e.unread_count,
339
- participants: St(e.participants, t?.participants),
348
+ participants: Mt(e.participants, t?.participants),
340
349
  is_muted: n,
341
350
  muted_until: s,
342
351
  ...r ? { last_message: r } : {},
343
352
  ...i ? { last_message_at: i } : {}
344
353
  };
345
354
  }
346
- function Mt(e) {
355
+ function wt(e) {
347
356
  return e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
348
357
  }
349
358
  function ee(e) {
350
- return Mt(e) ? 0 : e.unread_count || 0;
359
+ return wt(e) ? 0 : e.unread_count || 0;
351
360
  }
352
361
  function _e(e, t) {
353
362
  const s = t[e.id];
@@ -362,7 +371,7 @@ function _e(e, t) {
362
371
  function M(e) {
363
372
  return typeof e == "object" && e !== null;
364
373
  }
365
- function wt(e) {
374
+ function Rt(e) {
366
375
  return M(e) ? (M(e.response) ? e.response : null)?.status === 401 : !1;
367
376
  }
368
377
  function ye(e) {
@@ -386,7 +395,7 @@ function ye(e) {
386
395
  }
387
396
  return t;
388
397
  }
389
- function Rt(e, t) {
398
+ function At(e, t) {
390
399
  const s = M(t) ? t : null, n = s?.next ?? s?.next_cursor ?? e.next_cursor;
391
400
  if (!(typeof n != "string" || n.length === 0))
392
401
  return n;
@@ -396,7 +405,7 @@ function H(e, t) {
396
405
  let r = [];
397
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)), {
398
407
  items: r,
399
- nextCursor: Rt(s, n)
408
+ nextCursor: At(s, n)
400
409
  };
401
410
  }
402
411
  function be(e) {
@@ -411,18 +420,18 @@ function W(e, t) {
411
420
  const s = e.last_message_at ?? e.created_at, r = (t.last_message_at ?? t.created_at).localeCompare(s);
412
421
  return r !== 0 ? r : e.id.localeCompare(t.id);
413
422
  }
414
- function Y(e, t) {
423
+ function j(e, t) {
415
424
  return [t, ...e.filter((s) => s.id !== t.id)];
416
425
  }
417
426
  function $(e) {
418
427
  return [...e].sort((t, s) => t.sort_order !== s.sort_order ? t.sort_order - s.sort_order : t.name.localeCompare(s.name));
419
428
  }
420
- function At(e, t) {
429
+ function Et(e, t) {
421
430
  return typeof e != "string" || e.length === 0 ? null : t.has(e) ? e : null;
422
431
  }
423
432
  function Se(e, t) {
424
433
  return e.map((s) => {
425
- const n = At(s.folder_id, t);
434
+ const n = Et(s.folder_id, t);
426
435
  return (s.folder_id ?? null) === n ? s : {
427
436
  ...s,
428
437
  folder_id: n
@@ -437,7 +446,7 @@ function te(e) {
437
446
  s.is_request === !0 && t.set(s.id, s);
438
447
  return Array.from(t.values()).sort(W);
439
448
  }
440
- const De = Ge("messaging", {
449
+ const Ie = Ge("messaging", {
441
450
  state: () => ({
442
451
  conversations: [],
443
452
  requests: [],
@@ -568,7 +577,7 @@ const De = Ge("messaging", {
568
577
  const p = this.conversations.find(
569
578
  (F) => F.id === d.id
570
579
  );
571
- return I(d, p);
580
+ return D(d, p);
572
581
  });
573
582
  e ? this.conversations.push(...f) : this.conversations = f, this.normalizeFolderAssignmentsState(), this.lastFetch = Date.now();
574
583
  const y = {
@@ -592,7 +601,7 @@ const De = Ge("messaging", {
592
601
  }), this.backgroundPollRetryAfterUntil = 0, this.backgroundPollTransientFailureCount = 0, !0;
593
602
  } catch (e) {
594
603
  const t = e, s = ae(t.response?.status);
595
- 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() + ht(this.backgroundPollTransientFailureCount), !1) : (this.backgroundPollRetryAfterUntil = Date.now() + oe, !1));
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));
596
605
  }
597
606
  },
598
607
  async fetchConversation(e) {
@@ -600,7 +609,7 @@ const De = Ge("messaging", {
600
609
  try {
601
610
  const t = await l.get(`/v1/messaging/conversations/${e}`, {
602
611
  params: { include_presence: 1 }
603
- }), s = this.conversations.find((o) => o.id === e), n = I(t.data.data || t.data, s), r = this.conversations.findIndex((o) => o.id === e);
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);
604
613
  r >= 0 ? this.conversations[r] = n : this.conversations.push(n);
605
614
  const i = this.requests.findIndex((o) => o.id === e);
606
615
  return i >= 0 && (this.requests[i] = n), this.normalizeFolderAssignmentsState(), n;
@@ -623,7 +632,7 @@ const De = Ge("messaging", {
623
632
  "conversations"
624
633
  ), i = n.map((a) => {
625
634
  const u = this.requests.find((f) => f.id === a.id);
626
- return I(a, u);
635
+ return D(a, u);
627
636
  });
628
637
  e ? this.requests.push(...i) : this.requests = i, this.normalizeFolderAssignmentsState();
629
638
  const o = {
@@ -647,14 +656,14 @@ const De = Ge("messaging", {
647
656
  r = await l.get(`/v1/messaging/conversations/${e}/messages`, { params: s });
648
657
  break;
649
658
  } catch (d) {
650
- if (!(n < lt && me(d)))
659
+ if (!(n < ft && me(d)))
651
660
  throw d;
652
- n += 1, await pe(gt(d));
661
+ n += 1, await pe(mt(d));
653
662
  }
654
663
  const { items: i, nextCursor: o } = H(
655
664
  r.data,
656
665
  "messages"
657
- ), a = i.map(j), u = [...a].reverse();
666
+ ), a = i.map(Y), u = [...a].reverse();
658
667
  if (t ? this.messages[e] = [...u, ...this.messages[e] || []] : this.messages[e] = u, (() => {
659
668
  const d = this.conversations.find((p) => p.id === e) ?? this.requests.find((p) => p.id === e);
660
669
  return d ? !d.last_message || !d.last_message_at : !1;
@@ -702,7 +711,7 @@ const De = Ge("messaging", {
702
711
  if (s && s.length > 0) {
703
712
  const v = await Promise.all(
704
713
  s.map(async (E) => {
705
- const b = await ie.uploadImage(E);
714
+ const b = await it().uploadImage(E);
706
715
  return {
707
716
  media_id: b.id,
708
717
  mime: b.mime_type,
@@ -719,7 +728,7 @@ const De = Ge("messaging", {
719
728
  ...p,
720
729
  type: "text"
721
730
  });
722
- const F = d.data.data || d.data, N = { ...y, ...F, attachments: F.attachments ?? y.attachments }, A = j(N), T = this.messages[e], x = T.findIndex((v) => v.id === a);
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);
723
732
  x >= 0 && (T[x] = A), this._pendingSendIds.delete(a);
724
733
  const U = A.id;
725
734
  let h = 0;
@@ -824,9 +833,9 @@ const De = Ge("messaging", {
824
833
  async sendTyping(e, t = "start") {
825
834
  try {
826
835
  const s = await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
827
- if (t !== "start" || !mt(s.data))
836
+ if (t !== "start" || !pt(s.data))
828
837
  return;
829
- await pe(ft), await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
838
+ await pe(ht), await l.post(`/v1/messaging/conversations/${e}/typing`, { state: t });
830
839
  } catch (s) {
831
840
  console.warn("Failed to send typing indicator:", s);
832
841
  }
@@ -894,8 +903,8 @@ const De = Ge("messaging", {
894
903
  const n = await l.post("/v1/messaging/conversations/dm", s), r = n.data.data || n.data;
895
904
  if (!be(r))
896
905
  throw new Error("Invalid conversation payload from DM create endpoint.");
897
- const i = Ce(r) ? I(r) : await this.fetchConversation(r.id);
898
- return i.is_request === !0 ? (this.requests = Y(this.requests, i), this.conversations = this.conversations.filter((o) => o.id !== i.id), i) : (this.conversations = Y(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);
899
908
  } catch (s) {
900
909
  throw this.error = m(s), s;
901
910
  }
@@ -909,7 +918,7 @@ const De = Ge("messaging", {
909
918
  if (!be(n))
910
919
  throw new Error("Invalid conversation payload from group create endpoint.");
911
920
  const r = Ce(n) ? n : await this.fetchConversation(n.id);
912
- return this.conversations = Y(this.conversations, r), r;
921
+ return this.conversations = j(this.conversations, r), r;
913
922
  } catch (s) {
914
923
  throw this.error = m(s), s;
915
924
  }
@@ -945,7 +954,7 @@ const De = Ge("messaging", {
945
954
  if (!t)
946
955
  return;
947
956
  this.messages[t] || (this.messages[t] = []);
948
- const s = j({ ...e, attachments: e.attachments ?? [] }), n = this.messages[t];
957
+ const s = Y({ ...e, attachments: e.attachments ?? [] }), n = this.messages[t];
949
958
  if (n.find((u) => u.id === s.id))
950
959
  return;
951
960
  const i = L();
@@ -1004,7 +1013,7 @@ const De = Ge("messaging", {
1004
1013
  try {
1005
1014
  a = await l.post(n, r);
1006
1015
  } catch (d) {
1007
- if (!wt(d))
1016
+ if (!Rt(d))
1008
1017
  throw d;
1009
1018
  a = await l.post(n, r);
1010
1019
  }
@@ -1056,13 +1065,13 @@ const De = Ge("messaging", {
1056
1065
  try {
1057
1066
  const t = await P.acceptRequest(e);
1058
1067
  this.requests = this.requests.filter((n) => n.id !== e);
1059
- const s = I({
1068
+ const s = D({
1060
1069
  ...t,
1061
1070
  is_pinned: t.is_pinned ?? !1,
1062
1071
  is_archived: t.is_archived ?? !1,
1063
1072
  is_muted: t.is_muted ?? !1
1064
1073
  });
1065
- this.conversations = Y(this.conversations, s);
1074
+ this.conversations = j(this.conversations, s);
1066
1075
  } catch (t) {
1067
1076
  throw this.error = m(t), t;
1068
1077
  }
@@ -1140,8 +1149,8 @@ const De = Ge("messaging", {
1140
1149
  }
1141
1150
  }
1142
1151
  });
1143
- function kt(e) {
1144
- const t = De(), s = L(), n = Q(!1), r = Q(null), i = Q(null), o = Me(), a = o !== null, u = 20, f = 250;
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;
1145
1154
  let y = 0, d = null, p = null;
1146
1155
  const F = J(() => s.currentUser?.id), N = () => Oe(e)?.trim() ?? "", A = () => {
1147
1156
  d && (clearTimeout(d), d = null), y = 0;
@@ -1241,16 +1250,16 @@ function kt(e) {
1241
1250
  unsubscribe: v
1242
1251
  };
1243
1252
  }
1244
- const Ie = () => {
1253
+ const De = () => {
1245
1254
  };
1246
- let ce = Ie;
1247
- function Et(e) {
1255
+ let ce = De;
1256
+ function Ft(e) {
1248
1257
  ce = e;
1249
1258
  }
1250
- function Ft() {
1251
- ce = Ie;
1259
+ function Tt() {
1260
+ ce = De;
1252
1261
  }
1253
- const Tt = {
1262
+ const xt = {
1254
1263
  debug: () => {
1255
1264
  },
1256
1265
  info: () => {
@@ -1259,17 +1268,17 @@ const Tt = {
1259
1268
  },
1260
1269
  error: () => {
1261
1270
  }
1262
- }, $e = () => Tt;
1271
+ }, $e = () => xt;
1263
1272
  let ue = $e;
1264
- function xt(e) {
1273
+ function qt(e) {
1265
1274
  ue = e;
1266
1275
  }
1267
- function qt() {
1276
+ function Pt() {
1268
1277
  ue = $e;
1269
1278
  }
1270
- const se = ue("GlobalMessaging"), Pt = 3, Lt = (e) => e.replace(/\/+$/, ""), Nt = (e) => Lt(window.location.pathname) === `/messages/${e}`, Ut = (e) => e.is_muted ? !0 : typeof e.muted_until == "string" && e.muted_until.length > 0;
1271
- function Vt() {
1272
- const e = De(), t = L(), s = He(), n = Me(), { conversations: r } = ke(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();
1273
1282
  let a = !1;
1274
1283
  function u(h) {
1275
1284
  const v = o.get(h);
@@ -1308,7 +1317,7 @@ function Vt() {
1308
1317
  const c = C, g = t.currentUser?.id;
1309
1318
  if (!g || c.message.author_id === g) return;
1310
1319
  e.addMessage(c.message);
1311
- const w = e.hasDetailSubscription(c.conversation_id), R = Nt(c.conversation_id);
1320
+ const w = e.hasDetailSubscription(c.conversation_id), R = Ut(c.conversation_id);
1312
1321
  if (w || R) {
1313
1322
  const q = e.getConversationById(c.conversation_id);
1314
1323
  q && (q.unread_count = 0), e.markAsRead(c.conversation_id).catch(() => {
@@ -1317,7 +1326,7 @@ function Vt() {
1317
1326
  }
1318
1327
  const S = e.getConversationById(c.conversation_id);
1319
1328
  if (S) {
1320
- const q = Ut(S);
1329
+ const q = zt(S);
1321
1330
  q || S.unread_count++, ce(q);
1322
1331
  }
1323
1332
  }, k = (C) => {
@@ -1364,7 +1373,7 @@ function Vt() {
1364
1373
  function p() {
1365
1374
  const h = O();
1366
1375
  if (!h) return;
1367
- const v = e.conversations.slice(0, Pt), E = new Set(v.map((b) => b.id));
1376
+ const v = e.conversations.slice(0, Lt), E = new Set(v.map((b) => b.id));
1368
1377
  for (const b of i)
1369
1378
  if (!E.has(b) && !e.hasDetailSubscription(b)) {
1370
1379
  try {
@@ -1380,10 +1389,10 @@ function Vt() {
1380
1389
  e.updatePresenceForUser(h.user_id, h.status);
1381
1390
  }
1382
1391
  function N() {
1383
- !O() || a || (Ye(F), a = !0);
1392
+ !O() || a || (je(F), a = !0);
1384
1393
  }
1385
1394
  function A() {
1386
- a && (je(), a = !1);
1395
+ a && (Ye(), a = !1);
1387
1396
  }
1388
1397
  const T = de(
1389
1398
  r,
@@ -1403,45 +1412,45 @@ function Vt() {
1403
1412
  T(), x(), U(), d(), A();
1404
1413
  });
1405
1414
  }
1406
- function Bt(e) {
1407
- e.apiClient && tt(e.apiClient), e.authStore && nt(e.authStore), e.mediaApi && it(e.mediaApi), e.createLogger && xt(e.createLogger), e.playMessageNotification && Et(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);
1408
1417
  }
1409
- function Ht() {
1410
- st(), rt(), ot(), qt(), Ft(), Qe();
1418
+ function jt() {
1419
+ st(), rt(), at(), Pt(), Tt(), Qe();
1411
1420
  }
1412
1421
  export {
1413
1422
  l as api,
1414
- Bt as configureMessengerClient,
1423
+ Ht as configureMessengerClient,
1415
1424
  ue as createLogger,
1416
1425
  O as getEcho,
1417
1426
  le as getEchoInitializedEvent,
1418
1427
  m as getErrorMessage,
1419
- Gt as hasResponse,
1420
- Wt as isAxiosError,
1421
- Ot as isError,
1428
+ it as getMediaApi,
1429
+ kt as hasResponse,
1430
+ Zt as isAxiosError,
1431
+ Gt as isError,
1422
1432
  Ke as isValidMessageReadEvent,
1423
1433
  Je as isValidMessageSentEvent,
1424
1434
  et as isValidRequestAcceptedEvent,
1425
- ie as mediaApi,
1426
1435
  P as messagingApi,
1427
1436
  xe as onConnectionStatusChange,
1428
1437
  Qe as resetEchoRuntimeConfig,
1429
- qt as resetLoggerFactory,
1438
+ Pt as resetLoggerFactory,
1430
1439
  st as resetMessagingApiClient,
1431
1440
  rt as resetMessagingAuthStoreResolver,
1432
- ot as resetMessagingMediaApi,
1433
- Ht as resetMessengerClientConfig,
1441
+ at as resetMessagingMediaApi,
1442
+ jt as resetMessengerClientConfig,
1434
1443
  Xe as setEchoRuntimeConfig,
1435
- xt as setLoggerFactory,
1444
+ qt as setLoggerFactory,
1436
1445
  tt as setMessagingApiClient,
1437
1446
  nt as setMessagingAuthStoreResolver,
1438
- it as setMessagingMediaApi,
1447
+ ot as setMessagingMediaApi,
1439
1448
  We as subscribeToConversation,
1440
- Ye as subscribeToPresenceStatus,
1449
+ je as subscribeToPresenceStatus,
1441
1450
  Ze as unsubscribeFromConversation,
1442
- je as unsubscribeFromPresenceStatus,
1451
+ Ye as unsubscribeFromPresenceStatus,
1443
1452
  L as useAuthStore,
1444
- kt as useConversationChannel,
1445
- Vt as useGlobalMessaging,
1446
- De as useMessagingStore
1453
+ Vt as useConversationChannel,
1454
+ Bt as useGlobalMessaging,
1455
+ Ie as useMessagingStore
1447
1456
  };
@@ -6,6 +6,6 @@ export interface UploadedMedia {
6
6
  export interface MessagingMediaApi {
7
7
  uploadImage(file: File): Promise<UploadedMedia>;
8
8
  }
9
- export declare let mediaApi: MessagingMediaApi;
9
+ export declare function getMediaApi(): MessagingMediaApi;
10
10
  export declare function setMessagingMediaApi(client: MessagingMediaApi): void;
11
11
  export declare function resetMessagingMediaApi(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfactory/messenger-client",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Shared messaging frontend state, API helpers, and realtime composables.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",