signal-desktop/js/modules/signal.js

416 lines
12 KiB
JavaScript
Raw Normal View History

// The idea with this file is to make it webpackable for the style guide
2019-01-14 21:49:58 +00:00
const { bindActionCreators } = require('redux');
const Backbone = require('../../ts/backbone');
const Crypto = require('../../ts/Crypto');
const {
start: conversationControllerStart,
} = require('../../ts/ConversationController');
const Data = require('../../ts/sql/Client').default;
2019-05-24 23:58:27 +00:00
const Emojis = require('./emojis');
const EmojiLib = require('../../ts/components/emoji/lib');
2020-09-09 02:25:05 +00:00
const Groups = require('../../ts/groups');
const GroupChange = require('../../ts/groupChange');
2018-10-18 01:01:21 +00:00
const IndexedDB = require('./indexeddb');
const Notifications = require('../../ts/notifications');
const OS = require('../../ts/OS');
const Stickers = require('./stickers');
const Settings = require('./settings');
2020-05-27 21:37:06 +00:00
const RemoteConfig = require('../../ts/RemoteConfig');
const Util = require('../../ts/util');
const Metadata = require('./metadata/SecretSessionCipher');
const RefreshSenderCertificate = require('./refresh_sender_certificate');
2019-01-16 03:03:56 +00:00
const LinkPreviews = require('./link_previews');
const AttachmentDownloads = require('./attachment_downloads');
// Components
const {
AttachmentList,
} = require('../../ts/components/conversation/AttachmentList');
const { CaptionEditor } = require('../../ts/components/CaptionEditor');
2020-10-06 17:06:34 +00:00
const { ConfirmationModal } = require('../../ts/components/ConfirmationModal');
const {
ContactDetail,
} = require('../../ts/components/conversation/ContactDetail');
const { ContactListItem } = require('../../ts/components/ContactListItem');
const { Emojify } = require('../../ts/components/conversation/Emojify');
2020-10-06 17:06:34 +00:00
const { ErrorModal } = require('../../ts/components/ErrorModal');
const { Lightbox } = require('../../ts/components/Lightbox');
const { LightboxGallery } = require('../../ts/components/LightboxGallery');
const {
MediaGallery,
} = require('../../ts/components/conversation/media-gallery/MediaGallery');
const {
MessageDetail,
} = require('../../ts/components/conversation/MessageDetail');
const { Quote } = require('../../ts/components/conversation/Quote');
2020-10-06 17:06:34 +00:00
const { ProgressModal } = require('../../ts/components/ProgressModal');
const {
SafetyNumberChangeDialog,
} = require('../../ts/components/SafetyNumberChangeDialog');
2019-01-16 03:03:56 +00:00
const {
StagedLinkPreview,
} = require('../../ts/components/conversation/StagedLinkPreview');
const {
getCallingNotificationText,
} = require('../../ts/components/conversation/CallingNotification');
2019-01-14 21:49:58 +00:00
// State
const { createTimeline } = require('../../ts/state/roots/createTimeline');
const {
createCompositionArea,
} = require('../../ts/state/roots/createCompositionArea');
2020-10-30 17:52:21 +00:00
const {
createConversationHeader,
} = require('../../ts/state/roots/createConversationHeader');
2020-06-04 18:16:19 +00:00
const { createCallManager } = require('../../ts/state/roots/createCallManager');
const { createLeftPane } = require('../../ts/state/roots/createLeftPane');
const {
createSafetyNumberViewer,
} = require('../../ts/state/roots/createSafetyNumberViewer');
const {
createStickerManager,
} = require('../../ts/state/roots/createStickerManager');
const {
createStickerPreviewModal,
} = require('../../ts/state/roots/createStickerPreviewModal');
2019-11-07 21:36:16 +00:00
const {
createShortcutGuideModal,
} = require('../../ts/state/roots/createShortcutGuideModal');
2019-01-14 21:49:58 +00:00
const { createStore } = require('../../ts/state/createStore');
2020-06-04 18:16:19 +00:00
const callingDuck = require('../../ts/state/ducks/calling');
2019-01-14 21:49:58 +00:00
const conversationsDuck = require('../../ts/state/ducks/conversations');
2019-05-24 23:58:27 +00:00
const emojisDuck = require('../../ts/state/ducks/emojis');
const expirationDuck = require('../../ts/state/ducks/expiration');
const itemsDuck = require('../../ts/state/ducks/items');
const networkDuck = require('../../ts/state/ducks/network');
2019-08-09 23:12:29 +00:00
const searchDuck = require('../../ts/state/ducks/search');
const stickersDuck = require('../../ts/state/ducks/stickers');
const updatesDuck = require('../../ts/state/ducks/updates');
2019-01-14 21:49:58 +00:00
const userDuck = require('../../ts/state/ducks/user');
2019-11-07 21:36:16 +00:00
const conversationsSelectors = require('../../ts/state/selectors/conversations');
const searchSelectors = require('../../ts/state/selectors/search');
2019-11-07 21:36:16 +00:00
// Types
const AttachmentType = require('./types/attachment');
const VisualAttachment = require('./types/visual_attachment');
const Contact = require('../../ts/types/Contact');
2018-09-21 01:47:19 +00:00
const Conversation = require('./types/conversation');
const Errors = require('./types/errors');
const MediaGalleryMessage = require('../../ts/components/conversation/media-gallery/types/Message');
const MessageType = require('./types/message');
const MIME = require('../../ts/types/MIME');
const PhoneNumber = require('../../ts/types/PhoneNumber');
const SettingsType = require('../../ts/types/Settings');
// Views
const Initialization = require('./views/initialization');
// Workflow
const { IdleDetector } = require('./idle_detector');
const MessageDataMigrator = require('./messages_data_migrator');
// Processes / Services
2020-09-09 02:25:05 +00:00
const {
initializeGroupCredentialFetcher,
} = require('../../ts/services/groupCredentialFetcher');
const {
initializeNetworkObserver,
} = require('../../ts/services/networkObserver');
const {
initializeUpdateListener,
} = require('../../ts/services/updateListener');
2020-06-04 18:16:19 +00:00
const { notify } = require('../../ts/services/notify');
const { calling } = require('../../ts/services/calling');
const { onTimeout, removeTimeout } = require('../../ts/services/timers');
2020-09-09 00:56:23 +00:00
const {
enableStorageService,
2020-09-09 00:56:23 +00:00
eraseAllStorageServiceState,
runStorageServiceSyncJob,
storageServiceUploadJob,
} = require('../../ts/services/storage');
function initializeMigrations({
userDataPath,
getRegionCode,
Attachments,
Type,
VisualType,
logger,
}) {
if (!Attachments) {
return null;
}
const {
2019-08-07 00:40:25 +00:00
createAbsolutePathGetter,
createReader,
createWriterForExisting,
createWriterForNew,
createDoesExist,
2019-08-07 00:40:25 +00:00
getDraftPath,
getPath,
getStickersPath,
getTempPath,
openFileInFolder,
saveAttachmentToDisk,
} = Attachments;
const {
getImageDimensions,
makeImageThumbnail,
2019-08-07 00:40:25 +00:00
makeObjectUrl,
makeVideoScreenshot,
2019-08-07 00:40:25 +00:00
revokeObjectUrl,
} = VisualType;
const attachmentsPath = getPath(userDataPath);
const readAttachmentData = createReader(attachmentsPath);
const loadAttachmentData = Type.loadData(readAttachmentData);
const loadPreviewData = MessageType.loadPreviewData(loadAttachmentData);
const loadQuoteData = MessageType.loadQuoteData(loadAttachmentData);
const loadStickerData = MessageType.loadStickerData(loadAttachmentData);
const getAbsoluteAttachmentPath = createAbsolutePathGetter(attachmentsPath);
const deleteOnDisk = Attachments.createDeleter(attachmentsPath);
const writeNewAttachmentData = createWriterForNew(attachmentsPath);
const copyIntoAttachmentsDirectory = Attachments.copyIntoAttachmentsDirectory(
attachmentsPath
);
const doesAttachmentExist = createDoesExist(attachmentsPath);
const stickersPath = getStickersPath(userDataPath);
const writeNewStickerData = createWriterForNew(stickersPath);
const getAbsoluteStickerPath = createAbsolutePathGetter(stickersPath);
const deleteSticker = Attachments.createDeleter(stickersPath);
const readStickerData = createReader(stickersPath);
const tempPath = getTempPath(userDataPath);
const getAbsoluteTempPath = createAbsolutePathGetter(tempPath);
const writeNewTempData = createWriterForNew(tempPath);
const deleteTempFile = Attachments.createDeleter(tempPath);
const readTempData = createReader(tempPath);
2019-08-05 20:53:15 +00:00
const copyIntoTempDirectory = Attachments.copyIntoAttachmentsDirectory(
tempPath
);
2019-08-07 00:40:25 +00:00
const draftPath = getDraftPath(userDataPath);
const getAbsoluteDraftPath = createAbsolutePathGetter(draftPath);
const writeNewDraftData = createWriterForNew(draftPath);
const deleteDraftFile = Attachments.createDeleter(draftPath);
const readDraftData = createReader(draftPath);
return {
attachmentsPath,
copyIntoAttachmentsDirectory,
2019-08-05 20:53:15 +00:00
copyIntoTempDirectory,
deleteAttachmentData: deleteOnDisk,
2019-08-07 00:40:25 +00:00
deleteDraftFile,
deleteExternalMessageFiles: MessageType.deleteAllExternalFiles({
deleteAttachmentData: Type.deleteData(deleteOnDisk),
deleteOnDisk,
}),
deleteSticker,
deleteTempFile,
doesAttachmentExist,
getAbsoluteAttachmentPath,
2019-08-07 00:40:25 +00:00
getAbsoluteDraftPath,
getAbsoluteStickerPath,
2019-08-05 20:53:15 +00:00
getAbsoluteTempPath,
loadAttachmentData,
loadMessage: MessageType.createAttachmentLoader(loadAttachmentData),
2019-01-16 03:03:56 +00:00
loadPreviewData,
loadQuoteData,
loadStickerData,
openFileInFolder,
2018-12-13 21:41:42 +00:00
readAttachmentData,
2019-08-07 00:40:25 +00:00
readDraftData,
readStickerData,
readTempData,
saveAttachmentToDisk,
processNewAttachment: attachment =>
MessageType.processNewAttachment(attachment, {
writeNewAttachmentData,
getAbsoluteAttachmentPath,
makeObjectUrl,
revokeObjectUrl,
getImageDimensions,
makeImageThumbnail,
makeVideoScreenshot,
logger,
}),
processNewSticker: stickerData =>
MessageType.processNewSticker(stickerData, {
writeNewStickerData,
getAbsoluteStickerPath,
getImageDimensions,
logger,
}),
processNewEphemeralSticker: stickerData =>
MessageType.processNewSticker(stickerData, {
writeNewStickerData: writeNewTempData,
getAbsoluteStickerPath: getAbsoluteTempPath,
getImageDimensions,
logger,
}),
upgradeMessageSchema: (message, options = {}) => {
const { maxVersion } = options;
return MessageType.upgradeSchema(message, {
writeNewAttachmentData,
getRegionCode,
getAbsoluteAttachmentPath,
makeObjectUrl,
revokeObjectUrl,
getImageDimensions,
makeImageThumbnail,
makeVideoScreenshot,
logger,
maxVersion,
});
},
writeMessageAttachments: MessageType.createAttachmentDataWriter({
writeExistingAttachmentData: createWriterForExisting(attachmentsPath),
logger,
}),
writeNewAttachmentData: createWriterForNew(attachmentsPath),
2019-08-07 00:40:25 +00:00
writeNewDraftData,
};
}
exports.setup = (options = {}) => {
const { Attachments, userDataPath, getRegionCode, logger } = options;
const Migrations = initializeMigrations({
userDataPath,
getRegionCode,
Attachments,
Type: AttachmentType,
VisualType: VisualAttachment,
logger,
});
const Components = {
AttachmentList,
CaptionEditor,
2020-10-06 17:06:34 +00:00
ConfirmationModal,
ContactDetail,
ContactListItem,
Emojify,
2020-10-06 17:06:34 +00:00
ErrorModal,
getCallingNotificationText,
Lightbox,
LightboxGallery,
MediaGallery,
MessageDetail,
Quote,
2020-10-06 17:06:34 +00:00
ProgressModal,
SafetyNumberChangeDialog,
2019-01-16 03:03:56 +00:00
StagedLinkPreview,
Types: {
Message: MediaGalleryMessage,
},
};
2019-01-14 21:49:58 +00:00
const Roots = {
2020-06-04 18:16:19 +00:00
createCallManager,
createCompositionArea,
2020-10-30 17:52:21 +00:00
createConversationHeader,
2019-01-14 21:49:58 +00:00
createLeftPane,
createSafetyNumberViewer,
2019-11-07 21:36:16 +00:00
createShortcutGuideModal,
createStickerManager,
createStickerPreviewModal,
2019-11-07 21:36:16 +00:00
createTimeline,
2019-01-14 21:49:58 +00:00
};
2019-01-14 21:49:58 +00:00
const Ducks = {
2020-06-04 18:16:19 +00:00
calling: callingDuck,
2019-01-14 21:49:58 +00:00
conversations: conversationsDuck,
2019-05-24 23:58:27 +00:00
emojis: emojisDuck,
expiration: expirationDuck,
items: itemsDuck,
network: networkDuck,
updates: updatesDuck,
2019-01-14 21:49:58 +00:00
user: userDuck,
2019-08-09 23:12:29 +00:00
search: searchDuck,
stickers: stickersDuck,
2019-01-14 21:49:58 +00:00
};
2019-11-07 21:36:16 +00:00
const Selectors = {
conversations: conversationsSelectors,
search: searchSelectors,
2019-11-07 21:36:16 +00:00
};
const Services = {
2020-09-09 00:56:23 +00:00
calling,
enableStorageService,
2020-09-09 00:56:23 +00:00
eraseAllStorageServiceState,
2020-09-09 02:25:05 +00:00
initializeGroupCredentialFetcher,
initializeNetworkObserver,
initializeUpdateListener,
onTimeout,
2020-06-04 18:16:19 +00:00
notify,
removeTimeout,
2020-09-09 00:56:23 +00:00
runStorageServiceSyncJob,
storageServiceUploadJob,
};
2019-01-14 21:49:58 +00:00
const State = {
bindActionCreators,
createStore,
Roots,
Ducks,
2019-11-07 21:36:16 +00:00
Selectors,
2019-01-14 21:49:58 +00:00
};
const Types = {
Attachment: AttachmentType,
Contact,
Conversation,
Errors,
Message: MessageType,
MIME,
PhoneNumber,
Settings: SettingsType,
VisualAttachment,
};
const Views = {
Initialization,
};
const Workflow = {
IdleDetector,
MessageDataMigrator,
};
return {
AttachmentDownloads,
Backbone,
Components,
Crypto,
conversationControllerStart,
Data,
2019-05-24 23:58:27 +00:00
Emojis,
EmojiLib,
2020-09-09 02:25:05 +00:00
Groups,
GroupChange,
2018-10-18 01:01:21 +00:00
IndexedDB,
2019-01-16 03:03:56 +00:00
LinkPreviews,
Metadata,
Migrations,
Notifications,
OS,
RefreshSenderCertificate,
2020-05-27 21:37:06 +00:00
RemoteConfig,
Settings,
Services,
2019-01-14 21:49:58 +00:00
State,
Stickers,
Types,
Util,
Views,
Workflow,
};
};