mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Fix open groups not being restored when restoring device from recovery phrase.
This commit is contained in:
parent
4ee51b4ee9
commit
5adca482bd
1 changed files with 31 additions and 22 deletions
|
@ -57,22 +57,18 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
) {
|
||||
const lastConfigUpdate = await getItemById(hasSyncedInitialConfigurationItem);
|
||||
const lastConfigTimestamp = lastConfigUpdate?.timestamp;
|
||||
const isNewerConfig = lastConfigTimestamp && lastConfigTimestamp < _.toNumber(envelope.timestamp);
|
||||
const isNewerConfig =
|
||||
!lastConfigTimestamp ||
|
||||
(lastConfigTimestamp && lastConfigTimestamp < _.toNumber(envelope.timestamp));
|
||||
|
||||
if (isNewerConfig) {
|
||||
window?.log?.info(
|
||||
'Dropping configuration groups change as we already handled one... Only handling contacts '
|
||||
);
|
||||
if (isNewerConfig) {
|
||||
if (configMessage.contacts?.length) {
|
||||
await Promise.all(
|
||||
configMessage.contacts.map(async c => handleContactReceived(c, envelope))
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!isNewerConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
window?.log?.info(
|
||||
'Dropping configuration groups change as we already handled one... Only handling contacts '
|
||||
);
|
||||
|
||||
await createOrUpdateItem({
|
||||
id: 'hasSyncedInitialConfigurationItem',
|
||||
value: true,
|
||||
|
@ -103,12 +99,22 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
})
|
||||
);
|
||||
|
||||
const numberOpenGroup = configMessage.openGroups?.length || 0;
|
||||
await handleOpenGroupsFromConfig(configMessage.openGroups);
|
||||
|
||||
// Trigger a join for all open groups we are not already in.
|
||||
// Currently, if you left an open group but kept the conversation, you won't rejoin it here.
|
||||
if (configMessage.contacts?.length) {
|
||||
await Promise.all(configMessage.contacts.map(async c => handleContactFromConfig(c, envelope)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a join for all open groups we are not already in.
|
||||
* Currently, if you left an open group but kept the conversation, you won't rejoin it here.
|
||||
* @param openGroups string array of open group urls
|
||||
*/
|
||||
const handleOpenGroupsFromConfig = async (openGroups: Array<string>) => {
|
||||
const numberOpenGroup = openGroups?.length || 0;
|
||||
for (let i = 0; i < numberOpenGroup; i++) {
|
||||
const currentOpenGroupUrl = configMessage.openGroups[i];
|
||||
const currentOpenGroupUrl = openGroups[i];
|
||||
const parsedRoom = parseOpenGroupV2(currentOpenGroupUrl);
|
||||
if (!parsedRoom) {
|
||||
continue;
|
||||
|
@ -121,12 +127,15 @@ async function handleGroupsAndContactsFromConfigMessage(
|
|||
void joinOpenGroupV2WithUIEvents(currentOpenGroupUrl, false, true);
|
||||
}
|
||||
}
|
||||
if (configMessage.contacts?.length && isNewerConfig) {
|
||||
await Promise.all(configMessage.contacts.map(async c => handleContactReceived(c, envelope)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleContactReceived = async (
|
||||
/**
|
||||
* Handles adding of a contact and setting approval/block status
|
||||
* @param contactReceived Contact to sync
|
||||
* @param envelope
|
||||
* @returns
|
||||
*/
|
||||
const handleContactFromConfig = async (
|
||||
contactReceived: SignalService.ConfigurationMessage.IContact,
|
||||
envelope: EnvelopePlus
|
||||
) => {
|
||||
|
|
Loading…
Reference in a new issue