Skip to content

Commit d946596

Browse files
authored
Merge pull request #1592 from session-foundation/fix-reupload-issue-userprofile-2
fix: track and drop old profile updates from user messages
2 parents c6abdbf + 6245cf0 commit d946596

File tree

90 files changed

+1849
-1053
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1849
-1053
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"build-release-base": "cross-env NODE_ENV=production electron-builder --config.extraMetadata.environment=production",
4040
"build-release": "yarn build-release-base --publish=never --config.directories.output=release",
4141
"build-release-publish": "yarn build-release-base --publish=always",
42-
"ready": "yarn dedup --fail && yarn build-everything && yarn lint && yarn test",
42+
"ready": "yarn dedup --fail && yarn build && yarn lint && yarn test",
4343
"postinstall": "yarn patch-package && yarn electron-builder install-app-deps",
4444
"update-git-info": "node ./build/updateLocalConfig.js",
4545
"worker:utils": "webpack --config=./utils.worker.config.js",
@@ -76,7 +76,7 @@
7676
"fs-extra": "11.3.0",
7777
"glob": "10.4.5",
7878
"image-type": "^4.1.0",
79-
"libsession_util_nodejs": "https://github.com/session-foundation/libsession-util-nodejs/releases/download/v0.5.5/libsession_util_nodejs-v0.5.5.tar.gz",
79+
"libsession_util_nodejs": "https://github.com/session-foundation/libsession-util-nodejs/releases/download/v0.5.6/libsession_util_nodejs-v0.5.6.tar.gz",
8080
"libsodium-wrappers-sumo": "^0.7.15",
8181
"linkify-it": "^5.0.0",
8282
"lodash": "^4.17.21",

protos/SignalService.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ message DataMessage {
200200
message LokiProfile {
201201
optional string displayName = 1;
202202
optional string profilePicture = 2;
203+
/**
204+
* The timestamp of the last profile update.
205+
* This is used to prioritize the correct profile info based on multiple and outdated incoming messages.
206+
Note: this is in milliseconds.
207+
*/
208+
optional uint64 lastProfileUpdateMs = 3;
203209
}
204210

205211
message OpenGroupInvitation {

ts/components/SessionInboxView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function createSessionInboxStore() {
7575
conversationLookup: makeLookup(conversations, 'id'),
7676
},
7777
user: {
78-
ourDisplayNameInProfile: UserUtils.getOurProfile()?.displayName || '',
78+
ourDisplayNameInProfile: (await UserUtils.getOurProfile()).displayName || '',
7979
ourNumber: UserUtils.getOurPubKeyStrFromCache(),
8080
uploadingNewAvatarCurrentUser: false,
8181
uploadingNewAvatarCurrentUserFailed: false,

ts/components/conversation/header/ConversationHeader.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ function RecreateGroupButton() {
164164
ConversationTypeEnum.PRIVATE
165165
);
166166
if (!memberConvo.get('active_at')) {
167-
memberConvo.set({
168-
active_at: Constants.CONVERSATION.LAST_JOINED_FALLBACK_TIMESTAMP,
169-
});
167+
memberConvo.setActiveAt(Constants.CONVERSATION.LAST_JOINED_FALLBACK_TIMESTAMP);
170168
await memberConvo.commit();
171169
}
172170
/* eslint-enable no-await-in-loop */

ts/components/conversation/message/message-content/ClickToTrustSender.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const ClickToTrustSender = (props: { messageId: string }) => {
5151
},
5252
closeTheme: SessionButtonColor.Danger,
5353
onClickOk: async () => {
54-
convo.set({ isTrustedForAttachmentDownload: true });
54+
convo.setIsTrustedForAttachmentDownload(true);
5555
await convo.commit();
5656
const messagesInConvo = await Data.getLastMessagesByConversation(convo.id, 100, false);
5757

@@ -104,9 +104,9 @@ export const ClickToTrustSender = (props: { messageId: string }) => {
104104
})
105105
);
106106

107-
message.set({ preview });
107+
message.setPreview(preview);
108108

109-
message.set({ attachments: downloadedAttachments });
109+
message.setAttachments(downloadedAttachments);
110110
await message.commit();
111111
})
112112
);

ts/components/dialog/debug/components.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { releasedFeaturesActions } from '../../../state/ducks/releasedFeatures';
3535
import { networkDataActions } from '../../../state/ducks/networkData';
3636
import { DEBUG_MENU_PAGE, type DebugMenuPageProps } from './DebugMenuModal';
3737
import { SimpleSessionInput } from '../../inputs/SessionInput';
38+
import { NetworkTime } from '../../../util/NetworkTime';
3839

