2018-04-05 15:31:43 +00:00
|
|
|
import moment from 'moment';
|
2018-04-05 15:37:04 +00:00
|
|
|
import qs from 'qs';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-04-12 07:33:52 +00:00
|
|
|
import {
|
|
|
|
padStart,
|
|
|
|
sample,
|
|
|
|
} from 'lodash';
|
2018-04-05 15:37:04 +00:00
|
|
|
|
2018-04-05 15:31:43 +00:00
|
|
|
|
2018-04-05 22:30:40 +00:00
|
|
|
// Helper components used in the Style Guide, exposed at 'util' in the global scope via
|
|
|
|
// the 'context' option in react-styleguidist.
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-04-05 19:41:48 +00:00
|
|
|
export { ConversationContext } from './ConversationContext';
|
2018-04-05 22:30:40 +00:00
|
|
|
export { BackboneWrapper } from '../components/utility/BackboneWrapper';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
|
|
|
// Here we can make things inside Webpack available to Backbone views like preload.js.
|
|
|
|
|
2018-04-09 23:38:40 +00:00
|
|
|
import { Quote } from '../components/conversation/Quote';
|
2018-04-13 02:02:20 +00:00
|
|
|
import * as HTML from '../html';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-04-13 02:02:20 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import MIME from '../../js/modules/types/mime';
|
2018-04-05 15:30:30 +00:00
|
|
|
|
|
|
|
// TypeScript wants two things when you import:
|
|
|
|
// 1) a normal typescript file
|
2018-04-05 19:39:34 +00:00
|
|
|
// 2) a javascript file with type definitions
|
2018-04-05 15:30:30 +00:00
|
|
|
// Anything else will raise an error, that it can't find the module. And so, we ignore...
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import gif from '../../fixtures/giphy-GVNvOUpeYmI7e.gif';
|
2018-04-12 06:55:32 +00:00
|
|
|
const gifObjectUrl = makeObjectUrl(gif, 'image/gif');
|
2018-04-05 15:30:30 +00:00
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import mp3 from '../../fixtures/incompetech-com-Agnus-Dei-X.mp3';
|
2018-04-12 06:55:32 +00:00
|
|
|
const mp3ObjectUrl = makeObjectUrl(mp3, 'audio/mp3');
|
2018-04-05 15:30:30 +00:00
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import txt from '../../fixtures/lorem-ipsum.txt';
|
2018-04-12 06:55:32 +00:00
|
|
|
const txtObjectUrl = makeObjectUrl(txt, 'text/plain');
|
2018-04-05 15:30:30 +00:00
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import mp4 from '../../fixtures/pixabay-Soap-Bubble-7141.mp4';
|
2018-04-12 06:55:32 +00:00
|
|
|
const mp4ObjectUrl = makeObjectUrl(mp4, 'video/mp4');
|
|
|
|
|
|
|
|
function makeObjectUrl(data: ArrayBuffer, contentType: string): string {
|
|
|
|
const blob = new Blob([data], {
|
|
|
|
type: contentType,
|
|
|
|
});
|
|
|
|
return URL.createObjectURL(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ourNumber = '+12025559999';
|
2018-04-05 15:30:30 +00:00
|
|
|
|
|
|
|
export {
|
|
|
|
mp3,
|
2018-04-12 06:55:32 +00:00
|
|
|
mp3ObjectUrl,
|
2018-04-05 15:30:30 +00:00
|
|
|
gif,
|
2018-04-12 06:55:32 +00:00
|
|
|
gifObjectUrl,
|
2018-04-05 15:30:30 +00:00
|
|
|
mp4,
|
2018-04-12 06:55:32 +00:00
|
|
|
mp4ObjectUrl,
|
2018-04-05 15:30:30 +00:00
|
|
|
txt,
|
2018-04-12 06:55:32 +00:00
|
|
|
txtObjectUrl,
|
2018-04-12 07:33:52 +00:00
|
|
|
ourNumber,
|
2018-04-05 15:30:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-03 22:56:12 +00:00
|
|
|
// Required, or TypeScript complains about adding keys to window
|
|
|
|
const parent = window as any;
|
|
|
|
|
2018-04-05 15:31:43 +00:00
|
|
|
const query = window.location.search.replace(/^\?/, '');
|
|
|
|
const urlOptions = qs.parse(query);
|
|
|
|
const theme = urlOptions.theme || 'android';
|
|
|
|
const locale = urlOptions.locale || 'en';
|
|
|
|
|
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import localeMessages from '../../_locales/en/messages.json';
|
2018-04-05 15:31:43 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2018-04-05 22:30:40 +00:00
|
|
|
import { setup } from '../../js/modules/i18n';
|
2018-04-05 15:31:43 +00:00
|
|
|
|
|
|
|
const i18n = setup(locale, localeMessages);
|
|
|
|
|
|
|
|
export {
|
|
|
|
theme,
|
|
|
|
locale,
|
|
|
|
i18n,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parent.i18n = i18n;
|
|
|
|
parent.moment = moment;
|
|
|
|
|
|
|
|
parent.moment.updateLocale(locale, {
|
|
|
|
relativeTime: {
|
|
|
|
h: parent.i18n('timestamp_h'),
|
|
|
|
m: parent.i18n('timestamp_m'),
|
|
|
|
s: parent.i18n('timestamp_s'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
parent.moment.locale(locale);
|
|
|
|
|
2018-04-03 22:56:12 +00:00
|
|
|
parent.React = React;
|
|
|
|
parent.ReactDOM = ReactDOM;
|
|
|
|
|
2018-04-13 02:02:20 +00:00
|
|
|
parent.Signal.HTML = HTML;
|
|
|
|
parent.Signal.Types.MIME = MIME;
|
2018-04-06 00:16:15 +00:00
|
|
|
parent.Signal.Components = {
|
2018-04-09 23:38:40 +00:00
|
|
|
Quote,
|
2018-04-06 00:16:15 +00:00
|
|
|
};
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-04-05 16:19:00 +00:00
|
|
|
parent.ConversationController._initialFetchComplete = true;
|
|
|
|
parent.ConversationController._initialPromise = Promise.resolve();
|
2018-04-12 06:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
const COLORS = [
|
|
|
|
'red',
|
|
|
|
'pink',
|
|
|
|
'purple',
|
|
|
|
'deep_purple',
|
|
|
|
'indigo',
|
|
|
|
'blue',
|
|
|
|
'light_blue',
|
|
|
|
'cyan',
|
|
|
|
'teal',
|
|
|
|
'green',
|
|
|
|
'light_green',
|
|
|
|
'orange',
|
|
|
|
'deep_orange',
|
|
|
|
'amber',
|
|
|
|
'blue_grey',
|
|
|
|
'grey',
|
|
|
|
'default',
|
|
|
|
];
|
|
|
|
|
|
|
|
const CONTACTS = COLORS.map((color, index) => {
|
|
|
|
const title = `${sample(['Mr.', 'Mrs.', 'Ms.', 'Unknown'])} ${color}`;
|
|
|
|
const key = sample(['name', 'profileName']) as string;
|
|
|
|
const id = `+1202555${padStart(index.toString(), 4, '0')}`;
|
|
|
|
|
|
|
|
const contact = {
|
|
|
|
color,
|
|
|
|
[key]: title,
|
|
|
|
id,
|
|
|
|
type: 'private',
|
|
|
|
};
|
|
|
|
|
|
|
|
return parent.ConversationController.dangerouslyCreateAndAdd(contact);
|
|
|
|
});
|
|
|
|
|
2018-04-12 19:21:37 +00:00
|
|
|
const me = parent.ConversationController.dangerouslyCreateAndAdd({
|
|
|
|
id: ourNumber,
|
|
|
|
name: 'Me!',
|
|
|
|
type: 'private',
|
|
|
|
color: 'light_blue',
|
|
|
|
});
|
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
export {
|
|
|
|
COLORS,
|
|
|
|
CONTACTS,
|
2018-04-12 19:21:37 +00:00
|
|
|
me,
|
2018-04-12 07:33:52 +00:00
|
|
|
};
|
2018-04-12 06:55:32 +00:00
|
|
|
|
|
|
|
parent.textsecure.storage.user.getNumber = () => ourNumber;
|
|
|
|
|
|
|
|
// Telling Lodash to relinquish _ for use by underscore
|
|
|
|
// @ts-ignore
|
|
|
|
_.noConflict();
|