diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index f07ea1946..bb1bfb9bc 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -1,4 +1,4 @@ -import { compact, flatten, identity, isEmpty, isFinite, pickBy, toNumber } from 'lodash'; +import { compact, flatten, isEmpty, isFinite, toNumber } from 'lodash'; import { handleSwarmDataMessage } from './dataMessage'; import { EnvelopePlus } from './types'; diff --git a/ts/session/utils/libsession/libsession_utils_contacts.ts b/ts/session/utils/libsession/libsession_utils_contacts.ts index 490c4517c..aed810baf 100644 --- a/ts/session/utils/libsession/libsession_utils_contacts.ts +++ b/ts/session/utils/libsession/libsession_utils_contacts.ts @@ -4,6 +4,7 @@ import { getContactInfoFromDBValues } from '../../../types/sqlSharedTypes'; import { ContactsWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface'; import { ConvoHub } from '../../conversations'; import { PubKey } from '../../types'; +import { CONVERSATION_PRIORITIES } from '../../../models/conversationAttributes'; /** * This file is centralizing the management of data from the Contacts Wrapper of libsession. @@ -53,17 +54,22 @@ async function insertContactFromDBIntoWrapperAndRefresh( if (!SessionUtilContact.isContactToStoreInWrapper(foundConvo)) { return null; } - + // Note: We NEED those to come from the convo itself as .get() calls directly + // and not from the isApproved(), didApproveMe() functions. + // + // The reason is that when we make a change, we need to save it to the DB to update the libsession state (on commit()). + // But, if we use isApproved() instead of .get('isApproved'), we get the value from libsession which is not up to date with a change made in the convo yet! const dbName = foundConvo.getRealSessionUsername() || undefined; - const dbNickname = foundConvo.getNickname(); - const dbProfileUrl = foundConvo.getAvatarPointer() || undefined; - const dbProfileKey = foundConvo.getProfileKey() || undefined; - const dbApproved = foundConvo.isApproved(); - const dbApprovedMe = foundConvo.didApproveMe(); + const dbNickname = foundConvo.get('nickname'); + const dbProfileUrl = foundConvo.get('avatarPointer') || undefined; + const dbProfileKey = foundConvo.get('profileKey') || undefined; + const dbApproved = !!foundConvo.get('isApproved'); + const dbApprovedMe = !!foundConvo.get('didApproveMe'); const dbBlocked = foundConvo.isBlocked(); - const priority = foundConvo.getPriority() || 0; - const expirationMode = foundConvo.getExpirationMode() || undefined; - const expireTimer = foundConvo.getExpireTimer() || 0; + const priority = foundConvo.get('priority') || CONVERSATION_PRIORITIES.default; + const expirationMode = foundConvo.get('expirationMode') || undefined; + const expireTimer = foundConvo.get('expireTimer') || 0; + const wrapperContact = getContactInfoFromDBValues({ id, diff --git a/ts/session/utils/libsession/libsession_utils_user_groups.ts b/ts/session/utils/libsession/libsession_utils_user_groups.ts index a8bd2f108..fd132d09f 100644 --- a/ts/session/utils/libsession/libsession_utils_user_groups.ts +++ b/ts/session/utils/libsession/libsession_utils_user_groups.ts @@ -12,6 +12,7 @@ import { import { UserGroupsWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface'; import { ConvoHub } from '../../conversations'; import { PubKey } from '../../types'; +import { CONVERSATION_PRIORITIES } from '../../../models/conversationAttributes'; /** * Returns true if that conversation is an active group @@ -38,7 +39,7 @@ function isLegacyGroupToStoreInWrapper(convo: ConversationModel): boolean { } function isGroupToStoreInWrapper(convo: ConversationModel): boolean { - return convo.isGroup() && PubKey.is03Pubkey(convo.id) && convo.isActive(); // debugger TODO should we filter by left/kicked or they are on the wrapper itself? + return convo.isGroup() && PubKey.is03Pubkey(convo.id) && convo.isActive(); } /** @@ -104,7 +105,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh( ); const wrapperComm = getCommunityInfoFromDBValues({ - priority: foundConvo.getPriority(), + priority: foundConvo.get('priority') || CONVERSATION_PRIORITIES.default, // this has to be a direct call to .get fullUrl, }); @@ -129,13 +130,15 @@ async function insertGroupsFromDBIntoWrapperAndRefresh( case 'LegacyGroup': const encryptionKeyPair = await Data.getLatestClosedGroupEncryptionKeyPair(convoId); + // Note: For any fields stored in both the DB and libsession, + // we have to make direct calls to.get() and NOT the wrapped getPriority(), etc... const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({ id: foundConvo.id, - priority: foundConvo.getPriority(), - members: foundConvo.getGroupMembers() || [], - groupAdmins: foundConvo.getGroupAdmins(), - expirationMode: foundConvo.getExpirationMode() || 'off', - expireTimer: foundConvo.getExpireTimer() || 0, + priority: foundConvo.get('priority') || CONVERSATION_PRIORITIES.default, + members: foundConvo.get('members') || [], + groupAdmins: foundConvo.getGroupAdmins(), // cannot be changed for legacy groups, so we don't care + expirationMode: foundConvo.get('expirationMode') || 'off', + expireTimer: foundConvo.get('expireTimer') || 0, displayNameInProfile: foundConvo.getRealSessionUsername(), encPubkeyHex: encryptionKeyPair?.publicHex || '', encSeckeyHex: encryptionKeyPair?.privateHex || '', @@ -171,7 +174,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh( name: null, // not updated except when we process an invite/create a group secretKey: null, // not updated except when we process an promote/create a group kicked: foundConvo.isKickedFromGroup() ?? null, - priority: foundConvo.getPriority() ?? null, + priority: foundConvo.getPriority() ?? null, // for 03 group, the priority is only tracked with libsession, so this is fine }; try { window.log.debug( diff --git a/ts/session/utils/libsession/libsession_utils_user_profile.ts b/ts/session/utils/libsession/libsession_utils_user_profile.ts index 56f3b212e..9875b1608 100644 --- a/ts/session/utils/libsession/libsession_utils_user_profile.ts +++ b/ts/session/utils/libsession/libsession_utils_user_profile.ts @@ -22,7 +22,7 @@ async function insertUserProfileIntoWrapper(convoId: string) { const dbName = ourConvo.getRealSessionUsername() || ''; const dbProfileUrl = ourConvo.getAvatarPointer() || ''; const dbProfileKey = fromHexToArray(ourConvo.getProfileKey() || ''); - const priority = ourConvo.getPriority() || CONVERSATION_PRIORITIES.default; + const priority = ourConvo.get('priority') || CONVERSATION_PRIORITIES.default; // this has to be a direct call to .get() and not getPriority() const areBlindedMsgRequestEnabled = !!Storage.get(SettingsKey.hasBlindedMsgRequestsEnabled);