@unicitylabs/sphere-sdk 0.4.4 → 0.4.5
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/connect/index.cjs +10 -10
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +10 -10
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +55 -25
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +6 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +55 -25
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +10 -10
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +10 -10
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +10 -10
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +10 -10
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +10 -10
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +10 -10
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +10 -10
- package/dist/impl/nodejs/connect/index.cjs.map +1 -1
- package/dist/impl/nodejs/connect/index.js +10 -10
- package/dist/impl/nodejs/connect/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +10 -10
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.js +10 -10
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +55 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -18
- package/dist/index.d.ts +24 -18
- package/dist/index.js +55 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3266,6 +3266,7 @@ declare class CommunicationsModule {
|
|
|
3266
3266
|
private dmHandlers;
|
|
3267
3267
|
private composingHandlers;
|
|
3268
3268
|
private broadcastHandlers;
|
|
3269
|
+
private initializedAt;
|
|
3269
3270
|
constructor(config?: CommunicationsModuleConfig);
|
|
3270
3271
|
/**
|
|
3271
3272
|
* Initialize module with dependencies
|
|
@@ -3394,6 +3395,11 @@ declare class GroupChatModule {
|
|
|
3394
3395
|
private destroyConnection;
|
|
3395
3396
|
connect(): Promise<void>;
|
|
3396
3397
|
getConnectionStatus(): boolean;
|
|
3398
|
+
/**
|
|
3399
|
+
* Refresh subscriptions after load() switched to a different address.
|
|
3400
|
+
* Clears old subscriptions, restores groups if needed, and re-subscribes.
|
|
3401
|
+
*/
|
|
3402
|
+
private refreshSubscriptions;
|
|
3397
3403
|
private doConnect;
|
|
3398
3404
|
private scheduleReconnect;
|
|
3399
3405
|
private subscribeToJoinedGroups;
|
|
@@ -3661,15 +3667,7 @@ declare const STORAGE_KEYS_GLOBAL: {
|
|
|
3661
3667
|
readonly TRACKED_ADDRESSES: "tracked_addresses";
|
|
3662
3668
|
/** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
|
|
3663
3669
|
readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
|
|
3664
|
-
/** Group chat:
|
|
3665
|
-
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3666
|
-
/** Group chat: messages */
|
|
3667
|
-
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3668
|
-
/** Group chat: members */
|
|
3669
|
-
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3670
|
-
/** Group chat: processed event IDs for deduplication */
|
|
3671
|
-
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3672
|
-
/** Group chat: last used relay URL (stale data detection) */
|
|
3670
|
+
/** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
|
|
3673
3671
|
readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
|
|
3674
3672
|
/** Cached token registry JSON (fetched from remote) */
|
|
3675
3673
|
readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
|
|
@@ -3701,6 +3699,14 @@ declare const STORAGE_KEYS_ADDRESS: {
|
|
|
3701
3699
|
readonly TRANSACTION_HISTORY: "transaction_history";
|
|
3702
3700
|
/** Pending V5 finalization tokens (unconfirmed instant split tokens) */
|
|
3703
3701
|
readonly PENDING_V5_TOKENS: "pending_v5_tokens";
|
|
3702
|
+
/** Group chat: joined groups for this address */
|
|
3703
|
+
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3704
|
+
/** Group chat: messages for this address */
|
|
3705
|
+
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3706
|
+
/** Group chat: members for this address */
|
|
3707
|
+
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3708
|
+
/** Group chat: processed event IDs for deduplication */
|
|
3709
|
+
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3704
3710
|
};
|
|
3705
3711
|
/** @deprecated Use STORAGE_KEYS_GLOBAL and STORAGE_KEYS_ADDRESS instead */
|
|
3706
3712
|
declare const STORAGE_KEYS: {
|
|
@@ -3716,6 +3722,14 @@ declare const STORAGE_KEYS: {
|
|
|
3716
3722
|
readonly TRANSACTION_HISTORY: "transaction_history";
|
|
3717
3723
|
/** Pending V5 finalization tokens (unconfirmed instant split tokens) */
|
|
3718
3724
|
readonly PENDING_V5_TOKENS: "pending_v5_tokens";
|
|
3725
|
+
/** Group chat: joined groups for this address */
|
|
3726
|
+
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3727
|
+
/** Group chat: messages for this address */
|
|
3728
|
+
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3729
|
+
/** Group chat: members for this address */
|
|
3730
|
+
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3731
|
+
/** Group chat: processed event IDs for deduplication */
|
|
3732
|
+
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3719
3733
|
/** Encrypted BIP39 mnemonic */
|
|
3720
3734
|
readonly MNEMONIC: "mnemonic";
|
|
3721
3735
|
/** Encrypted master private key */
|
|
@@ -3740,15 +3754,7 @@ declare const STORAGE_KEYS: {
|
|
|
3740
3754
|
readonly TRACKED_ADDRESSES: "tracked_addresses";
|
|
3741
3755
|
/** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
|
|
3742
3756
|
readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
|
|
3743
|
-
/** Group chat:
|
|
3744
|
-
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3745
|
-
/** Group chat: messages */
|
|
3746
|
-
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3747
|
-
/** Group chat: members */
|
|
3748
|
-
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3749
|
-
/** Group chat: processed event IDs for deduplication */
|
|
3750
|
-
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3751
|
-
/** Group chat: last used relay URL (stale data detection) */
|
|
3757
|
+
/** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
|
|
3752
3758
|
readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
|
|
3753
3759
|
/** Cached token registry JSON (fetched from remote) */
|
|
3754
3760
|
readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
|
package/dist/index.d.ts
CHANGED
|
@@ -3266,6 +3266,7 @@ declare class CommunicationsModule {
|
|
|
3266
3266
|
private dmHandlers;
|
|
3267
3267
|
private composingHandlers;
|
|
3268
3268
|
private broadcastHandlers;
|
|
3269
|
+
private initializedAt;
|
|
3269
3270
|
constructor(config?: CommunicationsModuleConfig);
|
|
3270
3271
|
/**
|
|
3271
3272
|
* Initialize module with dependencies
|
|
@@ -3394,6 +3395,11 @@ declare class GroupChatModule {
|
|
|
3394
3395
|
private destroyConnection;
|
|
3395
3396
|
connect(): Promise<void>;
|
|
3396
3397
|
getConnectionStatus(): boolean;
|
|
3398
|
+
/**
|
|
3399
|
+
* Refresh subscriptions after load() switched to a different address.
|
|
3400
|
+
* Clears old subscriptions, restores groups if needed, and re-subscribes.
|
|
3401
|
+
*/
|
|
3402
|
+
private refreshSubscriptions;
|
|
3397
3403
|
private doConnect;
|
|
3398
3404
|
private scheduleReconnect;
|
|
3399
3405
|
private subscribeToJoinedGroups;
|
|
@@ -3661,15 +3667,7 @@ declare const STORAGE_KEYS_GLOBAL: {
|
|
|
3661
3667
|
readonly TRACKED_ADDRESSES: "tracked_addresses";
|
|
3662
3668
|
/** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
|
|
3663
3669
|
readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
|
|
3664
|
-
/** Group chat:
|
|
3665
|
-
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3666
|
-
/** Group chat: messages */
|
|
3667
|
-
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3668
|
-
/** Group chat: members */
|
|
3669
|
-
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3670
|
-
/** Group chat: processed event IDs for deduplication */
|
|
3671
|
-
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3672
|
-
/** Group chat: last used relay URL (stale data detection) */
|
|
3670
|
+
/** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
|
|
3673
3671
|
readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
|
|
3674
3672
|
/** Cached token registry JSON (fetched from remote) */
|
|
3675
3673
|
readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
|
|
@@ -3701,6 +3699,14 @@ declare const STORAGE_KEYS_ADDRESS: {
|
|
|
3701
3699
|
readonly TRANSACTION_HISTORY: "transaction_history";
|
|
3702
3700
|
/** Pending V5 finalization tokens (unconfirmed instant split tokens) */
|
|
3703
3701
|
readonly PENDING_V5_TOKENS: "pending_v5_tokens";
|
|
3702
|
+
/** Group chat: joined groups for this address */
|
|
3703
|
+
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3704
|
+
/** Group chat: messages for this address */
|
|
3705
|
+
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3706
|
+
/** Group chat: members for this address */
|
|
3707
|
+
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3708
|
+
/** Group chat: processed event IDs for deduplication */
|
|
3709
|
+
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3704
3710
|
};
|
|
3705
3711
|
/** @deprecated Use STORAGE_KEYS_GLOBAL and STORAGE_KEYS_ADDRESS instead */
|
|
3706
3712
|
declare const STORAGE_KEYS: {
|
|
@@ -3716,6 +3722,14 @@ declare const STORAGE_KEYS: {
|
|
|
3716
3722
|
readonly TRANSACTION_HISTORY: "transaction_history";
|
|
3717
3723
|
/** Pending V5 finalization tokens (unconfirmed instant split tokens) */
|
|
3718
3724
|
readonly PENDING_V5_TOKENS: "pending_v5_tokens";
|
|
3725
|
+
/** Group chat: joined groups for this address */
|
|
3726
|
+
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3727
|
+
/** Group chat: messages for this address */
|
|
3728
|
+
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3729
|
+
/** Group chat: members for this address */
|
|
3730
|
+
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3731
|
+
/** Group chat: processed event IDs for deduplication */
|
|
3732
|
+
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3719
3733
|
/** Encrypted BIP39 mnemonic */
|
|
3720
3734
|
readonly MNEMONIC: "mnemonic";
|
|
3721
3735
|
/** Encrypted master private key */
|
|
@@ -3740,15 +3754,7 @@ declare const STORAGE_KEYS: {
|
|
|
3740
3754
|
readonly TRACKED_ADDRESSES: "tracked_addresses";
|
|
3741
3755
|
/** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
|
|
3742
3756
|
readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
|
|
3743
|
-
/** Group chat:
|
|
3744
|
-
readonly GROUP_CHAT_GROUPS: "group_chat_groups";
|
|
3745
|
-
/** Group chat: messages */
|
|
3746
|
-
readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
|
|
3747
|
-
/** Group chat: members */
|
|
3748
|
-
readonly GROUP_CHAT_MEMBERS: "group_chat_members";
|
|
3749
|
-
/** Group chat: processed event IDs for deduplication */
|
|
3750
|
-
readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
|
|
3751
|
-
/** Group chat: last used relay URL (stale data detection) */
|
|
3757
|
+
/** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
|
|
3752
3758
|
readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
|
|
3753
3759
|
/** Cached token registry JSON (fetched from remote) */
|
|
3754
3760
|
readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
|
package/dist/index.js
CHANGED
|
@@ -2503,15 +2503,7 @@ var STORAGE_KEYS_GLOBAL = {
|
|
|
2503
2503
|
TRACKED_ADDRESSES: "tracked_addresses",
|
|
2504
2504
|
/** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
|
|
2505
2505
|
LAST_WALLET_EVENT_TS: "last_wallet_event_ts",
|
|
2506
|
-
/** Group chat:
|
|
2507
|
-
GROUP_CHAT_GROUPS: "group_chat_groups",
|
|
2508
|
-
/** Group chat: messages */
|
|
2509
|
-
GROUP_CHAT_MESSAGES: "group_chat_messages",
|
|
2510
|
-
/** Group chat: members */
|
|
2511
|
-
GROUP_CHAT_MEMBERS: "group_chat_members",
|
|
2512
|
-
/** Group chat: processed event IDs for deduplication */
|
|
2513
|
-
GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events",
|
|
2514
|
-
/** Group chat: last used relay URL (stale data detection) */
|
|
2506
|
+
/** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
|
|
2515
2507
|
GROUP_CHAT_RELAY_URL: "group_chat_relay_url",
|
|
2516
2508
|
/** Cached token registry JSON (fetched from remote) */
|
|
2517
2509
|
TOKEN_REGISTRY_CACHE: "token_registry_cache",
|
|
@@ -2534,7 +2526,15 @@ var STORAGE_KEYS_ADDRESS = {
|
|
|
2534
2526
|
/** Transaction history for this address */
|
|
2535
2527
|
TRANSACTION_HISTORY: "transaction_history",
|
|
2536
2528
|
/** Pending V5 finalization tokens (unconfirmed instant split tokens) */
|
|
2537
|
-
PENDING_V5_TOKENS: "pending_v5_tokens"
|
|
2529
|
+
PENDING_V5_TOKENS: "pending_v5_tokens",
|
|
2530
|
+
/** Group chat: joined groups for this address */
|
|
2531
|
+
GROUP_CHAT_GROUPS: "group_chat_groups",
|
|
2532
|
+
/** Group chat: messages for this address */
|
|
2533
|
+
GROUP_CHAT_MESSAGES: "group_chat_messages",
|
|
2534
|
+
/** Group chat: members for this address */
|
|
2535
|
+
GROUP_CHAT_MEMBERS: "group_chat_members",
|
|
2536
|
+
/** Group chat: processed event IDs for deduplication */
|
|
2537
|
+
GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events"
|
|
2538
2538
|
};
|
|
2539
2539
|
var STORAGE_KEYS = {
|
|
2540
2540
|
...STORAGE_KEYS_GLOBAL,
|
|
@@ -7645,6 +7645,8 @@ var CommunicationsModule = class {
|
|
|
7645
7645
|
dmHandlers = /* @__PURE__ */ new Set();
|
|
7646
7646
|
composingHandlers = /* @__PURE__ */ new Set();
|
|
7647
7647
|
broadcastHandlers = /* @__PURE__ */ new Set();
|
|
7648
|
+
// Timestamp of module initialization — messages older than this are historical
|
|
7649
|
+
initializedAt = 0;
|
|
7648
7650
|
constructor(config) {
|
|
7649
7651
|
this.config = {
|
|
7650
7652
|
autoSave: config?.autoSave ?? true,
|
|
@@ -7663,6 +7665,7 @@ var CommunicationsModule = class {
|
|
|
7663
7665
|
this.unsubscribeMessages?.();
|
|
7664
7666
|
this.unsubscribeComposing?.();
|
|
7665
7667
|
this.deps = deps;
|
|
7668
|
+
this.initializedAt = Date.now();
|
|
7666
7669
|
this.unsubscribeMessages = deps.transport.onMessage((msg) => {
|
|
7667
7670
|
this.handleIncomingMessage(msg);
|
|
7668
7671
|
});
|
|
@@ -7954,6 +7957,7 @@ var CommunicationsModule = class {
|
|
|
7954
7957
|
// Private: Message Handling
|
|
7955
7958
|
// ===========================================================================
|
|
7956
7959
|
handleIncomingMessage(msg) {
|
|
7960
|
+
const isHistorical = msg.timestamp < this.initializedAt;
|
|
7957
7961
|
if (msg.isSelfWrap && msg.recipientTransportPubkey) {
|
|
7958
7962
|
if (this.messages.has(msg.id)) return;
|
|
7959
7963
|
const message2 = {
|
|
@@ -7963,7 +7967,7 @@ var CommunicationsModule = class {
|
|
|
7963
7967
|
recipientPubkey: msg.recipientTransportPubkey,
|
|
7964
7968
|
content: msg.content,
|
|
7965
7969
|
timestamp: msg.timestamp,
|
|
7966
|
-
isRead:
|
|
7970
|
+
isRead: isHistorical
|
|
7967
7971
|
};
|
|
7968
7972
|
this.messages.set(message2.id, message2);
|
|
7969
7973
|
this.deps.emitEvent("message:dm", message2);
|
|
@@ -7981,7 +7985,7 @@ var CommunicationsModule = class {
|
|
|
7981
7985
|
recipientPubkey: this.deps.identity.chainPubkey,
|
|
7982
7986
|
content: msg.content,
|
|
7983
7987
|
timestamp: msg.timestamp,
|
|
7984
|
-
isRead:
|
|
7988
|
+
isRead: isHistorical
|
|
7985
7989
|
};
|
|
7986
7990
|
this.messages.set(message.id, message);
|
|
7987
7991
|
this.deps.emitEvent("message:dm", message);
|
|
@@ -8157,22 +8161,24 @@ var GroupChatModule = class {
|
|
|
8157
8161
|
async load() {
|
|
8158
8162
|
this.ensureInitialized();
|
|
8159
8163
|
const storage = this.deps.storage;
|
|
8160
|
-
|
|
8164
|
+
this.groups.clear();
|
|
8165
|
+
this.messages.clear();
|
|
8166
|
+
this.members.clear();
|
|
8167
|
+
this.processedEventIds.clear();
|
|
8168
|
+
const groupsJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_GROUPS);
|
|
8161
8169
|
if (groupsJson) {
|
|
8162
8170
|
try {
|
|
8163
8171
|
const parsed = JSON.parse(groupsJson);
|
|
8164
|
-
this.groups.clear();
|
|
8165
8172
|
for (const g of parsed) {
|
|
8166
8173
|
this.groups.set(g.id, g);
|
|
8167
8174
|
}
|
|
8168
8175
|
} catch {
|
|
8169
8176
|
}
|
|
8170
8177
|
}
|
|
8171
|
-
const messagesJson = await storage.get(
|
|
8178
|
+
const messagesJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MESSAGES);
|
|
8172
8179
|
if (messagesJson) {
|
|
8173
8180
|
try {
|
|
8174
8181
|
const parsed = JSON.parse(messagesJson);
|
|
8175
|
-
this.messages.clear();
|
|
8176
8182
|
for (const m of parsed) {
|
|
8177
8183
|
const groupId = m.groupId;
|
|
8178
8184
|
if (!this.messages.has(groupId)) {
|
|
@@ -8183,11 +8189,10 @@ var GroupChatModule = class {
|
|
|
8183
8189
|
} catch {
|
|
8184
8190
|
}
|
|
8185
8191
|
}
|
|
8186
|
-
const membersJson = await storage.get(
|
|
8192
|
+
const membersJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MEMBERS);
|
|
8187
8193
|
if (membersJson) {
|
|
8188
8194
|
try {
|
|
8189
8195
|
const parsed = JSON.parse(membersJson);
|
|
8190
|
-
this.members.clear();
|
|
8191
8196
|
for (const m of parsed) {
|
|
8192
8197
|
const groupId = m.groupId;
|
|
8193
8198
|
if (!this.members.has(groupId)) {
|
|
@@ -8198,7 +8203,7 @@ var GroupChatModule = class {
|
|
|
8198
8203
|
} catch {
|
|
8199
8204
|
}
|
|
8200
8205
|
}
|
|
8201
|
-
const processedJson = await storage.get(
|
|
8206
|
+
const processedJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_PROCESSED_EVENTS);
|
|
8202
8207
|
if (processedJson) {
|
|
8203
8208
|
try {
|
|
8204
8209
|
const parsed = JSON.parse(processedJson);
|
|
@@ -8252,7 +8257,10 @@ var GroupChatModule = class {
|
|
|
8252
8257
|
// Connection
|
|
8253
8258
|
// ===========================================================================
|
|
8254
8259
|
async connect() {
|
|
8255
|
-
if (this.connected)
|
|
8260
|
+
if (this.connected) {
|
|
8261
|
+
await this.refreshSubscriptions();
|
|
8262
|
+
return;
|
|
8263
|
+
}
|
|
8256
8264
|
if (this.connectPromise) {
|
|
8257
8265
|
return this.connectPromise;
|
|
8258
8266
|
}
|
|
@@ -8266,6 +8274,28 @@ var GroupChatModule = class {
|
|
|
8266
8274
|
getConnectionStatus() {
|
|
8267
8275
|
return this.connected;
|
|
8268
8276
|
}
|
|
8277
|
+
/**
|
|
8278
|
+
* Refresh subscriptions after load() switched to a different address.
|
|
8279
|
+
* Clears old subscriptions, restores groups if needed, and re-subscribes.
|
|
8280
|
+
*/
|
|
8281
|
+
async refreshSubscriptions() {
|
|
8282
|
+
if (!this.client) return;
|
|
8283
|
+
for (const subId of this.subscriptionIds) {
|
|
8284
|
+
try {
|
|
8285
|
+
this.client.unsubscribe(subId);
|
|
8286
|
+
} catch {
|
|
8287
|
+
}
|
|
8288
|
+
}
|
|
8289
|
+
this.subscriptionIds = [];
|
|
8290
|
+
const secretKey = Buffer.from(this.deps.identity.privateKey, "hex");
|
|
8291
|
+
this.keyManager = NostrKeyManager.fromPrivateKey(secretKey);
|
|
8292
|
+
if (this.groups.size === 0) {
|
|
8293
|
+
await this.restoreJoinedGroups();
|
|
8294
|
+
} else {
|
|
8295
|
+
await this.subscribeToJoinedGroups();
|
|
8296
|
+
}
|
|
8297
|
+
this.deps.emitEvent("groupchat:connection", { connected: true });
|
|
8298
|
+
}
|
|
8269
8299
|
async doConnect() {
|
|
8270
8300
|
this.ensureInitialized();
|
|
8271
8301
|
if (!this.keyManager) {
|
|
@@ -8281,12 +8311,12 @@ var GroupChatModule = class {
|
|
|
8281
8311
|
await this.client.connect(...this.config.relays);
|
|
8282
8312
|
this.connected = true;
|
|
8283
8313
|
this.reconnectAttempts = 0;
|
|
8284
|
-
this.deps.emitEvent("groupchat:connection", { connected: true });
|
|
8285
8314
|
if (this.groups.size === 0) {
|
|
8286
8315
|
await this.restoreJoinedGroups();
|
|
8287
8316
|
} else {
|
|
8288
8317
|
await this.subscribeToJoinedGroups();
|
|
8289
8318
|
}
|
|
8319
|
+
this.deps.emitEvent("groupchat:connection", { connected: true });
|
|
8290
8320
|
} catch (error) {
|
|
8291
8321
|
console.error("[GroupChat] Failed to connect to relays", error);
|
|
8292
8322
|
this.deps.emitEvent("groupchat:connection", { connected: false });
|
|
@@ -9269,7 +9299,7 @@ var GroupChatModule = class {
|
|
|
9269
9299
|
async persistGroups() {
|
|
9270
9300
|
if (!this.deps) return;
|
|
9271
9301
|
const data = Array.from(this.groups.values());
|
|
9272
|
-
await this.deps.storage.set(
|
|
9302
|
+
await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_GROUPS, JSON.stringify(data));
|
|
9273
9303
|
}
|
|
9274
9304
|
async persistMessages() {
|
|
9275
9305
|
if (!this.deps) return;
|
|
@@ -9277,7 +9307,7 @@ var GroupChatModule = class {
|
|
|
9277
9307
|
for (const msgs of this.messages.values()) {
|
|
9278
9308
|
allMessages.push(...msgs);
|
|
9279
9309
|
}
|
|
9280
|
-
await this.deps.storage.set(
|
|
9310
|
+
await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MESSAGES, JSON.stringify(allMessages));
|
|
9281
9311
|
}
|
|
9282
9312
|
async persistMembers() {
|
|
9283
9313
|
if (!this.deps) return;
|
|
@@ -9285,12 +9315,12 @@ var GroupChatModule = class {
|
|
|
9285
9315
|
for (const mems of this.members.values()) {
|
|
9286
9316
|
allMembers.push(...mems);
|
|
9287
9317
|
}
|
|
9288
|
-
await this.deps.storage.set(
|
|
9318
|
+
await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MEMBERS, JSON.stringify(allMembers));
|
|
9289
9319
|
}
|
|
9290
9320
|
async persistProcessedEvents() {
|
|
9291
9321
|
if (!this.deps) return;
|
|
9292
9322
|
const arr = Array.from(this.processedEventIds);
|
|
9293
|
-
await this.deps.storage.set(
|
|
9323
|
+
await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_PROCESSED_EVENTS, JSON.stringify(arr));
|
|
9294
9324
|
}
|
|
9295
9325
|
// ===========================================================================
|
|
9296
9326
|
// Private — Relay URL Change Detection
|