Skip to content

Commit 7608e53

Browse files
committed
fix: test and validate profile info override works
1 parent 6b3c491 commit 7608e53

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

ts/models/conversation.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,9 @@ export class ConversationModel extends Model<ConversationAttributes> {
14701470
}
14711471
}
14721472

1473-
private shouldApplyPrivateProfileUpdate(newProfile: SetSessionProfileDetails) {
1473+
private shouldApplyPrivateProfileUpdate<T extends SetSessionProfileDetails>(
1474+
newProfile: SetSessionProfileDetails
1475+
): newProfile is Extract<T, { profileUpdatedAtSeconds: number }> {
14741476
if (isSetProfileWithUpdatedAtSeconds(newProfile)) {
14751477
const ts = new Timestamp({ value: newProfile.profileUpdatedAtSeconds });
14761478
return this.getProfileUpdatedSeconds() < ts.seconds();
@@ -1500,6 +1502,10 @@ export class ConversationModel extends Model<ConversationAttributes> {
15001502
this.set({
15011503
displayNameInProfile: newProfile.displayName,
15021504
});
1505+
// name has changed, also apply the new profileUpdatedAtSeconds timestamp
1506+
if (isSetProfileWithUpdatedAtSeconds(newProfile)) {
1507+
this.set({ profileUpdatedSeconds: newProfile.profileUpdatedAtSeconds });
1508+
}
15031509
nameChanged = true;
15041510
}
15051511
const type = newProfile.type;
@@ -1533,9 +1539,13 @@ export class ConversationModel extends Model<ConversationAttributes> {
15331539
fallbackAvatarInProfile: undefined,
15341540
});
15351541
avatarChanged = true;
1542+
// avatar has changed, also apply the new profileUpdatedAtSeconds timestamp
1543+
if (isSetProfileWithUpdatedAtSeconds(newProfile)) {
1544+
this.set({ profileUpdatedSeconds: newProfile.profileUpdatedAtSeconds });
1545+
}
15361546
}
15371547
}
1538-
if (avatarChanged) {
1548+
if (avatarChanged || nameChanged) {
15391549
await this.commit();
15401550
}
15411551
return { nameChanged, avatarNeedsDownload: false, avatarChanged };
@@ -1562,6 +1572,10 @@ export class ConversationModel extends Model<ConversationAttributes> {
15621572
}
15631573
this.set({ avatarPointer: newProfile.avatarPointer, profileKey: newProfileKeyHex });
15641574

1575+
// avatar has changed, also apply the new profileUpdatedAtSeconds timestamp
1576+
if (isSetProfileWithUpdatedAtSeconds(newProfile)) {
1577+
this.set({ profileUpdatedSeconds: newProfile.profileUpdatedAtSeconds });
1578+
}
15651579
await this.commit();
15661580

15671581
return { nameChanged, avatarNeedsDownload: hasAvatarInNewProfile, avatarChanged: true };
@@ -1591,6 +1605,9 @@ export class ConversationModel extends Model<ConversationAttributes> {
15911605
return { nameChanged, avatarChanged: false, avatarNeedsDownload: false };
15921606
}
15931607

1608+
// avatar has changed, but we are only dealing with the downloaded part of it here
1609+
// so this actually is not a profile update change. Nothing to do, as the newProfile type suggests
1610+
15941611
this.set({
15951612
avatarPointer: newProfile.avatarPointer,
15961613
avatarInProfile: newProfile.avatarPath,

ts/session/utils/libsession/libsession_utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,16 @@ async function createMemberAndSetDetails({
624624
profileUpdatedSeconds: number;
625625
}) {
626626
await MetaGroupWrapperActions.memberConstructAndSet(groupPk, memberPubkey);
627-
await MetaGroupWrapperActions.memberSetProfileDetails(groupPk, memberPubkey, {
627+
const details = {
628628
name: displayName ?? '',
629629
profilePicture:
630630
profileKeyHex && avatarUrl
631631
? { url: avatarUrl, key: from_hex(profileKeyHex) }
632632
: { url: '', key: new Uint8Array() },
633633
profileUpdatedSeconds,
634-
});
634+
};
635+
636+
await MetaGroupWrapperActions.memberSetProfileDetails(groupPk, memberPubkey, details);
635637
}
636638

637639
export const LibSessionUtil = {

ts/state/ducks/metaGroups.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ const initNewGroupInWrapper = createAsyncThunk(
172172
const member = uniqMembers[index];
173173
const memberProfileDetails = ConvoHub.use().get(member).getPrivateProfileDetails() || null;
174174
const profilePic = memberProfileDetails?.toHexProfilePicture() || null;
175-
debugger;
176175

177176
// we just create the members in the state. Their invite state defaults to NOT_SENT,
178177
// which will make our logic kick in to send them an invite in the `GroupInviteJob`

ts/util/accountManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { PromiseUtils } from '../session/utils';
2424
import { SnodeAPI } from '../session/apis/snode_api/SNodeAPI';
2525
import { tr } from '../localization/localeTools';
2626
import { NetworkTime } from './NetworkTime';
27+
import { UserConfigWrapperActions } from '../webworker/workers/browser/libsession_worker_interface';
2728

2829
/**
2930
* Might throw
@@ -227,6 +228,8 @@ export async function registrationDone(ourPubkey: string, displayName: string) {
227228
ourPubkey,
228229
ConversationTypeEnum.PRIVATE
229230
);
231+
await UserConfigWrapperActions.setNameTruncated(displayName ?? 'Anonymous');
232+
230233
await conversation.setSessionProfile({
231234
type: 'displayNameChangeOnlyPrivate',
232235
displayName,

0 commit comments

Comments
 (0)