Skip to content

Commit 8391f4c

Browse files
committed
chore: cleanup PR
1 parent eb0780d commit 8391f4c

File tree

10 files changed

+49
-57
lines changed

10 files changed

+49
-57
lines changed

preload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ window.sessionFeatureFlags = {
6767
showPopoverAnchors: false,
6868
proAvailable: !isEmpty(process.env.SESSION_PRO),
6969
mockUserHasPro: !isEmpty(process.env.SESSION_HAS_PRO),
70-
fsTTL30s: !isEmpty(process.env.FILE_SERVER_TTL_30S), // Note: some stuff are init when the app start, so this flag should only be set from the env itself.
70+
// Note: some stuff are init when the app starts, so fsTTL30s should only be set from the env itself (before app starts)
71+
fsTTL30s: !isEmpty(process.env.FILE_SERVER_TTL_30S),
7172
debug: {
7273
debugLogging: !isEmpty(process.env.SESSION_DEBUG),
7374
debugLibsessionDumps: !isEmpty(process.env.SESSION_DEBUG_LIBSESSION_DUMPS),

ts/components/conversation/SessionConversation.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,13 @@ export class SessionConversation extends Component<Props, State> {
405405
// If we can, we use the scaled version, otherwise we use the original (and the filesize check will fail)
406406
//
407407
// Note: we do not save that scaled version here,
408-
// we just check if will be fine when sending the attachment.
408+
// we just check if it will be fine when sending the attachment.
409409
// Later, when the message is being sent, we will fetch the
410410
// file again and scale it down again for upload.
411411
//
412-
// The reason is simply that we'd need to store that in memory for the lifetime
412+
// The reason is simply that we'd need to store that scaled blob in memory for the lifetime
413413
// of the app if we were, as the user could switch conversations
414414
// before sending a message with attachments.
415-
416415
const scaledOrNot = await AttachmentUtil.autoScaleFile(file);
417416

418417
// `autoScaleFile` either

ts/components/dialog/debug/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ type DebugFeatureFlagsType = {
99
export const DEBUG_FEATURE_FLAGS: DebugFeatureFlagsType = {
1010
// NOTE Put new feature flags in here during development so they are not available in production environments. Remove from here when they are ready for QA and production
1111
DEV: ['showPopoverAnchors', 'debugInputCommands'],
12-
UNSUPPORTED: ['useTestNet', 'useLocalDevNet'],
12+
UNSUPPORTED: ['useTestNet', 'useLocalDevNet', 'fsTTL30s'],
1313
UNTESTED: ['useOnionRequests', 'replaceLocalizedStringsWithKeys'],
1414
};

ts/models/conversationAttributes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ export interface ConversationAttributes {
6565
* - if the avatarPath points to a file that is not animated, staticAvatarPath is the same as avatarPath
6666
*
6767
* avatarInProfile is the avatar as the user set it, once downloaded and stored in the application attachments folder.
68+
*
69+
* Note: if the user is Pro, but didn't set an animated avatar, `avatarInProfile` and `fallbackAvatarInProfile` will point to the same file
6870
*/
6971
avatarInProfile?: string;
7072
/**
7173
* This is the always static version of the avatar in profile.
7274
* If the user has pro, avatarInProfile will be used (and so his avatar will be animated if it was already).
7375
* If the user doesn't have pro, fallbackAvatarInProfile will be used, and the avatar will be displayed as a static image.
76+
*
77+
* Note: if the user is Pro, but didn't set an animated avatar, `avatarInProfile` and `fallbackAvatarInProfile` will point to the same file
7478
*/
7579
fallbackAvatarInProfile?: string;
7680

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ async function scheduleAvatarDownloadJobIfNeeded(groupPk: GroupPubkeyType) {
278278
if (!profileUrl || !profileKeyHex) {
279279
// no avatar set for this group: make sure we also remove the one we might have locally.
280280
if (conversation.get('avatarPointer') || conversation.get('profileKey')) {
281-
conversation.set({
281+
conversation.setKey('profileKey', undefined);
282+
await conversation.setSessionProfile({
282283
avatarPointer: undefined,
283-
profileKey: undefined,
284-
avatarInProfile: undefined, // we want to remove the avatar here
285-
fallbackAvatarInProfile: undefined, // and the fallback too
284+
avatarPath: undefined,
285+
fallbackAvatarPath: undefined,
286+
displayName: null,
286287
});
287-
await conversation.commit();
288288
}
289289

290290
return;

ts/session/profile_manager/ProfileManager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ async function updateProfileOfContact(
8181
(!profileUrl || !profileKeyHex) &&
8282
(conversation.getAvatarInProfilePath() || conversation.getFallbackAvatarInProfilePath())
8383
) {
84-
conversation.set({ avatarInProfile: undefined, fallbackAvatarInProfile: undefined });
84+
conversation.setKey('profileKey', undefined);
85+
await conversation.setSessionProfile({
86+
avatarPointer: undefined,
87+
avatarPath: undefined,
88+
fallbackAvatarPath: undefined,
89+
displayName: null,
90+
});
8591
changes = true;
8692
}
8793

ts/state/ducks/metaGroups.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,12 @@ async function handleClearAvatarFromUI({ groupPk }: WithGroupPubkey) {
11501150
}
11511151

11521152
await checkWeAreAdminOrThrow(groupPk, 'handleAvatarChangeFromUI');
1153-
convo.set({
1153+
convo.setKey('profileKey', undefined)
1154+
await convo.setSessionProfile({
11541155
avatarPointer: undefined,
1155-
avatarInProfile: undefined,
1156-
fallbackAvatarInProfile: undefined,
1157-
profileKey: undefined,
1156+
avatarPath: undefined,
1157+
fallbackAvatarPath: undefined,
1158+
displayName: null,
11581159
});
11591160

11601161
const createAtNetworkTimestamp = NetworkTime.now();

ts/state/ducks/user.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ const clearOurAvatar = createAsyncThunk('user/clearOurAvatar', async () => {
7474
return;
7575
}
7676

77-
convo.set({ avatarPointer: undefined, avatarInProfile: undefined, profileKey: undefined });
77+
convo.setKey('profileKey', undefined);
78+
await convo.setSessionProfile({
79+
avatarPath: undefined,
80+
fallbackAvatarPath: undefined,
81+
avatarPointer: undefined,
82+
displayName: null,
83+
});
7884

79-
await convo.commit();
8085
await SyncUtils.forceSyncConfigurationNowIfNeeded(true);
8186
});
8287

ts/util/attachment/attachmentsUtil.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* eslint-disable max-len */
2-
import imageType from 'image-type';
32

4-
import { arrayBufferToBlob } from 'blob-util';
53
import { StagedAttachmentType } from '../../components/conversation/composition/CompositionBox';
64
import { SignalService } from '../../protobuf';
75
import { DecryptedAttachmentsManager } from '../../session/crypto/DecryptedAttachmentsManager';
86
import { sendDataExtractionNotification } from '../../session/messages/outgoing/controlMessage/DataExtractionNotificationMessage';
97
import { AttachmentType, save } from '../../types/Attachment';
10-
import { IMAGE_UNKNOWN, type MIMEType } from '../../types/MIME';
118
import { getAbsoluteAttachmentPath, processNewAttachment } from '../../types/MessageAttachment';
129

1310
import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../../session/constants';
@@ -33,43 +30,13 @@ import type { ProcessedLinkPreviewThumbnailType } from '../../webworker/workers/
3330
* 10. We use the grabbed data for upload of the attachments, get an url for each of them and send the url with the attachments details to the user/opengroup/closed group
3431
*/
3532

36-
export type BetterBlob = Blob & {
37-
__brand: 'BetterBlob';
38-
/** @deprecated -- `type` should not be used, it can be tampered with, use @see {@link contentType} */
39-
type: Blob['type'];
40-
contentType: MIMEType;
41-
animated: boolean;
42-
width?: number;
43-
height?: number;
44-
};
45-
46-
export async function createBetterBlobFromArrayBuffer(
47-
arrayBuffer: ArrayBuffer,
48-
contentType?: MIMEType,
49-
isAnimated?: boolean
50-
): Promise<BetterBlob> {
51-
const type = contentType ?? imageTypeFromArrayBuffer(arrayBuffer);
52-
const blob = arrayBufferToBlob(arrayBuffer, type) satisfies Blob as unknown as BetterBlob;
53-
54-
blob.contentType = type;
55-
blob.animated =
56-
isAnimated ?? ((await ImageProcessor.imageMetadata(arrayBuffer))?.isAnimated || false);
57-
58-
return blob;
59-
}
60-
6133
type MaxScaleSize = {
6234
maxSizeBytes?: number;
6335
maxHeightPx?: number;
6436
maxWidthPx?: number;
6537
maxSidePx?: number; // use this to make avatars cropped if too big and centered if too small.
6638
};
6739

68-
function imageTypeFromArrayBuffer(arrayBuffer: ArrayBuffer) {
69-
const data = new Uint8Array(arrayBuffer);
70-
return imageType(data)?.mime ?? IMAGE_UNKNOWN;
71-
}
72-
7340
export async function autoScaleFile(file: File, maxMeasurements?: MaxScaleSize) {
7441
// this call returns null if not an image, or not one we can process, or we cannot scale it down enough
7542
try {

ts/webworker/workers/node/image_processor/image_processor.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export type ImageProcessorWorkerActions = {
6060

6161
/**
6262
* Process an image to get a thumbnail matching our required details for link previews
63-
* A link preview thumbnail is always a png, and resized to "contain" the image.
63+
* A link preview thumbnail is always a png, and resized to "cover".
6464
*/
6565
processForLinkPreviewThumbnail: (
6666
input: ArrayBufferLike,
@@ -71,10 +71,10 @@ export type ImageProcessorWorkerActions = {
7171
* Process an image to get a thumbnail matching our required details for in conversation thumbnails
7272
* This is about the thumbnail in the conversation list (for attachments in messages). We generate a preview to avoid loading huge files until we show them in fullscreen.
7373
*
74-
* Note: an animated image or not animated will always be returned as a png.
74+
* Note: animated or not, an image will always be returned as a png.
7575
* Note: eventually we want to support animated images as previews too. When we do, we will need to
7676
* convert them to webp and resize their preview heavily for performance reasons.
77-
* A 'in conversation thumbnail' is always resized to "fill" the image.
77+
* A 'in conversation thumbnail' is always resized to "cover".
7878
*/
7979
processForInConversationThumbnail: (
8080
input: ArrayBufferLike,
@@ -89,13 +89,22 @@ export type ImageProcessorWorkerActions = {
8989
* - not an image, or
9090
* - not one we can process (i.e enforced lossless),
9191
* - or we cannot get an image small enough after dropping the quality
92-
* null will be returned. The caller should check if the requirements are met before trying to upload.
93-
*
94-
* The caller should check that the requirements have been met before trying to upload.
92+
* null will be returned.
93+
* The caller should always check if the requirements are met before trying to upload.
9594
*
9695
* Note: the lossy formats are jpeg, webp and avif.
9796
* Anything else that is an image supported by sharp will only be scaled down to maxSidePx.
98-
* Anything else not an image supported by sharp will return null
97+
* Anything else not an image supported by sharp will return null.
98+
*
99+
* To make it clear,
100+
* - if the image is **lossy** and already fits the requirements, we return it as is.
101+
* - if the image is **lossless**:
102+
* - if it fits the requirements, we return it as is (not even scaled down, as we'd need a loader in the staged attachments list to display the loading state)
103+
* - if it does not fit the requirements, we return null
104+
* - if the image is **lossy** and doesn't fit:
105+
* - we first scale it down the maxSize, and then iterate over the quality to get something that fits the maxSizeBytes.
106+
* - if we cannot get a file under maxSizeBytes, we return null
107+
*
99108
*
100109
* @param input: the image data to process
101110
* @param maxSidePx: we cap an image to this size. If the image is larger, it will be scaled down to this before we start dropping the quality.

0 commit comments

Comments
 (0)