Normalize chat attachments

canvas-permission
Alex Gleason 2022-10-10 15:56:11 -05:00
rodzic 3e69419252
commit 7dff0391b1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 14 dodań i 6 usunięć

Wyświetl plik

@ -263,14 +263,13 @@ const Item: React.FC<IItem> = ({
interface IMediaGallery {
sensitive?: boolean,
media: ImmutableList<Attachment>,
size: number,
height: number,
onOpenMedia: (media: ImmutableList<Attachment>, index: number) => void,
defaultWidth: number,
cacheWidth: (width: number) => void,
defaultWidth?: number,
cacheWidth?: (width: number) => void,
visible?: boolean,
onToggleVisibility?: () => void,
displayMedia: string,
displayMedia?: string,
compact: boolean,
}
@ -278,7 +277,7 @@ const MediaGallery: React.FC<IMediaGallery> = (props) => {
const {
media,
sensitive = false,
defaultWidth,
defaultWidth = 0,
onToggleVisibility,
onOpenMedia,
cacheWidth,

Wyświetl plik

@ -178,6 +178,7 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chatId, chatMessageIds, a
media={ImmutableList([attachment])}
height={120}
onOpenMedia={onOpenMedia}
visible
/>
)}
</Bundle>

Wyświetl plik

@ -5,6 +5,8 @@ import {
fromJS,
} from 'immutable';
import { normalizeAttachment } from 'soapbox/normalizers/attachment';
import type { Attachment, Card, Emoji } from 'soapbox/types/entities';
export const ChatMessageRecord = ImmutableRecord({
@ -22,8 +24,14 @@ export const ChatMessageRecord = ImmutableRecord({
pending: false,
});
const normalizeMedia = (status: ImmutableMap<string, any>) => {
return status.update('attachment', null, normalizeAttachment);
};
export const normalizeChatMessage = (chatMessage: Record<string, any>) => {
return ChatMessageRecord(
ImmutableMap(fromJS(chatMessage)),
ImmutableMap(fromJS(chatMessage)).withMutations(chatMessage => {
normalizeMedia(chatMessage);
}),
);
};