Convert js/modules/types/message to Typescript
This commit is contained in:
parent
9975758fde
commit
924c271b13
18 changed files with 748 additions and 398 deletions
|
@ -24,8 +24,8 @@ import {
|
|||
} from '../util/GoogleChrome';
|
||||
import type { LocalizerType } from './Util';
|
||||
import { ThemeType } from './Util';
|
||||
import * as GoogleChrome from '../util/GoogleChrome';
|
||||
import { scaleImageToLevel } from '../util/scaleImageToLevel';
|
||||
import * as GoogleChrome from '../util/GoogleChrome';
|
||||
import { parseIntOrThrow } from '../util/parseIntOrThrow';
|
||||
import { getValue } from '../RemoteConfig';
|
||||
|
||||
|
@ -58,6 +58,7 @@ export type AttachmentType = {
|
|||
url?: string;
|
||||
contentType: MIME.MIMEType;
|
||||
path: string;
|
||||
data?: Uint8Array;
|
||||
};
|
||||
screenshotData?: Uint8Array;
|
||||
screenshotPath?: string;
|
||||
|
@ -74,6 +75,9 @@ export type AttachmentType = {
|
|||
/** Legacy field. Used only for downloading old attachments */
|
||||
id?: number;
|
||||
|
||||
/** Legacy field, used long ago for migrating attachments to disk. */
|
||||
schemaVersion?: number;
|
||||
|
||||
/** Removed once we download the attachment */
|
||||
digest?: string;
|
||||
key?: string;
|
||||
|
@ -159,11 +163,12 @@ export type AttachmentDraftType =
|
|||
};
|
||||
|
||||
export type ThumbnailType = {
|
||||
height: number;
|
||||
width: number;
|
||||
height?: number;
|
||||
width?: number;
|
||||
url?: string;
|
||||
contentType: MIME.MIMEType;
|
||||
path: string;
|
||||
path?: string;
|
||||
data?: Uint8Array;
|
||||
// Only used when quote needed to make an in-memory thumbnail
|
||||
objectUrl?: string;
|
||||
};
|
||||
|
@ -432,16 +437,19 @@ export async function captureDimensionsAndScreenshot(
|
|||
attachment: AttachmentType,
|
||||
params: {
|
||||
writeNewAttachmentData: (data: Uint8Array) => Promise<string>;
|
||||
getAbsoluteAttachmentPath: (path: string) => Promise<string>;
|
||||
getAbsoluteAttachmentPath: (path: string) => string;
|
||||
makeObjectUrl: (
|
||||
data: Uint8Array | ArrayBuffer,
|
||||
contentType: MIME.MIMEType
|
||||
) => string;
|
||||
revokeObjectUrl: (path: string) => void;
|
||||
getImageDimensions: (params: { objectUrl: string; logger: LoggerType }) => {
|
||||
getImageDimensions: (params: {
|
||||
objectUrl: string;
|
||||
logger: LoggerType;
|
||||
}) => Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}>;
|
||||
makeImageThumbnail: (params: {
|
||||
size: number;
|
||||
objectUrl: string;
|
||||
|
@ -481,7 +489,7 @@ export async function captureDimensionsAndScreenshot(
|
|||
return attachment;
|
||||
}
|
||||
|
||||
const absolutePath = await getAbsoluteAttachmentPath(attachment.path);
|
||||
const absolutePath = getAbsoluteAttachmentPath(attachment.path);
|
||||
|
||||
if (GoogleChrome.isImageTypeSupported(contentType)) {
|
||||
try {
|
||||
|
|
|
@ -191,12 +191,12 @@ export function parseAndWriteAvatar(
|
|||
contact: EmbeddedContactType,
|
||||
context: {
|
||||
message: MessageAttributesType;
|
||||
regionCode: string;
|
||||
getRegionCode: () => string | undefined;
|
||||
logger: Pick<LoggerType, 'error'>;
|
||||
writeNewAttachmentData: (data: Uint8Array) => Promise<string>;
|
||||
}
|
||||
): Promise<EmbeddedContactType> => {
|
||||
const { message, regionCode, logger } = context;
|
||||
const { message, getRegionCode, logger } = context;
|
||||
const { avatar } = contact;
|
||||
|
||||
const contactWithUpdatedAvatar =
|
||||
|
@ -212,7 +212,7 @@ export function parseAndWriteAvatar(
|
|||
|
||||
// eliminates empty numbers, emails, and addresses; adds type if not provided
|
||||
const parsedContact = parseContact(contactWithUpdatedAvatar, {
|
||||
regionCode,
|
||||
regionCode: getRegionCode(),
|
||||
});
|
||||
|
||||
const error = _validate(parsedContact, {
|
||||
|
@ -231,7 +231,7 @@ export function parseAndWriteAvatar(
|
|||
|
||||
function parseContact(
|
||||
contact: EmbeddedContactType,
|
||||
{ regionCode }: { regionCode: string }
|
||||
{ regionCode }: { regionCode: string | undefined }
|
||||
): EmbeddedContactType {
|
||||
const boundParsePhone = (phoneNumber: Phone): Phone | undefined =>
|
||||
parsePhoneItem(phoneNumber, { regionCode });
|
||||
|
@ -294,7 +294,7 @@ export function _validate(
|
|||
|
||||
function parsePhoneItem(
|
||||
item: Phone,
|
||||
{ regionCode }: { regionCode: string }
|
||||
{ regionCode }: { regionCode: string | undefined }
|
||||
): Phone | undefined {
|
||||
if (!item.value) {
|
||||
return undefined;
|
||||
|
|
|
@ -75,13 +75,13 @@ export type ProfileChangeNotificationMessage = Readonly<
|
|||
ExpirationTimerUpdate
|
||||
>;
|
||||
|
||||
type SharedMessageProperties = Readonly<{
|
||||
export type SharedMessageProperties = Readonly<{
|
||||
conversationId: string;
|
||||
sent_at: number;
|
||||
timestamp: number;
|
||||
}>;
|
||||
|
||||
type ExpirationTimerUpdate = Partial<
|
||||
export type ExpirationTimerUpdate = Partial<
|
||||
Readonly<{
|
||||
expirationTimerUpdate: Readonly<{
|
||||
expireTimer: number;
|
||||
|
@ -91,7 +91,7 @@ type ExpirationTimerUpdate = Partial<
|
|||
}>
|
||||
>;
|
||||
|
||||
type MessageSchemaVersion5 = Partial<
|
||||
export type MessageSchemaVersion5 = Partial<
|
||||
Readonly<{
|
||||
hasAttachments: IndexableBoolean;
|
||||
hasVisualMediaAttachments: IndexablePresence;
|
||||
|
@ -99,7 +99,7 @@ type MessageSchemaVersion5 = Partial<
|
|||
}>
|
||||
>;
|
||||
|
||||
type MessageSchemaVersion6 = Partial<
|
||||
export type MessageSchemaVersion6 = Partial<
|
||||
Readonly<{
|
||||
contact: Array<EmbeddedContactType>;
|
||||
}>
|
||||
|
|
1021
ts/types/Message2.ts
Normal file
1021
ts/types/Message2.ts
Normal file
File diff suppressed because it is too large
Load diff
|
@ -51,7 +51,7 @@ export const format = memoizee(_format, {
|
|||
export function parse(
|
||||
phoneNumber: string,
|
||||
options: {
|
||||
regionCode: string;
|
||||
regionCode: string | undefined;
|
||||
}
|
||||
): string {
|
||||
const { regionCode } = options;
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
import { isNumber } from 'lodash';
|
||||
|
||||
export const isValid = (value: unknown): boolean => {
|
||||
export const isValid = (value: unknown): value is number => {
|
||||
return Boolean(isNumber(value) && value >= 0);
|
||||
};
|
||||
|
|
|
@ -3,19 +3,20 @@
|
|||
|
||||
import * as Attachment from '../Attachment';
|
||||
import * as IndexedDB from '../IndexedDB';
|
||||
import type { Message, UserMessage } from '../Message';
|
||||
|
||||
import type { MessageAttributesType } from '../../model-types.d';
|
||||
|
||||
const hasAttachment =
|
||||
(predicate: (value: Attachment.AttachmentType) => boolean) =>
|
||||
(message: UserMessage): IndexedDB.IndexablePresence =>
|
||||
IndexedDB.toIndexablePresence(message.attachments.some(predicate));
|
||||
(message: MessageAttributesType): IndexedDB.IndexablePresence =>
|
||||
IndexedDB.toIndexablePresence((message.attachments || []).some(predicate));
|
||||
|
||||
const hasFileAttachment = hasAttachment(Attachment.isFile);
|
||||
const hasVisualMediaAttachment = hasAttachment(Attachment.isVisualMedia);
|
||||
|
||||
export const initializeAttachmentMetadata = async (
|
||||
message: Message
|
||||
): Promise<Message> => {
|
||||
message: MessageAttributesType
|
||||
): Promise<MessageAttributesType> => {
|
||||
if (message.type === 'verified-change') {
|
||||
return message;
|
||||
}
|
||||
|
@ -26,7 +27,7 @@ export const initializeAttachmentMetadata = async (
|
|||
return message;
|
||||
}
|
||||
|
||||
const attachments = message.attachments.filter(
|
||||
const attachments = (message.attachments || []).filter(
|
||||
(attachment: Attachment.AttachmentType) =>
|
||||
attachment.contentType !== 'text/x-signal-plain'
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue