@bcc-code/vue-bcc-chat-ui 7.1.28 → 7.1.29

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.
@@ -4180,7 +4180,7 @@ function cc({ environment: e }) {
4180
4180
  }
4181
4181
  let P = n(() => v.value.find((e) => e.id === T.value) ?? null), F = `bcc-ui-connection-${crypto.randomUUID()}`, I = `bcc-ui-message-${crypto.randomUUID()}`, L = !1, R = !1, te = null, z = null, ne = null, B = null, re = 0, ie = 0, V = !1, ae = !1, H = null, oe = /* @__PURE__ */ new Map(), se = /* @__PURE__ */ new Set(), ce = null, W = null, le = 0;
4182
4182
  async function ue() {
4183
- await lc(e), !t.value && (he(), lt(), t.value = !0, await st(), _.value && (ut(_.value.uid), pe(), we(), !m.value && !ae && Se()));
4183
+ await lc(e), !t.value && (he(), dt(), t.value = !0, await lt(), _.value && (ut(_.value.uid), pe(), we(), !m.value && !ae && Se()));
4184
4184
  }
4185
4185
  async function de(e) {
4186
4186
  g.value = null, r.value = !0;
@@ -4189,9 +4189,9 @@ function cc({ environment: e }) {
4189
4189
  let t = Ke();
4190
4190
  await U.getLoggedinUser() && t !== e && await U.logout(), qe(e);
4191
4191
  let n = await uc(e);
4192
- _.value = hc(await U.login(n)), ut(_.value.uid), h.value = !0, m.value = typeof navigator < "u" ? !navigator.onLine : !1, pe(), we(), ae || await Se(), await Oe(), Gt();
4192
+ _.value = hc(await U.login(n)), ut(_.value.uid), h.value = !0, m.value = typeof navigator < "u" ? !navigator.onLine : !1, pe(), we(), ae || await Se(), await Oe(), Kt();
4193
4193
  } catch (e) {
4194
- throw bt(), g.value = Z(e, "Unable to sign in to chat."), e;
4194
+ throw xt(), g.value = Z(e, "Unable to sign in to chat."), e;
4195
4195
  } finally {
4196
4196
  r.value = !1;
4197
4197
  }
@@ -4201,7 +4201,7 @@ function cc({ environment: e }) {
4201
4201
  try {
4202
4202
  qe(null), Ze(), await U.getLoggedinUser() && await U.logout();
4203
4203
  } finally {
4204
- bt();
4204
+ xt();
4205
4205
  }
4206
4206
  }
4207
4207
  function pe() {
@@ -4262,7 +4262,7 @@ function cc({ environment: e }) {
4262
4262
  let t = U.connect;
4263
4263
  typeof t == "function" && (await t.call(U), p.value = !0), ie = 0, V && await Ce();
4264
4264
  } catch (e) {
4265
- p.value = !1, ie += 1, Ft(e) || (g.value = Z(e, "Unable to reconnect to chat.")), xe();
4265
+ p.value = !1, ie += 1, It(e) || (g.value = Z(e, "Unable to reconnect to chat.")), xe();
4266
4266
  } finally {
4267
4267
  z = null;
4268
4268
  }
@@ -4272,7 +4272,7 @@ function cc({ environment: e }) {
4272
4272
  return ne || m.value || !h.value || ae || (ne = (async () => {
4273
4273
  V = !1, g.value = null;
4274
4274
  try {
4275
- await Oe(), Gt();
4275
+ await Oe(), Kt();
4276
4276
  } finally {
4277
4277
  ne = null;
4278
4278
  }
@@ -4298,7 +4298,7 @@ function cc({ environment: e }) {
4298
4298
  }
4299
4299
  async function Oe() {
4300
4300
  if (await ue(), i.value = !0, g.value = null, m.value && H) {
4301
- v.value = bc(H.getConversations()), P.value && await tt(), i.value = !1;
4301
+ v.value = bc(H.getConversations()), P.value && await nt(), i.value = !1;
4302
4302
  return;
4303
4303
  }
4304
4304
  try {
@@ -4311,7 +4311,7 @@ function cc({ environment: e }) {
4311
4311
  let t = r.get(e.id);
4312
4312
  t && (e.subtitle === "No messages yet" && t.subtitle && t.subtitle !== "No messages yet" && (e.subtitle = t.subtitle), !e.lastMessageAt && t.lastMessageAt && (e.lastMessageAt = t.lastMessageAt), !e.lastMessage && t.lastMessage && (e.lastMessage = t.lastMessage));
4313
4313
  }
4314
- v.value = bc(await ft(t)), H?.setConversations(v.value), P.value && await tt();
4314
+ v.value = bc(await pt(t)), H?.setConversations(v.value), P.value && await nt();
4315
4315
  } catch (e) {
4316
4316
  let t = H?.getConversations() ?? [];
4317
4317
  if (t.length > 0) {
@@ -4324,7 +4324,7 @@ function cc({ environment: e }) {
4324
4324
  }
4325
4325
  }
4326
4326
  async function ke(e) {
4327
- T.value = e, E.value = null, b.value = [], W = null, C.value = !1, D.value = null, O.value = null, Te(e), await tt();
4327
+ T.value = e, E.value = null, b.value = [], W = null, C.value = !1, D.value = null, O.value = null, Te(e), await nt();
4328
4328
  }
4329
4329
  function Ae(e) {
4330
4330
  e && (O.value = null), D.value = e;
@@ -4333,7 +4333,7 @@ function cc({ environment: e }) {
4333
4333
  e && (D.value = null), O.value = e;
4334
4334
  }
4335
4335
  async function Me(e) {
4336
- E.value = e, W = null, C.value = !1, D.value = null, O.value = null, await rt(e.id);
4336
+ E.value = e, W = null, C.value = !1, D.value = null, O.value = null, await it(e.id);
4337
4337
  }
4338
4338
  function Ne() {
4339
4339
  E.value = null, b.value = [], W = null, C.value = !1, D.value = null, O.value = null;
@@ -4348,14 +4348,14 @@ function cc({ environment: e }) {
4348
4348
  await Fe(O.value, r);
4349
4349
  return;
4350
4350
  }
4351
- let i = E.value?.id, a = crypto.randomUUID(), o = Dc(Nt(D.value, t), a);
4351
+ let i = E.value?.id, a = crypto.randomUUID(), o = Dc(Pt(D.value, t), a);
4352
4352
  u.value = !0, g.value = null;
4353
4353
  try {
4354
4354
  if (m.value) {
4355
- It(n, r, o, i, a), D.value = null;
4355
+ Lt(n, r, o, i, a), D.value = null;
4356
4356
  return;
4357
4357
  }
4358
- Ht(Mt({
4358
+ Ut(Nt({
4359
4359
  conversation: n,
4360
4360
  kind: "text",
4361
4361
  text: r,
@@ -4367,13 +4367,13 @@ function cc({ environment: e }) {
4367
4367
  let e = new U.TextMessage(n.targetId, r, kc(n));
4368
4368
  e.setMuid?.(a), Object.keys(o).length > 0 && e.setMetadata?.(o), i && e.setParentMessageId?.(Number(i));
4369
4369
  let t = await U.sendMessage(e);
4370
- St(N(t, _.value?.uid)), mt(t), await q(t), D.value = null;
4370
+ Ct(N(t, _.value?.uid)), ht(t), await vt(t), D.value = null;
4371
4371
  } catch (e) {
4372
- if (Ft(e)) {
4373
- Ut("queued", a), It(n, r, o, E.value?.id, a), D.value = null;
4372
+ if (It(e)) {
4373
+ Wt("queued", a), Lt(n, r, o, E.value?.id, a), D.value = null;
4374
4374
  return;
4375
4375
  }
4376
- throw Ut("failed", a), g.value = Z(e, "Unable to send the message."), e;
4376
+ throw Wt("failed", a), g.value = Z(e, "Unable to send the message."), e;
4377
4377
  } finally {
4378
4378
  u.value = !1;
4379
4379
  }
@@ -4388,7 +4388,7 @@ function cc({ environment: e }) {
4388
4388
  let t;
4389
4389
  e.kind === "text" ? t = new U.TextMessage(n.targetId, r, kc(n)) : (t = new U.MediaMessage(n.targetId, e.source?.getAttachment?.()?.getFileUrl?.() ?? e.source?.getAttachment?.()?.getUrl?.() ?? e.attachments[0]?.url ?? "", e.source?.getType?.() ?? e.type ?? e.kind, kc(n)), t.setCaption(r)), t.setId(Number(e.id));
4390
4390
  let i = await U.editMessage(t);
4391
- St(N(i, _.value?.uid)), mt(i), O.value = null;
4391
+ Ct(N(i, _.value?.uid)), ht(i), O.value = null;
4392
4392
  } catch (e) {
4393
4393
  throw g.value = Z(e, "Unable to edit the message."), e;
4394
4394
  } finally {
@@ -4400,14 +4400,14 @@ function cc({ environment: e }) {
4400
4400
  if (u.value) return;
4401
4401
  let n = P.value;
4402
4402
  if (!n) return;
4403
- let r = E.value?.id, i = crypto.randomUUID(), a = Dc(Nt(D.value, t), i), o = Nc(e.file);
4403
+ let r = E.value?.id, i = crypto.randomUUID(), a = Dc(Pt(D.value, t), i), o = Nc(e.file);
4404
4404
  u.value = !0, g.value = null;
4405
4405
  try {
4406
4406
  if (m.value) {
4407
- await zt(n, e, a, r, i), D.value = null;
4407
+ await Vt(n, e, a, r, i), D.value = null;
4408
4408
  return;
4409
4409
  }
4410
- Ht(Mt({
4410
+ Ut(Nt({
4411
4411
  conversation: n,
4412
4412
  kind: o,
4413
4413
  text: e.caption?.trim() ?? "",
@@ -4425,13 +4425,13 @@ function cc({ environment: e }) {
4425
4425
  let t = new U.MediaMessage(n.targetId, e.file, o, kc(n));
4426
4426
  t.setMuid?.(i), Object.keys(a).length > 0 && t.setMetadata?.(a), r && t.setParentMessageId?.(Number(r)), e.caption?.trim() && t.setCaption?.(e.caption.trim());
4427
4427
  let s = await U.sendMediaMessage(t);
4428
- St(N(s, _.value?.uid)), mt(s), await q(s), D.value = null;
4428
+ Ct(N(s, _.value?.uid)), ht(s), await vt(s), D.value = null;
4429
4429
  } catch (t) {
4430
- if (Ft(t)) {
4431
- Ut("queued", i), await zt(n, e, a, r, i), D.value = null;
4430
+ if (It(t)) {
4431
+ Wt("queued", i), await Vt(n, e, a, r, i), D.value = null;
4432
4432
  return;
4433
4433
  }
4434
- throw Ut("failed", i), g.value = Z(t, "Unable to send the attachment."), t;
4434
+ throw Wt("failed", i), g.value = Z(t, "Unable to send the attachment."), t;
4435
4435
  } finally {
4436
4436
  u.value = !1;
4437
4437
  }
@@ -4442,17 +4442,17 @@ function cc({ environment: e }) {
4442
4442
  if (!n) return;
4443
4443
  let r = e.question.trim(), i = e.options.map((e) => e.trim()).filter(Boolean);
4444
4444
  if (!r || i.length < 2) return;
4445
- let a = E.value?.id, o = crypto.randomUUID(), s = Dc(Nt(D.value, t), o);
4445
+ let a = E.value?.id, o = crypto.randomUUID(), s = Dc(Pt(D.value, t), o);
4446
4446
  u.value = !0, g.value = null;
4447
4447
  try {
4448
4448
  if (m.value) {
4449
- Lt(n, {
4449
+ Rt(n, {
4450
4450
  question: r,
4451
4451
  options: i
4452
4452
  }, s, a, o), D.value = null;
4453
4453
  return;
4454
4454
  }
4455
- Ht(Mt({
4455
+ Ut(Nt({
4456
4456
  conversation: n,
4457
4457
  kind: "poll",
4458
4458
  text: `Poll: ${r}`,
@@ -4473,16 +4473,16 @@ function cc({ environment: e }) {
4473
4473
  };
4474
4474
  a && (e.parentMessageId = Number(a)), Object.keys(s).length > 0 && (e.metadata = s);
4475
4475
  let t = await U.callExtension("polls", "POST", "v2/create", e), c = t?.message ?? t?.custom_message ?? t?.data?.message ?? null;
4476
- c ? (Wt(o), St(N(c, _.value?.uid)), mt(c), await q(c)) : (Wt(o), await xt()), D.value = null;
4476
+ c ? (Gt(o), Ct(N(c, _.value?.uid)), ht(c), await vt(c)) : (Gt(o), await St()), D.value = null;
4477
4477
  } catch (e) {
4478
- if (Ft(e)) {
4479
- Ut("queued", o), Lt(n, {
4478
+ if (It(e)) {
4479
+ Wt("queued", o), Rt(n, {
4480
4480
  question: r,
4481
4481
  options: i
4482
4482
  }, s, a, o), D.value = null;
4483
4483
  return;
4484
4484
  }
4485
- throw Ut("failed", o), g.value = Z(e, "Unable to send the poll."), e;
4485
+ throw Wt("failed", o), g.value = Z(e, "Unable to send the poll."), e;
4486
4486
  } finally {
4487
4487
  u.value = !1;
4488
4488
  }
@@ -4490,16 +4490,16 @@ function cc({ environment: e }) {
4490
4490
  async function G(e, t) {
4491
4491
  let n = e.poll?.id ?? e.id, r = _.value?.uid;
4492
4492
  if (!n || !t || m.value) return;
4493
- let i = wt(e.id, e.parentMessageId) ?? e;
4493
+ let i = Tt(e.id, e.parentMessageId) ?? e;
4494
4494
  if (i.poll && !i.poll.options.some((e) => e.id === t && e.voters.includes(r ?? ""))) {
4495
- g.value = null, r && St(Re(i, t, r));
4495
+ g.value = null, r && Ct(Re(i, t, r));
4496
4496
  try {
4497
4497
  await U.callExtension("polls", "POST", "v2/vote", {
4498
4498
  id: n,
4499
4499
  vote: t
4500
4500
  });
4501
4501
  } catch (e) {
4502
- throw St(i), g.value = Z(e, "Unable to cast the vote."), e;
4502
+ throw Ct(i), g.value = Z(e, "Unable to cast the vote."), e;
4503
4503
  }
4504
4504
  }
4505
4505
  }
@@ -4525,22 +4525,22 @@ function cc({ environment: e }) {
4525
4525
  }
4526
4526
  async function ze(e, t) {
4527
4527
  g.value = null;
4528
- let n = wt(e.id, e.parentMessageId) ?? e, r = n.reactions.find((e) => e.emoji === t && e.reactedByMe);
4529
- St(Tt(n, t));
4528
+ let n = Tt(e.id, e.parentMessageId) ?? e, r = n.reactions.find((e) => e.emoji === t && e.reactedByMe);
4529
+ Ct(Et(n, t));
4530
4530
  try {
4531
- St(N(r ? await U.removeReaction(Number(e.id), t) : await U.addReaction(Number(e.id), t), _.value?.uid));
4531
+ Ct(N(r ? await U.removeReaction(Number(e.id), t) : await U.addReaction(Number(e.id), t), _.value?.uid));
4532
4532
  } catch (e) {
4533
- throw St(n), g.value = Z(e, "Unable to update the reaction."), e;
4533
+ throw Ct(n), g.value = Z(e, "Unable to update the reaction."), e;
4534
4534
  }
4535
4535
  }
4536
4536
  async function Be(e) {
4537
4537
  if (g.value = null, e.deliveryState === "queued" || e.deliveryState === "failed") {
4538
- Ot(e);
4538
+ kt(e);
4539
4539
  return;
4540
4540
  }
4541
4541
  if (!m.value) try {
4542
4542
  let t = N(await U.deleteMessage(String(e.id)), _.value?.uid);
4543
- Ot(t), kt(t);
4543
+ kt(t), At(t);
4544
4544
  } catch (e) {
4545
4545
  throw g.value = Z(e, "Unable to delete the message."), e;
4546
4546
  }
@@ -4556,14 +4556,14 @@ function cc({ environment: e }) {
4556
4556
  languages: typeof navigator < "u" ? navigator.languages : ["en"]
4557
4557
  })).translations?.[0]?.message_translated?.trim();
4558
4558
  if (!n) return;
4559
- Ct({
4559
+ wt({
4560
4560
  ...e,
4561
4561
  translatedText: n,
4562
4562
  metadata: {
4563
4563
  ...e.metadata ?? {},
4564
4564
  translated_message: n
4565
4565
  }
4566
- }), Dt();
4566
+ }), Ot();
4567
4567
  } catch (e) {
4568
4568
  throw g.value = Z(e, "Unable to translate the message."), e;
4569
4569
  }
@@ -4676,7 +4676,7 @@ function cc({ environment: e }) {
4676
4676
  if (!Number.isNaN(r.getTime()) && !Number.isNaN(i.getTime())) return e.receipts.readAt = r, e.receipts.deliveredAt = i, e;
4677
4677
  }
4678
4678
  } catch {}
4679
- let n = await yt(e);
4679
+ let n = await bt(e);
4680
4680
  for (let t of n) t.kind === "read" && t.timestamp && (!e.receipts.readAt || t.timestamp > e.receipts.readAt) && (e.receipts.readAt = t.timestamp), t.kind === "delivered" && t.timestamp && (!e.receipts.deliveredAt || t.timestamp > e.receipts.deliveredAt) && (e.receipts.deliveredAt = t.timestamp);
4681
4681
  if (e.receipts.readAt) try {
4682
4682
  localStorage.setItem(t, JSON.stringify({
@@ -4687,18 +4687,26 @@ function cc({ environment: e }) {
4687
4687
  return e;
4688
4688
  }
4689
4689
  async function et(e) {
4690
+ try {
4691
+ return await e.fetchPrevious();
4692
+ } catch (e) {
4693
+ if (e && typeof e == "object" && "code" in e && e.code === "ERR_GROUP_NOT_JOINED") return [];
4694
+ throw e;
4695
+ }
4696
+ }
4697
+ async function tt(e) {
4690
4698
  let t = P.value;
4691
4699
  if (!t) return y.value = [], S.value = !1, !1;
4692
4700
  if ((e?.reset || ce?.conversationId !== t.id) && (ce = {
4693
4701
  conversationId: t.id,
4694
4702
  request: Xe(t)
4695
4703
  }, S.value = !0), !ce) return !1;
4696
- let n = await ce.request.fetchPrevious(), r = await Promise.all(n.map((e) => N(e, _.value?.uid)).filter(Tc).sort(xc).map($e));
4704
+ let n = await et(ce.request), r = await Promise.all(n.map((e) => N(e, _.value?.uid)).filter(Tc).sort(xc).map($e));
4697
4705
  y.value = e?.reset ? Cc(y.value.filter((e) => e.conversationId === t.id && wc(e)), r) : Cc(y.value, r), S.value = n.length === 50, H?.setMessages(t.id, y.value);
4698
4706
  let i = n[n.length - 1];
4699
- return i && (await vt(i), await q(i)), n.length > 0;
4707
+ return i && (await yt(i), await vt(i)), n.length > 0;
4700
4708
  }
4701
- async function tt() {
4709
+ async function nt() {
4702
4710
  let e = P.value;
4703
4711
  if (!e) {
4704
4712
  y.value = [], S.value = !1, ce = null;
@@ -4710,7 +4718,7 @@ function cc({ environment: e }) {
4710
4718
  return;
4711
4719
  }
4712
4720
  try {
4713
- await et({ reset: !0 }), v.value = v.value.map((t) => t.id === e.id ? {
4721
+ await tt({ reset: !0 }), v.value = v.value.map((t) => t.id === e.id ? {
4714
4722
  ...t,
4715
4723
  lastMessage: y.value.at(-1) ?? null,
4716
4724
  unreadCount: 0
@@ -4726,7 +4734,7 @@ function cc({ environment: e }) {
4726
4734
  a.value = !1;
4727
4735
  }
4728
4736
  }
4729
- async function nt(e) {
4737
+ async function rt(e) {
4730
4738
  let t = E.value?.id;
4731
4739
  if (!t) return b.value = [], C.value = !1, !1;
4732
4740
  if ((e?.reset || W?.parentMessageId !== t) && (W = {
@@ -4736,15 +4744,15 @@ function cc({ environment: e }) {
4736
4744
  let n = await W.request.fetchPrevious(), r = await Promise.all(n.map((e) => N(e, _.value?.uid)).filter(Tc).sort(xc).map($e));
4737
4745
  b.value = e?.reset ? Cc(b.value.filter((e) => e.parentMessageId === t && wc(e)), r) : Cc(b.value, r), C.value = n.length === 50, H?.setThreadMessages(t, b.value);
4738
4746
  let i = n[n.length - 1];
4739
- return i && (await vt(i), await q(i)), n.length > 0;
4747
+ return i && (await yt(i), await vt(i)), n.length > 0;
4740
4748
  }
4741
- async function rt(e) {
4749
+ async function it(e) {
4742
4750
  if (o.value = !0, m.value && H) {
4743
4751
  b.value = H.getThreadMessages(e).sort(xc), C.value = !1, W = null, o.value = !1;
4744
4752
  return;
4745
4753
  }
4746
4754
  try {
4747
- await nt({ reset: !0 });
4755
+ await rt({ reset: !0 });
4748
4756
  } catch (t) {
4749
4757
  let n = H?.getThreadMessages(e) ?? [];
4750
4758
  if (n.length > 0) {
@@ -4756,29 +4764,29 @@ function cc({ environment: e }) {
4756
4764
  o.value = !1;
4757
4765
  }
4758
4766
  }
4759
- async function it() {
4767
+ async function at() {
4760
4768
  if (a.value || s.value || !S.value) return !1;
4761
4769
  s.value = !0, g.value = null;
4762
4770
  try {
4763
- return await et();
4771
+ return await tt();
4764
4772
  } catch (e) {
4765
4773
  throw g.value = Z(e, "Unable to load messages."), e;
4766
4774
  } finally {
4767
4775
  s.value = !1;
4768
4776
  }
4769
4777
  }
4770
- async function at() {
4778
+ async function ot() {
4771
4779
  if (o.value || c.value || !C.value) return !1;
4772
4780
  c.value = !0, g.value = null;
4773
4781
  try {
4774
- return await nt();
4782
+ return await rt();
4775
4783
  } catch (e) {
4776
4784
  throw g.value = Z(e, "Unable to load thread."), e;
4777
4785
  } finally {
4778
4786
  c.value = !1;
4779
4787
  }
4780
4788
  }
4781
- async function ot(e) {
4789
+ async function st(e) {
4782
4790
  let t = e.trim();
4783
4791
  if (!t) return !1;
4784
4792
  let n = () => y.value.some((e) => e.id === t) || b.value.some((e) => e.id === t) || E.value?.id === t;
@@ -4786,92 +4794,92 @@ function cc({ environment: e }) {
4786
4794
  let r = 0;
4787
4795
  for (; C.value && E.value && r < 100;) {
4788
4796
  r += 1;
4789
- let e = await at();
4797
+ let e = await ot();
4790
4798
  if (n()) return !0;
4791
4799
  if (!e) break;
4792
4800
  }
4793
4801
  for (; S.value && P.value && r < 100;) {
4794
4802
  r += 1;
4795
- let e = await it();
4803
+ let e = await at();
4796
4804
  if (n()) return !0;
4797
4805
  if (!e) break;
4798
4806
  }
4799
4807
  return n();
4800
4808
  }
4801
- async function st() {
4809
+ async function lt() {
4802
4810
  let e = await U.getLoggedinUser();
4803
4811
  _.value = e ? hc(e) : null, h.value = !!e;
4804
4812
  }
4805
- function lt() {
4813
+ function dt() {
4806
4814
  L ||= (U.addConnectionListener(F, new U.ConnectionListener({
4807
4815
  onConnected: () => {
4808
4816
  if (p.value = !0, ie = 0, ve(), V) {
4809
4817
  Ce();
4810
4818
  return;
4811
4819
  }
4812
- Gt();
4820
+ Kt();
4813
4821
  },
4814
4822
  onDisconnected: () => {
4815
4823
  p.value = !1, !m.value && h.value && !ae && (V = !0, xe(!0));
4816
4824
  }
4817
4825
  })), U.addMessageListener(I, new U.MessageListener({
4818
4826
  onTextMessageReceived: (e) => {
4819
- dt(e);
4827
+ ft(e);
4820
4828
  },
4821
4829
  onMediaMessageReceived: (e) => {
4822
- dt(e);
4830
+ ft(e);
4823
4831
  },
4824
4832
  onCustomMessageReceived: (e) => {
4825
- dt(e);
4833
+ ft(e);
4826
4834
  },
4827
4835
  onMessagesDelivered: () => {
4828
- be() || xt({ includeThread: !1 });
4836
+ be() || St({ includeThread: !1 });
4829
4837
  },
4830
4838
  onMessagesRead: () => {
4831
- be() || xt({ includeThread: !1 });
4839
+ be() || St({ includeThread: !1 });
4832
4840
  },
4833
4841
  onMessageEdited: (e) => {
4834
4842
  let t = N(e, _.value?.uid);
4835
- Tc(t) && (ht(t), mt(e));
4843
+ Tc(t) && (gt(t), ht(e));
4836
4844
  },
4837
4845
  onMessageDeleted: (e) => {
4838
4846
  let t = N(e, _.value?.uid);
4839
- t.parentMessageId ? Ot(t) : (Ot(t), kt(t)), Dt();
4847
+ t.parentMessageId ? kt(t) : (kt(t), At(t)), Ot();
4840
4848
  },
4841
4849
  onMessageReactionAdded: () => {
4842
- xt();
4850
+ St();
4843
4851
  },
4844
4852
  onMessageReactionRemoved: () => {
4845
- xt();
4853
+ St();
4846
4854
  },
4847
4855
  onMessagesDeliveredToAll: () => {
4848
- be() || xt({ includeThread: !1 });
4856
+ be() || St({ includeThread: !1 });
4849
4857
  },
4850
4858
  onMessagesReadByAll: () => {
4851
- be() || xt({ includeThread: !1 });
4859
+ be() || St({ includeThread: !1 });
4852
4860
  }
4853
4861
  })), !0);
4854
4862
  }
4855
- async function dt(e) {
4863
+ async function ft(e) {
4856
4864
  let t = N(e, _.value?.uid);
4857
4865
  if (Tc(t)) {
4858
- if (mt(e), await vt(e), t.parentMessageId) {
4859
- gt(t), Et(t.parentMessageId), Dt();
4866
+ if (ht(e), await yt(e), t.parentMessageId) {
4867
+ q(t), Dt(t.parentMessageId), Ot();
4860
4868
  return;
4861
4869
  }
4862
- t.conversationId === T.value && (ht(t), Dt(), await q(e));
4870
+ t.conversationId === T.value && (gt(t), Ot(), await vt(e));
4863
4871
  }
4864
4872
  }
4865
- async function ft(e) {
4873
+ async function pt(e) {
4866
4874
  return await Promise.all(e.map(async (e) => {
4867
- let t = await pt(e.targetId);
4875
+ let t = await mt(e.targetId);
4868
4876
  return {
4869
4877
  ...e,
4870
4878
  muteSettings: t ? new Date(t) : null
4871
4879
  };
4872
4880
  }));
4873
4881
  }
4874
- async function pt(e) {
4882
+ async function mt(e) {
4875
4883
  let t = H?.getParticipantSettings(e), n = t?.lastUpdated ? Date.now() - t.lastUpdated > 1440 * 60 * 1e3 : !0;
4876
4884
  if (t && (m.value || !n)) return t.mutedUntil;
4877
4885
  if (m.value || !h.value) return t?.mutedUntil ?? null;
@@ -4898,7 +4906,7 @@ function cc({ environment: e }) {
4898
4906
  return t?.mutedUntil ?? null;
4899
4907
  }
4900
4908
  }
4901
- function mt(e) {
4909
+ function ht(e) {
4902
4910
  let t = N(e, _.value?.uid);
4903
4911
  if (!Tc(t) || t.isDeleted) return;
4904
4912
  let n = e.getConversationId(), r = v.value.find((e) => e.id === n);
@@ -4915,33 +4923,33 @@ function cc({ environment: e }) {
4915
4923
  };
4916
4924
  v.value = bc(v.value.map((e) => e.id === n ? i : e)), H?.setConversations(v.value);
4917
4925
  }
4918
- function ht(e) {
4926
+ function gt(e) {
4919
4927
  y.value = Sc(y.value, e), T.value && H?.setMessages(T.value, y.value);
4920
4928
  }
4921
- function gt(e) {
4929
+ function q(e) {
4922
4930
  e.parentMessageId === E.value?.id && (b.value = Sc(b.value, e), e.parentMessageId && H?.setThreadMessages(e.parentMessageId, b.value));
4923
4931
  }
4924
- async function q(e) {
4932
+ async function vt(e) {
4925
4933
  if (m.value) return;
4926
4934
  let t = e.getSender?.()?.getUid?.();
4927
4935
  !t || t === _.value?.uid || e.getReadByMeAt?.() || (ye(), await U.markAsRead(e));
4928
4936
  }
4929
- async function vt(e) {
4937
+ async function yt(e) {
4930
4938
  if (m.value) return;
4931
4939
  let t = e.getSender?.()?.getUid?.();
4932
4940
  !t || t === _.value?.uid || e.getDeliveredToMeAt?.() || (ye(), await U.markAsDelivered(e));
4933
4941
  }
4934
- async function yt(e) {
4942
+ async function bt(e) {
4935
4943
  return m.value ? [] : pc(await U.getMessageReceipts(String(e.id)));
4936
4944
  }
4937
- function bt() {
4945
+ function xt() {
4938
4946
  r.value = !1, i.value = !1, a.value = !1, o.value = !1, s.value = !1, c.value = !1, l.value = !1, u.value = !1, d.value = !1, f.value = !1, p.value = !1, ve(), ie = 0, V = !1, ae = !1, h.value = !1, _.value = null, v.value = [], y.value = [], b.value = [], x.value = [], E.value = null, D.value = null, O.value = null, k.value = [], T.value = null, S.value = !1, C.value = !1, ce = null, W = null, se.clear();
4939
4947
  }
4940
- async function xt(e) {
4948
+ async function St(e) {
4941
4949
  if (B) return B;
4942
4950
  let t = e?.includeThread ?? !0;
4943
4951
  B = (async () => {
4944
- P.value && await tt(), t && E.value && await rt(E.value.id);
4952
+ P.value && await nt(), t && E.value && await it(E.value.id);
4945
4953
  })();
4946
4954
  try {
4947
4955
  await B;
@@ -4949,20 +4957,20 @@ function cc({ environment: e }) {
4949
4957
  B = null;
4950
4958
  }
4951
4959
  }
4952
- function St(e) {
4953
- Ct(e), e.parentMessageId && Et(e.parentMessageId, e.replyCount), Dt();
4954
- }
4955
4960
  function Ct(e) {
4961
+ wt(e), e.parentMessageId && Dt(e.parentMessageId, e.replyCount), Ot();
4962
+ }
4963
+ function wt(e) {
4956
4964
  if (e.parentMessageId) {
4957
4965
  E.value?.id === e.parentMessageId && (b.value = Sc(b.value, e));
4958
4966
  return;
4959
4967
  }
4960
4968
  y.value = Sc(y.value, e), E.value?.id === e.id && (E.value = e);
4961
4969
  }
4962
- function wt(e, t) {
4970
+ function Tt(e, t) {
4963
4971
  return t ? b.value.find((t) => t.id === e) ?? null : E.value?.id === e ? E.value : y.value.find((t) => t.id === e) ?? null;
4964
4972
  }
4965
- function Tt(e, t) {
4973
+ function Et(e, t) {
4966
4974
  let n = e.reactions.find((e) => e.emoji === t);
4967
4975
  return n ? n.reactedByMe && n.count === 1 ? {
4968
4976
  ...e,
@@ -4983,7 +4991,7 @@ function cc({ environment: e }) {
4983
4991
  }]
4984
4992
  };
4985
4993
  }
4986
- function Et(e, t) {
4994
+ function Dt(e, t) {
4987
4995
  let n = y.value.find((t) => t.id === e);
4988
4996
  if (!n) return;
4989
4997
  let r = {
@@ -4992,18 +5000,18 @@ function cc({ environment: e }) {
4992
5000
  };
4993
5001
  y.value = Sc(y.value, r), E.value?.id === e && (E.value = r);
4994
5002
  }
4995
- function Dt() {
5003
+ function Ot() {
4996
5004
  T.value && H?.setMessages(T.value, y.value), E.value && H?.setThreadMessages(E.value.id, b.value);
4997
5005
  }
4998
- function Ot(e) {
5006
+ function kt(e) {
4999
5007
  if (e.parentMessageId ? (b.value = b.value.filter((t) => t.id !== e.id), H?.setThreadMessages(e.parentMessageId, b.value)) : (y.value = y.value.filter((t) => t.id !== e.id), T.value && H?.setMessages(T.value, y.value)), e.muid) {
5000
5008
  k.value = k.value.filter((t) => t.muid !== e.muid);
5001
5009
  let t = H?.getQueue().filter((t) => t.muid === e.muid) ?? [];
5002
5010
  for (let e of t) H?.dequeue(e.id), oe.delete(e.id), e.kind === "attachment" && H?.deleteQueuedAttachment(e.id);
5003
5011
  }
5004
- e.parentMessageId || At(e.conversationId);
5012
+ e.parentMessageId || jt(e.conversationId);
5005
5013
  }
5006
- function kt(e) {
5014
+ function At(e) {
5007
5015
  if (e.parentMessageId) return;
5008
5016
  let t = e.conversationId, n = v.value.find((e) => e.id === t);
5009
5017
  if (!n) return;
@@ -5028,7 +5036,7 @@ function cc({ environment: e }) {
5028
5036
  lastMessageAt: void 0
5029
5037
  } : e : e)), H?.setConversations(v.value);
5030
5038
  }
5031
- function At(e, t) {
5039
+ function jt(e, t) {
5032
5040
  let n = y.value.length > 0 ? y.value[y.value.length - 1] : null, r = t ?? n;
5033
5041
  v.value = bc(v.value.map((t) => t.id === e ? {
5034
5042
  ...t,
@@ -5037,7 +5045,7 @@ function cc({ environment: e }) {
5037
5045
  lastMessage: r
5038
5046
  } : t)), H?.setConversations(v.value);
5039
5047
  }
5040
- function jt(e) {
5048
+ function Mt(e) {
5041
5049
  v.value = bc(v.value.map((t) => t.id === e.conversationId ? {
5042
5050
  ...t,
5043
5051
  subtitle: Oc(e),
@@ -5046,8 +5054,8 @@ function cc({ environment: e }) {
5046
5054
  unreadCount: 0
5047
5055
  } : t)), H?.setConversations(v.value);
5048
5056
  }
5049
- function Mt(e) {
5050
- let t = /* @__PURE__ */ new Date(), n = Pt(e.metadata);
5057
+ function Nt(e) {
5058
+ let t = /* @__PURE__ */ new Date(), n = Ft(e.metadata);
5051
5059
  return {
5052
5060
  id: `local-${e.muid}`,
5053
5061
  muid: e.muid,
@@ -5086,11 +5094,11 @@ function cc({ environment: e }) {
5086
5094
  source: null
5087
5095
  };
5088
5096
  }
5089
- function Nt(e, t) {
5097
+ function Pt(e, t) {
5090
5098
  let n = {};
5091
5099
  return t?.senderDisplayName?.trim() && (n.senderDisplayName = t.senderDisplayName.trim()), e ? (n.replyToMessageId = e.id, n.replyPreview = Js(e), n) : n;
5092
5100
  }
5093
- function Pt(e) {
5101
+ function Ft(e) {
5094
5102
  let t = e.replyPreview;
5095
5103
  if (!t || typeof t != "object") return;
5096
5104
  let n = t;
@@ -5101,13 +5109,13 @@ function cc({ environment: e }) {
5101
5109
  kind: n.kind ?? "text"
5102
5110
  };
5103
5111
  }
5104
- function Ft(e) {
5112
+ function It(e) {
5105
5113
  if (typeof navigator < "u" && !navigator.onLine) return !0;
5106
5114
  let t = Z(e, "").toLowerCase();
5107
5115
  return t.includes("network") || t.includes("failed to fetch") || t.includes("socket") || t.includes("offline");
5108
5116
  }
5109
- function It(e, t, n, r, i) {
5110
- let a = Mt({
5117
+ function Lt(e, t, n, r, i) {
5118
+ let a = Nt({
5111
5119
  conversation: e,
5112
5120
  kind: "text",
5113
5121
  text: t,
@@ -5116,7 +5124,7 @@ function cc({ environment: e }) {
5116
5124
  muid: i,
5117
5125
  deliveryState: "queued"
5118
5126
  });
5119
- Vt(a, {
5127
+ Ht(a, {
5120
5128
  id: a.id,
5121
5129
  muid: i,
5122
5130
  conversationId: e.id,
@@ -5129,9 +5137,9 @@ function cc({ environment: e }) {
5129
5137
  createdAt: a.sentAt.toISOString()
5130
5138
  });
5131
5139
  }
5132
- function Lt(e, t, n, r, i) {
5133
- if (Rt(e, t, r)) return;
5134
- let a = Mt({
5140
+ function Rt(e, t, n, r, i) {
5141
+ if (zt(e, t, r)) return;
5142
+ let a = Nt({
5135
5143
  conversation: e,
5136
5144
  kind: "poll",
5137
5145
  text: `Poll: ${t.question}`,
@@ -5141,7 +5149,7 @@ function cc({ environment: e }) {
5141
5149
  muid: i,
5142
5150
  deliveryState: "queued"
5143
5151
  });
5144
- Vt(a, {
5152
+ Ht(a, {
5145
5153
  id: a.id,
5146
5154
  muid: i,
5147
5155
  conversationId: e.id,
@@ -5154,7 +5162,7 @@ function cc({ environment: e }) {
5154
5162
  createdAt: a.sentAt.toISOString()
5155
5163
  });
5156
5164
  }
5157
- function Rt(e, t, n) {
5165
+ function zt(e, t, n) {
5158
5166
  let r = Date.now(), i = (e) => e.trim().toLowerCase(), a = (e) => e.map((e) => i(e)).filter(Boolean).join("\0"), o = i(t.question), s = a(t.options);
5159
5167
  return k.value.some((t) => {
5160
5168
  if (t.kind !== "poll" || !t.poll || t.conversationId !== e.id || t.targetId !== e.targetId || t.parentMessageId !== n) return !1;
@@ -5162,8 +5170,8 @@ function cc({ environment: e }) {
5162
5170
  return Number.isNaN(c) || r - c > 5e3 ? !1 : i(t.poll.question) === o && a(t.poll.options) === s;
5163
5171
  });
5164
5172
  }
5165
- async function zt(e, t, n, r, i) {
5166
- let a = Nc(t.file), o = Mt({
5173
+ async function Vt(e, t, n, r, i) {
5174
+ let a = Nc(t.file), o = Nt({
5167
5175
  conversation: e,
5168
5176
  kind: a,
5169
5177
  text: t.caption?.trim() ?? "",
@@ -5199,15 +5207,15 @@ function cc({ environment: e }) {
5199
5207
  try {
5200
5208
  await H?.storeQueuedAttachment(s.id, t.file);
5201
5209
  } catch {}
5202
- Vt(o, s);
5210
+ Ht(o, s);
5203
5211
  }
5204
- function Vt(e, t) {
5205
- k.value = [...k.value, t], H?.enqueue(t), Ht(e);
5212
+ function Ht(e, t) {
5213
+ k.value = [...k.value, t], H?.enqueue(t), Ut(e);
5206
5214
  }
5207
- function Ht(e) {
5208
- e.parentMessageId ? (E.value?.id === e.parentMessageId && (b.value = Sc(b.value, e)), Et(e.parentMessageId)) : y.value = Sc(y.value, e), jt(e), Dt();
5215
+ function Ut(e) {
5216
+ e.parentMessageId ? (E.value?.id === e.parentMessageId && (b.value = Sc(b.value, e)), Dt(e.parentMessageId)) : y.value = Sc(y.value, e), Mt(e), Ot();
5209
5217
  }
5210
- function Ut(e, t) {
5218
+ function Wt(e, t) {
5211
5219
  let n = (n) => n.map((n) => {
5212
5220
  let r = Ec(n);
5213
5221
  return n.muid !== t && r !== t ? n : {
@@ -5215,18 +5223,18 @@ function cc({ environment: e }) {
5215
5223
  deliveryState: e
5216
5224
  };
5217
5225
  });
5218
- y.value = n(y.value), b.value = n(b.value), Dt();
5226
+ y.value = n(y.value), b.value = n(b.value), Ot();
5219
5227
  }
5220
- function Wt(e) {
5228
+ function Gt(e) {
5221
5229
  if (!e) return;
5222
5230
  let t = [...y.value, ...b.value].filter((t) => {
5223
5231
  if (!t.id.startsWith("local-")) return !1;
5224
5232
  let n = Ec(t);
5225
5233
  return t.muid === e || n === e;
5226
5234
  });
5227
- for (let e of t) Ot(e);
5235
+ for (let e of t) kt(e);
5228
5236
  }
5229
- async function Gt() {
5237
+ async function Kt() {
5230
5238
  if (!(f.value || k.value.length === 0 || !h.value || m.value)) {
5231
5239
  f.value = !0;
5232
5240
  try {
@@ -5234,20 +5242,20 @@ function cc({ environment: e }) {
5234
5242
  for (let t of e) if (!se.has(t.id)) {
5235
5243
  se.add(t.id);
5236
5244
  try {
5237
- let e = await Kt(t);
5238
- k.value = k.value.filter((e) => e.id !== t.id), H?.dequeue(t.id), oe.delete(t.id), t.kind === "attachment" && await H?.deleteQueuedAttachment(t.id), Wt(t.muid), e ? St(N(e, _.value?.uid)) : await xt();
5245
+ let e = await qt(t);
5246
+ k.value = k.value.filter((e) => e.id !== t.id), H?.dequeue(t.id), oe.delete(t.id), t.kind === "attachment" && await H?.deleteQueuedAttachment(t.id), Gt(t.muid), e ? Ct(N(e, _.value?.uid)) : await St();
5239
5247
  } finally {
5240
5248
  se.delete(t.id);
5241
5249
  }
5242
5250
  }
5243
5251
  } catch (e) {
5244
- Ft(e) || (g.value = Z(e, "Unable to sync queued messages."));
5252
+ It(e) || (g.value = Z(e, "Unable to sync queued messages."));
5245
5253
  } finally {
5246
5254
  f.value = !1;
5247
5255
  }
5248
5256
  }
5249
5257
  }
5250
- async function Kt(e) {
5258
+ async function qt(e) {
5251
5259
  let t = e.receiverType === "group" ? U.RECEIVER_TYPE.GROUP : U.RECEIVER_TYPE.USER;
5252
5260
  if (e.kind === "poll" && e.poll) {
5253
5261
  let n = {
@@ -5309,9 +5317,9 @@ function cc({ environment: e }) {
5309
5317
  sendAttachmentMessage: Ie,
5310
5318
  sendPollMessage: Le,
5311
5319
  fetchScheduledMessages: Ue,
5312
- loadOlderMessages: it,
5313
- loadOlderThreadMessages: at,
5314
- ensureMessageLoaded: ot,
5320
+ loadOlderMessages: at,
5321
+ loadOlderThreadMessages: ot,
5322
+ ensureMessageLoaded: st,
5315
5323
  scheduleMessage: We,
5316
5324
  rescheduleMessage: Ye,
5317
5325
  removeScheduledMessage: Ge,
@@ -5320,8 +5328,8 @@ function cc({ environment: e }) {
5320
5328
  setEditingMessage: je,
5321
5329
  openThread: Me,
5322
5330
  closeThread: Ne,
5323
- refreshVisibleMessages: xt,
5324
- fetchMessageReceipts: yt,
5331
+ refreshVisibleMessages: St,
5332
+ fetchMessageReceipts: bt,
5325
5333
  deleteMessage: Be,
5326
5334
  votePoll: G,
5327
5335
  toggleReaction: ze,