@unicitylabs/sphere-sdk 0.3.6 → 0.3.7

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.cjs CHANGED
@@ -7707,6 +7707,28 @@ var CommunicationsModule = class {
7707
7707
  this.unsubscribeMessages = deps.transport.onMessage((msg) => {
7708
7708
  this.handleIncomingMessage(msg);
7709
7709
  });
7710
+ if (deps.transport.onReadReceipt) {
7711
+ deps.transport.onReadReceipt((receipt) => {
7712
+ const msg = this.messages.get(receipt.messageEventId);
7713
+ if (msg && msg.senderPubkey === this.deps.identity.chainPubkey) {
7714
+ msg.isRead = true;
7715
+ this.save();
7716
+ this.deps.emitEvent("message:read", {
7717
+ messageIds: [receipt.messageEventId],
7718
+ peerPubkey: receipt.senderTransportPubkey
7719
+ });
7720
+ }
7721
+ });
7722
+ }
7723
+ if (deps.transport.onTypingIndicator) {
7724
+ deps.transport.onTypingIndicator((indicator) => {
7725
+ this.deps.emitEvent("message:typing", {
7726
+ senderPubkey: indicator.senderTransportPubkey,
7727
+ senderNametag: indicator.senderNametag,
7728
+ timestamp: indicator.timestamp
7729
+ });
7730
+ });
7731
+ }
7710
7732
  }
7711
7733
  /**
7712
7734
  * Load messages from storage
@@ -7750,7 +7772,7 @@ var CommunicationsModule = class {
7750
7772
  recipientPubkey,
7751
7773
  content,
7752
7774
  timestamp: Date.now(),
7753
- isRead: true
7775
+ isRead: false
7754
7776
  };
7755
7777
  this.messages.set(message.id, message);
7756
7778
  if (this.config.autoSave) {
@@ -7796,6 +7818,16 @@ var CommunicationsModule = class {
7796
7818
  if (this.config.autoSave) {
7797
7819
  await this.save();
7798
7820
  }
7821
+ if (this.config.readReceipts && this.deps?.transport.sendReadReceipt) {
7822
+ for (const id of messageIds) {
7823
+ const msg = this.messages.get(id);
7824
+ if (msg && msg.senderPubkey !== this.deps.identity.chainPubkey) {
7825
+ this.deps.transport.sendReadReceipt(msg.senderPubkey, id).catch((err) => {
7826
+ console.warn("[Communications] Failed to send read receipt:", err);
7827
+ });
7828
+ }
7829
+ }
7830
+ }
7799
7831
  }
7800
7832
  /**
7801
7833
  * Get unread count
@@ -7809,6 +7841,15 @@ var CommunicationsModule = class {
7809
7841
  }
7810
7842
  return messages.length;
7811
7843
  }
7844
+ /**
7845
+ * Send typing indicator to a peer
7846
+ */
7847
+ async sendTypingIndicator(peerPubkey) {
7848
+ this.ensureInitialized();
7849
+ if (this.deps.transport.sendTypingIndicator) {
7850
+ await this.deps.transport.sendTypingIndicator(peerPubkey);
7851
+ }
7852
+ }
7812
7853
  /**
7813
7854
  * Subscribe to incoming DMs
7814
7855
  */
@@ -7878,7 +7919,26 @@ var CommunicationsModule = class {
7878
7919
  // Private: Message Handling
7879
7920
  // ===========================================================================
7880
7921
  handleIncomingMessage(msg) {
7922
+ if (msg.isSelfWrap && msg.recipientTransportPubkey) {
7923
+ if (this.messages.has(msg.id)) return;
7924
+ const message2 = {
7925
+ id: msg.id,
7926
+ senderPubkey: this.deps.identity.chainPubkey,
7927
+ senderNametag: msg.senderNametag,
7928
+ recipientPubkey: msg.recipientTransportPubkey,
7929
+ content: msg.content,
7930
+ timestamp: msg.timestamp,
7931
+ isRead: false
7932
+ };
7933
+ this.messages.set(message2.id, message2);
7934
+ this.deps.emitEvent("message:dm", message2);
7935
+ if (this.config.autoSave) {
7936
+ this.save();
7937
+ }
7938
+ return;
7939
+ }
7881
7940
  if (msg.senderTransportPubkey === this.deps?.identity.chainPubkey) return;
7941
+ if (this.messages.has(msg.id)) return;
7882
7942
  const message = {
7883
7943
  id: msg.id,
7884
7944
  senderPubkey: msg.senderTransportPubkey,