Skip to content

Commit 6435038

Browse files
committed
chore: big refactor to use functions for convo model attributes
1 parent 0dcb507 commit 6435038

File tree

33 files changed

+631
-357
lines changed

33 files changed

+631
-357
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ async function generateOneRandomContact() {
5757
// createdAt is set to now in libsession-util itself,
5858
// but we still need to mark that conversation as active
5959
// for it to be inserted in the config
60-
created.setKey('active_at', Date.now());
61-
created.setKey('isApproved', true);
60+
created.setActiveAt(Date.now());
61+
await created.setIsApproved(true, false);
6262
created.setSessionDisplayNameNoCommit(id.slice(2, 8));
6363

6464
await created.commit();

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/interactions/avatar-interactions/nts-avatar-interactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { uploadFileToFsWithOnionV4 } from '../../session/apis/file_server_api/Fi
44
import { ConvoHub } from '../../session/conversations';
55
import { DecryptedAttachmentsManager } from '../../session/crypto/DecryptedAttachmentsManager';
66
import { UserUtils } from '../../session/utils';
7-
import { fromHexToArray, toHex } from '../../session/utils/String';
7+
import { fromHexToArray } from '../../session/utils/String';
88
import { urlToBlob } from '../../types/attachments/VisualAttachment';
99
import { processNewAttachment } from '../../types/MessageAttachment';
1010
import { IMAGE_JPEG } from '../../types/MIME';
@@ -109,7 +109,7 @@ export async function uploadAndSetOurAvatarShared({
109109
const displayName = ourConvo.getRealSessionUsername();
110110

111111
// write the profileKey even if it did not change
112-
ourConvo.set({ profileKey: toHex(profileKey) });
112+
await ourConvo.setProfileKey(profileKey);
113113
// Replace our temporary image with the attachment pointer from the server.
114114
// Note: this commits already to the DB.
115115
await ourConvo.setSessionProfile({

ts/interactions/conversationInteractions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,8 @@ export async function deleteAllMessagesByConvoIdNoConfirmation(conversationId: s
466466

467467
// destroy message keeps the active timestamp set so the
468468
// conversation still appears on the conversation list but is empty
469-
conversation.set({
470-
lastMessage: null,
471-
lastMessageInteractionType: null,
472-
lastMessageInteractionStatus: null,
473-
});
469+
conversation.setLastMessage(null);
470+
conversation.setLastMessageInteraction(null);
474471

475472
await conversation.commit();
476473
window.inboxStore?.dispatch(conversationReset(conversationId));
@@ -619,8 +616,7 @@ export async function updateConversationInteractionState({
619616
(type !== convo.get('lastMessageInteractionType') ||
620617
status !== convo.get('lastMessageInteractionStatus'))
621618
) {
622-
convo.setKey('lastMessageInteractionType', type);
623-
convo.setKey('lastMessageInteractionStatus', status);
619+
convo.setLastMessageInteraction({ type, status });
624620

625621
await convo.commit();
626622
window.log.debug(
@@ -643,8 +639,7 @@ export async function clearConversationInteractionState({
643639
convo &&
644640
(convo.get('lastMessageInteractionType') || convo.get('lastMessageInteractionStatus'))
645641
) {
646-
convo.setKey('lastMessageInteractionType', null);
647-
convo.setKey('lastMessageInteractionStatus', null);
642+
convo.setLastMessageInteraction(null);
648643

649644
await convo.commit();
650645
window.log.debug(`clearConversationInteractionState for ${conversationId}`);

0 commit comments

Comments
 (0)