🎨 Autoformat code

pull/1/head
Daniel Gasienica 7 years ago
parent 2fae89f0e8
commit 424965f876

@ -1,6 +1,8 @@
/**
* @prettier
*/
import * as MIME from './types/MIME'; import * as MIME from './types/MIME';
interface MIMETypeSupportMap { interface MIMETypeSupportMap {
[key: string]: boolean; [key: string]: boolean;
} }
@ -24,7 +26,7 @@ const SUPPORTED_IMAGE_MIME_TYPES: MIMETypeSupportMap = {
}; };
export const isImageTypeSupported = (mimeType: MIME.MIMEType): boolean => export const isImageTypeSupported = (mimeType: MIME.MIMEType): boolean =>
SUPPORTED_IMAGE_MIME_TYPES[mimeType] === true; SUPPORTED_IMAGE_MIME_TYPES[mimeType] === true;
const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = { const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = {
'video/mp4': true, 'video/mp4': true,
@ -34,4 +36,4 @@ const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = {
// See: https://www.chromium.org/audio-video // See: https://www.chromium.org/audio-video
export const isVideoTypeSupported = (mimeType: MIME.MIMEType): boolean => export const isVideoTypeSupported = (mimeType: MIME.MIMEType): boolean =>
SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true; SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true;

@ -1,3 +1,6 @@
/**
* @prettier
*/
import React from 'react'; import React from 'react';
import { DocumentListEntry } from './DocumentListEntry'; import { DocumentListEntry } from './DocumentListEntry';
@ -5,13 +8,11 @@ import { ImageThumbnail } from './ImageThumbnail';
import { Message } from './propTypes/Message'; import { Message } from './propTypes/Message';
import { missingCaseError } from '../../../missingCaseError'; import { missingCaseError } from '../../../missingCaseError';
const styles = { const styles = {
container: { container: {
width: '100%', width: '100%',
}, },
header: { header: {},
},
itemContainer: { itemContainer: {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
@ -32,18 +33,14 @@ export class AttachmentListSection extends React.Component<Props, {}> {
public renderItems() { public renderItems() {
const { i18n, messages, type } = this.props; const { i18n, messages, type } = this.props;
return messages.map((message) => { return messages.map(message => {
const { attachments } = message; const { attachments } = message;
const firstAttachment = attachments[0]; const firstAttachment = attachments[0];
switch (type) { switch (type) {
case 'media': case 'media':
return ( return (
<ImageThumbnail <ImageThumbnail key={message.id} i18n={i18n} message={message} />
key={message.id}
i18n={i18n}
message={message}
/>
); );
case 'documents': case 'documents':
return ( return (
@ -67,9 +64,7 @@ export class AttachmentListSection extends React.Component<Props, {}> {
return ( return (
<div style={styles.container}> <div style={styles.container}>
<div style={styles.header}>{header}</div> <div style={styles.header}>{header}</div>
<div style={styles.itemContainer}> <div style={styles.itemContainer}>{this.renderItems()}</div>
{this.renderItems()}
</div>
</div> </div>
); );
} }

@ -1,3 +1,6 @@
/**
* @prettier
*/
import React from 'react'; import React from 'react';
import moment from 'moment'; import moment from 'moment';
@ -5,7 +8,6 @@ import formatFileSize from 'filesize';
// import { LoadingIndicator } from './LoadingIndicator'; // import { LoadingIndicator } from './LoadingIndicator';
interface Props { interface Props {
fileName?: string; fileName?: string;
fileSize?: number; fileSize?: number;
@ -59,28 +61,20 @@ export class DocumentListEntry extends React.Component<Props, {}> {
// } // }
return ( return (
<div <div style={styles.itemContainer}>
style={styles.itemContainer}
>
<img <img
src="images/file.svg" src="images/file.svg"
width="48" width="48"
height="48" height="48"
style={styles.itemIcon} style={styles.itemIcon}
/> />
<div <div style={styles.itemMetadata}>
style={styles.itemMetadata}
>
<strong>{fileName}</strong> <strong>{fileName}</strong>
<span <span style={styles.itemFileSize}>
style={styles.itemFileSize}
>
{typeof fileSize === 'number' ? formatFileSize(fileSize) : ''} {typeof fileSize === 'number' ? formatFileSize(fileSize) : ''}
</span> </span>
</div> </div>
<div <div style={styles.itemDate}>
style={styles.itemDate}
>
{moment(timestamp).format('ddd, MMM D, Y')} {moment(timestamp).format('ddd, MMM D, Y')}
</div> </div>
</div> </div>
@ -88,10 +82,6 @@ export class DocumentListEntry extends React.Component<Props, {}> {
} }
public render() { public render() {
return ( return <div style={styles.container}>{this.renderContent()}</div>;
<div style={styles.container}>
{this.renderContent()}
</div>
);
} }
} }

@ -1,3 +1,6 @@
/**
* @prettier
*/
import React from 'react'; import React from 'react';
import { LoadingIndicator } from './LoadingIndicator'; import { LoadingIndicator } from './LoadingIndicator';
@ -27,7 +30,7 @@ const styles = {
export class ImageThumbnail extends React.Component<Props, {}> { export class ImageThumbnail extends React.Component<Props, {}> {
public renderContent() { public renderContent() {
const {/* i18n, */message } = this.props; const { /* i18n, */ message } = this.props;
if (!message.objectURL) { if (!message.objectURL) {
return <LoadingIndicator />; return <LoadingIndicator />;
@ -45,10 +48,6 @@ export class ImageThumbnail extends React.Component<Props, {}> {
} }
public render() { public render() {
return ( return <div style={styles.container}>{this.renderContent()}</div>;
<div style={styles.container}>
{this.renderContent()}
</div>
);
} }
} }

@ -1,3 +1,6 @@
/**
* @prettier
*/
import React from 'react'; import React from 'react';
export const LoadingIndicator = () => { export const LoadingIndicator = () => {

@ -1,3 +1,6 @@
/**
* @prettier
*/
import React from 'react'; import React from 'react';
import moment from 'moment'; import moment from 'moment';
@ -7,7 +10,6 @@ import { AttachmentListSection } from './AttachmentListSection';
import { groupMessagesByDate } from './groupMessagesByDate'; import { groupMessagesByDate } from './groupMessagesByDate';
import { Message } from './propTypes/Message'; import { Message } from './propTypes/Message';
type AttachmentType = 'media' | 'documents'; type AttachmentType = 'media' | 'documents';
interface Props { interface Props {
@ -58,13 +60,12 @@ const Tab = ({
onSelect, onSelect,
type, type,
}: { }: {
isSelected: boolean, isSelected: boolean;
label: string, label: string;
onSelect?: (event: TabSelectEvent) => void, onSelect?: (event: TabSelectEvent) => void;
type: AttachmentType, type: AttachmentType;
}) => { }) => {
const handleClick = onSelect ? const handleClick = onSelect ? () => onSelect({ type }) : undefined;
() => onSelect({ type }) : undefined;
return ( return (
<div <div
@ -76,7 +77,6 @@ const Tab = ({
); );
}; };
export class MediaGallery extends React.Component<Props, State> { export class MediaGallery extends React.Component<Props, State> {
public state: State = { public state: State = {
selectedTab: 'media', selectedTab: 'media',
@ -101,16 +101,14 @@ export class MediaGallery extends React.Component<Props, State> {
onSelect={this.handleTabSelect} onSelect={this.handleTabSelect}
/> />
</div> </div>
<div style={styles.attachmentsContainer}> <div style={styles.attachmentsContainer}>{this.renderSections()}</div>
{this.renderSections()}
</div>
</div> </div>
); );
} }
private handleTabSelect = (event: TabSelectEvent): void => { private handleTabSelect = (event: TabSelectEvent): void => {
this.setState({selectedTab: event.type}); this.setState({ selectedTab: event.type });
} };
private renderSections() { private renderSections() {
const { i18n, media, documents } = this.props; const { i18n, media, documents } = this.props;

@ -1,18 +1,25 @@
/**
* @prettier
*/
import moment from 'moment'; import moment from 'moment';
import { groupBy, sortBy } from 'lodash'; import { compact, groupBy, sortBy } from 'lodash';
import { Message } from './propTypes/Message'; import { Message } from './propTypes/Message';
export const groupMessagesByDate = (
export const groupMessagesByDate = (timestamp: number, messages: Array<Message>): any => { timestamp: number,
messages: Array<Message>
): any => {
const referenceDateTime = moment.utc(timestamp); const referenceDateTime = moment.utc(timestamp);
const today = moment(referenceDateTime).startOf('day'); const today = moment(referenceDateTime).startOf('day');
const yesterday = moment(referenceDateTime).subtract(1, 'day').startOf('day'); const yesterday = moment(referenceDateTime)
.subtract(1, 'day')
.startOf('day');
const thisWeek = moment(referenceDateTime).startOf('isoWeek'); const thisWeek = moment(referenceDateTime).startOf('isoWeek');
const thisMonth = moment(referenceDateTime).startOf('month'); const thisMonth = moment(referenceDateTime).startOf('month');
const sorted = sortBy(messages, (message) => -message.received_at); const sorted = sortBy(messages, message => -message.received_at);
const annotations = sorted.map((message) => { const annotations = sorted.map(message => {
const date = moment.utc(message.received_at); const date = moment.utc(message.received_at);
if (date.isAfter(today)) { if (date.isAfter(today)) {
@ -42,7 +49,7 @@ export const groupMessagesByDate = (timestamp: number, messages: Array<Message>)
} }
return { return {
order: (date.year() * 100) + date.month(), order: date.year() * 100 + date.month(),
label: 'yearMonth', label: 'yearMonth',
message, message,
}; };

@ -1,3 +1,6 @@
/**
* @prettier
*/
export interface Message { export interface Message {
id: string; id: string;
body?: string; body?: string;

@ -1,3 +1,6 @@
/**
* @prettier
*/
// `missingCaseError` is useful for compile-time checking that all `case`s in // `missingCaseError` is useful for compile-time checking that all `case`s in
// a `switch` statement have been handled, e.g. // a `switch` statement have been handled, e.g.
// //

@ -1,11 +1,11 @@
/**
* @prettier
*/
import 'mocha'; import 'mocha';
import { assert } from 'chai'; import { assert } from 'chai';
import { groupMessagesByDate } from import { groupMessagesByDate } from '../../../components/conversation/media-gallery/groupMessagesByDate';
'../../../components/conversation/media-gallery/groupMessagesByDate'; import { Message } from '../../../components/conversation/media-gallery/propTypes/Message';
import { Message } from
'../../../components/conversation/media-gallery/propTypes/Message';
const toMessage = (date: Date): Message => ({ const toMessage = (date: Date): Message => ({
id: date.toUTCString(), id: date.toUTCString(),

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

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

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

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

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

Loading…
Cancel
Save