Skip to content

Commit db0ce21

Browse files
committed
chore: renamed setSessionDisplayNameNoCommit as only for non private
1 parent 0aefe6b commit db0ce21

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

ts/models/conversation.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ type SetSessionProfileDetails = WithDisplayNameChange &
203203
WithAvatarPathAndFallback)
204204
);
205205

206+
type SetSessionProfileReturn = {
207+
nameChanged: boolean;
208+
avatarChanged: boolean;
209+
avatarNeedsDownload: boolean;
210+
};
211+
206212
/**
207213
*
208214
* Type guard for the set profile action that is private.
@@ -1480,15 +1486,17 @@ export class ConversationModel extends Model<ConversationAttributes> {
14801486
*
14811487
* This function does commit to the DB if any changes are detected.
14821488
*/
1483-
public async setSessionProfile(newProfile: SetSessionProfileDetails): Promise<{
1484-
nameChanged: boolean;
1485-
avatarChanged: boolean;
1486-
avatarNeedsDownload: boolean;
1487-
}> {
1489+
public async setSessionProfile(
1490+
newProfile: SetSessionProfileDetails
1491+
): Promise<SetSessionProfileReturn> {
14881492
let nameChanged = false;
14891493

14901494
const existingSessionName = this.getRealSessionUsername();
1491-
if (newProfile.displayName !== existingSessionName && newProfile.displayName) {
1495+
if (
1496+
this.shouldApplyPrivateProfileUpdate(newProfile) &&
1497+
newProfile.displayName !== existingSessionName &&
1498+
newProfile.displayName
1499+
) {
14921500
this.set({
14931501
displayNameInProfile: newProfile.displayName,
14941502
});
@@ -1659,15 +1667,12 @@ export class ConversationModel extends Model<ConversationAttributes> {
16591667

16601668
/**
16611669
* Update the display name of this conversation with the provided one.
1662-
* Note: cannot be called with private chats.
1663-
* Instead use `setSessionProfile`.
1664-
* The reason is that we might have a more recent name set for this user already, and we need to discard the change
1665-
* if what we are about to apply is older than what we have.
1670+
* Note: cannot be called with private chats: instead use `setSessionProfile`.
16661671
*/
1667-
public setSessionDisplayNameNoCommit(newDisplayName?: string | null) {
1672+
public setNonPrivateNameNoCommit(newDisplayName?: string | null) {
16681673
if (this.isPrivate()) {
16691674
// the name change is only allowed through setSessionProfile for private chats now, see above.
1670-
throw new Error('setSessionDisplayNameNoCommit should not be called with private chats');
1675+
throw new Error('setNonPrivateNameNoCommit should not be called with private chats');
16711676
}
16721677
const existingSessionName = this.getRealSessionUsername();
16731678
if (newDisplayName !== existingSessionName && newDisplayName) {
@@ -2108,7 +2113,7 @@ export class ConversationModel extends Model<ConversationAttributes> {
21082113

21092114
if (details.name && details.name !== this.getRealSessionUsername()) {
21102115
hasChange = hasChange || true;
2111-
this.setSessionDisplayNameNoCommit(details.name);
2116+
this.setNonPrivateNameNoCommit(details.name);
21122117
}
21132118

21142119
if (this.handleRoomDescriptionChange({ description: details.description || '' })) {

ts/receiver/configMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ async function handleSingleGroupUpdate({
637637
? groupInWrapper.disappearingTimerSeconds
638638
: undefined;
639639
created.setActiveAt(joinedAt);
640-
created.setSessionDisplayNameNoCommit(groupInWrapper.name || undefined);
640+
created.setNonPrivateNameNoCommit(groupInWrapper.name || undefined);
641641
await created.setPriorityFromWrapper(groupInWrapper.priority);
642642
created.setLastJoinedTimestamp(joinedAt);
643643
created.setExpirationArgs({

ts/receiver/groupv2/handleGroupV2Message.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ async function handleGroupUpdateInviteMessage({
139139

140140
window.log.debug(`received invite to group ${ed25519Str(groupPk)} by user:${ed25519Str(author)}`);
141141

142-
const convo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV2);
143-
convo.setActiveAt(signatureTimestamp);
144-
await convo.setDidApproveMe(true, false);
145-
await convo.setOriginConversationID(author, false);
142+
const groupConvo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV2);
143+
groupConvo.setActiveAt(signatureTimestamp);
144+
await groupConvo.setDidApproveMe(true, false);
145+
await groupConvo.setOriginConversationID(author, false);
146146

147-
if (inviteMessage.name && isEmpty(convo.getRealSessionUsername())) {
148-
convo.setSessionDisplayNameNoCommit(inviteMessage.name);
147+
if (inviteMessage.name && isEmpty(groupConvo.getRealSessionUsername())) {
148+
groupConvo.setNonPrivateNameNoCommit(inviteMessage.name);
149149
}
150150
const userEd25519Secretkey = (await UserUtils.getUserED25519KeyPairBytes()).privKeyBytes;
151151

@@ -162,10 +162,10 @@ async function handleGroupUpdateInviteMessage({
162162
await UserGroupsWrapperActions.setGroup(found);
163163
await UserGroupsWrapperActions.markGroupInvited(groupPk);
164164
// force markedAsUnread to be true so it shows the unread banner (we only show the banner if there are unread messages on at least one msg/group request)
165-
await convo.markAsUnread(true, false);
166-
await convo.commit();
165+
await groupConvo.markAsUnread(true, false);
166+
await groupConvo.commit();
167167

168-
await SessionUtilConvoInfoVolatile.insertConvoFromDBIntoWrapperAndRefresh(convo.id);
168+
await SessionUtilConvoInfoVolatile.insertConvoFromDBIntoWrapperAndRefresh(groupConvo.id);
169169

170170
if (wasKicked && !found.kicked) {
171171
// we have been reinvited to a group which we had been kicked from.
@@ -568,7 +568,7 @@ async function handleGroupUpdatePromoteMessage({
568568
await convo.setOriginConversationID(author, false);
569569

570570
if (change.name && isEmpty(convo.getRealSessionUsername())) {
571-
convo.setSessionDisplayNameNoCommit(change.name);
571+
convo.setNonPrivateNameNoCommit(change.name);
572572
}
573573
const userEd25519Secretkey = (await UserUtils.getUserED25519KeyPairBytes()).privKeyBytes;
574574

ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class OpenGroupManagerV2 {
210210
// mark active so it's not in the contacts list but in the conversation list
211211
// mark isApproved as this is a public chat
212212
conversation.setActiveAt(Date.now());
213-
conversation.setSessionDisplayNameNoCommit(updatedRoom.roomName);
213+
conversation.setNonPrivateNameNoCommit(updatedRoom.roomName);
214214
await conversation.setIsApproved(true, false);
215215
await conversation.setDidApproveMe(true, false);
216216
await conversation.setPriorityFromWrapper(CONVERSATION_PRIORITIES.default, false);

ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
144144
if (convo) {
145145
let changes = false;
146146
if (refreshedInfos.name !== convo.get('displayNameInProfile')) {
147-
convo.setSessionDisplayNameNoCommit(refreshedInfos.name || undefined);
147+
convo.setNonPrivateNameNoCommit(refreshedInfos.name || undefined);
148148
changes = true;
149149
}
150150
const expirationMode = refreshedInfos.expirySeconds ? 'deleteAfterSend' : 'off';

ts/state/ducks/metaGroups.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const handleUserGroupUpdate = createAsyncThunk(
345345
convo.setActiveAt(Date.now());
346346
}
347347

348-
convo.setSessionDisplayNameNoCommit(userGroup.name || undefined);
348+
convo.setNonPrivateNameNoCommit(userGroup.name || undefined);
349349

350350
await convo.commit();
351351

0 commit comments

Comments
 (0)