@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.cjs
CHANGED
|
@@ -2612,9 +2612,9 @@ var NostrTransportProvider = class _NostrTransportProvider {
|
|
|
2612
2612
|
if (subId) {
|
|
2613
2613
|
this.nostrClient?.unsubscribe(subId);
|
|
2614
2614
|
}
|
|
2615
|
-
logger.warn("Nostr", `queryEvents timed out after
|
|
2615
|
+
logger.warn("Nostr", `queryEvents timed out after 5s, returning ${events.length} event(s)`, { kinds: filterObj.kinds, limit: filterObj.limit });
|
|
2616
2616
|
resolve(events);
|
|
2617
|
-
},
|
|
2617
|
+
}, 5e3);
|
|
2618
2618
|
const subId = this.nostrClient.subscribe(filter, {
|
|
2619
2619
|
onEvent: (event) => {
|
|
2620
2620
|
events.push({
|
|
@@ -12528,20 +12528,8 @@ var GroupChatModule = class {
|
|
|
12528
12528
|
}
|
|
12529
12529
|
}
|
|
12530
12530
|
}
|
|
12531
|
-
|
|
12531
|
+
destroy() {
|
|
12532
12532
|
this.destroyConnection();
|
|
12533
|
-
if (this.persistTimer) {
|
|
12534
|
-
clearTimeout(this.persistTimer);
|
|
12535
|
-
this.persistTimer = null;
|
|
12536
|
-
}
|
|
12537
|
-
if (this.deps) {
|
|
12538
|
-
try {
|
|
12539
|
-
if (this.persistPromise) await this.persistPromise;
|
|
12540
|
-
await this.doPersistAll();
|
|
12541
|
-
} catch (err) {
|
|
12542
|
-
logger.debug("GroupChat", "Persist on destroy failed", err);
|
|
12543
|
-
}
|
|
12544
|
-
}
|
|
12545
12533
|
this.groups.clear();
|
|
12546
12534
|
this.messages.clear();
|
|
12547
12535
|
this.members.clear();
|
|
@@ -12550,7 +12538,10 @@ var GroupChatModule = class {
|
|
|
12550
12538
|
this.messageHandlers.clear();
|
|
12551
12539
|
this.relayAdminPubkeys = null;
|
|
12552
12540
|
this.relayAdminFetchPromise = null;
|
|
12553
|
-
this.
|
|
12541
|
+
if (this.persistTimer) {
|
|
12542
|
+
clearTimeout(this.persistTimer);
|
|
12543
|
+
this.persistTimer = null;
|
|
12544
|
+
}
|
|
12554
12545
|
this.deps = null;
|
|
12555
12546
|
}
|
|
12556
12547
|
destroyConnection() {
|
|
@@ -12675,12 +12666,12 @@ var GroupChatModule = class {
|
|
|
12675
12666
|
if (!this.client) return;
|
|
12676
12667
|
const groupIds = Array.from(this.groups.keys());
|
|
12677
12668
|
if (groupIds.length === 0) return;
|
|
12678
|
-
const
|
|
12669
|
+
const latestTimestamp = this.getLatestMessageTimestamp(groupIds);
|
|
12679
12670
|
this.trackSubscription(
|
|
12680
12671
|
createNip29Filter({
|
|
12681
12672
|
kinds: [NIP29_KINDS.CHAT_MESSAGE, NIP29_KINDS.THREAD_ROOT, NIP29_KINDS.THREAD_REPLY],
|
|
12682
12673
|
"#h": groupIds,
|
|
12683
|
-
...
|
|
12674
|
+
...latestTimestamp ? { since: latestTimestamp } : {}
|
|
12684
12675
|
}),
|
|
12685
12676
|
{ onEvent: (event) => this.handleGroupEvent(event) }
|
|
12686
12677
|
);
|
|
@@ -12701,12 +12692,12 @@ var GroupChatModule = class {
|
|
|
12701
12692
|
}
|
|
12702
12693
|
subscribeToGroup(groupId) {
|
|
12703
12694
|
if (!this.client) return;
|
|
12704
|
-
const
|
|
12695
|
+
const latestTimestamp = this.getLatestMessageTimestamp([groupId]);
|
|
12705
12696
|
this.trackSubscription(
|
|
12706
12697
|
createNip29Filter({
|
|
12707
12698
|
kinds: [NIP29_KINDS.CHAT_MESSAGE, NIP29_KINDS.THREAD_ROOT, NIP29_KINDS.THREAD_REPLY],
|
|
12708
12699
|
"#h": [groupId],
|
|
12709
|
-
...
|
|
12700
|
+
...latestTimestamp ? { since: latestTimestamp } : {}
|
|
12710
12701
|
}),
|
|
12711
12702
|
{ onEvent: (event) => this.handleGroupEvent(event) }
|
|
12712
12703
|
);
|
|
@@ -12780,7 +12771,7 @@ var GroupChatModule = class {
|
|
|
12780
12771
|
}
|
|
12781
12772
|
group.updatedAt = event.created_at * 1e3;
|
|
12782
12773
|
this.groups.set(groupId, group);
|
|
12783
|
-
this.
|
|
12774
|
+
this.persistGroups();
|
|
12784
12775
|
} else if (event.kind === NIP29_KINDS.GROUP_MEMBERS) {
|
|
12785
12776
|
this.updateMembersFromEvent(groupId, event);
|
|
12786
12777
|
} else if (event.kind === NIP29_KINDS.GROUP_ADMINS) {
|
|
@@ -12801,7 +12792,7 @@ var GroupChatModule = class {
|
|
|
12801
12792
|
}
|
|
12802
12793
|
}
|
|
12803
12794
|
this.deps.emitEvent("groupchat:updated", {});
|
|
12804
|
-
this.
|
|
12795
|
+
this.persistMessages();
|
|
12805
12796
|
} else if (event.kind === NIP29_KINDS.REMOVE_USER) {
|
|
12806
12797
|
if (this.processedEventIds.has(event.id)) return;
|
|
12807
12798
|
const eventTimestampMs = event.created_at * 1e3;
|
|
@@ -12862,7 +12853,7 @@ var GroupChatModule = class {
|
|
|
12862
12853
|
};
|
|
12863
12854
|
this.saveMemberToMemory(member);
|
|
12864
12855
|
}
|
|
12865
|
-
this.
|
|
12856
|
+
this.persistMembers();
|
|
12866
12857
|
}
|
|
12867
12858
|
updateAdminsFromEvent(groupId, event) {
|
|
12868
12859
|
const pTags = event.tags.filter((t) => t[0] === "p");
|
|
@@ -12882,7 +12873,7 @@ var GroupChatModule = class {
|
|
|
12882
12873
|
});
|
|
12883
12874
|
}
|
|
12884
12875
|
}
|
|
12885
|
-
this.
|
|
12876
|
+
this.persistMembers();
|
|
12886
12877
|
}
|
|
12887
12878
|
// ===========================================================================
|
|
12888
12879
|
// Group Membership Restoration
|
|
@@ -12893,11 +12884,13 @@ var GroupChatModule = class {
|
|
|
12893
12884
|
if (!myPubkey) return [];
|
|
12894
12885
|
const groupIdsWithMembership = /* @__PURE__ */ new Set();
|
|
12895
12886
|
await this.oneshotSubscription(
|
|
12896
|
-
|
|
12887
|
+
new import_nostr_js_sdk4.Filter({ kinds: [NIP29_KINDS.GROUP_MEMBERS] }),
|
|
12897
12888
|
{
|
|
12898
12889
|
onEvent: (event) => {
|
|
12899
12890
|
const groupId = this.getGroupIdFromMetadataEvent(event);
|
|
12900
|
-
if (groupId)
|
|
12891
|
+
if (!groupId) return;
|
|
12892
|
+
const pTags = event.tags.filter((t) => t[0] === "p");
|
|
12893
|
+
if (pTags.some((tag) => tag[1] === myPubkey)) {
|
|
12901
12894
|
groupIdsWithMembership.add(groupId);
|
|
12902
12895
|
}
|
|
12903
12896
|
},
|
|
@@ -12909,24 +12902,22 @@ var GroupChatModule = class {
|
|
|
12909
12902
|
);
|
|
12910
12903
|
if (groupIdsWithMembership.size === 0) return [];
|
|
12911
12904
|
const restoredGroups = [];
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
]);
|
|
12924
|
-
}
|
|
12925
|
-
} catch (error) {
|
|
12926
|
-
logger.warn("GroupChat", "Failed to restore group", groupId, error);
|
|
12905
|
+
for (const groupId of groupIdsWithMembership) {
|
|
12906
|
+
if (this.groups.has(groupId)) continue;
|
|
12907
|
+
try {
|
|
12908
|
+
const group = await this.fetchGroupMetadataInternal(groupId);
|
|
12909
|
+
if (group) {
|
|
12910
|
+
this.groups.set(groupId, group);
|
|
12911
|
+
restoredGroups.push(group);
|
|
12912
|
+
await Promise.all([
|
|
12913
|
+
this.fetchAndSaveMembers(groupId),
|
|
12914
|
+
this.fetchMessages(groupId)
|
|
12915
|
+
]);
|
|
12927
12916
|
}
|
|
12928
|
-
})
|
|
12929
|
-
|
|
12917
|
+
} catch (error) {
|
|
12918
|
+
logger.warn("GroupChat", "Failed to restore group", groupId, error);
|
|
12919
|
+
}
|
|
12920
|
+
}
|
|
12930
12921
|
if (restoredGroups.length > 0) {
|
|
12931
12922
|
await this.subscribeToJoinedGroups();
|
|
12932
12923
|
this.deps.emitEvent("groupchat:updated", {});
|
|
@@ -13312,7 +13303,7 @@ var GroupChatModule = class {
|
|
|
13312
13303
|
if (group && (group.unreadCount || 0) > 0) {
|
|
13313
13304
|
group.unreadCount = 0;
|
|
13314
13305
|
this.groups.set(groupId, group);
|
|
13315
|
-
this.
|
|
13306
|
+
this.persistGroups();
|
|
13316
13307
|
}
|
|
13317
13308
|
}
|
|
13318
13309
|
// ===========================================================================
|
|
@@ -13334,7 +13325,7 @@ var GroupChatModule = class {
|
|
|
13334
13325
|
if (eventId) {
|
|
13335
13326
|
this.removeMemberFromMemory(groupId, userPubkey);
|
|
13336
13327
|
this.deps.emitEvent("groupchat:updated", {});
|
|
13337
|
-
this.
|
|
13328
|
+
this.persistMembers();
|
|
13338
13329
|
return true;
|
|
13339
13330
|
}
|
|
13340
13331
|
return false;
|
|
@@ -13357,7 +13348,7 @@ var GroupChatModule = class {
|
|
|
13357
13348
|
if (eventId) {
|
|
13358
13349
|
this.deleteMessageFromMemory(groupId, messageId);
|
|
13359
13350
|
this.deps.emitEvent("groupchat:updated", {});
|
|
13360
|
-
this.
|
|
13351
|
+
this.persistMessages();
|
|
13361
13352
|
return true;
|
|
13362
13353
|
}
|
|
13363
13354
|
return false;
|
|
@@ -13437,19 +13428,13 @@ var GroupChatModule = class {
|
|
|
13437
13428
|
* or 0 if no messages exist. Used to set `since` on subscriptions so the relay
|
|
13438
13429
|
* only sends events we don't already have.
|
|
13439
13430
|
*/
|
|
13440
|
-
|
|
13431
|
+
getLatestMessageTimestamp(groupIds) {
|
|
13441
13432
|
let latest = 0;
|
|
13442
13433
|
for (const gid of groupIds) {
|
|
13443
13434
|
const msgs = this.messages.get(gid);
|
|
13444
|
-
if (msgs)
|
|
13445
|
-
|
|
13446
|
-
|
|
13447
|
-
if (ts > latest) latest = ts;
|
|
13448
|
-
}
|
|
13449
|
-
}
|
|
13450
|
-
const group = this.groups.get(gid);
|
|
13451
|
-
if (group) {
|
|
13452
|
-
const ts = Math.floor((group.updatedAt || group.createdAt) / 1e3);
|
|
13435
|
+
if (!msgs) continue;
|
|
13436
|
+
for (const m of msgs) {
|
|
13437
|
+
const ts = Math.floor(m.timestamp / 1e3);
|
|
13453
13438
|
if (ts > latest) latest = ts;
|
|
13454
13439
|
}
|
|
13455
13440
|
}
|
|
@@ -13524,7 +13509,7 @@ var GroupChatModule = class {
|
|
|
13524
13509
|
});
|
|
13525
13510
|
}
|
|
13526
13511
|
}
|
|
13527
|
-
this.
|
|
13512
|
+
this.persistMembers();
|
|
13528
13513
|
}
|
|
13529
13514
|
async fetchGroupMembersInternal(groupId) {
|
|
13530
13515
|
if (!this.client) return [];
|
|
@@ -13651,11 +13636,8 @@ var GroupChatModule = class {
|
|
|
13651
13636
|
addProcessedEventId(eventId) {
|
|
13652
13637
|
this.processedEventIds.add(eventId);
|
|
13653
13638
|
if (this.processedEventIds.size > 1e4) {
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
if (toDelete-- <= 0) break;
|
|
13657
|
-
this.processedEventIds.delete(id);
|
|
13658
|
-
}
|
|
13639
|
+
const arr = Array.from(this.processedEventIds);
|
|
13640
|
+
this.processedEventIds = new Set(arr.slice(arr.length - 1e4));
|
|
13659
13641
|
}
|
|
13660
13642
|
}
|
|
13661
13643
|
// ===========================================================================
|