feat: use details from GROUP_MEMBERS when we don't know him

pull/3052/head
Audric Ackermann 10 months ago
parent c4e9aab66c
commit a8c674c07a

@ -3,7 +3,7 @@ import { SignalService } from '../protobuf';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { TTL_DEFAULT } from '../session/constants';
import { CallManager, UserUtils } from '../session/utils';
import { WithOptExpireUpdate } from '../session/utils/calling/CallManager';
import { WithOptExpireUpdate } from '../session/utils/calling/CallManager';
import { IncomingMessageCache } from './cache';
import { EnvelopePlus } from './types';
import { WithMessageHash } from '../session/types/with';

@ -14,6 +14,7 @@ import { LibSessionUtil } from '../../../utils/libsession/libsession_utils';
import { SnodeNamespaces } from '../namespaces';
import { RetrieveMessageItemWithNamespace } from '../types';
import { ConvoHub } from '../../../conversations';
import { ProfileManager } from '../../../profile_manager/ProfileManager';
/**
* This is a basic optimization to avoid running the logic when the `deleteBeforeSeconds`
@ -127,6 +128,26 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
await convo.commit();
}
}
const members = await MetaGroupWrapperActions.memberGetAll(groupPk);
for (let index = 0; index < members.length; index++) {
const member = members[index];
// if our DB doesn't have details about this user, set them. Otherwise we don't want to overwrite our changes with those
// because they are most likely out of date from what we get from the user himself.
const memberConvo = ConvoHub.use().get(member.pubkeyHex);
if (!memberConvo) {
continue;
}
if (member.name && member.name !== memberConvo.getRealSessionUsername()) {
// eslint-disable-next-line no-await-in-loop
await ProfileManager.updateProfileOfContact(
member.pubkeyHex,
member.name,
member.profilePicture?.url || null,
member.profilePicture?.key || null
);
}
}
}
async function handleGroupSharedConfigMessages(

@ -1,4 +1 @@
export type WithMessageHash = { messageHash: string };
export type WithMessageHash = { messageHash: string };

@ -2,6 +2,7 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import { GroupPubkeyType, PubkeyType } from 'libsession_util_nodejs';
import { from_hex } from 'libsodium-wrappers-sumo';
import { compact, difference, isString, omit } from 'lodash';
import Long from 'long';
import { UserUtils } from '..';
@ -16,11 +17,11 @@ import {
GenericWrapperActions,
MetaGroupWrapperActions,
} from '../../../webworker/workers/browser/libsession_worker_interface';
import { SnodeNamespaces, SnodeNamespacesUserConfig } from '../../apis/snode_api/namespaces';
import {
BatchResultEntry,
NotEmptyArrayOfBatchResults,
} from '../../apis/snode_api/SnodeRequestTypes';
import { SnodeNamespaces, SnodeNamespacesUserConfig } from '../../apis/snode_api/namespaces';
import { PubKey } from '../../types';
import { UserSync } from '../job_runners/jobs/UserSyncJob';
import { ed25519Str } from '../String';
@ -387,6 +388,38 @@ async function saveDumpsToDb(pubkey: PubkeyType | GroupPubkeyType) {
}
}
/**
* Creates the specified member in the specified group wrapper and sets the details provided.
* Note: no checks are done, so if the member existed already it's name/profile picture are overriden.
*
* This should only be used when the current device is explicitely inviting a new member to the group.
*/
async function createMemberAndSetDetails({
displayName,
memberPubkey,
groupPk,
avatarUrl,
profileKeyHex,
}: {
memberPubkey: PubkeyType;
displayName: string | null;
groupPk: GroupPubkeyType;
profileKeyHex: string | null;
avatarUrl: string | null;
}) {
await MetaGroupWrapperActions.memberConstructAndSet(groupPk, memberPubkey);
if (displayName) {
await MetaGroupWrapperActions.memberSetName(groupPk, memberPubkey, displayName);
}
if (profileKeyHex && avatarUrl) {
await MetaGroupWrapperActions.memberSetProfilePicture(groupPk, memberPubkey, {
url: avatarUrl,
key: from_hex(profileKeyHex),
});
}
}
export const LibSessionUtil = {
initializeLibSessionUtilWrappers,
userNamespaceToVariant,
@ -396,4 +429,5 @@ export const LibSessionUtil = {
saveDumpsToDb,
batchResultsToGroupSuccessfulChange,
batchResultsToUserSuccessfulChange,
createMemberAndSetDetails,
};

@ -39,6 +39,7 @@ import { GroupSync } from '../../session/utils/job_runners/jobs/GroupSyncJob';
import { UserSync } from '../../session/utils/job_runners/jobs/UserSyncJob';
import { RunJobResult } from '../../session/utils/job_runners/PersistedJob';
import { LibSessionUtil } from '../../session/utils/libsession/libsession_utils';
import { ed25519Str } from '../../session/utils/String';
import { getUserED25519KeyPairBytes } from '../../session/utils/User';
import { stringify, toFixedUint8ArrayOfLength } from '../../types/sqlSharedTypes';
import {
@ -52,7 +53,6 @@ import {
import { StateType } from '../reducer';
import { openConversationWithMessages } from './conversations';
import { resetLeftOverlayMode } from './section';
import { ed25519Str } from '../../session/utils/String';
type WithFromMemberLeftMessage = { fromMemberLeftMessage: boolean }; // there are some changes we want to skip when doing changes triggered from a memberLeft message.
export type GroupState = {
@ -151,7 +151,19 @@ const initNewGroupInWrapper = createAsyncThunk(
for (let index = 0; index < uniqMembers.length; index++) {
const member = uniqMembers[index];
await MetaGroupWrapperActions.memberConstructAndSet(groupPk, member);
const convoMember = ConvoHub.use().get(member);
const displayName = convoMember?.getRealSessionUsername() || null;
const profileKeyHex = convoMember?.getProfileKey() || null;
const avatarUrl = convoMember?.getAvatarPointer() || null;
await LibSessionUtil.createMemberAndSetDetails({
avatarUrl,
displayName,
groupPk,
memberPubkey: member,
profileKeyHex,
});
if (member === us) {
await MetaGroupWrapperActions.memberSetAdmin(groupPk, member);
} else {
@ -493,7 +505,19 @@ async function handleWithHistoryMembers({
}) {
for (let index = 0; index < withHistory.length; index++) {
const member = withHistory[index];
await MetaGroupWrapperActions.memberConstructAndSet(groupPk, member);
const convoMember = ConvoHub.use().get(member);
const displayName = convoMember?.getRealSessionUsername() || null;
const profileKeyHex = convoMember?.getProfileKey() || null;
const avatarUrl = convoMember?.getAvatarPointer() || null;
await LibSessionUtil.createMemberAndSetDetails({
avatarUrl,
displayName,
groupPk,
memberPubkey: member,
profileKeyHex,
});
await MetaGroupWrapperActions.memberSetInvited(groupPk, member, false);
}
const encryptedSupplementKeys = withHistory.length
@ -512,7 +536,18 @@ async function handleWithoutHistoryMembers({
}: WithGroupPubkey & WithAddWithoutHistoryMembers) {
for (let index = 0; index < withoutHistory.length; index++) {
const member = withoutHistory[index];
await MetaGroupWrapperActions.memberConstructAndSet(groupPk, member);
const convoMember = ConvoHub.use().get(member);
const displayName = convoMember?.getRealSessionUsername() || null;
const profileKeyHex = convoMember?.getProfileKey() || null;
const avatarUrl = convoMember?.getAvatarPointer() || null;
await LibSessionUtil.createMemberAndSetDetails({
groupPk,
memberPubkey: member,
avatarUrl,
displayName,
profileKeyHex,
});
await MetaGroupWrapperActions.memberSetInvited(groupPk, member, false);
}

Loading…
Cancel
Save