3940
const hexRef = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
4041

@@ -57,9 +58,13 @@ async function generateOneRandomContact() {
5758
// createdAt is set to now in libsession-util itself,
5859
// but we still need to mark that conversation as active
5960
// for it to be inserted in the config
60-
created.setKey('active_at', Date.now());
61-
created.setKey('isApproved', true);
62-
created.setSessionDisplayNameNoCommit(id.slice(2, 8));
61+
created.setActiveAt(Date.now());
62+
await created.setIsApproved(true, false);
63+
await created.setSessionProfile({
64+
type: 'displayNameChangeOnlyPrivate',
65+
displayName: id.slice(2, 8),
66+
profileUpdatedAtSeconds: NetworkTime.nowSeconds(),
67+
});
6368

6469
await created.commit();
6570
return created;

ts/components/dialog/user-settings/pages/PrivacySettingsPage.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ import {
2020
useUserSettingsCloseAction,
2121
useUserSettingsTitle,
2222
} from './userSettingsHooks';
23-
import { CallManager, UserUtils } from '../../../../session/utils';
23+
import { CallManager } from '../../../../session/utils';
2424
import { SessionButtonColor } from '../../../basic/SessionButton';
2525
import {
2626
useHasLinkPreviewEnabled,
2727
useWeHaveBlindedMsgRequestsEnabled,
2828
} from '../../../../state/selectors/settings';
2929
import { SettingsKey } from '../../../../data/settings-key';
30-
import { SessionUtilUserProfile } from '../../../../session/utils/libsession/libsession_utils_user_profile';
3130
import { getPasswordHash, Storage } from '../../../../util/storage';
3231
import { SettingsToggleBasic } from '../components/SettingsToggleBasic';
3332
import { SettingsPanelButtonInlineBasic } from '../components/SettingsPanelButtonInlineBasic';
3433
import { UserSettingsModalContainer } from '../components/UserSettingsModalContainer';
34+
import { UserConfigWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
3535

3636
const toggleCallMediaPermissions = async (triggerUIUpdate: () => void) => {
3737
const currentValue = window.getCallMediaPermissions();
@@ -193,9 +193,8 @@ export function PrivacySettingsPage(modalState: UserSettingsModalState) {
193193
onClick={async () => {
194194
const toggledValue = !weHaveBlindedRequestsEnabled;
195195
await window.setSettingValue(SettingsKey.hasBlindedMsgRequestsEnabled, toggledValue);
196-
await SessionUtilUserProfile.insertUserProfileIntoWrapper(
197-
UserUtils.getOurPubKeyStrFromCache()
198-
);
196+
await UserConfigWrapperActions.setEnableBlindedMsgRequest(toggledValue);
197+
199198
forceUpdate();
200199
}}
201200
text={{ token: 'messageRequestsCommunities' }}

ts/components/leftpane/overlay/OverlayMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const OverlayMessage = () => {
8686
if (!convo.isActive() || convo.isHidden()) {
8787
// bump the timestamp only if we were not active before
8888
if (!convo.isActive()) {
89-
convo.set({ active_at: Date.now() });
89+
convo.setActiveAt(Date.now());
9090
}
9191
await convo.unhideIfNeeded(false);
9292

ts/components/menuAndSettingsHooks/useSetNotificationsFor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function setNotificationForConvoId(
99

1010
const existingSettings = conversation.getNotificationsFor();
1111
if (existingSettings !== selected) {
12-
conversation.set({ triggerNotificationsFor: selected });
12+
conversation.setNotificationsFor(selected);
1313
await conversation.commit();
1414
}
1515
}

ts/data/data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
FindAllMessageHashesInConversationTypeArgs,
3636
} from './sharedDataTypes';
3737
import { GuardNode, Snode } from './types';
38-
import { makeMessageModels } from '../models/models';
3938

4039
const ERASE_SQL_KEY = 'erase-sql-key';
4140
const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
@@ -324,6 +323,10 @@ async function filterAlreadyFetchedOpengroupMessage(
324323
return msgDetailsNotAlreadyThere || [];
325324
}
326325

326+
function makeMessageModels(modelsOrAttrs: Array<MessageAttributes>) {
327+
return modelsOrAttrs.map(a => new MessageModel(a));
328+
}
329+
327330
/**
328331
* Fetch all messages that match the sender pubkey and sent_at timestamp
329332
* @param propsList An array of objects containing a source (the sender id) and timestamp of the message - not to be confused with the serverTimestamp. This is equivalent to sent_at

0 commit comments

Comments
 (0)