spectrum-ts 1.9.0 → 1.9.2

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.
@@ -538,8 +538,7 @@ var setBackground = async (remote, spaceId, content) => {
538
538
  const buffer = await content.action.read();
539
539
  await remote.chats.setBackground(
540
540
  chat,
541
- new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength),
542
- content.action.mimeType
541
+ new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
543
542
  );
544
543
  };
545
544
 
@@ -578,8 +577,6 @@ var MessageCache = class {
578
577
  var PollCache = class {
579
578
  map = /* @__PURE__ */ new Map();
580
579
  max;
581
- selectionEventTimesByPoll = /* @__PURE__ */ new Map();
582
- selectionsByPoll = /* @__PURE__ */ new Map();
583
580
  constructor(max = DEFAULT_MAX) {
584
581
  this.max = max;
585
582
  }
@@ -595,61 +592,11 @@ var PollCache = class {
595
592
  const first = this.map.keys().next().value;
596
593
  if (first !== void 0) {
597
594
  this.map.delete(first);
598
- this.selectionEventTimesByPoll.delete(first);
599
- this.selectionsByPoll.delete(first);
600
595
  }
601
596
  }
602
597
  }
603
598
  clear() {
604
599
  this.map.clear();
605
- this.selectionEventTimesByPoll.clear();
606
- this.selectionsByPoll.clear();
607
- }
608
- actorSelectionDeltas(pollId, actorId, optionIds) {
609
- const previous = this.selectionsByPoll.get(pollId)?.get(actorId);
610
- if (!previous) {
611
- return optionIds.map((optionId) => ({ optionId, selected: true }));
612
- }
613
- const current = new Set(optionIds);
614
- const selected = optionIds.filter((optionId) => !previous.has(optionId)).map((optionId) => ({ optionId, selected: true }));
615
- const deselected = [...previous].filter((optionId) => !current.has(optionId)).map((optionId) => ({ optionId, selected: false }));
616
- return [...selected, ...deselected];
617
- }
618
- clearedActorSelectionDeltas(pollId, actorId) {
619
- const previous = this.selectionsByPoll.get(pollId)?.get(actorId);
620
- if (!previous) {
621
- return [];
622
- }
623
- return [...previous].map((optionId) => ({ optionId, selected: false }));
624
- }
625
- actorSelection(pollId, actorId) {
626
- const selection = this.selectionsByPoll.get(pollId)?.get(actorId);
627
- return selection ? [...selection] : void 0;
628
- }
629
- commitActorSelection(pollId, actorId, optionIds, at) {
630
- let selections = this.selectionsByPoll.get(pollId);
631
- if (!selections) {
632
- selections = /* @__PURE__ */ new Map();
633
- this.selectionsByPoll.set(pollId, selections);
634
- }
635
- selections.set(actorId, new Set(optionIds));
636
- if (!at) {
637
- return;
638
- }
639
- let eventTimes = this.selectionEventTimesByPoll.get(pollId);
640
- if (!eventTimes) {
641
- eventTimes = /* @__PURE__ */ new Map();
642
- this.selectionEventTimesByPoll.set(pollId, eventTimes);
643
- }
644
- const eventTime = at.getTime();
645
- const previousTime = eventTimes.get(actorId);
646
- if (previousTime === void 0 || eventTime >= previousTime) {
647
- eventTimes.set(actorId, eventTime);
648
- }
649
- }
650
- isStaleActorSelectionEvent(pollId, actorId, at) {
651
- const previousTime = this.selectionEventTimesByPoll.get(pollId)?.get(actorId);
652
- return previousTime !== void 0 && at.getTime() < previousTime;
653
600
  }
654
601
  };
655
602
  var messageCaches = /* @__PURE__ */ new WeakMap();
@@ -1711,8 +1658,7 @@ var fetchPollInfo = async (client, cache, event) => {
1711
1658
  }
1712
1659
  };
1713
1660
  var resolvePoll = async (client, cache, event) => {
1714
- const pollId = event.pollMessageGuid;
1715
- const cached = cache.get(pollId);
1661
+ const cached = cache.get(event.pollMessageGuid);
1716
1662
  if (cached) {
1717
1663
  return cached;
1718
1664
  }
@@ -1747,25 +1693,6 @@ var buildPollOptionMessage = (input) => {
1747
1693
  })
1748
1694
  };
1749
1695
  };
