mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Send related emoji along with Sticker, fix SendMessage types
This commit is contained in:
@@ -42,7 +42,7 @@ export type AttachmentType = {
|
||||
isVoiceMessage?: boolean;
|
||||
/** For messages not already on disk, this will be a data url */
|
||||
url?: string;
|
||||
size?: number;
|
||||
size: number;
|
||||
fileSize?: string;
|
||||
pending?: boolean;
|
||||
width?: number;
|
||||
@@ -95,6 +95,7 @@ export type InMemoryAttachmentDraftType =
|
||||
fileName: string;
|
||||
path: string;
|
||||
pending: true;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export type AttachmentDraftType =
|
||||
@@ -109,6 +110,7 @@ export type AttachmentDraftType =
|
||||
fileName: string;
|
||||
path: string;
|
||||
pending: true;
|
||||
size: number;
|
||||
};
|
||||
|
||||
export type ThumbnailType = {
|
||||
@@ -621,7 +623,9 @@ export function isImage(attachments?: ReadonlyArray<AttachmentType>): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function isImageAttachment(attachment?: AttachmentType): boolean {
|
||||
export function isImageAttachment(
|
||||
attachment?: Pick<AttachmentType, 'contentType'>
|
||||
): boolean {
|
||||
return Boolean(
|
||||
attachment &&
|
||||
attachment.contentType &&
|
||||
@@ -630,8 +634,8 @@ export function isImageAttachment(attachment?: AttachmentType): boolean {
|
||||
}
|
||||
|
||||
export function canBeTranscoded(
|
||||
attachment?: AttachmentType
|
||||
): attachment is AttachmentType {
|
||||
attachment?: Pick<AttachmentType, 'contentType'>
|
||||
): boolean {
|
||||
return Boolean(
|
||||
attachment &&
|
||||
isImageAttachment(attachment) &&
|
||||
|
||||
@@ -6,6 +6,9 @@ export type MIMEType = string & { _mimeTypeBrand: never };
|
||||
export const stringToMIMEType = (value: string): MIMEType => {
|
||||
return value as MIMEType;
|
||||
};
|
||||
export const MIMETypeToString = (value: MIMEType): string => {
|
||||
return value as string;
|
||||
};
|
||||
|
||||
export const APPLICATION_OCTET_STREAM = stringToMIMEType(
|
||||
'application/octet-stream'
|
||||
|
||||
+30
-7
@@ -11,6 +11,9 @@ import { makeLookup } from '../util/makeLookup';
|
||||
import { maybeParseUrl } from '../util/url';
|
||||
import * as Bytes from '../Bytes';
|
||||
import { deriveStickerPackKey, decryptAttachment } from '../Crypto';
|
||||
import { IMAGE_WEBP, MIMEType } from './MIME';
|
||||
import { sniffImageMimeType } from '../util/sniffImageMimeType';
|
||||
import type { AttachmentType } from './Attachment';
|
||||
import type {
|
||||
StickerType,
|
||||
StickerPackType,
|
||||
@@ -749,21 +752,41 @@ export function getSticker(
|
||||
export async function copyStickerToAttachments(
|
||||
packId: string,
|
||||
stickerId: number
|
||||
): Promise<StickerType | undefined> {
|
||||
): Promise<AttachmentType> {
|
||||
const sticker = getSticker(packId, stickerId);
|
||||
if (!sticker) {
|
||||
return undefined;
|
||||
throw new Error(
|
||||
`copyStickerToAttachments: Failed to find sticker ${packId}/${stickerId}`
|
||||
);
|
||||
}
|
||||
|
||||
const { path } = sticker;
|
||||
const absolutePath = window.Signal.Migrations.getAbsoluteStickerPath(path);
|
||||
const newPath = await window.Signal.Migrations.copyIntoAttachmentsDirectory(
|
||||
absolutePath
|
||||
const { path: stickerPath } = sticker;
|
||||
const absolutePath = window.Signal.Migrations.getAbsoluteStickerPath(
|
||||
stickerPath
|
||||
);
|
||||
const {
|
||||
path,
|
||||
size,
|
||||
} = await window.Signal.Migrations.copyIntoAttachmentsDirectory(absolutePath);
|
||||
|
||||
const data = window.Signal.Migrations.loadAttachmentData(path);
|
||||
|
||||
let contentType: MIMEType;
|
||||
const sniffedMimeType = sniffImageMimeType(data);
|
||||
if (sniffedMimeType) {
|
||||
contentType = sniffedMimeType;
|
||||
} else {
|
||||
log.warn(
|
||||
'copyStickerToAttachments: Unable to sniff sticker MIME type; falling back to WebP'
|
||||
);
|
||||
contentType = IMAGE_WEBP;
|
||||
}
|
||||
|
||||
return {
|
||||
...sticker,
|
||||
path: newPath,
|
||||
contentType,
|
||||
path,
|
||||
size,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,6 @@ export type LinkPreviewType = {
|
||||
domain: string;
|
||||
url: string;
|
||||
isStickerPack: boolean;
|
||||
image?: AttachmentType;
|
||||
image?: Readonly<AttachmentType>;
|
||||
date?: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user