@unicitylabs/sphere-sdk 0.6.10-dev.3 → 0.6.10-dev.4
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 +44 -62
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +44 -62
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +2 -2
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +2 -2
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +2 -2
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.js +2 -2
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +44 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +44 -62
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3679,7 +3679,7 @@ declare class GroupChatModule {
|
|
|
3679
3679
|
constructor(config?: GroupChatModuleConfig);
|
|
3680
3680
|
initialize(deps: GroupChatModuleDependencies): void;
|
|
3681
3681
|
load(): Promise<void>;
|
|
3682
|
-
destroy():
|
|
3682
|
+
destroy(): void;
|
|
3683
3683
|
private destroyConnection;
|
|
3684
3684
|
connect(): Promise<void>;
|
|
3685
3685
|
getConnectionStatus(): boolean;
|
|
@@ -3740,7 +3740,7 @@ declare class GroupChatModule {
|
|
|
3740
3740
|
* or 0 if no messages exist. Used to set `since` on subscriptions so the relay
|
|
3741
3741
|
* only sends events we don't already have.
|
|
3742
3742
|
*/
|
|
3743
|
-
private
|
|
3743
|
+
private getLatestMessageTimestamp;
|
|
3744
3744
|
private fetchRelayAdmins;
|
|
3745
3745
|
private doFetchRelayAdmins;
|
|
3746
3746
|
private fetchGroupMetadataInternal;
|
package/dist/index.d.ts
CHANGED
|
@@ -3679,7 +3679,7 @@ declare class GroupChatModule {
|
|
|
3679
3679
|
constructor(config?: GroupChatModuleConfig);
|
|
3680
3680
|
initialize(deps: GroupChatModuleDependencies): void;
|
|
3681
3681
|
load(): Promise<void>;
|
|
3682
|
-
destroy():
|
|
3682
|
+
destroy(): void;
|
|
3683
3683
|
private destroyConnection;
|
|
3684
3684
|
connect(): Promise<void>;
|
|
3685
3685
|
getConnectionStatus(): boolean;
|
|
@@ -3740,7 +3740,7 @@ declare class GroupChatModule {
|
|
|
3740
3740
|
* or 0 if no messages exist. Used to set `since` on subscriptions so the relay
|
|
3741
3741
|
* only sends events we don't already have.
|
|
3742
3742
|
*/
|
|
3743
|
-
private
|
|
3743
|
+
private getLatestMessageTimestamp;
|
|
3744
3744
|
private fetchRelayAdmins;
|
|
3745
3745
|
private doFetchRelayAdmins;
|
|
3746
3746
|
private fetchGroupMetadataInternal;
|
package/dist/index.js
CHANGED
|
@@ -2461,9 +2461,9 @@ var NostrTransportProvider = class _NostrTransportProvider {
|
|
|
2461
2461
|
if (subId) {
|
|
2462
2462
|
this.nostrClient?.unsubscribe(subId);
|
|
2463
2463
|
}
|
|
2464
|
-
logger.warn("Nostr", `queryEvents timed out after
|
|
2464
|
+
logger.warn("Nostr", `queryEvents timed out after 5s, returning ${events.length} event(s)`, { kinds: filterObj.kinds, limit: filterObj.limit });
|
|
2465
2465
|
resolve(events);
|
|
2466
|
-
},
|
|
2466
|
+
}, 5e3);
|
|
2467
2467
|
const subId = this.nostrClient.subscribe(filter, {
|
|
2468
2468
|
onEvent: (event) => {
|
|
2469
2469
|
events.push({
|
|
@@ -12381,20 +12381,8 @@ var GroupChatModule = class {
|
|
|
12381
12381
|
}
|
|
12382
12382
|
}
|
|
12383
12383
|
}
|
|
12384
|
-
|
|
12384
|
+
destroy() {
|
|
12385
12385
|
this.destroyConnection();
|
|
12386
|
-
if (this.persistTimer) {
|
|
12387
|
-
clearTimeout(this.persistTimer);
|
|
12388
|
-
this.persistTimer = null;
|
|
12389
|
-
}
|
|
12390
|
-
if (this.deps) {
|
|
12391
|
-
try {
|
|
12392
|
-
if (this.persistPromise) await this.persistPromise;
|
|
12393
|
-
await this.doPersistAll();
|
|
12394
|
-
} catch (err) {
|
|
12395
|
-
logger.debug("GroupChat", "Persist on destroy failed", err);
|
|
12396
|
-
}
|
|
12397
|
-
}
|
|
12398
12386
|
this.groups.clear();
|
|
12399
12387
|
this.messages.clear();
|
|
12400
12388
|
this.members.clear();
|
|
@@ -12403,7 +12391,10 @@ var GroupChatModule = class {
|
|
|
12403
12391
|
this.messageHandlers.clear();
|
|
12404
12392
|
this.relayAdminPubkeys = null;
|
|
12405
12393
|
this.relayAdminFetchPromise = null;
|
|
12406
|
-
this.
|
|
12394
|
+
if (this.persistTimer) {
|
|
12395
|
+
clearTimeout(this.persistTimer);
|
|
12396
|
+
this.persistTimer = null;
|
|
12397
|
+
}
|
|
12407
12398
|
this.deps = null;
|
|
12408
12399
|
}
|
|
12409
12400
|
destroyConnection() {
|
|
@@ -12528,12 +12519,12 @@ var GroupChatModule = class {
|
|
|
12528
12519
|
if (!this.client) return;
|
|
12529
12520
|
const groupIds = Array.from(this.groups.keys());
|
|
12530
12521
|
if (groupIds.length === 0) return;
|
|
12531
|
-
const
|
|
12522
|
+
const latestTimestamp = this.getLatestMessageTimestamp(groupIds);
|
|
12532
12523
|
this.trackSubscription(
|
|
12533
12524
|
createNip29Filter({
|
|
12534
12525
|
kinds: [NIP29_KINDS.CHAT_MESSAGE, NIP29_KINDS.THREAD_ROOT, NIP29_KINDS.THREAD_REPLY],
|
|
12535
12526
|
"#h": groupIds,
|
|
12536
|
-
...
|
|
12527
|
+
...latestTimestamp ? { since: latestTimestamp } : {}
|
|
12537
12528
|
}),
|
|
12538
12529
|
{ onEvent: (event) => this.handleGroupEvent(event) }
|
|
12539
12530
|
);
|
|
@@ -12554,12 +12545,12 @@ var GroupChatModule = class {
|
|
|
12554
12545
|
}
|
|
12555
12546
|
subscribeToGroup(groupId) {
|
|
12556
12547
|
if (!this.client) return;
|
|
12557
|
-
const
|
|
12548
|
+
const latestTimestamp = this.getLatestMessageTimestamp([groupId]);
|
|
12558
12549
|
this.trackSubscription(
|
|
12559
12550
|
createNip29Filter({
|
|
12560
12551
|
kinds: [NIP29_KINDS.CHAT_MESSAGE, NIP29_KINDS.THREAD_ROOT, NIP29_KINDS.THREAD_REPLY],
|
|
12561
12552
|
"#h": [groupId],
|
|
12562
|
-
...
|
|
12553
|
+
...latestTimestamp ? { since: latestTimestamp } : {}
|
|
12563
12554
|
}),
|
|
12564
12555
|
{ onEvent: (event) => this.handleGroupEvent(event) }
|
|
12565
12556
|
);
|
|
@@ -12633,7 +12624,7 @@ var GroupChatModule = class {
|
|
|
12633
12624
|
}
|
|
12634
12625
|
group.updatedAt = event.created_at * 1e3;
|
|
12635
12626
|
this.groups.set(groupId, group);
|
|
12636
|
-
this.
|
|
12627
|
+
this.persistGroups();
|
|
12637
12628
|
} else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
|
|
12638
12629
|
this.updateMembersFromEvent(groupId, event);
|
|
12639
12630
|
} else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
|
|
@@ -12654,7 +12645,7 @@ var GroupChatModule = class {
|
|
|
12654
12645
|
}
|
|
12655
12646
|
}
|
|
12656
12647
|
this.deps.emitEvent("groupchat:updated", {});
|
|
12657
|
-
this.
|
|
12648
|
+
this.persistMessages();
|
|
12658
12649
|
} else if (event.kind === NIP29_KINDS.REMOVE_USER) {
|
|
12659
12650
|
if (this.processedEventIds.has(event.id)) return;
|
|
12660
12651
|
const eventTimestampMs = event.created_at * 1e3;
|
|
@@ -12715,7 +12706,7 @@ var GroupChatModule = class {
|
|
|
12715
12706
|
};
|
|
12716
12707
|
this.saveMemberToMemory(member);
|
|
12717
12708
|
}
|
|
12718
|
-
this.
|
|
12709
|
+
this.persistMembers();
|
|
12719
12710
|
}
|
|
12720
12711
|
updateAdminsFromEvent(groupId, event) {
|
|
12721
12712
|
const pTags = event.tags.filter((t) => t[0] === "p");
|
|
@@ -12735,7 +12726,7 @@ var GroupChatModule = class {
|
|
|
12735
12726
|
});
|
|
12736
12727
|
}
|
|
12737
12728
|
}
|
|
12738
|
-
this.
|
|
12729
|
+
this.persistMembers();
|
|
12739
12730
|
}
|
|
12740
12731
|
// ===========================================================================
|
|
12741
12732
|
// Group Membership Restoration
|
|
@@ -12746,11 +12737,13 @@ var GroupChatModule = class {
|
|
|
12746
12737
|
if (!myPubkey) return [];
|
|
12747
12738
|
const groupIdsWithMembership = /* @__PURE__ */ new Set();
|
|
12748
12739
|
await this.oneshotSubscription(
|
|
12749
|
-
|
|
12740
|
+
new Filter3({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
|
|
12750
12741
|
{
|
|
12751
12742
|
onEvent: (event) => {
|
|
12752
12743
|
const groupId = this.getGroupIdFromMetadataEvent(event);
|
|
12753
|
-
if (groupId)
|
|
12744
|
+
if (!groupId) return;
|
|
12745
|
+
const pTags = event.tags.filter((t) => t[0] === "p");
|
|
12746
|
+
if (pTags.some((tag) => tag[1] === myPubkey)) {
|
|
12754
12747
|
groupIdsWithMembership.add(groupId);
|
|
12755
12748
|
}
|
|
12756
12749
|
},
|
|
@@ -12762,24 +12755,22 @@ var GroupChatModule = class {
|
|
|
12762
12755
|
);
|
|
12763
12756
|
if (groupIdsWithMembership.size === 0) return [];
|
|
12764
12757
|
const restoredGroups = [];
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12771
|
-
|
|
12772
|
-
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
]);
|
|
12777
|
-
}
|
|
12778
|
-
} catch (error) {
|
|
12779
|
-
logger.warn("GroupChat", "Failed to restore group", groupId, error);
|
|
12758
|
+
for (const groupId of groupIdsWithMembership) {
|
|
12759
|
+
if (this.groups.has(groupId)) continue;
|
|
12760
|
+
try {
|
|
12761
|
+
const group = await this.fetchGroupMetadataInternal(groupId);
|
|
12762
|
+
if (group) {
|
|
12763
|
+
this.groups.set(groupId, group);
|
|
12764
|
+
restoredGroups.push(group);
|
|
12765
|
+
await Promise.all([
|
|
12766
|
+
this.fetchAndSaveMembers(groupId),
|
|
12767
|
+
this.fetchMessages(groupId)
|
|
12768
|
+
]);
|
|
12780
12769
|
}
|
|
12781
|
-
})
|
|
12782
|
-
|
|
12770
|
+
} catch (error) {
|
|
12771
|
+
logger.warn("GroupChat", "Failed to restore group", groupId, error);
|
|
12772
|
+
}
|
|
12773
|
+
}
|
|
12783
12774
|
if (restoredGroups.length > 0) {
|
|
12784
12775
|
await this.subscribeToJoinedGroups();
|
|
12785
12776
|
this.deps.emitEvent("groupchat:updated", {});
|
|
@@ -13165,7 +13156,7 @@ var GroupChatModule = class {
|
|
|
13165
13156
|
if (group && (group.unreadCount || 0) > 0) {
|
|
13166
13157
|
group.unreadCount = 0;
|
|
13167
13158
|
this.groups.set(groupId, group);
|
|
13168
|
-
this.
|
|
13159
|
+
this.persistGroups();
|
|
13169
13160
|
}
|
|
13170
13161
|
}
|
|
13171
13162
|
// ===========================================================================
|
|
@@ -13187,7 +13178,7 @@ var GroupChatModule = class {
|
|
|
13187
13178
|
if (eventId) {
|
|
13188
13179
|
this.removeMemberFromMemory(groupId, userPubkey);
|
|
13189
13180
|
this.deps.emitEvent("groupchat:updated", {});
|
|
13190
|
-
this.
|
|
13181
|
+
this.persistMembers();
|
|
13191
13182
|
return true;
|
|
13192
13183
|
}
|
|
13193
13184
|
return false;
|
|
@@ -13210,7 +13201,7 @@ var GroupChatModule = class {
|
|
|
13210
13201
|
if (eventId) {
|
|
13211
13202
|
this.deleteMessageFromMemory(groupId, messageId);
|
|
13212
13203
|
this.deps.emitEvent("groupchat:updated", {});
|
|
13213
|
-
this.
|
|
13204
|
+
this.persistMessages();
|
|
13214
13205
|
return true;
|
|
13215
13206
|
}
|
|
13216
13207
|
return false;
|
|
@@ -13290,19 +13281,13 @@ var GroupChatModule = class {
|
|
|
13290
13281
|
* or 0 if no messages exist. Used to set `since` on subscriptions so the relay
|
|
13291
13282
|
* only sends events we don't already have.
|
|
13292
13283
|
*/
|
|
13293
|
-
|
|
13284
|
+
getLatestMessageTimestamp(groupIds) {
|
|
13294
13285
|
let latest = 0;
|
|
13295
13286
|
for (const gid of groupIds) {
|
|
13296
13287
|
const msgs = this.messages.get(gid);
|
|
13297
|
-
if (msgs)
|
|
13298
|
-
|
|
13299
|
-
|
|
13300
|
-
if (ts > latest) latest = ts;
|
|
13301
|
-
}
|
|
13302
|
-
}
|
|
13303
|
-
const group = this.groups.get(gid);
|
|
13304
|
-
if (group) {
|
|
13305
|
-
const ts = Math.floor((group.updatedAt || group.createdAt) / 1e3);
|
|
13288
|
+
if (!msgs) continue;
|
|
13289
|
+
for (const m of msgs) {
|
|
13290
|
+
const ts = Math.floor(m.timestamp / 1e3);
|
|
13306
13291
|
if (ts > latest) latest = ts;
|
|
13307
13292
|
}
|
|
13308
13293
|
}
|
|
@@ -13377,7 +13362,7 @@ var GroupChatModule = class {
|
|
|
13377
13362
|
});
|
|
13378
13363
|
}
|
|
13379
13364
|
}
|
|
13380
|
-
this.
|
|
13365
|
+
this.persistMembers();
|
|
13381
13366
|
}
|
|
13382
13367
|
async fetchGroupMembersInternal(groupId) {
|
|
13383
13368
|
if (!this.client) return [];
|
|
@@ -13504,11 +13489,8 @@ var GroupChatModule = class {
|
|
|
13504
13489
|
addProcessedEventId(eventId) {
|
|
13505
13490
|
this.processedEventIds.add(eventId);
|
|
13506
13491
|
if (this.processedEventIds.size > 1e4) {
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
if (toDelete-- <= 0) break;
|
|
13510
|
-
this.processedEventIds.delete(id);
|
|
13511
|
-
}
|
|
13492
|
+
const arr = Array.from(this.processedEventIds);
|
|
13493
|
+
this.processedEventIds = new Set(arr.slice(arr.length - 1e4));
|
|
13512
13494
|
}
|
|
13513
13495
|
}
|
|
13514
13496
|
// ===========================================================================
|