diff --git a/dist/index.js b/dist/index.js index 04d12c0c..29134a2b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -641,11 +641,15 @@ function resetAddressInput() { serverAddressInput.value = currentAddress.value; } - UDN.onconnect = () => { - isConnected.value = true; + function subscribeChannels() { chats.value.forEach((chat) => { UDN.subscribe(chat.primaryChannel.value); }); + } + UDN.onconnect = () => { + isConnected.value = true; + subscribeChannels(); + if (mailboxId.value != "") UDN.connectMailbox(mailboxId.value); }; UDN.onmessage = (data) => { chats.value.forEach((chat) => { @@ -683,6 +687,7 @@ UDN.onmailboxdelete = () => { isMailboxActive.value = false; mailboxId.value = ""; + subscribeChannels(); }; var isEncryptionAvailable = window.crypto.subtle != void 0; var senderName = restoreState("sender-name", ""); diff --git a/src/Model/model.ts b/src/Model/model.ts index 45db37a6..56cba749 100644 --- a/src/Model/model.ts +++ b/src/Model/model.ts @@ -56,13 +56,17 @@ export function resetAddressInput(): void { serverAddressInput.value = currentAddress.value; } -// listeners -UDN.onconnect = () => { - isConnected.value = true; - +export function subscribeChannels() { chats.value.forEach((chat) => { UDN.subscribe(chat.primaryChannel.value); }); +} + +// listeners +UDN.onconnect = () => { + isConnected.value = true; + subscribeChannels(); + if (mailboxId.value != "") UDN.connectMailbox(mailboxId.value); }; UDN.onmessage = (data) => { @@ -115,6 +119,7 @@ UDN.onmailboxconnect = () => { UDN.onmailboxdelete = () => { isMailboxActive.value = false; mailboxId.value = ""; + subscribeChannels(); }; // MISC