1750
- var buildPollOptionMessages = (input) => {
1751
- const messages5 = [];
1752
- for (const delta of input.deltas) {
1753
- const message = buildPollOptionMessage({
1754
- cached: input.cached,
1755
- chatGuid: input.chatGuid,
1756
- event: input.event,
1757
- optionId: delta.optionId,
1758
- phone: input.phone,
1759
- selected: delta.selected,
1760
- senderAddress: input.senderAddress
1761
- });
1762
- if (message) {
1763
- messages5.push(message);
1764
- }
1765
- }
1766
- return messages5;
1767
- };
1768
- var allOptionIdsKnown = (cached, optionIds) => optionIds.every((optionId) => cached.optionsByIdentifier.has(optionId));
1769
1696
  var refreshPollMetadata = async (client, pollCache, event) => {
1770
1697
  const info = await fetchPollInfo(client, pollCache, event);
1771
1698
  if (!info) {
@@ -1773,94 +1700,39 @@ var refreshPollMetadata = async (client, pollCache, event) => {
1773
1700
  }
1774
1701
  return pollCache.get(info.pollMessageGuid);
1775
1702
  };
1776
- var toPollVoteMessages = async (client, pollCache, event, phone) => {
1703
+ var toPollOptionMessage = async (client, pollCache, event, phone) => {
1777
1704
  const senderAddress = event.actor?.address;
1778
- if (!senderAddress) {
1779
- return [];
1780
- }
1781
- const pollId = event.pollMessageGuid;
1782
- if (pollCache.isStaleActorSelectionEvent(
1783
- pollId,
1784
- senderAddress,
1785
- event.occurredAt
1786
- )) {
1705
+ const optionId = event.delta.optionIdentifier;
1706
+ if (!(senderAddress && optionId)) {
1787
1707
  return [];
1788
1708
  }
1789
- const cached = await resolvePoll(client, pollCache, event);
1709
+ let cached = await resolvePoll(client, pollCache, event);
1790
1710
  if (!cached) {
1791
1711
  return [];
1792
1712
  }
1793
- const chatGuidStr = event.chatGuid;
1794
- const currentOptionIds = [event.delta.optionIdentifier];
1795
- let resolvedPoll = cached;
1796
- if (currentOptionIds.some(
1797
- (optionId) => !resolvedPoll.optionsByIdentifier.has(optionId)
1798
- )) {
1799
- const snapshot = await refreshPollMetadata(client, pollCache, event);
1800
- if (snapshot) {
1801
- resolvedPoll = snapshot;
1713
+ if (!cached.optionsByIdentifier.has(optionId)) {
1714
+ const refreshed = await refreshPollMetadata(client, pollCache, event);
1715
+ if (refreshed) {
1716
+ cached = refreshed;
1802
1717
  }
1803
1718
  }
1804
- if (!allOptionIdsKnown(resolvedPoll, currentOptionIds)) {
1805
- return [];
1806
- }
1807
- const deltas = pollCache.actorSelectionDeltas(
1808
- pollId,
1809
- senderAddress,
1810
- currentOptionIds
1811
- );
1812
- const messages5 = buildPollOptionMessages({
1813
- cached: resolvedPoll,
1814
- chatGuid: chatGuidStr,
1815
- deltas,
1816
- event,
1817
- phone,
1818
- senderAddress
1819
- });
1820
- pollCache.commitActorSelection(
1821
- pollId,
1822
- senderAddress,
1823
- currentOptionIds,
1824
- event.occurredAt
1825
- );
1826
- return messages5;
1827
- };
1828
- var toPollUnvoteMessages = async (client, pollCache, event, phone) => {
1829
- const senderAddress = event.actor?.address;
1830
- if (!senderAddress) {
1831
- return [];
1832
- }
1833
- const pollId = event.pollMessageGuid;
1834
- if (pollCache.isStaleActorSelectionEvent(
1835
- pollId,
1836
- senderAddress,
1837
- event.occurredAt
1838
- )) {
1839
- return [];
1840
- }
1841
- const cached = await resolvePoll(client, pollCache, event);
1842
- if (!cached) {
1843
- return [];
1844
- }
1845
- const chatGuidStr = event.chatGuid;
1846
- const deltas = pollCache.clearedActorSelectionDeltas(pollId, senderAddress);
1847
- const messages5 = buildPollOptionMessages({
1719
+ const message = buildPollOptionMessage({
1848
1720
  cached,
1849
- chatGuid: chatGuidStr,
1850
- deltas,
1721
+ chatGuid: event.chatGuid,
1851
1722
  event,
1723
+ optionId,
1852
1724
  phone,
1725
+ selected: event.delta.type === "voted",
1853
1726
  senderAddress
1854
1727
  });
1855
- pollCache.commitActorSelection(pollId, senderAddress, [], event.occurredAt);
1856
- return messages5;
1728
+ return message ? [message] : [];
1857
1729
  };
1858
1730
  var toPollDeltaMessages = async (client, pollCache, event, phone) => {
1859
1731
  if (isVotedPollEvent(event)) {
1860
- return toPollVoteMessages(client, pollCache, event, phone);
1732
+ return toPollOptionMessage(client, pollCache, event, phone);
1861
1733
  }
1862
1734
  if (isUnvotedPollEvent(event)) {
1863
- return toPollUnvoteMessages(client, pollCache, event, phone);
1735
+ return toPollOptionMessage(client, pollCache, event, phone);
1864
1736
  }
1865
1737
  return [];
1866
1738
  };
@@ -1875,7 +1747,7 @@ var isRetryableIMessageStreamError = (error) => {
1875
1747
  }
1876
1748
  return false;
1877
1749
  };
1878
- var isEventFromCurrentAccount = (event, phone) => phone !== SHARED_PHONE && event.actor?.address !== void 0 && event.actor.address === phone;
1750
+ var isEventFromCurrentAccount = (event, phone) => event.isFromMe || phone !== SHARED_PHONE && event.actor?.address !== void 0 && event.actor.address === phone;
1879
1751
  var toMessageItem = async (client, event, phone, cursor) => {
1880
1752
  if (event.type === "message.received") {
1881
1753
  if (event.message.isFromMe) {
@@ -2,7 +2,7 @@ import {
2
2
  background,
3
3
  effect,
4
4
  imessage
5
- } from "../../chunk-OM5VSKWD.js";
5
+ } from "../../chunk-7O5BCLGQ.js";
6
6
  import "../../chunk-5NHNMN4H.js";
7
7
  import "../../chunk-HWADNTQF.js";
8
8
  import "../../chunk-XZSBR26X.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  imessage
3
- } from "../chunk-OM5VSKWD.js";
3
+ } from "../chunk-7O5BCLGQ.js";
4
4
  import "../chunk-5NHNMN4H.js";
5
5
  import {
6
6
  terminal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@photon-ai/advanced-imessage": "^0.7.0",
26
+ "@photon-ai/advanced-imessage": "^0.8.0",
27
27
  "@photon-ai/imessage-kit": "^3.0.0",
28
28
  "@photon-ai/otel": "^0.1.1",
29
29
  "@photon-ai/whatsapp-business": "^0.1.1",