Send related emoji along with Sticker, fix SendMessage types

This commit is contained in:
Scott Nonnenberg
2021-10-05 15:10:08 -07:00
committed by GitHub
parent 3c91dce993
commit bd380086a4
35 changed files with 522 additions and 376 deletions
+8 -4
View File
@@ -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) &&
+3
View File
@@ -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
View File
@@ -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,
};
}
+1 -1
View File
@@ -9,6 +9,6 @@ export type LinkPreviewType = {
domain: string;
url: string;
isStickerPack: boolean;
image?: AttachmentType;
image?: Readonly<AttachmentType>;
date?: number;
};