🎨 Autoformat code

This commit is contained in:
Daniel Gasienica
2018-04-13 16:25:52 -04:00
parent 2fae89f0e8
commit 424965f876
15 changed files with 158 additions and 140 deletions

View File

@@ -1,9 +1,11 @@
/**
* @prettier
*/
import is from '@sindresorhus/is';
import * as GoogleChrome from '../GoogleChrome';
import { MIMEType } from './MIME';
export interface Attachment {
fileName?: string;
contentType?: MIMEType;

View File

@@ -1,7 +1,9 @@
/**
* @prettier
*/
import is from '@sindresorhus/is';
import { Message } from './Message';
interface ConversationLastMessageUpdate {
lastMessage: string | null;
timestamp: number | null;
@@ -13,10 +15,10 @@ export const createLastMessageUpdate = ({
lastMessage,
lastMessageNotificationText,
}: {
currentLastMessageText: string | null,
currentTimestamp: number | null,
lastMessage: Message | null,
lastMessageNotificationText: string | null,
currentLastMessageText: string | null;
currentTimestamp: number | null;
lastMessage: Message | null;
lastMessageNotificationText: string | null;
}): ConversationLastMessageUpdate => {
if (lastMessage === null) {
return {
@@ -30,13 +32,14 @@ export const createLastMessageUpdate = ({
const isExpiringMessage = is.object(lastMessage.expirationTimerUpdate);
const shouldUpdateTimestamp = !isVerifiedChangeMessage && !isExpiringMessage;
const newTimestamp = shouldUpdateTimestamp ?
lastMessage.sent_at :
currentTimestamp;
const newTimestamp = shouldUpdateTimestamp
? lastMessage.sent_at
: currentTimestamp;
const shouldUpdateLastMessageText = !isVerifiedChangeMessage;
const newLastMessageText = shouldUpdateLastMessageText ?
lastMessageNotificationText : currentLastMessageText;
const newLastMessageText = shouldUpdateLastMessageText
? lastMessageNotificationText
: currentLastMessageText;
return {
lastMessage: newLastMessageText,

View File

@@ -1,14 +1,12 @@
/**
* @prettier
*/
export type MIMEType = string & { _mimeTypeBrand: any };
export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg';
export const isJPEG = (value: MIMEType): boolean =>
value === 'image/jpeg';
export const isImage = (value: MIMEType): boolean => value.startsWith('image/');
export const isImage = (value: MIMEType): boolean =>
value.startsWith('image/');
export const isVideo = (value: MIMEType): boolean => value.startsWith('video/');
export const isVideo = (value: MIMEType): boolean =>
value.startsWith('video/');
export const isAudio = (value: MIMEType): boolean =>
value.startsWith('audio/');
export const isAudio = (value: MIMEType): boolean => value.startsWith('audio/');

View File

@@ -1,52 +1,63 @@
/**
* @prettier
*/
import { Attachment } from './Attachment';
export type Message = IncomingMessage | OutgoingMessage | VerifiedChangeMessage;
export type Message
= IncomingMessage
| OutgoingMessage
| VerifiedChangeMessage;
export type IncomingMessage = Readonly<
{
type: 'incoming';
// Required
attachments: Array<Attachment>;
id: string;
received_at: number;
export type IncomingMessage = Readonly<{
type: 'incoming';
// Required
attachments: Array<Attachment>;
id: string;
received_at: number;
// Optional
body?: string;
decrypted_at?: number;
errors?: Array<any>;
flags?: number;
source?: string;
sourceDevice?: number;
} & SharedMessageProperties &
Message4 &
ExpirationTimerUpdate
>;
// Optional
body?: string;
decrypted_at?: number;
errors?: Array<any>;
flags?: number;
source?: string;
sourceDevice?: number;
} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>;
export type OutgoingMessage = Readonly<
{
type: 'outgoing';
export type OutgoingMessage = Readonly<{
type: 'outgoing';
// Required
attachments: Array<Attachment>;
delivered: number;
delivered_to: Array<string>;
destination: string; // PhoneNumber
expirationStartTimestamp: number;
id: string;
received_at: number;
sent: boolean;
sent_to: Array<string>; // Array<PhoneNumber>
// Required
attachments: Array<Attachment>;
delivered: number;
delivered_to: Array<string>;
destination: string; // PhoneNumber
expirationStartTimestamp: number;
id: string;
received_at: number;
sent: boolean;
sent_to: Array<string>; // Array<PhoneNumber>
// Optional
body?: string;
expires_at?: number;
expireTimer?: number;
recipients?: Array<string>; // Array<PhoneNumber>
synced: boolean;
} & SharedMessageProperties &
Message4 &
ExpirationTimerUpdate
>;
// Optional
body?: string;
expires_at?: number;
expireTimer?: number;
recipients?: Array<string>; // Array<PhoneNumber>
synced: boolean;
} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>;
export type VerifiedChangeMessage = Readonly<{
type: 'verified-change';
} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>;
export type VerifiedChangeMessage = Readonly<
{
type: 'verified-change';
} & SharedMessageProperties &
Message4 &
ExpirationTimerUpdate
>;
type SharedMessageProperties = Readonly<{
conversationId: string;
@@ -59,7 +70,7 @@ type ExpirationTimerUpdate = Readonly<{
expireTimer: number;
fromSync: boolean;
source: string; // PhoneNumber
}>,
}>;
}>;
type Message4 = Readonly<{

View File

@@ -1,20 +1,24 @@
/**
* @prettier
*/
import { partition } from 'lodash';
import * as Attachment from '../Attachment';
import { Message } from '../message';
import { Message } from '../Message';
export const initializeAttachmentMetadata = async (
message: Message
): Promise<Message> => {
const numAttachments = message.attachments.length;
const [numVisualMediaAttachments, numFileAttachments] = partition(
message.attachments,
Attachment.isVisualMedia
).map(attachments => attachments.length);
export const initializeAttachmentMetadata =
async (message: Message): Promise<Message> => {
const numAttachments = message.attachments.length;
const [numVisualMediaAttachments, numFileAttachments] =
partition(message.attachments, Attachment.isVisualMedia)
.map((attachments) => attachments.length);
return {
...message,
numAttachments,
numVisualMediaAttachments,
numFileAttachments,
};
return {
...message,
numAttachments,
numVisualMediaAttachments,
numFileAttachments,
};
};