feat(app): drop the compact attachments media size preference (#1872)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-24 12:35:28 +02:00
1 parent eda29c0e34
commit 844952db51
18 files changed
+62 -383

No files matched your search

@@ -133,13 +133,12 @@ function claimScheduleAttachments(params: ScheduleMessageParams, nonce: string):
params.content,
params.messageReference,
params.replyMentioning,
params.favoriteMemeId,
);
}
async function prepareScheduledMessage(params: ScheduleMessageParams): Promise<PreparedScheduledMessage> {
const nonce = SnowflakeUtils.fromTimestamp(Date.now());
const normalized = normalizeMessageContent(params.content, params.favoriteMemeId);
const normalized = normalizeMessageContent(params.content);
claimScheduleAttachments(params, nonce);
let attachments: Array<ApiAttachmentMetadata> | undefined;
let files: Array<File> | undefined;
@@ -105,7 +105,6 @@ export const useMessageSubmission = ({channel, referencedMessage, replyingMessag
content,
messageReference,
replyingMessage?.mentioning,
favoriteMemeId,
),
{
formatMultipleFileLabel: (count) => formatUploadingAttachmentSummary(i18n, count),
@@ -1,36 +1,55 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import Accessibility, {MediaDimensionSize} from '@app/features/accessibility/state/Accessibility';
import type {Message} from '@app/features/messaging/models/MessagingMessage';
import {fitMediaWithinBounds} from '@app/features/ui/utils/DimensionUtils';
import type {MediaDimensions} from '@app/lib/branded-types';
import {MessageFlags} from '@fluxer/constants/src/ChannelConstants';
interface MediaDimensionConstraints extends MediaDimensions {}
const DIMENSION_PRESETS = {
SMALL: {
maxWidth: 400,
maxHeight: 300,
},
LARGE: {
maxWidth: 550,
maxHeight: 400,
},
} as const;
export const ATTACHMENT_MAX_WIDTH = 550;
export const ATTACHMENT_MAX_HEIGHT = 350;
export const EMBED_MAX_WIDTH = 400;
export const EMBED_MAX_HEIGHT = 300;
export const EMBED_TALL_MAX_HEIGHT = 450;
export const MIN_USEFUL_MEDIA_SIZE = 40;
export function getAttachmentMediaDimensions(message?: Message): MediaDimensionConstraints {
if (message && (message.flags & MessageFlags.COMPACT_ATTACHMENTS) !== 0) {
return DIMENSION_PRESETS.SMALL;
}
const size = Accessibility.attachmentMediaDimensionSize;
return size === MediaDimensionSize.SMALL ? DIMENSION_PRESETS.SMALL : DIMENSION_PRESETS.LARGE;
const ATTACHMENT_DIMENSIONS: MediaDimensionConstraints = {
maxWidth: ATTACHMENT_MAX_WIDTH,
maxHeight: ATTACHMENT_MAX_HEIGHT,
};
const EMBED_DIMENSIONS: MediaDimensionConstraints = {
maxWidth: EMBED_MAX_WIDTH,
maxHeight: EMBED_MAX_HEIGHT,
};
const EMBED_TALL_DIMENSIONS: MediaDimensionConstraints = {
maxWidth: EMBED_MAX_WIDTH,
maxHeight: EMBED_TALL_MAX_HEIGHT,
};
export function getAttachmentMediaDimensions(): MediaDimensionConstraints {
return ATTACHMENT_DIMENSIONS;
}
export function getEmbedMediaDimensions(): MediaDimensionConstraints {
const size = Accessibility.embedMediaDimensionSize;
return size === MediaDimensionSize.SMALL ? DIMENSION_PRESETS.SMALL : DIMENSION_PRESETS.LARGE;
export function getEmbedMediaDimensions(isTallMedia = false): MediaDimensionConstraints {
return isTallMedia ? EMBED_TALL_DIMENSIONS : EMBED_DIMENSIONS;
}
export function getMosaicMediaDimensions(message?: Message): MediaDimensionConstraints {
return getAttachmentMediaDimensions(message);
export function getMosaicMediaDimensions(): MediaDimensionConstraints {
return ATTACHMENT_DIMENSIONS;
}
export function isUsefulVisualMediaSize(
naturalWidth: number,
naturalHeight: number,
constraints: MediaDimensionConstraints = ATTACHMENT_DIMENSIONS,
): boolean {
if (!(naturalWidth > 0) || !(naturalHeight > 0)) return false;
const fitted = fitMediaWithinBounds({
width: naturalWidth,
height: naturalHeight,
maxWidth: constraints.maxWidth,
maxHeight: constraints.maxHeight,
});
return fitted.width >= MIN_USEFUL_MEDIA_SIZE && fitted.height >= MIN_USEFUL_MEDIA_SIZE;
}
@@ -74,12 +74,12 @@ export interface NormalizedMessageContent {
flags: number;
}
export function normalizeMessageContent(content: string, favoriteMemeId?: string): NormalizedMessageContent {
export function normalizeMessageContent(content: string): NormalizedMessageContent {
const withoutSilent = removeSilentFlag(content);
const converted = applyOutgoingEmoticonConversion(withoutSilent);
const sanitized = maybeSanitizeOutgoingMessage(converted);
const normalizedContent = hasVisibleMessageContent(sanitized) ? sanitized : '';
const flags = getMessageFlags(content, favoriteMemeId);
const flags = getMessageFlags(content);
return {content: normalizedContent, flags};
}
@@ -130,14 +130,11 @@ const removeSilentFlag = (content: string): string => {
const applyOutgoingEmoticonConversion = (content: string): string => {
return ChatInputSettings.convertEmoticons ? convertEmoticonsToEmoji(content) : content;
};
const getMessageFlags = (content: string, favoriteMemeId?: string): number => {
const getMessageFlags = (content: string): number => {
let flags = 0;
if (isSilentMessage(content)) {
flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
}
if (favoriteMemeId) {
flags |= MessageFlags.COMPACT_ATTACHMENTS;
}
return flags;
};
const shouldIncludeAllowedMentions = (allowedMentions?: AllowedMentions): boolean => {
@@ -40,7 +40,7 @@ export function createUploadingAttachments(
}
export function createOptimisticMessage(data: MessageSubmitData, attachments: Array<MessageAttachment>): Message {
const normalized = normalizeMessageContent(data.content, data.favoriteMemeId);
const normalized = normalizeMessageContent(data.content);
const content = normalized.content;
const flags = normalized.flags;
return new Message({
@@ -77,14 +77,13 @@ export function claimMessageAttachments(
content: string,
messageReference?: MessageReference,
replyMentioning?: boolean,
favoriteMemeId?: string,
): Array<{
filename: string;
file: {
size: number;
};
}> {
const normalized = normalizeMessageContent(content, favoriteMemeId);
const normalized = normalizeMessageContent(content);
const allowedMentions: AllowedMentions = {replied_user: replyMentioning ?? true};
return CloudUpload.claimAttachmentsForMessage(channelId, nonce, undefined, {
content: normalized.content,