@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/core/index.cjs +61 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +57 -1
- package/dist/core/index.d.ts +57 -1
- package/dist/core/index.js +61 -1
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +167 -32
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +170 -33
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +114 -4
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +49 -0
- package/dist/impl/nodejs/index.d.ts +49 -0
- package/dist/impl/nodejs/index.js +117 -5
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +61 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +61 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -7352,6 +7352,28 @@ var CommunicationsModule = class {
|
|
|
7352
7352
|
this.unsubscribeMessages = deps.transport.onMessage((msg) => {
|
|
7353
7353
|
this.handleIncomingMessage(msg);
|
|
7354
7354
|
});
|
|
7355
|
+
if (deps.transport.onReadReceipt) {
|
|
7356
|
+
deps.transport.onReadReceipt((receipt) => {
|
|
7357
|
+
const msg = this.messages.get(receipt.messageEventId);
|
|
7358
|
+
if (msg && msg.senderPubkey === this.deps.identity.chainPubkey) {
|
|
7359
|
+
msg.isRead = true;
|
|
7360
|
+
this.save();
|
|
7361
|
+
this.deps.emitEvent("message:read", {
|
|
7362
|
+
messageIds: [receipt.messageEventId],
|
|
7363
|
+
peerPubkey: receipt.senderTransportPubkey
|
|
7364
|
+
});
|
|
7365
|
+
}
|
|
7366
|
+
});
|
|
7367
|
+
}
|
|
7368
|
+
if (deps.transport.onTypingIndicator) {
|
|
7369
|
+
deps.transport.onTypingIndicator((indicator) => {
|
|
7370
|
+
this.deps.emitEvent("message:typing", {
|
|
7371
|
+
senderPubkey: indicator.senderTransportPubkey,
|
|
7372
|
+
senderNametag: indicator.senderNametag,
|
|
7373
|
+
timestamp: indicator.timestamp
|
|
7374
|
+
});
|
|
7375
|
+
});
|
|
7376
|
+
}
|
|
7355
7377
|
}
|
|
7356
7378
|
/**
|
|
7357
7379
|
* Load messages from storage
|
|
@@ -7395,7 +7417,7 @@ var CommunicationsModule = class {
|
|
|
7395
7417
|
recipientPubkey,
|
|
7396
7418
|
content,
|
|
7397
7419
|
timestamp: Date.now(),
|
|
7398
|
-
isRead:
|
|
7420
|
+
isRead: false
|
|
7399
7421
|
};
|
|
7400
7422
|
this.messages.set(message.id, message);
|
|
7401
7423
|
if (this.config.autoSave) {
|
|
@@ -7441,6 +7463,16 @@ var CommunicationsModule = class {
|
|
|
7441
7463
|
if (this.config.autoSave) {
|
|
7442
7464
|
await this.save();
|
|
7443
7465
|
}
|
|
7466
|
+
if (this.config.readReceipts && this.deps?.transport.sendReadReceipt) {
|
|
7467
|
+
for (const id of messageIds) {
|
|
7468
|
+
const msg = this.messages.get(id);
|
|
7469
|
+
if (msg && msg.senderPubkey !== this.deps.identity.chainPubkey) {
|
|
7470
|
+
this.deps.transport.sendReadReceipt(msg.senderPubkey, id).catch((err) => {
|
|
7471
|
+
console.warn("[Communications] Failed to send read receipt:", err);
|
|
7472
|
+
});
|
|
7473
|
+
}
|
|
7474
|
+
}
|
|
7475
|
+
}
|
|
7444
7476
|
}
|
|
7445
7477
|
/**
|
|
7446
7478
|
* Get unread count
|
|
@@ -7454,6 +7486,15 @@ var CommunicationsModule = class {
|
|
|
7454
7486
|
}
|
|
7455
7487
|
return messages.length;
|
|
7456
7488
|
}
|
|
7489
|
+
/**
|
|
7490
|
+
* Send typing indicator to a peer
|
|
7491
|
+
*/
|
|
7492
|
+
async sendTypingIndicator(peerPubkey) {
|
|
7493
|
+
this.ensureInitialized();
|
|
7494
|
+
if (this.deps.transport.sendTypingIndicator) {
|
|
7495
|
+
await this.deps.transport.sendTypingIndicator(peerPubkey);
|
|
7496
|
+
}
|
|
7497
|
+
}
|
|
7457
7498
|
/**
|
|
7458
7499
|
* Subscribe to incoming DMs
|
|
7459
7500
|
*/
|
|
@@ -7523,7 +7564,26 @@ var CommunicationsModule = class {
|
|
|
7523
7564
|
// Private: Message Handling
|
|
7524
7565
|
// ===========================================================================
|
|
7525
7566
|
handleIncomingMessage(msg) {
|
|
7567
|
+
if (msg.isSelfWrap && msg.recipientTransportPubkey) {
|
|
7568
|
+
if (this.messages.has(msg.id)) return;
|
|
7569
|
+
const message2 = {
|
|
7570
|
+
id: msg.id,
|
|
7571
|
+
senderPubkey: this.deps.identity.chainPubkey,
|
|
7572
|
+
senderNametag: msg.senderNametag,
|
|
7573
|
+
recipientPubkey: msg.recipientTransportPubkey,
|
|
7574
|
+
content: msg.content,
|
|
7575
|
+
timestamp: msg.timestamp,
|
|
7576
|
+
isRead: false
|
|
7577
|
+
};
|
|
7578
|
+
this.messages.set(message2.id, message2);
|
|
7579
|
+
this.deps.emitEvent("message:dm", message2);
|
|
7580
|
+
if (this.config.autoSave) {
|
|
7581
|
+
this.save();
|
|
7582
|
+
}
|
|
7583
|
+
return;
|
|
7584
|
+
}
|
|
7526
7585
|
if (msg.senderTransportPubkey === this.deps?.identity.chainPubkey) return;
|
|
7586
|
+
if (this.messages.has(msg.id)) return;
|
|
7527
7587
|
const message = {
|
|
7528
7588
|
id: msg.id,
|
|
7529
7589
|
senderPubkey: msg.senderTransportPubkey,
|