2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2021-08-18 20:08:14 +00:00
import { webFrame } from 'electron' ;
2023-02-08 17:19:25 +00:00
import { isNumber , throttle , groupBy } from 'lodash' ;
2021-06-15 23:30:23 +00:00
import { bindActionCreators } from 'redux' ;
2021-11-01 23:38:08 +00:00
import { render } from 'react-dom' ;
import { batch as batchDispatch } from 'react-redux' ;
2022-08-25 05:04:42 +00:00
import PQueue from 'p-queue' ;
2021-05-28 19:11:19 +00:00
2023-04-11 03:54:43 +00:00
import * as Registration from './util/registration' ;
2021-07-09 19:36:10 +00:00
import MessageReceiver from './textsecure/MessageReceiver' ;
2021-10-26 19:15:33 +00:00
import type {
SessionResetsType ,
ProcessedDataMessage ,
} from './textsecure/Types.d' ;
2021-09-22 00:58:03 +00:00
import { HTTPError } from './textsecure/Errors' ;
2022-03-02 22:53:47 +00:00
import createTaskWithTimeout , {
2021-09-27 18:22:46 +00:00
suspendTasksWithTimeout ,
resumeTasksWithTimeout ,
2022-10-26 00:03:05 +00:00
reportLongRunningTasks ,
2021-09-27 18:22:46 +00:00
} from './textsecure/TaskWithTimeout' ;
2021-10-26 19:15:33 +00:00
import type {
2021-07-09 19:36:10 +00:00
MessageAttributesType ,
ConversationAttributesType ,
2022-01-04 15:27:16 +00:00
ReactionAttributesType ,
2021-07-09 19:36:10 +00:00
} from './model-types.d' ;
import * as Bytes from './Bytes' ;
2021-10-07 18:18:22 +00:00
import * as Timers from './Timers' ;
2022-06-01 16:51:30 +00:00
import * as indexedDb from './indexeddb' ;
2022-06-08 22:00:32 +00:00
import type { MenuOptionsType } from './types/menu' ;
2021-12-07 22:41:40 +00:00
import type { Receipt } from './types/Receipt' ;
2023-02-06 17:24:34 +00:00
import { ReceiptType } from './types/Receipt' ;
2021-06-09 22:28:54 +00:00
import { SocketStatus } from './types/SocketStatus' ;
2021-06-08 21:31:35 +00:00
import { DEFAULT_CONVERSATION_COLOR } from './types/Colors' ;
2022-05-11 22:58:14 +00:00
import { ThemeType } from './types/Util' ;
2021-05-06 00:09:29 +00:00
import { ChallengeHandler } from './challenge' ;
2021-08-26 14:10:58 +00:00
import * as durations from './util/durations' ;
2022-12-21 18:41:48 +00:00
import { drop } from './util/drop' ;
2021-10-07 18:18:22 +00:00
import { explodePromise } from './util/explodePromise' ;
2021-03-08 22:42:29 +00:00
import { isWindowDragElement } from './util/isWindowDragElement' ;
2022-09-15 19:17:15 +00:00
import { assertDev , strictAssert } from './util/assert' ;
2021-07-09 19:36:10 +00:00
import { normalizeUuid } from './util/normalizeUuid' ;
2021-06-18 19:12:04 +00:00
import { filter } from './util/iterables' ;
import { isNotNil } from './util/isNotNil' ;
2022-12-20 20:29:17 +00:00
import { isPnpEnabled } from './util/isPnpEnabled' ;
2022-06-01 19:57:30 +00:00
import { setAppLoadingScreenMessage } from './setAppLoadingScreenMessage' ;
2021-12-10 23:20:24 +00:00
import { IdleDetector } from './IdleDetector' ;
2022-05-31 23:53:14 +00:00
import { expiringMessagesDeletionService } from './services/expiringMessagesDeletion' ;
import { tapToViewMessagesDeletionService } from './services/tapToViewMessagesDeletionService' ;
2022-05-11 21:02:26 +00:00
import { getStoriesForRedux , loadStories } from './services/storyLoader' ;
2022-07-01 00:52:03 +00:00
import {
getDistributionListsForRedux ,
loadDistributionLists ,
} from './services/distributionListLoader' ;
2021-04-08 16:24:21 +00:00
import { senderCertificateService } from './services/senderCertificate' ;
2021-09-28 16:30:30 +00:00
import { GROUP_CREDENTIALS_KEY } from './services/groupCredentialFetcher' ;
2021-09-29 21:20:52 +00:00
import * as KeyboardLayout from './services/keyboardLayout' ;
2022-10-08 00:19:02 +00:00
import * as StorageService from './services/storage' ;
2023-02-09 21:13:08 +00:00
import { optimizeFTS } from './services/ftsOptimizer' ;
2022-07-08 20:46:25 +00:00
import { RoutineProfileRefresher } from './routineProfileRefresh' ;
2023-01-13 00:24:59 +00:00
import { isOlderThan , toDayMillis } from './util/timestamp' ;
2021-04-07 17:04:42 +00:00
import { isValidReactionEmoji } from './reactions/isValidReactionEmoji' ;
2021-10-26 19:15:33 +00:00
import type { ConversationModel } from './models/conversations' ;
2022-08-15 21:53:33 +00:00
import { getContact , isIncoming } from './messages/helpers' ;
2022-05-31 23:56:25 +00:00
import { migrateMessageData } from './messages/migrateMessageData' ;
2021-04-08 00:35:22 +00:00
import { createBatcher } from './util/batcher' ;
2021-04-28 18:36:10 +00:00
import { updateConversationsWithUuidLookup } from './updateConversationsWithUuidLookup' ;
2023-02-24 19:03:17 +00:00
import {
initializeAllJobQueues ,
shutdownAllJobQueues ,
} from './jobs/initializeAllJobQueues' ;
2021-04-29 23:02:27 +00:00
import { removeStorageKeyJobQueue } from './jobs/removeStorageKeyJobQueue' ;
2021-05-05 16:39:16 +00:00
import { ourProfileKeyService } from './services/ourProfileKey' ;
2021-09-23 18:16:09 +00:00
import { notificationService } from './services/notifications' ;
2021-11-30 16:29:57 +00:00
import { areWeASubscriberService } from './services/areWeASubscriber' ;
2022-08-25 05:04:42 +00:00
import { onContactSync , setIsInitialSync } from './services/contactSync' ;
2022-05-31 16:22:31 +00:00
import { startTimeTravelDetector } from './util/startTimeTravelDetector' ;
2021-05-05 16:39:16 +00:00
import { shouldRespondWithProfileKey } from './util/shouldRespondWithProfileKey' ;
2021-05-17 18:29:37 +00:00
import { LatestQueue } from './util/LatestQueue' ;
2021-05-28 19:11:19 +00:00
import { parseIntOrThrow } from './util/parseIntOrThrow' ;
2021-07-21 20:45:41 +00:00
import { getProfile } from './util/getProfile' ;
2021-10-26 19:15:33 +00:00
import type {
2021-10-20 21:50:00 +00:00
ConfigurationEvent ,
DecryptionErrorEvent ,
2021-07-09 19:36:10 +00:00
DeliveryEvent ,
2021-10-20 21:50:00 +00:00
EnvelopeEvent ,
ErrorEvent ,
FetchLatestEvent ,
GroupEvent ,
2023-05-03 20:53:28 +00:00
InvalidPlaintextEvent ,
2021-10-20 21:50:00 +00:00
KeysEvent ,
2021-07-09 19:36:10 +00:00
MessageEvent ,
MessageEventData ,
MessageRequestResponseEvent ,
2021-10-20 21:50:00 +00:00
ProfileKeyUpdateEvent ,
ReadEvent ,
ReadSyncEvent ,
RetryRequestEvent ,
SentEvent ,
SentEventData ,
2021-07-09 19:36:10 +00:00
StickerPackEvent ,
2021-10-20 21:50:00 +00:00
TypingEvent ,
ViewEvent ,
ViewOnceOpenSyncEvent ,
2021-08-12 18:15:55 +00:00
ViewSyncEvent ,
2021-07-09 19:36:10 +00:00
} from './textsecure/messageReceiverEvents' ;
2021-07-23 17:23:50 +00:00
import type { WebAPIType } from './textsecure/WebAPI' ;
2021-09-10 02:38:11 +00:00
import * as KeyChangeListener from './textsecure/KeyChangeListener' ;
2021-11-30 19:33:51 +00:00
import { RotateSignedPreKeyListener } from './textsecure/RotateSignedPreKeyListener' ;
2021-06-07 16:39:13 +00:00
import { isDirectConversation , isGroupV2 } from './util/whatTypeOfConversation' ;
2021-06-23 14:47:42 +00:00
import { BackOff , FIBONACCI_TIMEOUTS } from './util/BackOff' ;
2021-06-16 00:44:14 +00:00
import { AppViewType } from './state/ducks/app' ;
2021-11-02 23:01:13 +00:00
import type { BadgesStateType } from './state/ducks/badges' ;
2022-11-17 02:52:04 +00:00
import { areAnyCallsActiveOrRinging } from './state/selectors/calling' ;
2021-11-02 23:01:13 +00:00
import { badgeImageFileDownloader } from './badges/badgeImageFileDownloader' ;
2021-06-15 23:30:23 +00:00
import { actionCreators } from './state/actions' ;
2021-06-17 17:15:10 +00:00
import { Deletes } from './messageModifiers/Deletes' ;
2023-03-27 23:48:57 +00:00
import type { EditAttributesType } from './messageModifiers/Edits' ;
import * as Edits from './messageModifiers/Edits' ;
2021-07-20 20:17:25 +00:00
import {
MessageReceipts ,
MessageReceiptType ,
} from './messageModifiers/MessageReceipts' ;
2021-06-17 17:15:10 +00:00
import { MessageRequests } from './messageModifiers/MessageRequests' ;
import { Reactions } from './messageModifiers/Reactions' ;
import { ReadSyncs } from './messageModifiers/ReadSyncs' ;
2021-08-12 18:15:55 +00:00
import { ViewSyncs } from './messageModifiers/ViewSyncs' ;
2021-07-22 17:07:53 +00:00
import { ViewOnceOpenSyncs } from './messageModifiers/ViewOnceOpenSyncs' ;
2022-01-04 15:27:16 +00:00
import type { DeleteAttributesType } from './messageModifiers/Deletes' ;
import type { MessageReceiptAttributesType } from './messageModifiers/MessageReceipts' ;
import type { MessageRequestAttributesType } from './messageModifiers/MessageRequests' ;
import type { ReadSyncAttributesType } from './messageModifiers/ReadSyncs' ;
import type { ViewSyncAttributesType } from './messageModifiers/ViewSyncs' ;
import type { ViewOnceOpenSyncAttributesType } from './messageModifiers/ViewOnceOpenSyncs' ;
2021-08-12 18:15:55 +00:00
import { ReadStatus } from './messages/MessageReadStatus' ;
2021-10-26 19:15:33 +00:00
import type { SendStateByConversationId } from './messages/MessageSendState' ;
import { SendStatus } from './messages/MessageSendState' ;
2021-06-17 17:15:10 +00:00
import * as AttachmentDownloads from './messageModifiers/AttachmentDownloads' ;
2021-09-24 00:49:05 +00:00
import * as Conversation from './types/Conversation' ;
2021-07-09 19:36:10 +00:00
import * as Stickers from './types/Stickers' ;
2021-09-24 00:49:05 +00:00
import * as Errors from './types/errors' ;
2021-07-02 19:21:24 +00:00
import { SignalService as Proto } from './protobuf' ;
2023-05-03 20:53:28 +00:00
import {
onRetryRequest ,
onDecryptionError ,
onInvalidPlaintextMessage ,
} from './util/handleRetry' ;
2021-08-18 20:08:14 +00:00
import { themeChanged } from './shims/themeChanged' ;
import { createIPCEvents } from './util/createIPCEvents' ;
2021-08-30 21:39:57 +00:00
import { RemoveAllConfiguration } from './types/RemoveAllConfiguration' ;
2022-07-13 00:37:21 +00:00
import { isValidUuid , UUIDKind , UUID } from './types/UUID' ;
2021-09-17 18:27:53 +00:00
import * as log from './logging/log' ;
2022-02-23 18:48:40 +00:00
import { loadRecentEmojis } from './util/loadRecentEmojis' ;
2021-09-21 00:25:29 +00:00
import { deleteAllLogs } from './util/deleteAllLogs' ;
2021-09-22 20:59:54 +00:00
import { ToastCaptchaFailed } from './components/ToastCaptchaFailed' ;
import { ToastCaptchaSolved } from './components/ToastCaptchaSolved' ;
import { showToast } from './util/showToast' ;
2023-03-14 15:55:31 +00:00
import { startInteractionMode } from './services/InteractionMode' ;
2022-06-08 22:00:32 +00:00
import type { MainWindowStatsType } from './windows/context' ;
2022-01-04 15:27:16 +00:00
import { ReactionSource } from './reactions/ReactionSource' ;
2022-01-14 21:34:52 +00:00
import { singleProtoJobQueue } from './jobs/singleProtoJobQueue' ;
2022-02-23 18:48:40 +00:00
import { getInitialState } from './state/getInitialState' ;
2023-02-06 17:24:34 +00:00
import {
conversationJobQueue ,
conversationQueueJobEnum ,
} from './jobs/conversationJobQueue' ;
2022-04-22 18:35:14 +00:00
import { SeenStatus } from './MessageSeenStatus' ;
2022-06-13 21:39:35 +00:00
import MessageSender from './textsecure/SendMessage' ;
import type AccountManager from './textsecure/AccountManager' ;
2022-07-13 23:09:18 +00:00
import { onStoryRecipientUpdate } from './util/onStoryRecipientUpdate' ;
2022-10-11 17:59:02 +00:00
import { StoryViewModeType , StoryViewTargetType } from './types/Stories' ;
2022-11-09 02:38:19 +00:00
import { downloadOnboardingStory } from './util/downloadOnboardingStory' ;
2022-12-14 19:05:32 +00:00
import { clearConversationDraftAttachments } from './util/clearConversationDraftAttachments' ;
import { removeLinkPreview } from './services/LinkPreview' ;
2022-12-20 17:50:23 +00:00
import { PanelType } from './types/Panels' ;
2023-01-05 00:22:36 +00:00
import { getQuotedMessageSelector } from './state/selectors/composer' ;
2023-01-13 00:24:59 +00:00
import { flushAttachmentDownloadQueue } from './util/attachmentDownloadQueue' ;
import { StartupQueue } from './util/StartupQueue' ;
import { showConfirmationDialog } from './util/showConfirmationDialog' ;
2023-01-10 00:52:01 +00:00
import { onCallEventSync } from './util/onCallEventSync' ;
2023-02-24 19:03:17 +00:00
import { sleeper } from './util/sleeper' ;
2023-05-10 01:25:57 +00:00
import { DAY , HOUR , MINUTE } from './util/durations' ;
2023-04-20 16:31:59 +00:00
import { copyDataMessageIntoMessage } from './util/copyDataMessageIntoMessage' ;
2023-04-11 03:54:43 +00:00
import {
flushMessageCounter ,
incrementMessageCounter ,
initializeMessageCounter ,
} from './util/incrementMessageCounter' ;
import { RetryPlaceholders } from './util/retryPlaceholders' ;
import { setBatchingStrategy } from './util/messageBatcher' ;
import { parseRemoteClientExpiration } from './util/parseRemoteClientExpiration' ;
import { makeLookup } from './util/makeLookup' ;
2023-05-04 19:34:52 +00:00
import { focusableSelectors } from './util/focusableSelectors' ;
2021-03-22 21:08:52 +00:00
2021-05-28 19:11:19 +00:00
export function isOverHourIntoPast ( timestamp : number ) : boolean {
return isNumber ( timestamp ) && isOlderThan ( timestamp , HOUR ) ;
}
export async function cleanupSessionResets ( ) : Promise < void > {
2021-06-15 00:09:37 +00:00
const sessionResets = window . storage . get (
2021-05-28 19:11:19 +00:00
'sessionResets' ,
2023-03-28 18:26:46 +00:00
{ } as SessionResetsType
2021-05-28 19:11:19 +00:00
) ;
const keys = Object . keys ( sessionResets ) ;
keys . forEach ( key = > {
const timestamp = sessionResets [ key ] ;
if ( ! timestamp || isOverHourIntoPast ( timestamp ) ) {
delete sessionResets [ key ] ;
}
} ) ;
await window . storage . put ( 'sessionResets' , sessionResets ) ;
}
2021-02-26 21:06:37 +00:00
export async function startApp ( ) : Promise < void > {
2022-06-03 16:30:03 +00:00
window . textsecure . storage . protocol = new window . SignalProtocolStore ( ) ;
2022-05-11 22:58:14 +00:00
if ( window . initialTheme === ThemeType . light ) {
document . body . classList . add ( 'light-theme' ) ;
}
if ( window . initialTheme === ThemeType . dark ) {
document . body . classList . add ( 'dark-theme' ) ;
}
2021-12-10 23:20:24 +00:00
const idleDetector = new IdleDetector ( ) ;
2021-09-29 21:20:52 +00:00
await KeyboardLayout . initialize ( ) ;
2023-01-13 00:24:59 +00:00
StartupQueue . initialize ( ) ;
2021-09-23 18:16:09 +00:00
notificationService . initialize ( {
i18n : window.i18n ,
storage : window.storage ,
} ) ;
2021-04-08 16:24:21 +00:00
2023-04-11 03:54:43 +00:00
await initializeMessageCounter ( ) ;
2021-09-15 18:45:22 +00:00
2021-11-02 23:01:13 +00:00
let initialBadgesState : BadgesStateType = { byId : { } } ;
async function loadInitialBadgesState ( ) : Promise < void > {
initialBadgesState = {
2023-04-11 03:54:43 +00:00
byId : makeLookup ( await window . Signal . Data . getAllBadges ( ) , 'id' ) ,
2021-11-02 23:01:13 +00:00
} ;
}
2021-07-23 17:23:50 +00:00
// Initialize WebAPI as early as possible
let server : WebAPIType | undefined ;
2021-07-28 21:37:09 +00:00
let messageReceiver : MessageReceiver | undefined ;
2022-03-21 21:19:37 +00:00
let challengeHandler : ChallengeHandler | undefined ;
2022-07-08 20:46:25 +00:00
let routineProfileRefresher : RoutineProfileRefresher | undefined ;
2022-03-21 21:19:37 +00:00
2021-07-23 17:23:50 +00:00
window . storage . onready ( ( ) = > {
2022-10-05 00:48:25 +00:00
server = window . WebAPI . connect ( {
. . . window . textsecure . storage . user . getWebAPICredentials ( ) ,
hasStoriesDisabled : window.storage.get ( 'hasStoriesDisabled' , false ) ,
} ) ;
2021-07-28 21:37:09 +00:00
window . textsecure . server = server ;
2022-10-15 00:22:04 +00:00
window . textsecure . messaging = new window . textsecure . MessageSender ( server ) ;
2021-07-23 17:23:50 +00:00
2022-03-22 00:20:03 +00:00
initializeAllJobQueues ( {
server ,
} ) ;
2022-03-21 21:19:37 +00:00
challengeHandler = new ChallengeHandler ( {
storage : window.storage ,
startQueue ( conversationId : string ) {
conversationJobQueue . resolveVerificationWaiter ( conversationId ) ;
} ,
requestChallenge ( request ) {
2023-01-19 00:02:03 +00:00
if ( window . SignalCI ) {
window . SignalCI . handleEvent ( 'challenge' , request ) ;
2022-09-19 22:08:55 +00:00
return ;
}
2022-03-21 21:19:37 +00:00
window . sendChallengeRequest ( request ) ;
} ,
async sendChallengeResponse ( data ) {
2022-06-13 21:39:35 +00:00
const { messaging } = window . textsecure ;
if ( ! messaging ) {
throw new Error ( 'sendChallengeResponse: messaging is not available!' ) ;
}
await messaging . sendChallengeResponse ( data ) ;
2022-03-21 21:19:37 +00:00
} ,
onChallengeFailed() {
// TODO: DESKTOP-1530
// Display humanized `retryAfter`
showToast ( ToastCaptchaFailed ) ;
} ,
onChallengeSolved() {
showToast ( ToastCaptchaSolved ) ;
} ,
setChallengeStatus ( challengeStatus ) {
window . reduxActions . network . setChallengeStatus ( challengeStatus ) ;
} ,
2021-07-23 17:23:50 +00:00
} ) ;
2021-07-28 21:37:09 +00:00
2022-03-21 21:19:37 +00:00
window . Whisper . events . on ( 'challengeResponse' , response = > {
if ( ! challengeHandler ) {
throw new Error ( 'Expected challenge handler to be there' ) ;
}
challengeHandler . onResponse ( response ) ;
} ) ;
window . Signal . challengeHandler = challengeHandler ;
2021-09-17 18:27:53 +00:00
log . info ( 'Initializing MessageReceiver' ) ;
2021-07-28 21:37:09 +00:00
messageReceiver = new MessageReceiver ( {
server ,
storage : window.storage ,
serverTrustRoot : window.getServerTrustRoot ( ) ,
} ) ;
2022-11-09 18:59:32 +00:00
function queuedEventListener < E extends Event > (
handler : ( event : E ) = > Promise < void > | void ,
2021-07-28 21:37:09 +00:00
track = true
2022-11-09 18:59:32 +00:00
) : ( event : E ) = > void {
return ( event : E ) : void = > {
2022-12-21 18:41:48 +00:00
drop (
eventHandlerQueue . add (
createTaskWithTimeout ( async ( ) = > {
try {
await handler ( event ) ;
} finally {
// message/sent: Message.handleDataMessage has its own queue and will
// trigger this event itself when complete.
// error: Error processing (below) also has its own queue and
// self-trigger.
if ( track ) {
window . Whisper . events . trigger ( 'incrementProgress' ) ;
}
2022-11-09 18:59:32 +00:00
}
2022-12-21 18:41:48 +00:00
} , ` queuedEventListener( ${ event . type } , ${ event . timeStamp } ) ` )
)
2022-11-09 18:59:32 +00:00
) ;
2021-07-28 21:37:09 +00:00
} ;
}
2021-08-05 23:34:49 +00:00
messageReceiver . addEventListener (
'envelope' ,
queuedEventListener ( onEnvelopeReceived , false )
) ;
2021-07-28 21:37:09 +00:00
messageReceiver . addEventListener (
'message' ,
queuedEventListener ( onMessageReceived , false )
) ;
messageReceiver . addEventListener (
'delivery' ,
queuedEventListener ( onDeliveryReceipt )
) ;
messageReceiver . addEventListener (
'contactSync' ,
2022-08-25 05:04:42 +00:00
queuedEventListener ( onContactSync )
2021-07-28 21:37:09 +00:00
) ;
messageReceiver . addEventListener (
'group' ,
queuedEventListener ( onGroupReceived )
) ;
messageReceiver . addEventListener (
'groupSync' ,
queuedEventListener ( onGroupSyncComplete )
) ;
messageReceiver . addEventListener (
'sent' ,
queuedEventListener ( onSentMessage , false )
) ;
messageReceiver . addEventListener (
'readSync' ,
queuedEventListener ( onReadSync )
) ;
2021-08-12 18:15:55 +00:00
messageReceiver . addEventListener (
'viewSync' ,
queuedEventListener ( onViewSync )
) ;
2021-07-28 21:37:09 +00:00
messageReceiver . addEventListener (
'read' ,
queuedEventListener ( onReadReceipt )
) ;
messageReceiver . addEventListener (
'view' ,
queuedEventListener ( onViewReceipt )
) ;
messageReceiver . addEventListener (
'error' ,
queuedEventListener ( onError , false )
) ;
messageReceiver . addEventListener (
'decryption-error' ,
2022-11-09 18:59:32 +00:00
queuedEventListener ( ( event : DecryptionErrorEvent ) : void = > {
2022-12-21 18:41:48 +00:00
drop ( onDecryptionErrorQueue . add ( ( ) = > onDecryptionError ( event ) ) ) ;
2021-10-20 21:50:00 +00:00
} )
2021-07-28 21:37:09 +00:00
) ;
2023-05-03 20:53:28 +00:00
messageReceiver . addEventListener (
'invalid-plaintext' ,
queuedEventListener ( ( event : InvalidPlaintextEvent ) : void = > {
drop (
onDecryptionErrorQueue . add ( ( ) = > onInvalidPlaintextMessage ( event ) )
) ;
} )
) ;
2021-07-28 21:37:09 +00:00
messageReceiver . addEventListener (
'retry-request' ,
2022-11-09 18:59:32 +00:00
queuedEventListener ( ( event : RetryRequestEvent ) : void = > {
2022-12-21 18:41:48 +00:00
drop ( onRetryRequestQueue . add ( ( ) = > onRetryRequest ( event ) ) ) ;
2021-10-20 21:50:00 +00:00
} )
2021-07-28 21:37:09 +00:00
) ;
messageReceiver . addEventListener ( 'empty' , queuedEventListener ( onEmpty ) ) ;
messageReceiver . addEventListener (
'configuration' ,
queuedEventListener ( onConfiguration )
) ;
messageReceiver . addEventListener ( 'typing' , queuedEventListener ( onTyping ) ) ;
messageReceiver . addEventListener (
'sticker-pack' ,
queuedEventListener ( onStickerPack )
) ;
messageReceiver . addEventListener (
'viewOnceOpenSync' ,
queuedEventListener ( onViewOnceOpenSync )
) ;
messageReceiver . addEventListener (
'messageRequestResponse' ,
queuedEventListener ( onMessageRequestResponse )
) ;
messageReceiver . addEventListener (
'profileKeyUpdate' ,
queuedEventListener ( onProfileKeyUpdate )
) ;
messageReceiver . addEventListener (
'fetchLatest' ,
queuedEventListener ( onFetchLatestSync )
) ;
messageReceiver . addEventListener ( 'keys' , queuedEventListener ( onKeysSync ) ) ;
2022-07-13 23:09:18 +00:00
messageReceiver . addEventListener (
'storyRecipientUpdate' ,
queuedEventListener ( onStoryRecipientUpdate , false )
) ;
2023-01-10 00:52:01 +00:00
messageReceiver . addEventListener (
'callEventSync' ,
queuedEventListener ( onCallEventSync , false )
) ;
2021-07-23 17:23:50 +00:00
} ) ;
2021-04-29 23:02:27 +00:00
2021-05-05 16:39:16 +00:00
ourProfileKeyService . initialize ( window . storage ) ;
2021-06-07 22:17:44 +00:00
window . storage . onready ( ( ) = > {
if ( ! window . storage . get ( 'defaultConversationColor' ) ) {
2022-12-21 18:41:48 +00:00
drop (
window . storage . put (
'defaultConversationColor' ,
DEFAULT_CONVERSATION_COLOR
)
2021-06-08 21:31:35 +00:00
) ;
2021-06-07 22:17:44 +00:00
}
} ) ;
2022-11-10 04:24:42 +00:00
window . SignalContext . activeWindowService . registerForChange ( isActive = > {
if ( ! isActive ) {
2022-11-16 18:06:33 +00:00
window . reduxActions ? . stories . setHasAllStoriesUnmuted ( false ) ;
2022-11-10 04:24:42 +00:00
}
} ) ;
2021-04-15 18:17:28 +00:00
let resolveOnAppView : ( ( ) = > void ) | undefined ;
const onAppView = new Promise < void > ( resolve = > {
resolveOnAppView = resolve ;
} ) ;
2021-06-23 14:47:42 +00:00
const reconnectBackOff = new BackOff ( FIBONACCI_TIMEOUTS ) ;
2021-06-09 22:28:54 +00:00
2021-07-02 19:21:24 +00:00
window . storage . onready ( ( ) = > {
2021-07-23 17:23:50 +00:00
strictAssert ( server , 'WebAPI not ready' ) ;
2021-07-02 19:21:24 +00:00
senderCertificateService . initialize ( {
2021-07-23 17:23:50 +00:00
server ,
2021-07-02 19:21:24 +00:00
navigator ,
onlineEventTarget : window ,
storage : window.storage ,
2021-04-08 16:24:21 +00:00
} ) ;
2021-11-30 16:29:57 +00:00
areWeASubscriberService . update ( window . storage , server ) ;
2021-04-08 16:24:21 +00:00
} ) ;
2022-08-25 05:04:42 +00:00
const eventHandlerQueue = new PQueue ( {
2020-09-18 20:40:41 +00:00
concurrency : 1 ,
} ) ;
2021-05-05 16:39:16 +00:00
2022-07-21 02:40:53 +00:00
// Note: this queue is meant to allow for stop/start of tasks, not limit parallelism.
2022-08-25 05:04:42 +00:00
const profileKeyResponseQueue = new PQueue ( ) ;
2021-05-05 16:39:16 +00:00
profileKeyResponseQueue . pause ( ) ;
2022-08-25 05:04:42 +00:00
const lightSessionResetQueue = new PQueue ( { concurrency : 1 } ) ;
2021-07-15 23:48:09 +00:00
window . Signal . Services . lightSessionResetQueue = lightSessionResetQueue ;
2021-05-18 00:41:28 +00:00
lightSessionResetQueue . pause ( ) ;
2022-08-25 05:04:42 +00:00
const onDecryptionErrorQueue = new PQueue ( { concurrency : 1 } ) ;
2021-10-20 21:50:00 +00:00
onDecryptionErrorQueue . pause ( ) ;
2022-08-25 05:04:42 +00:00
const onRetryRequestQueue = new PQueue ( { concurrency : 1 } ) ;
2021-10-20 21:50:00 +00:00
onRetryRequestQueue . pause ( ) ;
2022-08-25 05:04:42 +00:00
window . Whisper . deliveryReceiptQueue = new PQueue ( {
2019-08-16 16:15:39 +00:00
concurrency : 1 ,
2022-06-27 16:46:43 +00:00
timeout : durations.MINUTE * 30 ,
2019-08-16 16:15:39 +00:00
} ) ;
2020-09-24 20:57:54 +00:00
window . Whisper . deliveryReceiptQueue . pause ( ) ;
2023-04-11 03:54:43 +00:00
window . Whisper . deliveryReceiptBatcher = createBatcher < Receipt > ( {
name : 'Whisper.deliveryReceiptBatcher' ,
wait : 500 ,
maxSize : 100 ,
processBatch : async deliveryReceipts = > {
const groups = groupBy ( deliveryReceipts , 'conversationId' ) ;
await Promise . all (
Object . keys ( groups ) . map ( async conversationId = > {
await conversationJobQueue . add ( {
type : conversationQueueJobEnum . enum . Receipts ,
conversationId ,
receiptsType : ReceiptType.Delivery ,
receipts : groups [ conversationId ] ,
} ) ;
} )
) ;
} ,
} ) ;
2019-06-14 22:17:37 +00:00
2022-06-08 22:00:32 +00:00
if ( window . platform === 'darwin' ) {
2021-03-08 22:42:29 +00:00
window . addEventListener ( 'dblclick' , ( event : Event ) = > {
const target = event . target as HTMLElement ;
if ( isWindowDragElement ( target ) ) {
2023-01-13 00:24:59 +00:00
window . IPC . titleBarDoubleClick ( ) ;
2021-03-08 22:42:29 +00:00
}
} ) ;
}
2021-02-01 20:01:25 +00:00
2018-08-11 00:54:09 +00:00
// Globally disable drag and drop
document . body . addEventListener (
'dragover' ,
e = > {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ,
false
) ;
document . body . addEventListener (
'drop' ,
e = > {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ,
false
) ;
2021-10-28 00:05:56 +00:00
startInteractionMode ( ) ;
2019-11-21 19:16:06 +00:00
2018-05-26 01:01:56 +00:00
// We add this to window here because the default Node context is erased at the end
// of preload.js processing
window . setImmediate = window . nodeSetImmediate ;
2021-09-24 00:49:05 +00:00
const { Message } = window . Signal . Types ;
2018-09-21 01:47:19 +00:00
const {
upgradeMessageSchema ,
writeNewAttachmentData ,
deleteAttachmentData ,
2019-12-03 20:02:50 +00:00
doesAttachmentExist ,
2018-10-25 22:44:59 +00:00
} = window . Signal . Migrations ;
2018-04-27 21:25:04 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'background page reloaded' ) ;
log . info ( 'environment:' , window . getEnvironment ( ) ) ;
2018-04-27 21:25:04 +00:00
2018-07-27 01:13:56 +00:00
let newVersion = false ;
2022-02-03 01:21:02 +00:00
let lastVersion : string | undefined ;
2018-07-27 01:13:56 +00:00
2018-06-02 00:55:35 +00:00
window . document . title = window . getTitle ( ) ;
2015-09-25 18:10:25 +00:00
2022-03-02 18:41:16 +00:00
document . documentElement . setAttribute (
'lang' ,
2023-01-25 00:54:46 +00:00
window . getResolvedMessagesLocale ( ) . split ( /[-_]/ ) [ 0 ]
2022-03-02 18:41:16 +00:00
) ;
2023-04-20 17:03:43 +00:00
document . documentElement . setAttribute (
'dir' ,
window . getResolvedMessagesLocaleDirection ( )
) ;
2021-09-10 02:38:11 +00:00
KeyChangeListener . init ( window . textsecure . storage . protocol ) ;
2021-11-30 19:33:51 +00:00
window . textsecure . storage . protocol . on ( 'removePreKey' , ( ourUuid : UUID ) = > {
const uuidKind = window . textsecure . storage . user . getOurUuidKind ( ourUuid ) ;
2022-12-21 18:41:48 +00:00
void window . getAccountManager ( ) . refreshPreKeys ( uuidKind ) ;
2018-04-27 21:25:04 +00:00
} ) ;
2015-05-23 00:06:49 +00:00
2022-10-20 19:16:37 +00:00
window . textsecure . storage . protocol . on ( 'removeAllData' , ( ) = > {
window . reduxActions . stories . removeAllStories ( ) ;
} ) ;
2018-05-25 01:50:49 +00:00
window . getSocketStatus = ( ) = > {
2021-07-28 21:37:09 +00:00
if ( server === undefined ) {
return SocketStatus . CLOSED ;
2020-09-04 01:25:19 +00:00
}
2021-07-28 21:37:09 +00:00
return server . getSocketStatus ( ) ;
2018-04-27 21:25:04 +00:00
} ;
2022-06-13 21:39:35 +00:00
let accountManager : AccountManager ;
2018-05-25 01:50:49 +00:00
window . getAccountManager = ( ) = > {
2021-07-23 17:23:50 +00:00
if ( accountManager ) {
return accountManager ;
Beta versions support: SxS support, in-app env/instance display (#1606)
* Script for beta config; unique data dir, in-app env/type display
To release a beta build, increment the version and add -beta-N to the
end, then go through all the standard release activities.
The prepare-build npm script then updates key bits of the package.json
to ensure that the beta build can be installed alongside a production
build. This includes a new name ('Signal Beta') and a different location
for application data.
Note: Beta builds can be installed alongside production builds.
As part of this, a couple new bits of data are shown across the app:
- Environment (development or test, not shown if production)
- App Instance (disabled in production; used for multiple accounts)
These are shown in:
- The window title - both environment and app instance. You can tell
beta builds because the app name, preceding these data bits, is
different.
- The about window - both environment and app instance. You can tell
beta builds from the version number.
- The header added to the debug log - just environment. The version
number will tell us if it's a beta build, and app instance isn't
helpful.
* Turn on single-window mode in non-production modes
Because it's really frightening when you see 'unable to read from db'
errors in the console.
* aply.sh: More instructions for initial setup and testing
* Gruntfile: Get consistent with use of package.json datas
* Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
}
2022-06-13 21:39:35 +00:00
if ( ! server ) {
throw new Error ( 'getAccountManager: server is not available!' ) ;
}
2021-07-23 17:23:50 +00:00
accountManager = new window . textsecure . AccountManager ( server ) ;
accountManager . addEventListener ( 'registration' , ( ) = > {
2021-09-02 21:47:42 +00:00
window . Whisper . events . trigger ( 'userChanged' , false ) ;
2021-07-23 17:23:50 +00:00
2023-04-11 03:54:43 +00:00
drop ( Registration . markDone ( ) ) ;
2021-09-17 18:27:53 +00:00
log . info ( 'dispatching registration event' ) ;
2021-07-23 17:23:50 +00:00
window . Whisper . events . trigger ( 'registration_done' ) ;
} ) ;
2018-04-27 21:25:04 +00:00
return accountManager ;
} ;
2015-09-01 19:57:02 +00:00
2022-06-01 19:57:30 +00:00
const cancelInitializationMessage = setAppLoadingScreenMessage (
undefined ,
window . i18n
) ;
2018-03-26 18:57:10 +00:00
2019-06-27 20:21:52 +00:00
const version = await window . Signal . Data . getItemById ( 'version' ) ;
if ( ! version ) {
2022-06-01 16:51:30 +00:00
const isIndexedDBPresent = await indexedDb . doesDatabaseExist ( ) ;
2019-06-27 20:21:52 +00:00
if ( isIndexedDBPresent ) {
2021-09-17 18:27:53 +00:00
log . info ( 'Found IndexedDB database.' ) ;
2020-04-28 21:18:41 +00:00
try {
2021-09-17 18:27:53 +00:00
log . info ( 'Confirming deletion of old data with user...' ) ;
2020-04-28 21:18:41 +00:00
try {
2021-01-04 19:46:24 +00:00
await new Promise < void > ( ( resolve , reject ) = > {
2023-01-13 00:24:59 +00:00
showConfirmationDialog ( {
2022-09-27 20:24:21 +00:00
dialogName : 'deleteOldIndexedDBData' ,
2021-12-03 23:04:34 +00:00
onTopOfEverything : true ,
2023-03-30 00:03:25 +00:00
cancelText : window.i18n ( 'icu:quit' ) ,
2021-01-04 18:47:14 +00:00
confirmStyle : 'negative' ,
2023-03-30 00:03:25 +00:00
title : window.i18n ( 'icu:deleteOldIndexedDBData' ) ,
okText : window.i18n ( 'icu:deleteOldData' ) ,
2021-01-04 18:47:14 +00:00
reject : ( ) = > reject ( ) ,
resolve : ( ) = > resolve ( ) ,
2020-04-28 21:18:41 +00:00
} ) ;
} ) ;
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . info (
2020-04-28 21:18:41 +00:00
'User chose not to delete old data. Shutting down.' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2020-04-28 21:18:41 +00:00
) ;
2023-01-13 00:24:59 +00:00
window . IPC . shutdown ( ) ;
2020-04-28 21:18:41 +00:00
return ;
}
2021-09-17 18:27:53 +00:00
log . info ( 'Deleting all previously-migrated data in SQL...' ) ;
log . info ( 'Deleting IndexedDB file...' ) ;
2020-04-28 21:18:41 +00:00
await Promise . all ( [
2022-06-01 16:51:30 +00:00
indexedDb . removeDatabase ( ) ,
2020-04-28 21:18:41 +00:00
window . Signal . Data . removeAll ( ) ,
window . Signal . Data . removeIndexedDBFiles ( ) ,
] ) ;
2021-09-17 18:27:53 +00:00
log . info ( 'Done with SQL deletion and IndexedDB file deletion.' ) ;
2020-04-28 21:18:41 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-04-28 21:18:41 +00:00
'Failed to remove IndexedDB file or remove SQL data:' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2020-04-28 21:18:41 +00:00
) ;
}
// Set a flag to delete IndexedDB on next startup if it wasn't deleted just now.
2020-09-24 20:57:54 +00:00
// We need to use direct data calls, since window.storage isn't ready yet.
2020-04-28 21:18:41 +00:00
await window . Signal . Data . createOrUpdateItem ( {
id : 'indexeddb-delete-needed' ,
value : true ,
} ) ;
2019-06-27 20:21:52 +00:00
}
2018-10-18 01:01:21 +00:00
}
2018-09-21 01:47:19 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'Storage fetch' ) ;
2022-12-21 18:41:48 +00:00
drop ( window . storage . fetch ( ) ) ;
2018-03-26 18:57:10 +00:00
2021-08-18 20:08:14 +00:00
function mapOldThemeToNew (
theme : Readonly <
'system' | 'light' | 'dark' | 'android' | 'ios' | 'android-dark'
>
) : 'system' | 'light' | 'dark' {
2018-06-25 23:57:06 +00:00
switch ( theme ) {
2018-07-09 21:29:13 +00:00
case 'dark' :
case 'light' :
2019-05-16 22:32:38 +00:00
case 'system' :
2018-07-09 21:29:13 +00:00
return theme ;
2018-06-25 23:57:06 +00:00
case 'android-dark' :
return 'dark' ;
case 'android' :
case 'ios' :
default :
return 'light' ;
}
}
2018-04-27 21:25:04 +00:00
// We need this 'first' check because we don't want to start the app up any other time
2020-09-24 20:57:54 +00:00
// than the first time. And window.storage.fetch() will cause onready() to fire.
2018-05-25 01:50:49 +00:00
let first = true ;
2020-09-24 20:57:54 +00:00
window . storage . onready ( async ( ) = > {
2018-04-27 21:25:04 +00:00
if ( ! first ) {
return ;
}
first = false ;
2017-08-08 00:24:59 +00:00
2021-07-23 17:23:50 +00:00
strictAssert ( server !== undefined , 'WebAPI not ready' ) ;
2022-12-21 18:41:48 +00:00
void cleanupSessionResets ( ) ;
2021-05-28 19:11:19 +00:00
2018-08-03 00:18:45 +00:00
// These make key operations available to IPC handlers created in preload.js
2021-08-18 20:08:14 +00:00
window . Events = createIPCEvents ( {
2018-11-05 19:06:12 +00:00
shutdown : async ( ) = > {
2021-09-17 18:27:53 +00:00
log . info ( 'background/shutdown' ) ;
2021-09-08 23:28:18 +00:00
2023-04-11 03:54:43 +00:00
flushMessageCounter ( ) ;
2021-09-08 23:28:18 +00:00
2019-02-19 20:10:26 +00:00
// Stop background processing
2022-12-21 18:41:48 +00:00
void AttachmentDownloads . stop ( ) ;
2021-12-10 23:20:24 +00:00
idleDetector . stop ( ) ;
2019-02-19 20:10:26 +00:00
// Stop processing incoming messages
if ( messageReceiver ) {
2021-07-28 21:37:09 +00:00
strictAssert (
server !== undefined ,
'WebAPI should be initialized together with MessageReceiver'
) ;
2022-04-11 17:53:57 +00:00
log . info ( 'background/shutdown: shutting down messageReceiver' ) ;
2021-07-28 21:37:09 +00:00
server . unregisterRequestHandler ( messageReceiver ) ;
2021-09-15 18:44:27 +00:00
messageReceiver . stopProcessing ( ) ;
2019-09-26 19:56:31 +00:00
await window . waitForAllBatchers ( ) ;
2019-11-21 19:16:06 +00:00
}
2019-09-26 19:56:31 +00:00
2022-04-12 18:16:58 +00:00
log . info ( 'background/shutdown: flushing conversations' ) ;
// Flush debounced updates for conversations
await Promise . all (
window . ConversationController . getAll ( ) . map ( convo = >
convo . flushDebouncedUpdates ( )
)
) ;
2023-02-24 19:03:17 +00:00
sleeper . shutdown ( ) ;
const shutdownQueues = async ( ) = > {
2023-04-05 23:37:25 +00:00
log . info ( 'background/shutdown: shutting down queues' ) ;
2023-02-24 19:03:17 +00:00
await Promise . allSettled ( [
StartupQueue . shutdown ( ) ,
shutdownAllJobQueues ( ) ,
] ) ;
2023-04-05 23:37:25 +00:00
log . info ( 'background/shutdown: shutting down conversation queues' ) ;
2023-02-24 19:03:17 +00:00
await Promise . allSettled (
window . ConversationController . getAll ( ) . map ( async convo = > {
try {
await convo . shutdownJobQueue ( ) ;
} catch ( err ) {
log . error (
` background/shutdown: error waiting for conversation ${ convo . idForLogging } job queue shutdown ` ,
Errors . toLogFormat ( err )
) ;
}
} )
) ;
2023-04-05 23:37:25 +00:00
log . info ( 'background/shutdown: all queues shutdown' ) ;
2023-02-24 19:03:17 +00:00
} ;
2023-04-05 23:37:25 +00:00
// wait for at most 1 minutes for startup queue and job queues to drain
2023-02-24 19:03:17 +00:00
let timeout : NodeJS.Timeout | undefined ;
await Promise . race ( [
shutdownQueues ( ) ,
new Promise < void > ( ( resolve , _ ) = > {
timeout = setTimeout ( ( ) = > {
log . warn (
'background/shutdown - timed out waiting for StartupQueue/JobQueues, continuing with shutdown'
) ;
timeout = undefined ;
resolve ( ) ;
2023-04-05 23:37:25 +00:00
} , 1 * MINUTE ) ;
2023-02-24 19:03:17 +00:00
} ) ,
] ) ;
if ( timeout ) {
clearTimeout ( timeout ) ;
}
2022-04-12 18:16:58 +00:00
log . info ( 'background/shutdown: waiting for all batchers' ) ;
2019-09-26 19:56:31 +00:00
// A number of still-to-queue database queries might be waiting inside batchers.
// We wait for these to empty first, and then shut down the data interface.
await Promise . all ( [
window . waitForAllBatchers ( ) ,
window . waitForAllWaitBatchers ( ) ,
] ) ;
2022-04-12 18:16:58 +00:00
log . info ( 'background/shutdown: closing the database' ) ;
2019-02-19 20:10:26 +00:00
// Shut down the data interface cleanly
2018-11-05 19:06:12 +00:00
await window . Signal . Data . shutdown ( ) ;
} ,
2021-08-18 20:08:14 +00:00
} ) ;
2019-05-16 22:32:11 +00:00
2022-06-20 18:26:31 +00:00
const zoomFactor = window . Events . getZoomFactor ( ) ;
webFrame . setZoomFactor ( zoomFactor ) ;
document . body . style . setProperty ( '--zoom-factor' , zoomFactor . toString ( ) ) ;
window . addEventListener ( 'resize' , ( ) = > {
document . body . style . setProperty (
'--zoom-factor' ,
webFrame . getZoomFactor ( ) . toString ( )
) ;
} ) ;
2018-08-03 00:18:45 +00:00
2019-11-13 23:25:57 +00:00
// How long since we were last running?
2021-09-24 17:01:46 +00:00
const lastHeartbeat = toDayMillis ( window . storage . get ( 'lastHeartbeat' , 0 ) ) ;
2021-07-16 18:21:00 +00:00
const previousLastStartup = window . storage . get ( 'lastStartup' ) ;
2020-09-24 20:57:54 +00:00
await window . storage . put ( 'lastStartup' , Date . now ( ) ) ;
2019-11-12 22:56:57 +00:00
2019-10-02 20:52:20 +00:00
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000 ;
2021-03-22 21:08:52 +00:00
if ( lastHeartbeat > 0 && isOlderThan ( lastHeartbeat , THIRTY_DAYS ) ) {
2021-09-17 18:27:53 +00:00
log . warn (
2021-07-16 18:21:00 +00:00
` This instance has not been used for 30 days. Last heartbeat: ${ lastHeartbeat } . Last startup: ${ previousLastStartup } . `
) ;
2021-08-30 21:39:57 +00:00
await unlinkAndDisconnect ( RemoveAllConfiguration . Soft ) ;
2019-10-02 20:52:20 +00:00
}
2019-11-13 23:25:57 +00:00
// Start heartbeat timer
2022-12-21 18:41:48 +00:00
await window . storage . put ( 'lastHeartbeat' , toDayMillis ( Date . now ( ) ) ) ;
2019-11-13 23:25:57 +00:00
const TWELVE_HOURS = 12 * 60 * 60 * 1000 ;
2020-09-24 20:57:54 +00:00
setInterval (
2021-09-24 17:01:46 +00:00
( ) = > window . storage . put ( 'lastHeartbeat' , toDayMillis ( Date . now ( ) ) ) ,
2020-09-24 20:57:54 +00:00
TWELVE_HOURS
) ;
2019-11-13 23:25:57 +00:00
2018-07-27 01:13:56 +00:00
const currentVersion = window . getVersion ( ) ;
2022-02-03 01:21:02 +00:00
lastVersion = window . storage . get ( 'version' ) ;
2018-07-27 01:13:56 +00:00
newVersion = ! lastVersion || currentVersion !== lastVersion ;
2020-09-24 20:57:54 +00:00
await window . storage . put ( 'version' , currentVersion ) ;
2018-07-27 01:13:56 +00:00
2019-05-16 22:32:11 +00:00
if ( newVersion && lastVersion ) {
2021-09-17 18:27:53 +00:00
log . info (
2018-07-27 01:13:56 +00:00
` New version detected: ${ currentVersion } ; previous: ${ lastVersion } `
) ;
2019-05-16 22:32:11 +00:00
2021-08-24 23:36:43 +00:00
const remoteBuildExpiration = window . storage . get ( 'remoteBuildExpiration' ) ;
if ( remoteBuildExpiration ) {
2021-09-17 18:27:53 +00:00
log . info (
2021-08-24 23:36:43 +00:00
` Clearing remoteBuildExpiration. Previous value was ${ remoteBuildExpiration } `
) ;
2022-12-21 18:41:48 +00:00
await window . storage . remove ( 'remoteBuildExpiration' ) ;
2021-08-24 23:36:43 +00:00
}
2019-12-17 20:24:46 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v1.29.2-beta.1' ) ) {
2019-05-16 22:32:11 +00:00
// Stickers flags
await Promise . all ( [
2020-09-24 20:57:54 +00:00
window . storage . put ( 'showStickersIntroduction' , true ) ,
window . storage . put ( 'showStickerPickerHint' , true ) ,
2019-05-16 22:32:11 +00:00
] ) ;
}
2019-07-29 19:17:33 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v1.26.0' ) ) {
// Ensure that we re-register our support for sealed sender
2020-09-24 20:57:54 +00:00
await window . storage . put (
2019-07-29 19:17:33 +00:00
'hasRegisterSupportForUnauthenticatedDelivery' ,
false
) ;
}
2021-12-09 00:32:00 +00:00
const themeSetting = window . Events . getThemeSetting ( ) ;
const newThemeSetting = mapOldThemeToNew ( themeSetting ) ;
if ( window . isBeforeVersion ( lastVersion , 'v1.25.0' ) ) {
if ( newThemeSetting === window . systemTheme ) {
2022-12-21 18:41:48 +00:00
void window . Events . setThemeSetting ( 'system' ) ;
2021-12-09 00:32:00 +00:00
} else {
2022-12-21 18:41:48 +00:00
void window . Events . setThemeSetting ( newThemeSetting ) ;
2021-12-09 00:32:00 +00:00
}
2019-12-17 20:24:46 +00:00
}
2020-07-24 23:32:08 +00:00
if (
2022-01-26 23:39:25 +00:00
window . isBeforeVersion ( lastVersion , 'v1.36.0-beta.1' ) &&
window . isAfterVersion ( lastVersion , 'v1.35.0-beta.1' )
2020-07-24 23:32:08 +00:00
) {
2022-10-08 00:19:02 +00:00
await StorageService . eraseAllStorageServiceState ( ) ;
2020-07-24 23:32:08 +00:00
}
2021-04-29 23:02:27 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.2.0' ) ) {
const legacySenderCertificateStorageKey = 'senderCertificateWithUuid' ;
await removeStorageKeyJobQueue . add ( {
key : legacySenderCertificateStorageKey ,
} ) ;
}
2021-09-27 17:31:34 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.18.0' ) ) {
await window . storage . remove ( 'senderCertificate' ) ;
await window . storage . remove ( 'senderCertificateNoE164' ) ;
}
2021-09-28 16:30:30 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.19.0' ) ) {
await window . storage . remove ( GROUP_CREDENTIALS_KEY ) ;
}
2022-03-16 19:18:16 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.37.0-alpha' ) ) {
2022-03-21 21:19:37 +00:00
const legacyChallengeKey = 'challenge:retry-message-ids' ;
await removeStorageKeyJobQueue . add ( {
key : legacyChallengeKey ,
} ) ;
2022-03-16 19:18:16 +00:00
await window . Signal . Data . clearAllErrorStickerPackAttempts ( ) ;
}
2022-07-18 20:05:41 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.51.0-beta.2' ) ) {
2022-07-08 20:46:25 +00:00
await window . storage . put ( 'groupCredentials' , [ ] ) ;
await window . Signal . Data . removeAllProfileKeyCredentials ( ) ;
}
2019-05-16 22:32:38 +00:00
// This one should always be last - it could restart the app
2022-01-24 23:36:05 +00:00
if ( window . isBeforeVersion ( lastVersion , 'v5.30.0-alpha' ) ) {
2021-09-21 00:25:29 +00:00
await deleteAllLogs ( ) ;
2023-01-13 00:24:59 +00:00
window . IPC . restart ( ) ;
2019-06-27 20:21:52 +00:00
return ;
2019-05-16 22:32:11 +00:00
}
2018-07-27 01:13:56 +00:00
}
2022-06-01 19:57:30 +00:00
setAppLoadingScreenMessage (
2023-03-30 00:03:25 +00:00
window . i18n ( 'icu:optimizingApplication' ) ,
2022-06-01 19:57:30 +00:00
window . i18n
) ;
2018-08-07 19:33:56 +00:00
2018-08-08 17:00:33 +00:00
if ( newVersion ) {
2022-11-17 00:29:15 +00:00
await window . Signal . Data . cleanupOrphanedAttachments ( ) ;
2021-02-26 15:08:59 +00:00
2023-02-09 21:13:08 +00:00
optimizeFTS ( ) ;
2020-02-21 23:40:04 +00:00
// Don't block on the following operation
2022-12-21 18:41:48 +00:00
void window . Signal . Data . ensureFilePermissions ( ) ;
2018-08-08 17:00:33 +00:00
}
2023-03-30 00:03:25 +00:00
setAppLoadingScreenMessage ( window . i18n ( 'icu:loading' ) , window . i18n ) ;
2018-08-02 01:34:50 +00:00
2018-07-27 01:13:56 +00:00
let isMigrationWithIndexComplete = false ;
2022-07-08 20:35:08 +00:00
let isIdleTaskProcessing = false ;
2021-09-17 18:27:53 +00:00
log . info (
2020-01-08 17:44:54 +00:00
` Starting background data migration. Target version: ${ Message . CURRENT_SCHEMA_VERSION } `
2018-07-27 01:13:56 +00:00
) ;
idleDetector . on ( 'idle' , async ( ) = > {
2022-07-08 20:35:08 +00:00
const NUM_MESSAGES_PER_BATCH = 25 ;
const BATCH_DELAY = 10 * durations . SECOND ;
if ( isIdleTaskProcessing ) {
log . warn (
'idleDetector/idle: previous batch incomplete, not starting another'
) ;
return ;
2018-07-27 01:13:56 +00:00
}
2022-07-08 20:35:08 +00:00
try {
isIdleTaskProcessing = true ;
if ( ! isMigrationWithIndexComplete ) {
log . warn (
` idleDetector/idle: fetching at most ${ NUM_MESSAGES_PER_BATCH } for migration `
) ;
const batchWithIndex = await migrateMessageData ( {
numMessagesPerBatch : NUM_MESSAGES_PER_BATCH ,
upgradeMessageSchema ,
getMessagesNeedingUpgrade :
window . Signal . Data . getMessagesNeedingUpgrade ,
saveMessages : window.Signal.Data.saveMessages ,
} ) ;
log . info ( 'idleDetector/idle: Upgraded messages:' , batchWithIndex ) ;
isMigrationWithIndexComplete = batchWithIndex . done ;
}
} finally {
idleDetector . stop ( ) ;
2018-07-27 01:13:56 +00:00
2022-07-08 20:35:08 +00:00
if ( isMigrationWithIndexComplete ) {
log . info (
'idleDetector/idle: Background migration complete. Stopping.'
) ;
} else {
log . info (
` idleDetector/idle: Background migration not complete. Pausing for ${ BATCH_DELAY } ms. `
) ;
2022-06-20 21:18:23 +00:00
2022-07-08 20:35:08 +00:00
setTimeout ( ( ) = > {
idleDetector . start ( ) ;
} , BATCH_DELAY ) ;
}
2022-06-20 21:18:23 +00:00
2022-07-08 20:35:08 +00:00
isIdleTaskProcessing = false ;
2018-07-27 01:13:56 +00:00
}
} ) ;
2022-12-21 18:41:48 +00:00
void window . Signal . RemoteConfig . initRemoteConfig ( server ) ;
2020-08-05 01:13:19 +00:00
2023-04-11 03:54:43 +00:00
const retryPlaceholders = new RetryPlaceholders ( {
2023-05-10 01:25:57 +00:00
retryReceiptLifespan : HOUR ,
2021-06-08 21:51:58 +00:00
} ) ;
window . Signal . Services . retryPlaceholders = retryPlaceholders ;
setInterval ( async ( ) = > {
2021-07-15 23:48:09 +00:00
const now = Date . now ( ) ;
2021-08-06 00:17:23 +00:00
let sentProtoMaxAge = 14 * DAY ;
2021-07-15 23:48:09 +00:00
try {
2021-08-06 00:17:23 +00:00
sentProtoMaxAge = parseIntOrThrow (
window . Signal . RemoteConfig . getValue ( 'desktop.retryRespondMaxAge' ) ,
'retryRespondMaxAge'
) ;
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . warn (
2021-08-06 00:17:23 +00:00
'background/setInterval: Failed to parse integer from desktop.retryRespondMaxAge feature flag' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2021-08-06 00:17:23 +00:00
) ;
}
try {
await window . Signal . Data . deleteSentProtosOlderThan (
now - sentProtoMaxAge
) ;
2021-07-15 23:48:09 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2021-07-15 23:48:09 +00:00
'background/onready/setInterval: Error deleting sent protos: ' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2021-07-15 23:48:09 +00:00
) ;
}
try {
const expired = await retryPlaceholders . getExpiredAndRemove ( ) ;
2021-09-17 18:27:53 +00:00
log . info (
2021-07-15 23:48:09 +00:00
` retryPlaceholders/interval: Found ${ expired . length } expired items `
) ;
expired . forEach ( item = > {
2021-07-27 00:00:16 +00:00
const { conversationId , senderUuid , sentAt } = item ;
2021-11-11 22:43:05 +00:00
const conversation =
window . ConversationController . get ( conversationId ) ;
2021-07-15 23:48:09 +00:00
if ( conversation ) {
const receivedAt = Date . now ( ) ;
2023-04-11 03:54:43 +00:00
const receivedAtCounter = incrementMessageCounter ( ) ;
2022-12-21 18:41:48 +00:00
drop (
conversation . queueJob ( 'addDeliveryIssue' , ( ) = >
conversation . addDeliveryIssue ( {
receivedAt ,
receivedAtCounter ,
senderUuid ,
sentAt ,
} )
)
2021-07-15 23:48:09 +00:00
) ;
}
} ) ;
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2021-07-15 23:48:09 +00:00
'background/onready/setInterval: Error getting expired retry placeholders: ' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2021-07-15 23:48:09 +00:00
) ;
}
2021-06-08 21:51:58 +00:00
} , FIVE_MINUTES ) ;
2022-10-26 00:03:05 +00:00
setInterval ( ( ) = > {
reportLongRunningTasks ( ) ;
} , FIVE_MINUTES ) ;
2022-06-08 22:00:32 +00:00
let mainWindowStats = {
isMaximized : false ,
isFullScreen : false ,
} ;
let menuOptions = {
development : false ,
devTools : false ,
includeSetup : false ,
isProduction : true ,
platform : 'unknown' ,
} ;
2018-05-25 01:50:49 +00:00
try {
2022-10-22 06:26:16 +00:00
// This needs to load before we prime the data because we expect
// ConversationController to be loaded and ready to use by then.
await window . ConversationController . load ( ) ;
2019-02-04 23:54:37 +00:00
await Promise . all ( [
2022-11-09 21:11:45 +00:00
window . ConversationController . getOrCreateSignalConversation ( ) ,
2021-07-09 19:36:10 +00:00
Stickers . load ( ) ,
2021-09-20 17:59:09 +00:00
loadRecentEmojis ( ) ,
2021-11-02 23:01:13 +00:00
loadInitialBadgesState ( ) ,
2022-03-04 21:14:52 +00:00
loadStories ( ) ,
2022-07-01 00:52:03 +00:00
loadDistributionLists ( ) ,
2020-09-24 20:57:54 +00:00
window . textsecure . storage . protocol . hydrateCaches ( ) ,
2022-06-08 22:00:32 +00:00
( async ( ) = > {
mainWindowStats = await window . SignalContext . getMainWindowStats ( ) ;
} ) ( ) ,
( async ( ) = > {
menuOptions = await window . SignalContext . getMenuOptions ( ) ;
} ) ( ) ,
2022-11-09 02:38:19 +00:00
downloadOnboardingStory ( ) ,
2019-02-04 23:54:37 +00:00
] ) ;
2020-09-24 20:57:54 +00:00
await window . ConversationController . checkForConflicts ( ) ;
2018-07-27 01:13:56 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2018-07-27 01:13:56 +00:00
'background.js: ConversationController failed to load:' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2018-07-27 01:13:56 +00:00
) ;
2018-05-25 01:50:49 +00:00
} finally {
2022-06-08 22:00:32 +00:00
initializeRedux ( { mainWindowStats , menuOptions } ) ;
2023-01-18 23:31:10 +00:00
drop ( start ( ) ) ;
2020-02-12 21:30:58 +00:00
window . Signal . Services . initializeNetworkObserver (
window . reduxActions . network
) ;
window . Signal . Services . initializeUpdateListener (
2021-08-19 22:56:29 +00:00
window . reduxActions . updates
2020-02-12 21:30:58 +00:00
) ;
2020-12-07 19:40:11 +00:00
window . Signal . Services . calling . initialize (
2022-11-17 02:52:04 +00:00
{
. . . window . reduxActions . calling ,
areAnyCallsActiveOrRinging : ( ) = >
areAnyCallsActiveOrRinging ( window . reduxStore . getState ( ) ) ,
} ,
2020-12-07 19:40:11 +00:00
window . getSfuUrl ( )
) ;
2020-02-12 21:30:58 +00:00
window . reduxActions . expiration . hydrateExpirationStatus (
2023-01-18 23:31:10 +00:00
window . getBuildExpiration ( )
2020-02-12 21:30:58 +00:00
) ;
2018-05-25 01:50:49 +00:00
}
2018-04-27 21:25:04 +00:00
} ) ;
2017-08-08 00:24:59 +00:00
2022-06-08 22:00:32 +00:00
function initializeRedux ( {
mainWindowStats ,
menuOptions ,
} : {
mainWindowStats : MainWindowStatsType ;
menuOptions : MenuOptionsType ;
} ) {
2019-04-18 00:50:36 +00:00
// Here we set up a full redux store with initial state for our LeftPane Root
const convoCollection = window . getConversations ( ) ;
2022-03-04 21:14:52 +00:00
const initialState = getInitialState ( {
badges : initialBadgesState ,
2022-06-08 22:00:32 +00:00
mainWindowStats ,
menuOptions ,
2022-07-01 00:52:03 +00:00
stories : getStoriesForRedux ( ) ,
storyDistributionLists : getDistributionListsForRedux ( ) ,
2022-03-04 21:14:52 +00:00
} ) ;
2019-04-18 00:50:36 +00:00
2020-09-24 20:57:54 +00:00
const store = window . Signal . State . createStore ( initialState ) ;
2019-04-18 00:50:36 +00:00
window . reduxStore = store ;
// Binding these actions to our redux store and exposing them allows us to update
// redux when things change in the backbone world.
2021-06-15 23:30:23 +00:00
window . reduxActions = {
2021-06-17 17:15:10 +00:00
accounts : bindActionCreators ( actionCreators . accounts , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
app : bindActionCreators ( actionCreators . app , store . dispatch ) ,
audioPlayer : bindActionCreators (
actionCreators . audioPlayer ,
store . dispatch
) ,
2021-09-29 20:23:06 +00:00
audioRecorder : bindActionCreators (
actionCreators . audioRecorder ,
store . dispatch
) ,
2021-11-02 23:01:13 +00:00
badges : bindActionCreators ( actionCreators . badges , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
calling : bindActionCreators ( actionCreators . calling , store . dispatch ) ,
2021-06-25 16:08:16 +00:00
composer : bindActionCreators ( actionCreators . composer , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
conversations : bindActionCreators (
actionCreators . conversations ,
store . dispatch
) ,
2022-01-11 20:02:46 +00:00
crashReports : bindActionCreators (
actionCreators . crashReports ,
store . dispatch
) ,
2023-03-28 20:31:24 +00:00
inbox : bindActionCreators ( actionCreators . inbox , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
emojis : bindActionCreators ( actionCreators . emojis , store . dispatch ) ,
expiration : bindActionCreators ( actionCreators . expiration , store . dispatch ) ,
globalModals : bindActionCreators (
actionCreators . globalModals ,
store . dispatch
) ,
items : bindActionCreators ( actionCreators . items , store . dispatch ) ,
2022-12-10 02:02:22 +00:00
lightbox : bindActionCreators ( actionCreators . lightbox , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
linkPreviews : bindActionCreators (
actionCreators . linkPreviews ,
store . dispatch
) ,
2022-12-20 17:50:23 +00:00
mediaGallery : bindActionCreators (
actionCreators . mediaGallery ,
store . dispatch
) ,
2021-06-15 23:30:23 +00:00
network : bindActionCreators ( actionCreators . network , store . dispatch ) ,
safetyNumber : bindActionCreators (
actionCreators . safetyNumber ,
store . dispatch
) ,
search : bindActionCreators ( actionCreators . search , store . dispatch ) ,
stickers : bindActionCreators ( actionCreators . stickers , store . dispatch ) ,
2022-03-04 21:14:52 +00:00
stories : bindActionCreators ( actionCreators . stories , store . dispatch ) ,
2022-07-01 00:52:03 +00:00
storyDistributionLists : bindActionCreators (
actionCreators . storyDistributionLists ,
store . dispatch
) ,
2022-07-12 16:41:41 +00:00
toast : bindActionCreators ( actionCreators . toast , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
updates : bindActionCreators ( actionCreators . updates , store . dispatch ) ,
user : bindActionCreators ( actionCreators . user , store . dispatch ) ,
2022-10-18 17:12:02 +00:00
username : bindActionCreators ( actionCreators . username , store . dispatch ) ,
2021-06-15 23:30:23 +00:00
} ;
2019-04-18 00:50:36 +00:00
const {
conversationAdded ,
conversationChanged ,
conversationRemoved ,
removeAllConversations ,
2023-01-02 21:34:41 +00:00
onConversationClosed ,
2021-06-15 23:30:23 +00:00
} = window . reduxActions . conversations ;
2019-04-18 00:50:36 +00:00
convoCollection . on ( 'remove' , conversation = > {
const { id } = conversation || { } ;
2021-11-30 23:16:13 +00:00
2023-01-02 21:34:41 +00:00
onConversationClosed ( id , 'removed' ) ;
2019-04-18 00:50:36 +00:00
conversationRemoved ( id ) ;
} ) ;
convoCollection . on ( 'add' , conversation = > {
2020-10-26 14:39:45 +00:00
if ( ! conversation ) {
return ;
}
2023-02-17 20:31:07 +00:00
conversationAdded ( conversation . id , conversation . format ( ) ) ;
2019-04-18 00:50:36 +00:00
} ) ;
2021-04-08 00:35:22 +00:00
const changedConvoBatcher = createBatcher < ConversationModel > ( {
name : 'changedConvoBatcher' ,
processBatch ( batch ) {
2021-04-26 18:11:30 +00:00
const deduped = new Set ( batch ) ;
2021-09-17 18:27:53 +00:00
log . info (
2021-04-08 00:35:22 +00:00
'changedConvoBatcher: deduped ' +
2021-04-26 18:11:30 +00:00
` ${ batch . length } into ${ deduped . size } `
2021-04-08 00:35:22 +00:00
) ;
2021-11-01 23:38:08 +00:00
batchDispatch ( ( ) = > {
2021-08-11 16:23:21 +00:00
deduped . forEach ( conversation = > {
conversationChanged ( conversation . id , conversation . format ( ) ) ;
} ) ;
2021-04-08 00:35:22 +00:00
} ) ;
} ,
2021-01-11 21:59:46 +00:00
// This delay ensures that the .format() call isn't synchronous as a
// Backbone property is changed. Important because our _byUuid/_byE164
// lookups aren't up-to-date as the change happens; just a little bit
// after.
2021-04-08 00:35:22 +00:00
wait : 1 ,
maxSize : Infinity ,
} ) ;
2021-11-01 23:38:08 +00:00
convoCollection . on ( 'props-change' , ( conversation , isBatched ) = > {
2021-04-08 00:35:22 +00:00
if ( ! conversation ) {
return ;
}
2021-11-01 23:38:08 +00:00
// `isBatched` is true when the `.set()` call on the conversation model
// already runs from within `react-redux`'s batch. Instead of batching
// the redux update for later - clear all queued updates and update
// immediately.
if ( isBatched ) {
changedConvoBatcher . removeAll ( conversation ) ;
conversationChanged ( conversation . id , conversation . format ( ) ) ;
return ;
}
2021-04-08 00:35:22 +00:00
changedConvoBatcher . add ( conversation ) ;
2019-04-18 00:50:36 +00:00
} ) ;
2022-10-20 19:16:37 +00:00
// Called by SignalProtocolStore#removeAllData()
2019-04-18 00:50:36 +00:00
convoCollection . on ( 'reset' , removeAllConversations ) ;
2021-09-02 21:47:42 +00:00
window . Whisper . events . on ( 'userChanged' , ( reconnect = false ) = > {
2021-08-05 23:34:49 +00:00
const newDeviceId = window . textsecure . storage . user . getDeviceId ( ) ;
const newNumber = window . textsecure . storage . user . getNumber ( ) ;
2022-07-08 20:46:25 +00:00
const newACI = window . textsecure . storage . user
. getUuid ( UUIDKind . ACI )
? . toString ( ) ;
const newPNI = window . textsecure . storage . user
. getUuid ( UUIDKind . PNI )
? . toString ( ) ;
2021-11-11 22:43:05 +00:00
const ourConversation =
window . ConversationController . getOurConversation ( ) ;
2021-08-06 18:20:11 +00:00
if ( ourConversation ? . get ( 'e164' ) !== newNumber ) {
ourConversation ? . set ( 'e164' , newNumber ) ;
}
2021-08-05 23:34:49 +00:00
window . reduxActions . user . userChanged ( {
2021-08-06 18:20:11 +00:00
ourConversationId : ourConversation?.get ( 'id' ) ,
2021-08-05 23:34:49 +00:00
ourDeviceId : newDeviceId ,
ourNumber : newNumber ,
2022-07-08 20:46:25 +00:00
ourACI : newACI ,
ourPNI : newPNI ,
2021-08-05 23:34:49 +00:00
regionCode : window.storage.get ( 'regionCode' ) ,
} ) ;
2021-09-02 21:47:42 +00:00
if ( reconnect ) {
2021-09-17 18:27:53 +00:00
log . info ( 'background: reconnecting websocket on user change' ) ;
2021-09-02 21:47:42 +00:00
enqueueReconnectToWebSocket ( ) ;
}
2021-08-05 23:34:49 +00:00
} ) ;
2019-04-18 00:50:36 +00:00
2022-06-08 22:00:32 +00:00
window . Whisper . events . on ( 'setMenuOptions' , ( options : MenuOptionsType ) = > {
window . reduxActions . user . userChanged ( { menuOptions : options } ) ;
} ) ;
2019-11-07 21:36:16 +00:00
document . addEventListener ( 'keydown' , event = > {
2023-02-22 10:28:32 +00:00
const { ctrlKey , metaKey , shiftKey , altKey } = event ;
2019-11-07 21:36:16 +00:00
2019-12-17 18:52:36 +00:00
const commandKey = window . platform === 'darwin' && metaKey ;
const controlKey = window . platform !== 'darwin' && ctrlKey ;
const commandOrCtrl = commandKey || controlKey ;
2019-11-07 21:36:16 +00:00
const state = store . getState ( ) ;
2021-02-12 21:58:14 +00:00
const selectedId = state . conversations . selectedConversationId ;
2020-09-24 20:57:54 +00:00
const conversation = window . ConversationController . get ( selectedId ) ;
2019-11-07 21:36:16 +00:00
2021-09-29 21:20:52 +00:00
const key = KeyboardLayout . lookup ( event ) ;
2019-11-07 21:36:16 +00:00
// NAVIGATION
// Show keyboard shortcuts - handled by Electron-managed keyboard shortcuts
2019-11-14 20:36:30 +00:00
// However, on linux Ctrl+/ selects all text, so we prevent that
2023-02-22 10:28:32 +00:00
if ( commandOrCtrl && ! altKey && key === '/' ) {
2022-12-22 03:07:45 +00:00
window . Events . showKeyboardShortcuts ( ) ;
2019-11-14 20:36:30 +00:00
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
return ;
}
2019-11-07 21:36:16 +00:00
2023-05-04 19:34:52 +00:00
// Super tab :)
2023-05-09 15:52:03 +00:00
if (
( commandOrCtrl && key === 'F6' ) ||
( commandOrCtrl && ! shiftKey && ( key === 't' || key === 'T' ) )
) {
2023-05-04 19:34:52 +00:00
window . enterKeyboardMode ( ) ;
const focusedElement = document . activeElement ;
const targets : Array < HTMLElement > = Array . from (
document . querySelectorAll ( '[data-supertab="true"]' )
) ;
const focusedIndex = targets . findIndex ( target = > {
if ( ! target || ! focusedElement ) {
return false ;
}
if ( target === focusedElement ) {
return true ;
}
if ( target . contains ( focusedElement ) ) {
return true ;
}
return false ;
} ) ;
const lastIndex = targets . length - 1 ;
const increment = shiftKey ? - 1 : 1 ;
let index ;
if ( focusedIndex < 0 || focusedIndex >= lastIndex ) {
index = 0 ;
} else {
index = focusedIndex + increment ;
}
while ( ! targets [ index ] ) {
index += increment ;
if ( index > lastIndex || index < 0 ) {
index = 0 ;
}
}
2023-05-09 15:52:03 +00:00
const node = targets [ index ] ;
const firstFocusableElement = node . querySelectorAll < HTMLElement > (
focusableSelectors . join ( ',' )
) [ 0 ] ;
2019-11-07 21:36:16 +00:00
2023-05-09 15:52:03 +00:00
if ( firstFocusableElement ) {
firstFocusableElement . focus ( ) ;
2019-11-07 21:36:16 +00:00
} else {
2023-05-09 15:52:03 +00:00
const nodeInfo = Array . from ( node . attributes )
. map ( attr = > ` ${ attr . name } = ${ attr . value } ` )
. join ( ',' ) ;
log . warn (
` supertab: could not find focus for DOM node ${ node . nodeName } < ${ nodeInfo } > `
) ;
window . enterMouseMode ( ) ;
const { activeElement } = document ;
if (
activeElement &&
'blur' in activeElement &&
typeof activeElement . blur === 'function'
) {
activeElement . blur ( ) ;
2019-11-07 21:36:16 +00:00
}
}
}
// Cancel out of keyboard shortcut screen - has first precedence
2022-12-22 03:07:45 +00:00
const isShortcutGuideModalVisible = window . reduxStore
? window . reduxStore . getState ( ) . globalModals . isShortcutGuideModalVisible
: false ;
if ( isShortcutGuideModalVisible && key === 'Escape' ) {
window . reduxActions . globalModals . closeShortcutGuideModal ( ) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
// Escape is heavily overloaded - here we avoid clashes with other Escape handlers
if ( key === 'Escape' ) {
// Check origin - if within a react component which handles escape, don't handle.
// Why? Because React's synthetic events can cause events to be handled twice.
const target = document . activeElement ;
2020-09-24 20:57:54 +00:00
// We might want to use NamedNodeMap.getNamedItem('class')
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
if (
target &&
target . attributes &&
2020-09-24 20:57:54 +00:00
( target . attributes as any ) . class &&
( target . attributes as any ) . class . value
2019-11-07 21:36:16 +00:00
) {
2020-09-24 20:57:54 +00:00
const className = ( target . attributes as any ) . class . value ;
/* eslint-enable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
2021-11-10 00:25:29 +00:00
// Search box wants to handle events internally
2021-11-01 18:43:02 +00:00
if ( className . includes ( 'LeftPaneSearchInput__input' ) ) {
2019-11-07 21:36:16 +00:00
return ;
}
}
// These add listeners to document, but we'll run first
const confirmationModal = document . querySelector (
'.module-confirmation-dialog__overlay'
) ;
if ( confirmationModal ) {
return ;
}
const emojiPicker = document . querySelector ( '.module-emoji-picker' ) ;
if ( emojiPicker ) {
return ;
}
2021-09-07 16:12:26 +00:00
const lightBox = document . querySelector ( '.Lightbox' ) ;
2019-11-07 21:36:16 +00:00
if ( lightBox ) {
return ;
}
const stickerPicker = document . querySelector ( '.module-sticker-picker' ) ;
if ( stickerPicker ) {
return ;
}
const stickerPreview = document . querySelector (
'.module-sticker-manager__preview-modal__overlay'
) ;
if ( stickerPreview ) {
return ;
}
2020-01-17 22:23:19 +00:00
const reactionViewer = document . querySelector (
'.module-reaction-viewer'
) ;
if ( reactionViewer ) {
return ;
}
2020-01-23 23:57:37 +00:00
2021-09-13 17:04:45 +00:00
const reactionPicker = document . querySelector ( '.module-ReactionPicker' ) ;
2020-01-23 23:57:37 +00:00
if ( reactionPicker ) {
return ;
}
2020-11-20 17:30:45 +00:00
const contactModal = document . querySelector ( '.module-contact-modal' ) ;
if ( contactModal ) {
return ;
}
const modalHost = document . querySelector ( '.module-modal-host__overlay' ) ;
if ( modalHost ) {
return ;
}
2019-11-07 21:36:16 +00:00
}
// Send Escape to active conversation so it can close panels
if ( conversation && key === 'Escape' ) {
2022-12-21 20:44:23 +00:00
window . reduxActions . conversations . popPanelForConversation ( ) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
// Preferences - handled by Electron-managed keyboard shortcuts
// Open the top-right menu for current conversation
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
2019-11-15 22:31:51 +00:00
( key === 'l' || key === 'L' )
2019-11-14 20:35:59 +00:00
) {
2019-11-07 21:36:16 +00:00
const button = document . querySelector (
2021-05-11 18:40:36 +00:00
'.module-ConversationHeader__button--more'
2019-11-07 21:36:16 +00:00
) ;
if ( ! button ) {
return ;
}
// Because the menu is shown at a location based on the initiating click, we need
// to fake up a mouse event to get the menu to show somewhere other than (0,0).
const { x , y , width , height } = button . getBoundingClientRect ( ) ;
const mouseEvent = document . createEvent ( 'MouseEvents' ) ;
2020-09-24 20:57:54 +00:00
// Types do not match signature
/* eslint-disable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
mouseEvent . initMouseEvent (
'click' ,
true , // bubbles
false , // cancelable
2020-09-24 20:57:54 +00:00
null as any , // view
null as any , // detail
2019-11-07 21:36:16 +00:00
0 , // screenX,
0 , // screenY,
x + width / 2 ,
y + height / 2 ,
false , // ctrlKey,
false , // altKey,
false , // shiftKey,
false , // metaKey,
2020-09-24 20:57:54 +00:00
false as any , // button,
2019-11-07 21:36:16 +00:00
document . body
) ;
2020-09-24 20:57:54 +00:00
/* eslint-enable @typescript-eslint/no-explicit-any */
2019-11-07 21:36:16 +00:00
button . dispatchEvent ( mouseEvent ) ;
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
// Focus composer field
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 't' || key === 'T' )
) {
2022-12-08 23:56:17 +00:00
window . reduxActions . composer . setComposerFocus ( conversation . id ) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
2023-05-09 15:52:03 +00:00
if (
conversation &&
commandOrCtrl &&
! shiftKey &&
( key === 'j' || key === 'J' )
) {
window . enterKeyboardMode ( ) ;
const item : HTMLElement | null =
document . querySelector (
'.module-last-seen-indicator ~ div .module-message'
) ||
document . querySelector (
'.module-timeline__last-message .module-message'
) ;
item ? . focus ( ) ;
}
2019-11-07 21:36:16 +00:00
// Open all media
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 'm' || key === 'M' )
) {
2022-12-21 20:44:23 +00:00
window . reduxActions . conversations . pushPanelForConversation ( {
type : PanelType . AllMedia ,
} ) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
// Open emoji picker - handled by component
// Open sticker picker - handled by component
2021-09-29 20:23:06 +00:00
// Begin recording voice note - handled by component
2019-11-07 21:36:16 +00:00
// Archive or unarchive conversation
if (
conversation &&
! conversation . get ( 'isArchived' ) &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-07 21:36:16 +00:00
shiftKey &&
2019-11-14 20:35:59 +00:00
( key === 'a' || key === 'A' )
2019-11-07 21:36:16 +00:00
) {
2022-12-21 03:25:10 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
window . reduxActions . conversations . onArchive ( conversation . id ) ;
2019-11-07 21:36:16 +00:00
2019-12-03 20:02:50 +00:00
// It's very likely that the act of archiving a conversation will set focus to
2021-02-23 20:34:28 +00:00
// 'none,' or the top-level body element. This resets it to the left pane.
2019-12-03 20:02:50 +00:00
if ( document . activeElement === document . body ) {
2020-09-24 20:57:54 +00:00
const leftPaneEl : HTMLElement | null = document . querySelector (
'.module-left-pane__list'
) ;
2019-12-03 20:02:50 +00:00
if ( leftPaneEl ) {
leftPaneEl . focus ( ) ;
}
}
2019-11-07 21:36:16 +00:00
return ;
}
if (
conversation &&
conversation . get ( 'isArchived' ) &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-07 21:36:16 +00:00
shiftKey &&
2019-11-14 20:35:59 +00:00
( key === 'u' || key === 'U' )
2019-11-07 21:36:16 +00:00
) {
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2022-12-21 03:25:10 +00:00
window . reduxActions . conversations . onMoveToInbox ( conversation . id ) ;
2019-11-07 21:36:16 +00:00
return ;
}
// Scroll to bottom of list - handled by component
// Scroll to top of list - handled by component
// Close conversation
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 'c' || key === 'C' )
) {
2022-12-21 03:25:10 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2023-01-02 21:34:41 +00:00
onConversationClosed ( conversation . id , 'keyboard shortcut close' ) ;
2022-06-16 19:12:50 +00:00
window . reduxActions . conversations . showConversation ( {
conversationId : undefined ,
messageId : undefined ,
} ) ;
2022-12-21 03:25:10 +00:00
2019-11-07 21:36:16 +00:00
return ;
}
// MESSAGES
// Show message details
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
! shiftKey &&
( key === 'd' || key === 'D' )
) {
2022-12-21 03:25:10 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2023-03-20 22:23:53 +00:00
const { targetedMessage } = state . conversations ;
if ( ! targetedMessage ) {
2019-11-07 21:36:16 +00:00
return ;
}
2022-12-21 20:44:23 +00:00
window . reduxActions . conversations . pushPanelForConversation ( {
type : PanelType . MessageDetails ,
args : {
2023-03-20 22:23:53 +00:00
messageId : targetedMessage ,
2022-12-21 20:44:23 +00:00
} ,
} ) ;
2019-11-07 21:36:16 +00:00
return ;
}
// Toggle reply to message
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 'r' || key === 'R' )
) {
2022-12-21 03:25:10 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2023-03-20 22:23:53 +00:00
const { targetedMessage } = state . conversations ;
2019-11-07 21:36:16 +00:00
2023-01-05 00:22:36 +00:00
const quotedMessageSelector = getQuotedMessageSelector ( state ) ;
const quote = quotedMessageSelector ( conversation . id ) ;
2022-12-09 19:11:14 +00:00
window . reduxActions . composer . setQuoteByMessageId (
conversation . id ,
2023-03-20 22:23:53 +00:00
quote ? undefined : targetedMessage
2022-12-09 19:11:14 +00:00
) ;
2019-11-07 21:36:16 +00:00
return ;
}
// Save attachment
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
! shiftKey &&
( key === 's' || key === 'S' )
) {
2022-12-21 03:25:10 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2023-03-20 22:23:53 +00:00
const { targetedMessage } = state . conversations ;
2019-11-07 21:36:16 +00:00
2023-03-20 22:23:53 +00:00
if ( targetedMessage ) {
2022-12-14 18:12:04 +00:00
window . reduxActions . conversations . saveAttachmentFromMessage (
2023-03-20 22:23:53 +00:00
targetedMessage
2022-12-14 18:12:04 +00:00
) ;
2019-11-07 21:36:16 +00:00
return ;
}
}
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 'd' || key === 'D' )
) {
2023-03-24 21:16:48 +00:00
const { forwardMessagesProps } = state . globalModals ;
const { targetedMessage , selectedMessageIds } = state . conversations ;
2019-11-07 21:36:16 +00:00
2023-03-24 21:16:48 +00:00
const messageIds =
selectedMessageIds ? ?
( targetedMessage != null ? [ targetedMessage ] : null ) ;
if ( forwardMessagesProps == null && messageIds != null ) {
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
2022-12-14 22:45:39 +00:00
2023-04-10 21:38:34 +00:00
window . reduxActions . globalModals . toggleDeleteMessagesModal ( {
conversationId : conversation.id ,
messageIds ,
onDelete() {
if ( selectedMessageIds != null ) {
window . reduxActions . conversations . toggleSelectMode ( false ) ;
}
2022-12-14 22:45:39 +00:00
} ,
} ) ;
2019-11-07 21:36:16 +00:00
return ;
}
}
2023-04-06 01:04:41 +00:00
if (
conversation &&
commandOrCtrl &&
shiftKey &&
( key === 's' || key === 'S' )
) {
const { hasConfirmationModal } = state . globalModals ;
const { targetedMessage , selectedMessageIds } = state . conversations ;
const messageIds =
selectedMessageIds ? ?
( targetedMessage != null ? [ targetedMessage ] : null ) ;
if ( ! hasConfirmationModal && messageIds != null ) {
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
window . reduxActions . globalModals . toggleForwardMessagesModal (
2023-04-10 21:38:34 +00:00
messageIds ,
( ) = > {
if ( selectedMessageIds != null ) {
window . reduxActions . conversations . toggleSelectMode ( false ) ;
}
}
2023-04-06 01:04:41 +00:00
) ;
return ;
}
}
2019-11-07 21:36:16 +00:00
// COMPOSER
// Create a newline in your message - handled by component
// Expand composer - handled by component
// Send in expanded composer - handled by component
// Attach file
2021-10-15 18:51:58 +00:00
// hooks/useKeyboardShorcuts useAttachFileShortcut
2019-11-07 21:36:16 +00:00
// Remove draft link preview
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
! shiftKey &&
( key === 'p' || key === 'P' )
) {
2023-01-05 00:22:36 +00:00
removeLinkPreview ( conversation . id ) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
return ;
}
// Attach file
2019-11-14 20:35:59 +00:00
if (
conversation &&
2019-12-17 18:52:36 +00:00
commandOrCtrl &&
2019-11-14 20:35:59 +00:00
shiftKey &&
( key === 'p' || key === 'P' )
) {
2022-12-21 18:41:48 +00:00
void clearConversationDraftAttachments (
2022-12-14 19:05:32 +00:00
conversation . id ,
conversation . get ( 'draftAttachments' )
) ;
2019-11-07 21:36:16 +00:00
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
// Commented out because this is the last item
// return;
}
} ) ;
2019-04-18 00:50:36 +00:00
}
2020-09-24 20:57:54 +00:00
window . Whisper . events . on ( 'setupAsNewDevice' , ( ) = > {
2023-03-20 20:42:00 +00:00
window . IPC . readyForUpdates ( ) ;
2021-06-14 19:01:00 +00:00
window . reduxActions . app . openInstaller ( ) ;
2018-04-27 21:25:04 +00:00
} ) ;
2017-10-18 18:57:34 +00:00
2020-09-24 20:57:54 +00:00
window . Whisper . events . on ( 'setupAsStandalone' , ( ) = > {
2021-06-14 19:01:00 +00:00
window . reduxActions . app . openStandalone ( ) ;
2018-04-27 21:25:04 +00:00
} ) ;
2015-09-22 00:05:19 +00:00
2021-06-09 22:28:54 +00:00
window . Whisper . events . on ( 'powerMonitorSuspend' , ( ) = > {
2021-09-17 18:27:53 +00:00
log . info ( 'powerMonitor: suspend' ) ;
2023-01-24 19:17:00 +00:00
server ? . cancelInflightRequests ( 'powerMonitorSuspend' ) ;
2021-09-27 18:22:46 +00:00
suspendTasksWithTimeout ( ) ;
2021-06-09 22:28:54 +00:00
} ) ;
window . Whisper . events . on ( 'powerMonitorResume' , ( ) = > {
2021-09-17 18:27:53 +00:00
log . info ( 'powerMonitor: resume' ) ;
2022-01-20 22:47:06 +00:00
server ? . checkSockets ( ) ;
2023-01-24 19:17:00 +00:00
server ? . cancelInflightRequests ( 'powerMonitorResume' ) ;
2022-01-24 23:50:32 +00:00
resumeTasksWithTimeout ( ) ;
2021-06-09 22:28:54 +00:00
} ) ;
2022-01-24 20:32:09 +00:00
window . Whisper . events . on ( 'powerMonitorLockScreen' , ( ) = > {
2022-08-16 23:52:09 +00:00
window . reduxActions . calling . hangUpActiveCall ( 'powerMonitorLockScreen' ) ;
2022-01-24 20:32:09 +00:00
} ) ;
2021-05-17 18:29:37 +00:00
const reconnectToWebSocketQueue = new LatestQueue ( ) ;
const enqueueReconnectToWebSocket = ( ) = > {
reconnectToWebSocketQueue . add ( async ( ) = > {
2021-07-28 21:37:09 +00:00
if ( ! server ) {
2021-09-17 18:27:53 +00:00
log . info ( 'reconnectToWebSocket: No server. Early return.' ) ;
2021-05-17 18:29:37 +00:00
return ;
}
2021-09-17 18:27:53 +00:00
log . info ( 'reconnectToWebSocket starting...' ) ;
2022-10-05 00:48:25 +00:00
await server . reconnect ( ) ;
2021-05-17 18:29:37 +00:00
} ) ;
} ;
2023-02-08 17:19:25 +00:00
const throttledEnqueueReconnectToWebSocket = throttle (
enqueueReconnectToWebSocket ,
1000
2021-05-17 18:29:37 +00:00
) ;
2023-02-08 17:19:25 +00:00
window . Whisper . events . on ( 'mightBeUnlinked' , ( ) = > {
2023-04-11 03:54:43 +00:00
if ( Registration . everDone ( ) ) {
2023-02-08 17:19:25 +00:00
throttledEnqueueReconnectToWebSocket ( ) ;
}
} ) ;
2021-08-31 20:34:32 +00:00
window . Whisper . events . on ( 'unlinkAndDisconnect' , ( ) = > {
2022-12-21 18:41:48 +00:00
void unlinkAndDisconnect ( RemoveAllConfiguration . Full ) ;
2021-08-31 20:34:32 +00:00
} ) ;
2021-07-28 21:37:09 +00:00
2022-01-14 21:34:52 +00:00
async function runStorageService() {
2022-10-08 00:19:02 +00:00
StorageService . enableStorageService ( ) ;
2021-07-15 23:48:09 +00:00
if ( window . ConversationController . areWePrimaryDevice ( ) ) {
2021-09-17 18:27:53 +00:00
log . warn (
2021-07-15 23:48:09 +00:00
'background/runStorageService: We are primary device; not sending key sync request'
) ;
return ;
}
2022-01-14 21:34:52 +00:00
try {
2022-06-13 21:39:35 +00:00
await singleProtoJobQueue . add ( MessageSender . getRequestKeySyncMessage ( ) ) ;
2022-01-14 21:34:52 +00:00
} catch ( error ) {
log . error (
'runStorageService: Failed to queue sync message' ,
Errors . toLogFormat ( error )
) ;
}
2020-09-29 23:29:11 +00:00
}
2018-07-18 23:49:03 +00:00
async function start() {
2021-07-23 17:23:50 +00:00
// Storage is ready because `start()` is called from `storage.onready()`
2022-03-21 21:19:37 +00:00
strictAssert ( challengeHandler , 'start: challengeHandler' ) ;
2021-07-23 17:23:50 +00:00
await challengeHandler . load ( ) ;
2021-05-06 00:09:29 +00:00
2021-08-06 18:20:11 +00:00
if ( ! window . storage . user . getNumber ( ) ) {
2021-11-11 22:43:05 +00:00
const ourConversation =
window . ConversationController . getOurConversation ( ) ;
2021-08-06 18:20:11 +00:00
const ourE164 = ourConversation ? . get ( 'e164' ) ;
if ( ourE164 ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Restoring E164 from our conversation' ) ;
2022-12-21 18:41:48 +00:00
await window . storage . user . setNumber ( ourE164 ) ;
2021-08-06 18:20:11 +00:00
}
}
2022-02-03 01:21:02 +00:00
if ( newVersion && lastVersion ) {
if ( window . isBeforeVersion ( lastVersion , 'v5.31.0' ) ) {
window . ConversationController . repairPinnedConversations ( ) ;
}
}
2018-04-27 21:25:04 +00:00
window . dispatchEvent ( new Event ( 'storage_ready' ) ) ;
2017-03-31 01:11:13 +00:00
2022-12-21 18:41:48 +00:00
void badgeImageFileDownloader . checkForFilesToDownload ( ) ;
2021-11-02 23:01:13 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'Expiration start timestamp cleanup: starting...' ) ;
2021-11-11 22:43:05 +00:00
const messagesUnexpectedlyMissingExpirationStartTimestamp =
await window . Signal . Data . getMessagesUnexpectedlyMissingExpirationStartTimestamp ( ) ;
2021-09-17 18:27:53 +00:00
log . info (
2021-06-18 19:12:04 +00:00
` Expiration start timestamp cleanup: Found ${ messagesUnexpectedlyMissingExpirationStartTimestamp . length } messages for cleanup `
2019-02-26 23:08:43 +00:00
) ;
2022-02-07 22:26:20 +00:00
if ( ! window . textsecure . storage . user . getUuid ( ) ) {
log . info (
"Expiration start timestamp cleanup: Cancelling update; we don't have our own UUID"
) ;
} else if ( messagesUnexpectedlyMissingExpirationStartTimestamp . length ) {
2021-11-11 22:43:05 +00:00
const newMessageAttributes =
messagesUnexpectedlyMissingExpirationStartTimestamp . map ( message = > {
2021-06-18 19:12:04 +00:00
const expirationStartTimestamp = Math . min (
. . . filter (
[
// These messages should always have a sent_at, but we have fallbacks
// just in case.
message . sent_at ,
Date . now ( ) ,
// The query shouldn't return messages with expiration start timestamps,
// but we're trying to be extra careful.
message . expirationStartTimestamp ,
] ,
isNotNil
)
) ;
2021-09-17 18:27:53 +00:00
log . info (
2022-02-07 22:26:20 +00:00
` Expiration start timestamp cleanup: starting timer for ${ message . type } message sent at ${ message . sent_at } . Starting timer at ${ expirationStartTimestamp } `
2019-02-26 23:08:43 +00:00
) ;
2021-06-18 19:12:04 +00:00
return {
. . . message ,
expirationStartTimestamp ,
} ;
2021-11-11 22:43:05 +00:00
} ) ;
2019-02-26 23:08:43 +00:00
2021-12-20 21:04:02 +00:00
await window . Signal . Data . saveMessages ( newMessageAttributes , {
ourUuid : window.textsecure.storage.user.getCheckedUuid ( ) . toString ( ) ,
} ) ;
2021-06-16 22:20:17 +00:00
}
2021-09-17 18:27:53 +00:00
log . info ( 'Expiration start timestamp cleanup: complete' ) ;
2019-02-26 23:08:43 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'listening for registration events' ) ;
2020-09-24 20:57:54 +00:00
window . Whisper . events . on ( 'registration_done' , ( ) = > {
2021-09-17 18:27:53 +00:00
log . info ( 'handling registration event' ) ;
2021-08-04 20:12:35 +00:00
strictAssert ( server !== undefined , 'WebAPI not ready' ) ;
2022-12-21 18:41:48 +00:00
void server . authenticate (
2021-08-04 20:12:35 +00:00
window . textsecure . storage . user . getWebAPICredentials ( )
) ;
2022-08-10 23:38:52 +00:00
// Cancel throttled calls to refreshRemoteConfig since our auth changed.
window . Signal . RemoteConfig . maybeRefreshRemoteConfig . cancel ( ) ;
2022-12-21 18:41:48 +00:00
void window . Signal . RemoteConfig . maybeRefreshRemoteConfig ( server ) ;
2022-08-10 23:38:52 +00:00
2022-12-21 18:41:48 +00:00
void connect ( true ) ;
2018-04-27 21:25:04 +00:00
} ) ;
2017-04-12 21:20:56 +00:00
2018-04-27 21:25:04 +00:00
cancelInitializationMessage ( ) ;
2021-06-14 19:01:00 +00:00
render (
window . Signal . State . Roots . createApp ( window . reduxStore ) ,
2021-06-23 14:33:27 +00:00
document . getElementById ( 'app-container' )
2021-06-14 19:01:00 +00:00
) ;
const hideMenuBar = window . storage . get ( 'hide-menu-bar' , false ) ;
2023-01-13 00:24:59 +00:00
window . IPC . setAutoHideMenuBar ( hideMenuBar ) ;
window . IPC . setMenuBarVisibility ( ! hideMenuBar ) ;
2018-04-27 21:25:04 +00:00
2022-05-31 16:22:31 +00:00
startTimeTravelDetector ( ( ) = > {
window . Whisper . events . trigger ( 'timetravel' ) ;
} ) ;
2022-12-21 18:41:48 +00:00
void expiringMessagesDeletionService . update ( ) ;
void tapToViewMessagesDeletionService . update ( ) ;
2022-05-31 23:53:14 +00:00
window . Whisper . events . on ( 'timetravel' , ( ) = > {
2022-12-21 18:41:48 +00:00
void expiringMessagesDeletionService . update ( ) ;
void tapToViewMessagesDeletionService . update ( ) ;
2022-05-31 23:53:14 +00:00
} ) ;
2018-04-27 21:25:04 +00:00
2021-12-07 19:20:40 +00:00
const isCoreDataValid = Boolean (
window . textsecure . storage . user . getUuid ( ) &&
window . ConversationController . getOurConversation ( )
) ;
2023-04-11 03:54:43 +00:00
if ( isCoreDataValid && Registration . everDone ( ) ) {
2022-12-21 18:41:48 +00:00
void connect ( ) ;
2021-06-14 19:01:00 +00:00
window . reduxActions . app . openInbox ( ) ;
2018-04-27 21:25:04 +00:00
} else {
2023-03-20 20:42:00 +00:00
window . IPC . readyForUpdates ( ) ;
2021-06-14 19:01:00 +00:00
window . reduxActions . app . openInstaller ( ) ;
2017-08-08 00:24:59 +00:00
}
2015-08-31 17:40:25 +00:00
2022-07-05 16:44:53 +00:00
const { activeWindowService } = window . SignalContext ;
activeWindowService . registerForActive ( ( ) = > notificationService . clear ( ) ) ;
2021-09-23 18:16:09 +00:00
window . addEventListener ( 'unload' , ( ) = > notificationService . fastClear ( ) ) ;
2018-05-09 22:12:31 +00:00
2022-10-11 17:59:02 +00:00
notificationService . on ( 'click' , ( id , messageId , storyId ) = > {
2023-01-13 00:24:59 +00:00
window . IPC . showWindow ( ) ;
2022-10-11 17:59:02 +00:00
2019-01-14 21:49:58 +00:00
if ( id ) {
2022-10-11 17:59:02 +00:00
if ( storyId ) {
window . reduxActions . stories . viewStory ( {
storyId ,
storyViewMode : StoryViewModeType.Single ,
viewTarget : StoryViewTargetType.Replies ,
} ) ;
} else {
2022-12-14 19:05:32 +00:00
window . reduxActions . conversations . showConversation ( {
conversationId : id ,
messageId ,
} ) ;
2022-10-11 17:59:02 +00:00
}
Full export, migration banner, and full migration workflow - behind flag (#1342)
* Add support for backup and restore
This first pass works for all stores except messages, pending some scaling
improvements.
// FREEBIE
* Import of messages and attachments
Properly sanitize filenames. Logging information that will help with
debugging but won't threaten privacy (no contact or group names),
where the on-disk directories have this information to make things
human-readable
FREEBIE
* First fully operational single-action export and import!
FREEBIE
* Add migration export flow
A banner alert leads to a blocking ui for the migration. We close the socket and
wait for incoming messages to drain before starting the export.
FREEBIE
* A number of updates for the export flow
1. We don't immediately pop the directory selection dialog box, instead
showing an explicit 'choose directory' button after explaining what is
about to happen
2. We show a 'submit debug log' button on most steps of the process
3. We handle export errors and encourage the user to double-check their
filesystem then submit their log
4. We are resilient to restarts during the process
5. We handle the user cancelling out of the directory selection dialog
differently from other errors.
6. The export process is now serialized: non-messages, then messages.
7. After successful export, show where the data is on disk
FREEBUE
* Put migration behind a flag
FREEBIE
* Shut down websocket before proceeding with export
FREEBIE
* Add MigrationView to test/index.html to fix test
FREEBIE
* Remove 'Submit Debug Log' button when the export process is complete
FREEBIE
* Create a 'Signal Export' directory below user-chosen dir
This cleans things up a bit so we don't litter the user's target
directory with lots of stuff.
FREEBIE
* Clarify MessageReceiver.drain() method comments
FREEBIE
* A couple updates for clarity - event names, else handling
Also the removal of wait(), which wasn't used anywhere.
FREEBIE
* A number of wording updates for the export flow
FREEBIE
* Export complete: put dir on its own line, make text selectable
FREEBIE
2017-08-28 20:06:10 +00:00
} else {
2021-06-14 19:01:00 +00:00
window . reduxActions . app . openInbox ( ) ;
Full export, migration banner, and full migration workflow - behind flag (#1342)
* Add support for backup and restore
This first pass works for all stores except messages, pending some scaling
improvements.
// FREEBIE
* Import of messages and attachments
Properly sanitize filenames. Logging information that will help with
debugging but won't threaten privacy (no contact or group names),
where the on-disk directories have this information to make things
human-readable
FREEBIE
* First fully operational single-action export and import!
FREEBIE
* Add migration export flow
A banner alert leads to a blocking ui for the migration. We close the socket and
wait for incoming messages to drain before starting the export.
FREEBIE
* A number of updates for the export flow
1. We don't immediately pop the directory selection dialog box, instead
showing an explicit 'choose directory' button after explaining what is
about to happen
2. We show a 'submit debug log' button on most steps of the process
3. We handle export errors and encourage the user to double-check their
filesystem then submit their log
4. We are resilient to restarts during the process
5. We handle the user cancelling out of the directory selection dialog
differently from other errors.
6. The export process is now serialized: non-messages, then messages.
7. After successful export, show where the data is on disk
FREEBUE
* Put migration behind a flag
FREEBIE
* Shut down websocket before proceeding with export
FREEBIE
* Add MigrationView to test/index.html to fix test
FREEBIE
* Remove 'Submit Debug Log' button when the export process is complete
FREEBIE
* Create a 'Signal Export' directory below user-chosen dir
This cleans things up a bit so we don't litter the user's target
directory with lots of stuff.
FREEBIE
* Clarify MessageReceiver.drain() method comments
FREEBIE
* A couple updates for clarity - event names, else handling
Also the removal of wait(), which wasn't used anywhere.
FREEBIE
* A number of wording updates for the export flow
FREEBIE
* Export complete: put dir on its own line, make text selectable
FREEBIE
2017-08-28 20:06:10 +00:00
}
} ) ;
2020-05-27 21:37:06 +00:00
// Maybe refresh remote configuration when we become active
2022-07-05 16:44:53 +00:00
activeWindowService . registerForActive ( async ( ) = > {
2021-07-23 17:23:50 +00:00
strictAssert ( server !== undefined , 'WebAPI not ready' ) ;
2021-01-13 00:42:15 +00:00
try {
2021-07-23 17:23:50 +00:00
await window . Signal . RemoteConfig . maybeRefreshRemoteConfig ( server ) ;
2021-01-13 00:42:15 +00:00
} catch ( error ) {
2021-09-22 00:58:03 +00:00
if ( error instanceof HTTPError ) {
2021-09-17 18:27:53 +00:00
log . warn (
2021-01-13 00:42:15 +00:00
` registerForActive: Failed to to refresh remote config. Code: ${ error . code } `
) ;
return ;
}
throw error ;
}
2020-05-27 21:37:06 +00:00
} ) ;
2020-09-09 22:50:44 +00:00
// Listen for changes to the `desktop.clientExpiration` remote flag
window . Signal . RemoteConfig . onChange (
'desktop.clientExpiration' ,
( { value } ) = > {
2023-04-11 03:54:43 +00:00
const remoteBuildExpirationTimestamp = parseRemoteClientExpiration (
value as string
) ;
2020-09-09 22:50:44 +00:00
if ( remoteBuildExpirationTimestamp ) {
2022-12-21 18:41:48 +00:00
drop (
window . storage . put (
'remoteBuildExpiration' ,
remoteBuildExpirationTimestamp
)
2020-09-09 22:50:44 +00:00
) ;
}
}
) ;
2020-05-27 21:37:06 +00:00
// Listen for changes to the `desktop.messageRequests` remote configuration flag
const removeMessageRequestListener = window . Signal . RemoteConfig . onChange (
'desktop.messageRequests' ,
( { enabled } ) = > {
if ( ! enabled ) {
return ;
}
const conversations = window . getConversations ( ) ;
conversations . forEach ( conversation = > {
conversation . set ( {
messageCountBeforeMessageRequests :
conversation . get ( 'messageCount' ) || 0 ,
} ) ;
window . Signal . Data . updateConversation ( conversation . attributes ) ;
} ) ;
removeMessageRequestListener ( ) ;
}
) ;
2020-09-09 02:25:05 +00:00
2021-04-15 18:17:28 +00:00
if ( resolveOnAppView ) {
resolveOnAppView ( ) ;
resolveOnAppView = undefined ;
}
2018-04-27 21:25:04 +00:00
}
Full export, migration banner, and full migration workflow - behind flag (#1342)
* Add support for backup and restore
This first pass works for all stores except messages, pending some scaling
improvements.
// FREEBIE
* Import of messages and attachments
Properly sanitize filenames. Logging information that will help with
debugging but won't threaten privacy (no contact or group names),
where the on-disk directories have this information to make things
human-readable
FREEBIE
* First fully operational single-action export and import!
FREEBIE
* Add migration export flow
A banner alert leads to a blocking ui for the migration. We close the socket and
wait for incoming messages to drain before starting the export.
FREEBIE
* A number of updates for the export flow
1. We don't immediately pop the directory selection dialog box, instead
showing an explicit 'choose directory' button after explaining what is
about to happen
2. We show a 'submit debug log' button on most steps of the process
3. We handle export errors and encourage the user to double-check their
filesystem then submit their log
4. We are resilient to restarts during the process
5. We handle the user cancelling out of the directory selection dialog
differently from other errors.
6. The export process is now serialized: non-messages, then messages.
7. After successful export, show where the data is on disk
FREEBUE
* Put migration behind a flag
FREEBIE
* Shut down websocket before proceeding with export
FREEBIE
* Add MigrationView to test/index.html to fix test
FREEBIE
* Remove 'Submit Debug Log' button when the export process is complete
FREEBIE
* Create a 'Signal Export' directory below user-chosen dir
This cleans things up a bit so we don't litter the user's target
directory with lots of stuff.
FREEBIE
* Clarify MessageReceiver.drain() method comments
FREEBIE
* A couple updates for clarity - event names, else handling
Also the removal of wait(), which wasn't used anywhere.
FREEBIE
* A number of wording updates for the export flow
FREEBIE
* Export complete: put dir on its own line, make text selectable
FREEBIE
2017-08-28 20:06:10 +00:00
2021-04-08 17:09:54 +00:00
window . getSyncRequest = ( timeoutMillis? : number ) = > {
2021-07-09 19:36:10 +00:00
strictAssert ( messageReceiver , 'MessageReceiver not initialized' ) ;
2021-04-08 16:24:21 +00:00
const syncRequest = new window . textsecure . SyncRequest (
2021-04-08 17:09:54 +00:00
messageReceiver ,
timeoutMillis
2020-09-24 20:57:54 +00:00
) ;
2021-04-08 16:24:21 +00:00
syncRequest . start ( ) ;
return syncRequest ;
} ;
2017-10-14 00:02:08 +00:00
2021-10-07 18:18:22 +00:00
let disconnectTimer : Timers.Timeout | undefined ;
let reconnectTimer : Timers.Timeout | undefined ;
2018-04-27 21:25:04 +00:00
function onOffline() {
2021-09-17 18:27:53 +00:00
log . info ( 'offline' ) ;
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
window . removeEventListener ( 'offline' , onOffline ) ;
window . addEventListener ( 'online' , onOnline ) ;
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
// We've received logs from Linux where we get an 'offline' event, then 30ms later
// we get an online event. This waits a bit after getting an 'offline' event
// before disconnecting the socket manually.
2021-10-07 18:18:22 +00:00
disconnectTimer = Timers . setTimeout ( disconnect , 1000 ) ;
2021-05-06 00:09:29 +00:00
if ( challengeHandler ) {
2022-12-21 18:41:48 +00:00
void challengeHandler . onOffline ( ) ;
2021-05-06 00:09:29 +00:00
}
2018-04-27 21:25:04 +00:00
}
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
function onOnline() {
2021-09-17 18:27:53 +00:00
log . info ( 'online' ) ;
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
window . removeEventListener ( 'online' , onOnline ) ;
window . addEventListener ( 'offline' , onOffline ) ;
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
if ( disconnectTimer && isSocketOnline ( ) ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Already online. Had a blip in online/offline status.' ) ;
2021-10-07 18:18:22 +00:00
Timers . clearTimeout ( disconnectTimer ) ;
2021-07-09 19:36:10 +00:00
disconnectTimer = undefined ;
2018-04-27 21:25:04 +00:00
return ;
2017-10-14 00:02:08 +00:00
}
2018-04-27 21:25:04 +00:00
if ( disconnectTimer ) {
2021-10-07 18:18:22 +00:00
Timers . clearTimeout ( disconnectTimer ) ;
2021-07-09 19:36:10 +00:00
disconnectTimer = undefined ;
2017-10-14 00:02:08 +00:00
}
2022-12-21 18:41:48 +00:00
void connect ( ) ;
2018-04-27 21:25:04 +00:00
}
function isSocketOnline() {
2018-05-25 01:50:49 +00:00
const socketStatus = window . getSocketStatus ( ) ;
2018-04-27 21:25:04 +00:00
return (
2021-06-09 22:28:54 +00:00
socketStatus === SocketStatus . CONNECTING ||
socketStatus === SocketStatus . OPEN
2018-04-27 21:25:04 +00:00
) ;
}
2017-10-14 00:02:08 +00:00
2021-05-17 18:29:37 +00:00
async function disconnect() {
2021-09-17 18:27:53 +00:00
log . info ( 'disconnect' ) ;
2017-10-14 00:02:08 +00:00
2018-04-27 21:25:04 +00:00
// Clear timer, since we're only called when the timer is expired
2021-07-09 19:36:10 +00:00
disconnectTimer = undefined ;
2018-04-27 21:25:04 +00:00
2022-12-21 18:41:48 +00:00
void AttachmentDownloads . stop ( ) ;
2021-07-28 21:37:09 +00:00
if ( server !== undefined ) {
strictAssert (
messageReceiver !== undefined ,
'WebAPI should be initialized together with MessageReceiver'
) ;
await server . onOffline ( ) ;
await messageReceiver . drain ( ) ;
2017-10-14 00:02:08 +00:00
}
2018-04-27 21:25:04 +00:00
}
2017-10-14 00:02:08 +00:00
2018-05-25 01:50:49 +00:00
let connectCount = 0 ;
2020-11-11 16:24:29 +00:00
let connecting = false ;
2020-09-24 20:57:54 +00:00
async function connect ( firstRun? : boolean ) {
2020-11-11 16:24:29 +00:00
if ( connecting ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'connect already running' , { connectCount } ) ;
2018-04-27 21:25:04 +00:00
return ;
}
2021-07-23 17:23:50 +00:00
strictAssert ( server !== undefined , 'WebAPI not connected' ) ;
2020-11-11 16:24:29 +00:00
try {
connecting = true ;
2017-04-12 21:20:56 +00:00
2022-05-25 20:48:23 +00:00
// Reset the flag and update it below if needed
2022-08-25 05:04:42 +00:00
setIsInitialSync ( false ) ;
2022-05-25 20:48:23 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'connect' , { firstRun , connectCount } ) ;
2014-12-20 00:49:18 +00:00
2020-11-11 16:24:29 +00:00
if ( reconnectTimer ) {
2021-10-07 18:18:22 +00:00
Timers . clearTimeout ( reconnectTimer ) ;
2021-07-09 19:36:10 +00:00
reconnectTimer = undefined ;
2020-11-11 16:24:29 +00:00
}
2020-09-04 01:25:19 +00:00
2020-11-11 16:24:29 +00:00
// Bootstrap our online/offline detection, only the first time we connect
if ( connectCount === 0 && navigator . onLine ) {
window . addEventListener ( 'offline' , onOffline ) ;
}
if ( connectCount === 0 && ! navigator . onLine ) {
2021-09-17 18:27:53 +00:00
log . warn (
2020-11-11 16:24:29 +00:00
'Starting up offline; will connect when we have network access'
) ;
window . addEventListener ( 'online' , onOnline ) ;
2022-12-21 18:41:48 +00:00
void onEmpty ( ) ; // this ensures that the loading screen is dismissed
2022-08-11 20:28:31 +00:00
// Switch to inbox view even if contact sync is still running
if (
window . reduxStore . getState ( ) . app . appView === AppViewType . Installer
) {
log . info ( 'firstRun: offline, opening inbox' ) ;
window . reduxActions . app . openInbox ( ) ;
} else {
log . info ( 'firstRun: offline, not opening inbox' ) ;
}
2020-11-11 16:24:29 +00:00
return ;
}
2019-09-26 19:56:31 +00:00
2023-04-11 03:54:43 +00:00
if ( ! Registration . everDone ( ) ) {
2020-11-11 16:24:29 +00:00
return ;
}
2019-09-26 19:56:31 +00:00
2021-11-30 17:51:53 +00:00
// Update our profile key in the conversation if we just got linked.
const profileKey = await ourProfileKeyService . get ( ) ;
if ( firstRun && profileKey ) {
const me = window . ConversationController . getOurConversation ( ) ;
strictAssert ( me !== undefined , "Didn't find newly created ourselves" ) ;
await me . setProfileKey ( Bytes . toBase64 ( profileKey ) ) ;
}
2020-11-11 16:24:29 +00:00
if ( connectCount === 0 ) {
try {
// Force a re-fetch before we process our queue. We may want to turn on
// something which changes how we process incoming messages!
2021-07-23 17:23:50 +00:00
await window . Signal . RemoteConfig . refreshRemoteConfig ( server ) ;
2021-08-24 23:36:43 +00:00
const expiration = window . Signal . RemoteConfig . getValue (
'desktop.clientExpiration'
) ;
if ( expiration ) {
2023-04-11 03:54:43 +00:00
const remoteBuildExpirationTimestamp = parseRemoteClientExpiration (
expiration as string
) ;
2021-08-24 23:36:43 +00:00
if ( remoteBuildExpirationTimestamp ) {
2022-12-21 18:41:48 +00:00
await window . storage . put (
2021-08-24 23:36:43 +00:00
'remoteBuildExpiration' ,
remoteBuildExpirationTimestamp
) ;
}
}
2020-11-11 16:24:29 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-11-11 16:24:29 +00:00
'connect: Error refreshing remote config:' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2020-11-11 16:24:29 +00:00
) ;
}
try {
2021-04-28 18:36:10 +00:00
const lonelyE164Conversations = window
2021-04-26 18:15:00 +00:00
. getConversations ( )
. filter ( c = >
Boolean (
2021-06-07 16:39:13 +00:00
isDirectConversation ( c . attributes ) &&
2021-04-26 18:15:00 +00:00
c . get ( 'e164' ) &&
! c . get ( 'uuid' ) &&
! c . isEverUnregistered ( )
2020-11-11 16:24:29 +00:00
)
2021-04-26 18:15:00 +00:00
) ;
2022-08-18 20:44:53 +00:00
strictAssert ( window . textsecure . server , 'server must be initialized' ) ;
2021-04-28 18:36:10 +00:00
await updateConversationsWithUuidLookup ( {
conversationController : window.ConversationController ,
conversations : lonelyE164Conversations ,
2022-08-18 20:44:53 +00:00
server : window.textsecure.server ,
2021-04-28 18:36:10 +00:00
} ) ;
2020-11-11 16:24:29 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-11-11 16:24:29 +00:00
'connect: Error fetching UUIDs for lonely e164s:' ,
2022-08-18 20:44:53 +00:00
Errors . toLogFormat ( error )
2020-11-11 16:24:29 +00:00
) ;
2020-09-04 01:25:19 +00:00
}
}
2017-09-28 21:58:45 +00:00
2020-11-11 16:24:29 +00:00
connectCount += 1 ;
2021-05-05 16:39:16 +00:00
// To avoid a flood of operations before we catch up, we pause some queues.
profileKeyResponseQueue . pause ( ) ;
2021-05-18 00:41:28 +00:00
lightSessionResetQueue . pause ( ) ;
2021-10-20 21:50:00 +00:00
onDecryptionErrorQueue . pause ( ) ;
onRetryRequestQueue . pause ( ) ;
2021-05-05 16:39:16 +00:00
window . Whisper . deliveryReceiptQueue . pause ( ) ;
2021-09-23 18:16:09 +00:00
notificationService . disable ( ) ;
2020-11-11 16:24:29 +00:00
2022-12-21 18:41:48 +00:00
void window . Signal . Services . initializeGroupCredentialFetcher ( ) ;
2020-11-11 16:24:29 +00:00
2021-07-28 21:37:09 +00:00
strictAssert ( server !== undefined , 'WebAPI not initialized' ) ;
strictAssert (
messageReceiver !== undefined ,
'MessageReceiver not initialized'
2021-07-09 19:36:10 +00:00
) ;
2021-07-28 21:37:09 +00:00
messageReceiver . reset ( ) ;
server . registerRequestHandler ( messageReceiver ) ;
// If coming here after `offline` event - connect again.
await server . onOnline ( ) ;
2019-06-14 22:17:37 +00:00
2022-12-21 18:41:48 +00:00
void AttachmentDownloads . start ( {
2021-09-17 18:27:53 +00:00
logger : log ,
2020-11-11 16:24:29 +00:00
} ) ;
2019-01-30 20:15:07 +00:00
2020-11-11 16:24:29 +00:00
if ( connectCount === 1 ) {
2021-07-09 19:36:10 +00:00
Stickers . downloadQueuedPacks ( ) ;
2020-11-11 16:24:29 +00:00
if ( ! newVersion ) {
2022-12-21 18:41:48 +00:00
void runStorageService ( ) ;
2020-11-11 16:24:29 +00:00
}
2020-09-29 23:29:11 +00:00
}
2019-05-16 22:32:11 +00:00
2020-11-11 16:24:29 +00:00
// On startup after upgrading to a new version, request a contact sync
// (but only if we're not the primary device)
if (
! firstRun &&
connectCount === 1 &&
newVersion &&
2021-06-15 00:09:37 +00:00
window . textsecure . storage . user . getDeviceId ( ) !== 1
2020-11-11 16:24:29 +00:00
) {
2021-09-17 18:27:53 +00:00
log . info ( 'Boot after upgrading. Requesting contact sync' ) ;
2020-11-11 16:24:29 +00:00
window . getSyncRequest ( ) ;
2019-01-11 16:53:35 +00:00
2022-12-21 18:41:48 +00:00
void StorageService . reprocessUnknownFields ( ) ;
void runStorageService ( ) ;
2020-09-29 23:29:11 +00:00
2020-11-11 16:24:29 +00:00
try {
2021-07-23 17:23:50 +00:00
const manager = window . getAccountManager ( ) ;
2020-11-11 16:24:29 +00:00
await Promise . all ( [
manager . maybeUpdateDeviceName ( ) ,
2021-07-20 01:11:07 +00:00
window . textsecure . storage . user . removeSignalingKey ( ) ,
2020-11-11 16:24:29 +00:00
] ) ;
} catch ( e ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-11-11 16:24:29 +00:00
'Problem with account manager updates after starting new version: ' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( e )
2020-11-11 16:24:29 +00:00
) ;
}
2019-01-11 16:53:35 +00:00
}
2017-09-14 19:08:10 +00:00
2020-11-11 16:24:29 +00:00
const udSupportKey = 'hasRegisterSupportForUnauthenticatedDelivery' ;
if ( ! window . storage . get ( udSupportKey ) ) {
try {
await server . registerSupportForUnauthenticatedDelivery ( ) ;
2022-12-21 18:41:48 +00:00
await window . storage . put ( udSupportKey , true ) ;
2020-11-11 16:24:29 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-11-11 16:24:29 +00:00
'Error: Unable to register for unauthenticated delivery support.' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2020-11-11 16:24:29 +00:00
) ;
}
2018-10-18 01:01:21 +00:00
}
2020-03-05 21:14:58 +00:00
2020-11-11 16:24:29 +00:00
const deviceId = window . textsecure . storage . user . getDeviceId ( ) ;
2020-03-05 21:14:58 +00:00
2020-11-11 16:24:29 +00:00
if ( ! window . textsecure . storage . user . getUuid ( ) ) {
2021-09-17 18:27:53 +00:00
log . error ( 'UUID not captured during registration, unlinking' ) ;
2021-09-10 02:38:11 +00:00
return unlinkAndDisconnect ( RemoveAllConfiguration . Full ) ;
2020-10-30 17:56:03 +00:00
}
2020-11-20 17:30:45 +00:00
if ( connectCount === 1 ) {
2020-11-11 16:24:29 +00:00
try {
2020-11-20 17:30:45 +00:00
// Note: we always have to register our capabilities all at once, so we do this
// after connect on every startup
2023-02-02 18:03:51 +00:00
await server . registerCapabilities ( {
announcementGroup : true ,
giftBadges : true ,
'gv2-3' : true ,
senderKey : true ,
changeNumber : true ,
stories : true ,
pni : isPnpEnabled ( ) ,
} ) ;
2020-11-11 16:24:29 +00:00
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2020-11-20 17:30:45 +00:00
'Error: Unable to register our capabilities.' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( error )
2019-05-16 22:32:11 +00:00
) ;
2020-11-11 16:24:29 +00:00
}
}
2022-07-18 22:32:00 +00:00
if ( ! window . textsecure . storage . user . getUuid ( UUIDKind . PNI ) ) {
log . error ( 'PNI not captured during registration, unlinking softly' ) ;
return unlinkAndDisconnect ( RemoveAllConfiguration . Soft ) ;
}
2021-06-15 00:09:37 +00:00
if ( firstRun === true && deviceId !== 1 ) {
2020-11-11 16:24:29 +00:00
const hasThemeSetting = Boolean ( window . storage . get ( 'theme-setting' ) ) ;
if (
! hasThemeSetting &&
window . textsecure . storage . get ( 'userAgent' ) === 'OWI'
) {
2022-12-21 18:41:48 +00:00
await window . storage . put (
2021-03-03 01:14:00 +00:00
'theme-setting' ,
await window . Events . getThemeSetting ( )
) ;
2021-08-18 20:08:14 +00:00
themeChanged ( ) ;
2020-11-11 16:24:29 +00:00
}
2022-03-02 22:53:47 +00:00
const waitForEvent = createTaskWithTimeout (
( event : string ) : Promise < void > = > {
const { promise , resolve } = explodePromise < void > ( ) ;
window . Whisper . events . once ( event , ( ) = > resolve ( ) ) ;
return promise ;
} ,
2023-02-06 22:03:38 +00:00
'firstRun:waitForEvent' ,
{ timeout : 2 * durations . MINUTE }
2022-03-02 22:53:47 +00:00
) ;
let storageServiceSyncComplete : Promise < void > ;
if ( window . ConversationController . areWePrimaryDevice ( ) ) {
storageServiceSyncComplete = Promise . resolve ( ) ;
} else {
storageServiceSyncComplete = waitForEvent (
'storageService:syncComplete'
) ;
}
const contactSyncComplete = waitForEvent ( 'contactSync:complete' ) ;
log . info ( 'firstRun: requesting initial sync' ) ;
2022-08-25 05:04:42 +00:00
setIsInitialSync ( true ) ;
2022-03-02 22:53:47 +00:00
// Request configuration, block, GV1 sync messages, contacts
// (only avatars and inboxPosition),and Storage Service sync.
try {
await Promise . all ( [
singleProtoJobQueue . add (
2022-06-13 21:39:35 +00:00
MessageSender . getRequestConfigurationSyncMessage ( )
) ,
singleProtoJobQueue . add ( MessageSender . getRequestBlockSyncMessage ( ) ) ,
singleProtoJobQueue . add ( MessageSender . getRequestGroupSyncMessage ( ) ) ,
singleProtoJobQueue . add (
MessageSender . getRequestContactSyncMessage ( )
2022-03-02 22:53:47 +00:00
) ,
runStorageService ( ) ,
] ) ;
} catch ( error ) {
log . error (
'connect: Failed to request initial syncs' ,
Errors . toLogFormat ( error )
) ;
}
log . info ( 'firstRun: waiting for storage service and contact sync' ) ;
try {
await Promise . all ( [ storageServiceSyncComplete , contactSyncComplete ] ) ;
} catch ( error ) {
log . error (
'connect: Failed to run storage service and contact syncs' ,
Errors . toLogFormat ( error )
) ;
}
2022-05-25 20:48:23 +00:00
log . info ( 'firstRun: initial sync complete' ) ;
2022-08-25 05:04:42 +00:00
setIsInitialSync ( false ) ;
2022-05-25 20:48:23 +00:00
2022-03-02 22:53:47 +00:00
// Switch to inbox view even if contact sync is still running
if (
window . reduxStore . getState ( ) . app . appView === AppViewType . Installer
) {
log . info ( 'firstRun: opening inbox' ) ;
window . reduxActions . app . openInbox ( ) ;
} else {
log . info ( 'firstRun: not opening inbox' ) ;
}
2020-11-11 16:24:29 +00:00
2021-07-09 19:36:10 +00:00
const installedStickerPacks = Stickers . getInstalledStickerPacks ( ) ;
2020-11-11 16:24:29 +00:00
if ( installedStickerPacks . length ) {
2021-07-09 19:36:10 +00:00
const operations = installedStickerPacks . map ( pack = > ( {
2020-11-11 16:24:29 +00:00
packId : pack.id ,
packKey : pack.key ,
installed : true ,
} ) ) ;
2021-07-15 23:48:09 +00:00
if ( window . ConversationController . areWePrimaryDevice ( ) ) {
2021-09-17 18:27:53 +00:00
log . warn (
2021-07-15 23:48:09 +00:00
'background/connect: We are primary device; not sending sticker pack sync'
) ;
return ;
}
2022-03-02 22:53:47 +00:00
log . info ( 'firstRun: requesting stickers' , operations . length ) ;
2022-01-14 21:34:52 +00:00
try {
await singleProtoJobQueue . add (
2022-06-13 21:39:35 +00:00
MessageSender . getStickerPackSync ( operations )
2022-01-14 21:34:52 +00:00
) ;
} catch ( error ) {
2021-09-17 18:27:53 +00:00
log . error (
2022-01-14 21:34:52 +00:00
'connect: Failed to queue sticker sync message' ,
Errors . toLogFormat ( error )
2020-11-11 16:24:29 +00:00
) ;
2022-01-14 21:34:52 +00:00
}
2020-11-11 16:24:29 +00:00
}
2022-02-04 21:33:09 +00:00
2022-03-02 22:53:47 +00:00
log . info ( 'firstRun: done' ) ;
2019-05-16 22:32:11 +00:00
}
2015-09-01 19:13:38 +00:00
2020-11-11 16:24:29 +00:00
window . storage . onready ( async ( ) = > {
idleDetector . start ( ) ;
} ) ;
2021-05-06 00:09:29 +00:00
if ( ! challengeHandler ) {
throw new Error ( 'Expected challenge handler to be initialized' ) ;
}
// Intentionally not awaiting
2022-12-21 18:41:48 +00:00
void challengeHandler . onOnline ( ) ;
2021-06-09 22:28:54 +00:00
reconnectBackOff . reset ( ) ;
2020-11-11 16:24:29 +00:00
} finally {
connecting = false ;
}
2018-04-30 17:53:07 +00:00
}
2021-08-18 20:08:14 +00:00
window . SignalContext . nativeThemeListener . subscribe ( themeChanged ) ;
2021-06-30 18:57:43 +00:00
2021-08-26 14:10:58 +00:00
const FIVE_MINUTES = 5 * durations . MINUTE ;
2020-09-09 02:25:05 +00:00
// Note: once this function returns, there still might be messages being processed on
// a given conversation's queue. But we have processed all events from the websocket.
async function waitForEmptyEventQueue() {
if ( ! messageReceiver ) {
2021-09-17 18:27:53 +00:00
log . info (
2020-09-09 02:25:05 +00:00
'waitForEmptyEventQueue: No messageReceiver available, returning early'
) ;
return ;
}
if ( ! messageReceiver . hasEmptied ( ) ) {
2021-09-17 18:27:53 +00:00
log . info (
2020-09-09 02:25:05 +00:00
'waitForEmptyEventQueue: Waiting for MessageReceiver empty event...'
) ;
2021-10-07 18:18:22 +00:00
const { resolve , reject , promise } = explodePromise < void > ( ) ;
const timeout = Timers . setTimeout ( ( ) = > {
reject ( new Error ( 'Empty queue never fired' ) ) ;
} , FIVE_MINUTES ) ;
2020-09-09 02:25:05 +00:00
const onEmptyOnce = ( ) = > {
2021-07-09 19:36:10 +00:00
if ( messageReceiver ) {
messageReceiver . removeEventListener ( 'empty' , onEmptyOnce ) ;
}
2021-10-07 18:18:22 +00:00
Timers . clearTimeout ( timeout ) ;
2021-07-09 19:36:10 +00:00
if ( resolve ) {
resolve ( ) ;
}
2020-09-09 02:25:05 +00:00
} ;
messageReceiver . addEventListener ( 'empty' , onEmptyOnce ) ;
await promise ;
}
2021-09-17 18:27:53 +00:00
log . info ( 'waitForEmptyEventQueue: Waiting for event handler queue idle...' ) ;
2020-09-09 02:25:05 +00:00
await eventHandlerQueue . onIdle ( ) ;
}
window . waitForEmptyEventQueue = waitForEmptyEventQueue ;
2022-11-09 18:59:32 +00:00
async function onEmpty ( ) : Promise < void > {
2022-06-13 21:39:35 +00:00
const { storage } = window . textsecure ;
2022-03-25 17:36:08 +00:00
2019-09-26 19:56:31 +00:00
await Promise . all ( [
window . waitForAllBatchers ( ) ,
2021-03-26 00:00:03 +00:00
window . flushAllWaitBatchers ( ) ,
2019-09-26 19:56:31 +00:00
] ) ;
2021-09-17 18:27:53 +00:00
log . info ( 'onEmpty: All outstanding database requests complete' ) ;
2023-01-13 00:24:59 +00:00
window . IPC . readyForUpdates ( ) ;
2022-06-01 01:26:57 +00:00
window . ConversationController . onEmpty ( ) ;
2019-03-28 17:09:26 +00:00
2020-07-22 21:05:15 +00:00
// Start listeners here, after we get through our queue.
2021-11-30 19:33:51 +00:00
RotateSignedPreKeyListener . init ( window . Whisper . events , newVersion ) ;
2021-04-02 16:23:47 +00:00
2021-05-05 16:39:16 +00:00
profileKeyResponseQueue . start ( ) ;
2021-05-18 00:41:28 +00:00
lightSessionResetQueue . start ( ) ;
2021-10-20 21:50:00 +00:00
onDecryptionErrorQueue . start ( ) ;
onRetryRequestQueue . start ( ) ;
2021-03-26 00:00:03 +00:00
window . Whisper . deliveryReceiptQueue . start ( ) ;
2021-09-23 18:16:09 +00:00
notificationService . enable ( ) ;
2021-03-13 01:22:36 +00:00
2021-04-15 18:17:28 +00:00
await onAppView ;
2021-03-13 01:22:36 +00:00
2021-06-14 19:01:00 +00:00
window . reduxActions . app . initialLoadComplete ( ) ;
2021-03-13 01:22:36 +00:00
2022-05-25 18:15:09 +00:00
const processedCount = messageReceiver ? . getAndResetProcessedCount ( ) || 0 ;
2023-01-13 00:24:59 +00:00
window . IPC . logAppLoadedEvent ? . ( {
2022-05-25 18:15:09 +00:00
processedCount ,
2021-04-13 23:43:56 +00:00
} ) ;
2021-03-26 00:00:03 +00:00
if ( messageReceiver ) {
2022-05-25 18:15:09 +00:00
log . info ( 'App loaded - messages:' , processedCount ) ;
2021-03-26 00:00:03 +00:00
}
2021-03-13 01:22:36 +00:00
2023-04-11 03:54:43 +00:00
setBatchingStrategy ( false ) ;
2023-01-13 00:24:59 +00:00
StartupQueue . flush ( ) ;
await flushAttachmentDownloadQueue ( ) ;
2022-01-11 20:02:46 +00:00
// Process crash reports if any
window . reduxActions . crashReports . setCrashReportCount (
2023-01-13 00:24:59 +00:00
await window . IPC . crashReports . getCount ( )
2022-01-11 20:02:46 +00:00
) ;
2022-03-17 00:52:05 +00:00
// Kick off a profile refresh if necessary, but don't wait for it, as failure is
// tolerable.
2022-07-08 20:46:25 +00:00
if ( ! routineProfileRefresher ) {
routineProfileRefresher = new RoutineProfileRefresher ( {
getAllConversations : ( ) = > window . ConversationController . getAll ( ) ,
getOurConversationId : ( ) = >
window . ConversationController . getOurConversationId ( ) ,
2022-03-25 17:36:08 +00:00
storage ,
2022-03-17 00:52:05 +00:00
} ) ;
2022-07-08 20:46:25 +00:00
2022-12-21 18:41:48 +00:00
void routineProfileRefresher . start ( ) ;
2022-03-17 00:52:05 +00:00
}
2022-03-25 17:36:08 +00:00
// Make sure we have the PNI identity
const pni = storage . user . getCheckedUuid ( UUIDKind . PNI ) ;
const pniIdentity = await storage . protocol . getIdentityKeyPair ( pni ) ;
if ( ! pniIdentity ) {
log . info ( 'Requesting PNI identity sync' ) ;
await singleProtoJobQueue . add (
2022-06-13 21:39:35 +00:00
MessageSender . getRequestPniIdentitySyncMessage ( )
2022-03-25 17:36:08 +00:00
) ;
}
2018-04-27 21:25:04 +00:00
}
2019-10-17 17:18:10 +00:00
let initialStartupCount = 0 ;
2020-09-24 20:57:54 +00:00
window . Whisper . events . on ( 'incrementProgress' , incrementProgress ) ;
2019-10-17 17:18:10 +00:00
function incrementProgress() {
initialStartupCount += 1 ;
// Only update progress every 10 items
if ( initialStartupCount % 10 !== 0 ) {
return ;
}
2021-09-17 18:27:53 +00:00
log . info ( ` incrementProgress: Message count is ${ initialStartupCount } ` ) ;
2017-09-29 16:15:28 +00:00
2021-06-14 19:01:00 +00:00
window . Whisper . events . trigger ( 'loadingProgress' , initialStartupCount ) ;
2018-04-27 21:25:04 +00:00
}
2019-10-17 17:18:10 +00:00
2020-09-24 20:57:54 +00:00
window . Whisper . events . on ( 'manualConnect' , manualConnect ) ;
2020-03-20 18:01:55 +00:00
function manualConnect() {
2020-10-08 21:57:17 +00:00
if ( isSocketOnline ( ) ) {
2021-09-17 18:27:53 +00:00
log . info ( 'manualConnect: already online; not connecting again' ) ;
2020-10-08 21:57:17 +00:00
return ;
}
2021-09-17 18:27:53 +00:00
log . info ( 'manualConnect: calling connect()' ) ;
2022-12-21 18:41:48 +00:00
void connect ( ) ;
2020-03-20 18:01:55 +00:00
}
2022-12-21 18:41:48 +00:00
async function onConfiguration ( ev : ConfigurationEvent ) : Promise < void > {
2019-09-26 19:56:31 +00:00
ev . confirm ( ) ;
2018-10-18 01:01:21 +00:00
const { configuration } = ev ;
2018-11-14 19:10:32 +00:00
const {
readReceipts ,
typingIndicators ,
unidentifiedDeliveryIndicators ,
2019-01-16 03:03:56 +00:00
linkPreviews ,
2018-11-14 19:10:32 +00:00
} = configuration ;
2018-10-18 01:01:21 +00:00
2022-12-21 18:41:48 +00:00
await window . storage . put ( 'read-receipt-setting' , Boolean ( readReceipts ) ) ;
2018-10-18 01:01:21 +00:00
if (
unidentifiedDeliveryIndicators === true ||
unidentifiedDeliveryIndicators === false
) {
2022-12-21 18:41:48 +00:00
await window . storage . put (
2018-10-18 01:01:21 +00:00
'unidentifiedDeliveryIndicators' ,
unidentifiedDeliveryIndicators
) ;
}
2018-11-14 19:10:32 +00:00
if ( typingIndicators === true || typingIndicators === false ) {
2022-12-21 18:41:48 +00:00
await window . storage . put ( 'typingIndicators' , typingIndicators ) ;
2018-11-14 19:10:32 +00:00
}
2019-01-16 03:03:56 +00:00
if ( linkPreviews === true || linkPreviews === false ) {
2022-12-21 18:41:48 +00:00
await window . storage . put ( 'linkPreviews' , linkPreviews ) ;
2019-01-16 03:03:56 +00:00
}
2018-04-27 21:25:04 +00:00
}
2017-07-25 23:00:06 +00:00
2022-11-09 18:59:32 +00:00
function onTyping ( ev : TypingEvent ) : void {
2019-09-26 19:56:31 +00:00
// Note: this type of message is automatically removed from cache in MessageReceiver
2020-03-05 21:14:58 +00:00
const { typing , sender , senderUuid , senderDevice } = ev ;
2023-04-15 00:52:50 +00:00
const { groupV2Id , started } = typing || { } ;
2018-11-14 19:10:32 +00:00
// We don't do anything with incoming typing messages if the setting is disabled
2020-09-24 20:57:54 +00:00
if ( ! window . storage . get ( 'typingIndicators' ) ) {
2018-11-14 19:10:32 +00:00
return ;
}
2020-11-20 17:30:45 +00:00
let conversation ;
2022-12-05 22:46:54 +00:00
const { conversation : senderConversation } =
window . ConversationController . maybeMergeContacts ( {
2022-08-09 21:39:00 +00:00
e164 : sender ,
aci : senderUuid ,
reason : ` onTyping( ${ typing . timestamp } ) ` ,
2022-12-05 22:46:54 +00:00
} ) ;
2020-11-20 17:30:45 +00:00
// We multiplex between GV1/GV2 groups here, but we don't kick off migrations
if ( groupV2Id ) {
conversation = window . ConversationController . get ( groupV2Id ) ;
2023-04-15 00:52:50 +00:00
} else {
2022-08-09 21:39:00 +00:00
conversation = senderConversation ;
2020-11-20 17:30:45 +00:00
}
2020-09-24 20:57:54 +00:00
const ourId = window . ConversationController . getOurConversationId ( ) ;
2018-11-14 19:10:32 +00:00
2020-11-20 17:30:45 +00:00
if ( ! ourId ) {
2021-09-17 18:27:53 +00:00
log . warn ( "onTyping: Couldn't get our own id!" ) ;
2020-11-20 17:30:45 +00:00
return ;
}
2020-09-09 02:25:05 +00:00
if ( ! conversation ) {
2021-09-17 18:27:53 +00:00
log . warn (
2023-04-15 00:52:50 +00:00
` onTyping: Did not find conversation for typing indicator (groupv2( ${ groupV2Id } ), ${ sender } , ${ senderUuid } ) `
2020-09-09 02:25:05 +00:00
) ;
return ;
}
2019-05-13 22:00:41 +00:00
2022-07-08 20:46:25 +00:00
const ourACI = window . textsecure . storage . user . getUuid ( UUIDKind . ACI ) ;
const ourPNI = window . textsecure . storage . user . getUuid ( UUIDKind . PNI ) ;
2020-09-09 02:25:05 +00:00
// We drop typing notifications in groups we're not a part of
2021-06-07 16:39:13 +00:00
if (
! isDirectConversation ( conversation . attributes ) &&
2022-07-08 20:46:25 +00:00
! ( ourACI && conversation . hasMember ( ourACI ) ) &&
! ( ourPNI && conversation . hasMember ( ourPNI ) )
2021-06-07 16:39:13 +00:00
) {
2021-09-17 18:27:53 +00:00
log . warn (
2020-09-09 02:25:05 +00:00
` Received typing indicator for group ${ conversation . idForLogging ( ) } , which we're not a part of. Dropping. `
) ;
return ;
2018-11-14 19:10:32 +00:00
}
2022-01-20 00:39:27 +00:00
if ( conversation ? . isBlocked ( ) ) {
log . info (
` onTyping: conversation ${ conversation . idForLogging ( ) } is blocked, dropping typing message `
) ;
return ;
}
if ( ! senderConversation ) {
log . warn ( 'onTyping: No conversation for sender!' ) ;
return ;
}
if ( senderConversation . isBlocked ( ) ) {
log . info (
` onTyping: sender ${ conversation . idForLogging ( ) } is blocked, dropping typing message `
) ;
return ;
}
2020-09-09 02:25:05 +00:00
2022-08-09 21:39:00 +00:00
const senderId = senderConversation . id ;
2020-09-09 02:25:05 +00:00
conversation . notifyTyping ( {
isTyping : started ,
2020-11-20 17:30:45 +00:00
fromMe : senderId === ourId ,
2020-09-09 02:25:05 +00:00
senderId ,
senderDevice ,
2020-11-20 17:30:45 +00:00
} ) ;
2018-11-14 19:10:32 +00:00
}
2022-11-09 18:59:32 +00:00
function onStickerPack ( ev : StickerPackEvent ) : void {
2019-09-26 19:56:31 +00:00
ev . confirm ( ) ;
2021-07-09 19:36:10 +00:00
const packs = ev . stickerPacks ;
2019-05-16 22:32:11 +00:00
2021-07-09 19:36:10 +00:00
packs . forEach ( pack = > {
2019-05-16 22:32:11 +00:00
const { id , key , isInstall , isRemove } = pack || { } ;
if ( ! id || ! key || ( ! isInstall && ! isRemove ) ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Received malformed sticker pack operation sync message' ) ;
2019-05-16 22:32:11 +00:00
return ;
}
2021-07-09 19:36:10 +00:00
const status = Stickers . getStickerPackStatus ( id ) ;
2019-05-16 22:32:11 +00:00
if ( status === 'installed' && isRemove ) {
window . reduxActions . stickers . uninstallStickerPack ( id , key , {
fromSync : true ,
} ) ;
} else if ( isInstall ) {
2019-05-24 01:27:42 +00:00
if ( status === 'downloaded' ) {
2019-05-16 22:32:11 +00:00
window . reduxActions . stickers . installStickerPack ( id , key , {
fromSync : true ,
} ) ;
} else {
2022-12-21 18:41:48 +00:00
void Stickers . downloadStickerPack ( id , key , {
2019-05-16 22:32:11 +00:00
finalStatus : 'installed' ,
fromSync : true ,
} ) ;
}
}
} ) ;
}
2022-11-09 18:59:32 +00:00
async function onGroupSyncComplete ( ) : Promise < void > {
2021-09-17 18:27:53 +00:00
log . info ( 'onGroupSyncComplete' ) ;
2021-04-08 17:09:54 +00:00
await window . storage . put ( 'synced_at' , Date . now ( ) ) ;
}
2020-09-09 02:25:05 +00:00
// Note: this handler is only for v1 groups received via 'group sync' messages
2022-11-09 18:59:32 +00:00
async function onGroupReceived ( ev : GroupEvent ) : Promise < void > {
2018-05-25 01:50:49 +00:00
const details = ev . groupDetails ;
const { id } = details ;
2018-04-27 21:25:04 +00:00
2020-09-24 20:57:54 +00:00
const conversation = await window . ConversationController . getOrCreateAndWait (
2021-07-23 20:47:03 +00:00
id ,
2018-05-25 01:50:49 +00:00
'group'
) ;
2021-06-07 16:39:13 +00:00
if ( isGroupV2 ( conversation . attributes ) ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Got group sync for v2 group: ' , conversation . idForLogging ( ) ) ;
2020-09-09 02:25:05 +00:00
return ;
}
2018-09-21 01:47:19 +00:00
2021-07-09 19:36:10 +00:00
const memberConversations = details . membersE164 . map ( e164 = >
2020-09-24 20:57:54 +00:00
window . ConversationController . getOrCreate ( e164 , 'private' )
2020-03-05 21:14:58 +00:00
) ;
2021-07-09 19:36:10 +00:00
const members = memberConversations . map ( c = > c . get ( 'id' ) ) ;
2020-03-05 21:14:58 +00:00
2021-07-09 19:36:10 +00:00
const updates : Partial < ConversationAttributesType > = {
2018-05-25 01:50:49 +00:00
name : details.name ,
2020-03-05 21:14:58 +00:00
members ,
2018-05-25 01:50:49 +00:00
type : 'group' ,
2020-03-10 00:43:09 +00:00
inbox_position : details.inboxPosition ,
2021-07-09 19:36:10 +00:00
} ;
2018-09-21 01:47:19 +00:00
2018-05-25 01:50:49 +00:00
if ( details . active ) {
updates . left = false ;
} else {
updates . left = true ;
}
2015-06-01 21:08:21 +00:00
2018-09-17 22:58:27 +00:00
if ( details . blocked ) {
2020-09-01 20:56:37 +00:00
conversation . block ( ) ;
2018-09-17 22:58:27 +00:00
} else {
2020-09-01 20:56:37 +00:00
conversation . unblock ( ) ;
2018-09-13 19:57:07 +00:00
}
2018-09-21 01:47:19 +00:00
conversation . set ( updates ) ;
// Update the conversation avatar only if new avatar exists and hash differs
const { avatar } = details ;
if ( avatar && avatar . data ) {
2021-09-24 00:49:05 +00:00
const newAttributes = await Conversation . maybeUpdateAvatar (
2018-09-21 01:47:19 +00:00
conversation . attributes ,
avatar . data ,
{
writeNewAttachmentData ,
deleteAttachmentData ,
2019-12-03 20:02:50 +00:00
doesAttachmentExist ,
2018-09-21 01:47:19 +00:00
}
) ;
conversation . set ( newAttributes ) ;
}
2020-04-01 18:59:11 +00:00
window . Signal . Data . updateConversation ( conversation . attributes ) ;
2019-10-04 17:30:43 +00:00
2018-05-25 01:50:49 +00:00
const { expireTimer } = details ;
const isValidExpireTimer = typeof expireTimer === 'number' ;
if ( ! isValidExpireTimer ) {
return ;
}
2022-06-20 22:43:16 +00:00
await conversation . updateExpirationTimer ( expireTimer , {
2022-09-06 23:52:07 +00:00
// Note: because it's our conversationId, this notification will be marked read. But
// setting this will make 'isSetByOther' check true.
source : window.ConversationController.getOurConversationId ( ) ,
2022-06-20 22:43:16 +00:00
fromSync : true ,
receivedAt : ev.receivedAtCounter ,
reason : 'group sync' ,
} ) ;
2018-05-25 01:50:49 +00:00
}
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
// Received:
async function handleMessageReceivedProfileUpdate ( {
data ,
confirm ,
messageDescriptor ,
2021-07-09 19:36:10 +00:00
} : {
data : MessageEventData ;
confirm : ( ) = > void ;
messageDescriptor : MessageDescriptor ;
} ) {
const { profileKey } = data . message ;
strictAssert (
profileKey !== undefined ,
'handleMessageReceivedProfileUpdate: missing profileKey'
) ;
2020-09-24 20:57:54 +00:00
const sender = window . ConversationController . get ( messageDescriptor . id ) ;
2018-09-21 01:47:19 +00:00
2020-07-10 18:28:49 +00:00
if ( sender ) {
// Will do the save for us
await sender . setProfileKey ( profileKey ) ;
}
2018-09-21 01:47:19 +00:00
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
return confirm ( ) ;
}
2021-05-11 18:26:44 +00:00
const respondWithProfileKeyBatcher = createBatcher < ConversationModel > ( {
name : 'respondWithProfileKeyBatcher' ,
processBatch ( batch ) {
const deduped = new Set ( batch ) ;
deduped . forEach ( async sender = > {
try {
if ( ! ( await shouldRespondWithProfileKey ( sender ) ) ) {
return ;
}
} catch ( error ) {
2022-11-22 18:43:43 +00:00
log . error (
'respondWithProfileKeyBatcher error' ,
Errors . toLogFormat ( error )
) ;
2021-05-11 18:26:44 +00:00
}
2022-12-21 18:41:48 +00:00
drop (
sender . queueJob ( 'sendProfileKeyUpdate' , ( ) = >
sender . sendProfileKeyUpdate ( )
)
2021-06-14 21:55:14 +00:00
) ;
2021-05-11 18:26:44 +00:00
} ) ;
} ,
wait : 200 ,
maxSize : Infinity ,
} ) ;
2023-03-28 20:31:24 +00:00
const throttledSetInboxEnvelopeTimestamp = throttle (
serverTimestamp = > {
window . reduxActions . inbox . setInboxEnvelopeTimestamp ( serverTimestamp ) ;
} ,
100 ,
{ leading : false }
) ;
2022-12-05 22:46:54 +00:00
async function onEnvelopeReceived ( {
envelope ,
} : EnvelopeEvent ) : Promise < void > {
2023-03-28 20:31:24 +00:00
throttledSetInboxEnvelopeTimestamp ( envelope . serverTimestamp ) ;
2021-09-10 02:38:11 +00:00
const ourUuid = window . textsecure . storage . user . getUuid ( ) ? . toString ( ) ;
2021-08-05 23:34:49 +00:00
if ( envelope . sourceUuid && envelope . sourceUuid !== ourUuid ) {
2023-02-08 00:55:12 +00:00
const { mergePromises , conversation } =
2022-12-05 22:46:54 +00:00
window . ConversationController . maybeMergeContacts ( {
e164 : envelope.source ,
aci : envelope.sourceUuid ,
reason : ` onEnvelopeReceived( ${ envelope . timestamp } ) ` ,
} ) ;
if ( mergePromises . length > 0 ) {
await Promise . all ( mergePromises ) ;
}
2023-02-08 00:55:12 +00:00
if ( envelope . reportingToken ) {
await conversation . updateReportingToken ( envelope . reportingToken ) ;
}
2021-08-05 23:34:49 +00:00
}
}
2020-02-14 21:28:35 +00:00
// Note: We do very little in this function, since everything in handleDataMessage is
// inside a conversation-specific queue(). Any code here might run before an earlier
// message is processed in handleDataMessage().
2022-11-09 18:59:32 +00:00
async function onMessageReceived ( event : MessageEvent ) : Promise < void > {
2019-05-09 15:38:05 +00:00
const { data , confirm } = event ;
2020-11-20 17:30:45 +00:00
const messageDescriptor = getMessageDescriptor ( {
2022-08-15 21:53:33 +00:00
message : data.message ,
2020-11-20 17:30:45 +00:00
// 'message' event: for 1:1 converations, the conversation is same as sender
destination : data.source ,
destinationUuid : data.sourceUuid ,
} ) ;
2019-05-09 15:38:05 +00:00
2021-07-02 19:21:24 +00:00
const { PROFILE_KEY_UPDATE } = Proto . DataMessage . Flags ;
2019-05-09 15:38:05 +00:00
// eslint-disable-next-line no-bitwise
const isProfileUpdate = Boolean ( data . message . flags & PROFILE_KEY_UPDATE ) ;
if ( isProfileUpdate ) {
2020-04-29 21:24:12 +00:00
return handleMessageReceivedProfileUpdate ( {
2019-05-09 15:38:05 +00:00
data ,
confirm ,
messageDescriptor ,
} ) ;
}
2020-06-12 22:36:32 +00:00
const message = initIncomingMessage ( data , messageDescriptor ) ;
2020-03-05 21:14:58 +00:00
2022-08-15 21:53:33 +00:00
if ( isIncoming ( message . attributes ) ) {
2021-12-10 22:51:54 +00:00
const sender = getContact ( message . attributes ) ;
2022-08-15 21:53:33 +00:00
strictAssert ( sender , 'MessageModel has no sender' ) ;
const uuidKind = window . textsecure . storage . user . getOurUuidKind (
new UUID ( data . destinationUuid )
) ;
2021-05-05 16:39:16 +00:00
2022-08-15 21:53:33 +00:00
if ( uuidKind === UUIDKind . PNI && ! sender . get ( 'shareMyPhoneNumber' ) ) {
log . info (
'onMessageReceived: setting shareMyPhoneNumber ' +
` for ${ sender . idForLogging ( ) } `
) ;
sender . set ( { shareMyPhoneNumber : true } ) ;
window . Signal . Data . updateConversation ( sender . attributes ) ;
2021-05-05 16:39:16 +00:00
}
2021-05-11 18:26:44 +00:00
2022-08-15 21:53:33 +00:00
if ( ! message . get ( 'unidentifiedDeliveryReceived' ) ) {
2022-12-21 18:41:48 +00:00
drop (
profileKeyResponseQueue . add ( ( ) = > {
respondWithProfileKeyBatcher . add ( sender ) ;
} )
) ;
2022-08-15 21:53:33 +00:00
}
2021-05-11 18:26:44 +00:00
}
2021-05-05 16:39:16 +00:00
2020-01-17 22:23:19 +00:00
if ( data . message . reaction ) {
2021-07-09 19:36:10 +00:00
strictAssert (
data . message . reaction . targetAuthorUuid ,
'Reaction without targetAuthorUuid'
) ;
const targetAuthorUuid = normalizeUuid (
data . message . reaction . targetAuthorUuid ,
'DataMessage.Reaction.targetAuthorUuid'
2020-11-02 22:49:07 +00:00
) ;
2021-10-29 23:19:44 +00:00
const { reaction , timestamp } = data . message ;
2021-04-07 17:04:42 +00:00
if ( ! isValidReactionEmoji ( reaction . emoji ) ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Received an invalid reaction emoji. Dropping it' ) ;
2021-04-07 17:04:42 +00:00
confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2021-04-07 17:04:42 +00:00
}
2022-01-04 15:27:16 +00:00
strictAssert (
reaction . targetTimestamp ,
'Reaction without targetTimestamp'
) ;
2022-08-09 21:39:00 +00:00
const fromConversation = window . ConversationController . lookupOrCreate ( {
2022-01-04 15:27:16 +00:00
e164 : data.source ,
uuid : data.sourceUuid ,
2022-12-03 01:05:27 +00:00
reason : 'onMessageReceived:reaction' ,
2022-01-04 15:27:16 +00:00
} ) ;
2022-08-09 21:39:00 +00:00
strictAssert ( fromConversation , 'Reaction without fromConversation' ) ;
2022-01-04 15:27:16 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'Queuing incoming reaction for' , reaction . targetTimestamp ) ;
2022-01-04 15:27:16 +00:00
const attributes : ReactionAttributesType = {
2020-01-17 22:23:19 +00:00
emoji : reaction.emoji ,
2023-01-11 22:54:06 +00:00
fromId : fromConversation.id ,
2020-01-17 22:23:19 +00:00
remove : reaction.remove ,
2023-01-11 22:54:06 +00:00
source : ReactionSource.FromSomeoneElse ,
storyReactionMessage : message ,
2021-07-09 19:36:10 +00:00
targetAuthorUuid ,
2020-09-09 02:25:05 +00:00
targetTimestamp : reaction.targetTimestamp ,
2021-10-29 23:19:44 +00:00
timestamp ,
2022-01-04 15:27:16 +00:00
} ;
const reactionModel = Reactions . getSingleton ( ) . add ( attributes ) ;
2022-05-10 19:02:21 +00:00
2023-01-11 22:54:06 +00:00
drop ( Reactions . getSingleton ( ) . onReaction ( reactionModel ) ) ;
2020-01-17 22:23:19 +00:00
confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2020-04-29 21:24:12 +00:00
}
if ( data . message . delete ) {
const { delete : del } = data . message ;
2021-09-17 18:27:53 +00:00
log . info ( 'Queuing incoming DOE for' , del . targetSentTimestamp ) ;
2022-01-04 15:27:16 +00:00
strictAssert (
del . targetSentTimestamp ,
'Delete missing targetSentTimestamp'
) ;
strictAssert ( data . serverTimestamp , 'Delete missing serverTimestamp' ) ;
2022-08-09 21:39:00 +00:00
const fromConversation = window . ConversationController . lookupOrCreate ( {
2022-01-04 15:27:16 +00:00
e164 : data.source ,
uuid : data.sourceUuid ,
2022-12-03 01:05:27 +00:00
reason : 'onMessageReceived:delete' ,
2022-01-04 15:27:16 +00:00
} ) ;
2022-08-09 21:39:00 +00:00
strictAssert ( fromConversation , 'Delete missing fromConversation' ) ;
2022-01-04 15:27:16 +00:00
const attributes : DeleteAttributesType = {
2020-04-29 21:24:12 +00:00
targetSentTimestamp : del.targetSentTimestamp ,
serverTimestamp : data.serverTimestamp ,
2022-08-09 21:39:00 +00:00
fromId : fromConversation.id ,
2022-01-04 15:27:16 +00:00
} ;
const deleteModel = Deletes . getSingleton ( ) . add ( attributes ) ;
2020-04-29 21:24:12 +00:00
// Note: We do not wait for completion here
2022-12-21 18:41:48 +00:00
void Deletes . getSingleton ( ) . onDelete ( deleteModel ) ;
2022-01-04 15:27:16 +00:00
2020-04-29 21:24:12 +00:00
confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2020-01-17 22:23:19 +00:00
}
2023-03-27 23:48:57 +00:00
if ( data . message . editedMessageTimestamp ) {
const { editedMessageTimestamp } = data . message ;
strictAssert ( editedMessageTimestamp , 'Edit missing targetSentTimestamp' ) ;
const fromConversation = window . ConversationController . lookupOrCreate ( {
e164 : data.source ,
uuid : data.sourceUuid ,
reason : 'onMessageReceived:edit' ,
} ) ;
strictAssert ( fromConversation , 'Edit missing fromConversation' ) ;
log . info ( 'Queuing incoming edit for' , {
editedMessageTimestamp ,
sentAt : data.timestamp ,
} ) ;
const editAttributes : EditAttributesType = {
2023-04-20 16:31:59 +00:00
conversationId : message.attributes.conversationId ,
2023-03-27 23:48:57 +00:00
fromId : fromConversation.id ,
2023-04-20 16:31:59 +00:00
message : copyDataMessageIntoMessage ( data . message , message . attributes ) ,
2023-03-27 23:48:57 +00:00
targetSentTimestamp : editedMessageTimestamp ,
} ;
drop ( Edits . onEdit ( editAttributes ) ) ;
confirm ( ) ;
return ;
}
2020-12-09 22:04:34 +00:00
if ( handleGroupCallUpdateMessage ( data . message , messageDescriptor ) ) {
2022-04-28 21:41:56 +00:00
confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2020-11-20 17:19:28 +00:00
}
2019-09-26 19:56:31 +00:00
// Don't wait for handleDataMessage, as it has its own per-conversation queueing
2022-12-21 18:41:48 +00:00
void message . handleDataMessage ( data . message , event . confirm ) ;
2019-05-09 15:38:05 +00:00
}
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
2022-11-09 18:59:32 +00:00
async function onProfileKeyUpdate ( {
data ,
confirm ,
} : ProfileKeyUpdateEvent ) : Promise < void > {
2022-12-05 22:46:54 +00:00
const { conversation } = window . ConversationController . maybeMergeContacts ( {
2022-08-09 21:39:00 +00:00
aci : data.sourceUuid ,
2020-07-10 18:28:49 +00:00
e164 : data.source ,
2022-01-20 22:44:25 +00:00
reason : 'onProfileKeyUpdate' ,
2020-07-10 18:28:49 +00:00
} ) ;
2020-05-27 21:37:06 +00:00
if ( ! data . profileKey ) {
2021-09-17 18:27:53 +00:00
log . error ( 'onProfileKeyUpdate: missing profileKey' , data . profileKey ) ;
2020-05-27 21:37:06 +00:00
confirm ( ) ;
return ;
}
2021-09-17 18:27:53 +00:00
log . info (
2022-02-08 17:30:42 +00:00
'onProfileKeyUpdate: updating profileKey for' ,
data . sourceUuid ,
data . source
2020-05-27 21:37:06 +00:00
) ;
await conversation . setProfileKey ( data . profileKey ) ;
confirm ( ) ;
}
2018-04-27 21:25:04 +00:00
async function handleMessageSentProfileUpdate ( {
2018-10-31 23:58:14 +00:00
data ,
2018-04-27 21:25:04 +00:00
confirm ,
messageDescriptor ,
2021-07-09 19:36:10 +00:00
} : {
data : SentEventData ;
confirm : ( ) = > void ;
messageDescriptor : MessageDescriptor ;
} ) {
2018-10-31 23:58:14 +00:00
// First set profileSharing = true for the conversation we sent to
2020-07-10 18:28:49 +00:00
const { id } = messageDescriptor ;
2020-09-24 20:57:54 +00:00
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const conversation = window . ConversationController . get ( id ) ! ;
2018-09-21 01:47:19 +00:00
2020-05-27 21:37:06 +00:00
conversation . enableProfileSharing ( ) ;
2020-04-01 18:59:11 +00:00
window . Signal . Data . updateConversation ( conversation . attributes ) ;
2018-09-21 01:47:19 +00:00
2018-10-31 23:58:14 +00:00
// Then we update our own profileKey if it's different from what we have
2020-09-24 20:57:54 +00:00
const ourId = window . ConversationController . getOurConversationId ( ) ;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const me = window . ConversationController . get ( ourId ) ! ;
2021-07-09 19:36:10 +00:00
const { profileKey } = data . message ;
strictAssert (
profileKey !== undefined ,
'handleMessageSentProfileUpdate: missing profileKey'
) ;
2018-10-31 23:58:14 +00:00
// Will do the save for us if needed
await me . setProfileKey ( profileKey ) ;
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
return confirm ( ) ;
}
2021-07-09 19:36:10 +00:00
function createSentMessage (
data : SentEventData ,
descriptor : MessageDescriptor
) {
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
const now = Date . now ( ) ;
2021-06-29 14:41:42 +00:00
const timestamp = data . timestamp || now ;
2021-07-19 22:44:49 +00:00
const ourId = window . ConversationController . getOurConversationIdOrThrow ( ) ;
2021-07-09 19:36:10 +00:00
const { unidentifiedStatus = [ ] } = data ;
2021-07-19 22:44:49 +00:00
2021-11-11 22:43:05 +00:00
const sendStateByConversationId : SendStateByConversationId =
unidentifiedStatus . reduce (
(
result : SendStateByConversationId ,
2022-07-01 00:52:03 +00:00
{ destinationUuid , destination , isAllowedToReplyToStory }
2021-11-11 22:43:05 +00:00
) = > {
2022-08-09 21:39:00 +00:00
const conversation = window . ConversationController . lookupOrCreate ( {
uuid : destinationUuid ,
e164 : destination ,
2022-12-03 01:05:27 +00:00
reason : 'createSentMessage' ,
2022-08-09 21:39:00 +00:00
} ) ;
if ( ! conversation || conversation . id === ourId ) {
2021-11-11 22:43:05 +00:00
return result ;
}
2021-07-19 22:44:49 +00:00
2021-11-11 22:43:05 +00:00
return {
. . . result ,
2022-08-09 21:39:00 +00:00
[ conversation . id ] : {
2022-07-01 00:52:03 +00:00
isAllowedToReplyToStory ,
2021-11-11 22:43:05 +00:00
status : SendStatus.Sent ,
updatedAt : timestamp ,
} ,
} ;
} ,
{
[ ourId ] : {
2021-07-28 18:53:18 +00:00
status : SendStatus.Sent ,
2021-07-19 22:44:49 +00:00
updatedAt : timestamp ,
} ,
2021-11-11 22:43:05 +00:00
}
) ;
2021-06-29 14:41:42 +00:00
2021-07-09 19:36:10 +00:00
let unidentifiedDeliveries : Array < string > = [ ] ;
2021-06-29 14:41:42 +00:00
if ( unidentifiedStatus . length ) {
2022-11-30 00:53:39 +00:00
unidentifiedDeliveries = unidentifiedStatus
. filter ( item = > Boolean ( item . unidentified ) )
2021-07-09 19:36:10 +00:00
. map ( item = > item . destinationUuid || item . destination )
. filter ( isNotNil ) ;
2018-10-18 01:01:21 +00:00
}
2018-05-31 01:07:25 +00:00
2022-07-13 00:37:21 +00:00
const partialMessage : MessageAttributesType = {
id : UUID.generate ( ) . toString ( ) ,
2022-07-01 00:52:03 +00:00
canReplyToStory : data.message.isStory
? data . message . canReplyToStory
: undefined ,
2020-09-09 02:25:05 +00:00
conversationId : descriptor.id ,
2018-09-04 23:19:51 +00:00
expirationStartTimestamp : Math.min (
2021-06-29 14:41:42 +00:00
data . expirationStartTimestamp || timestamp ,
2021-03-04 21:44:57 +00:00
now
2018-09-04 23:19:51 +00:00
) ,
2022-04-22 18:35:14 +00:00
readStatus : ReadStatus.Read ,
received_at_ms : data.receivedAtDate ,
received_at : data.receivedAtCounter ,
seenStatus : SeenStatus.NotApplicable ,
sendStateByConversationId ,
sent_at : timestamp ,
serverTimestamp : data.serverTimestamp ,
source : window.textsecure.storage.user.getNumber ( ) ,
sourceDevice : data.device ,
sourceUuid : window.textsecure.storage.user.getUuid ( ) ? . toString ( ) ,
timestamp ,
2022-07-01 00:52:03 +00:00
type : data . message . isStory ? 'story' : 'outgoing' ,
storyDistributionListId : data.storyDistributionListId ,
2022-04-22 18:35:14 +00:00
unidentifiedDeliveries ,
2022-07-13 00:37:21 +00:00
} ;
return new window . Whisper . Message ( partialMessage ) ;
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
}
2023-04-15 00:52:50 +00:00
// Works with 'sent' and 'message' data sent from MessageReceiver
2020-11-20 17:30:45 +00:00
const getMessageDescriptor = ( {
2020-09-24 20:57:54 +00:00
message ,
destination ,
destinationUuid ,
2020-11-20 17:30:45 +00:00
} : {
2021-07-09 19:36:10 +00:00
message : ProcessedDataMessage ;
destination? : string ;
destinationUuid? : string ;
2020-11-20 17:30:45 +00:00
} ) : MessageDescriptor = > {
2020-09-09 02:25:05 +00:00
if ( message . groupV2 ) {
const { id } = message . groupV2 ;
2020-11-20 17:30:45 +00:00
if ( ! id ) {
throw new Error ( 'getMessageDescriptor: GroupV2 data was missing an id' ) ;
}
// First we check for an existing GroupV2 group
const groupV2 = window . ConversationController . get ( id ) ;
if ( groupV2 ) {
return {
type : Message . GROUP ,
id : groupV2.id ,
} ;
}
// Then check for V1 group with matching derived GV2 id
const groupV1 = window . ConversationController . getByDerivedGroupV2Id ( id ) ;
if ( groupV1 ) {
return {
type : Message . GROUP ,
id : groupV1.id ,
} ;
}
// Finally create the V2 group normally
2020-09-24 20:57:54 +00:00
const conversationId = window . ConversationController . ensureGroup ( id , {
2020-09-09 02:25:05 +00:00
groupVersion : 2 ,
masterKey : message.groupV2.masterKey ,
secretParams : message.groupV2.secretParams ,
publicParams : message.groupV2.publicParams ,
} ) ;
return {
type : Message . GROUP ,
id : conversationId ,
} ;
}
2023-04-10 20:30:16 +00:00
const conversation = window . ConversationController . lookupOrCreate ( {
uuid : destinationUuid ,
2020-11-20 17:30:45 +00:00
e164 : destination ,
2022-01-20 22:44:25 +00:00
reason : ` getMessageDescriptor( ${ message . timestamp } ): private ` ,
2020-11-20 17:30:45 +00:00
} ) ;
2023-04-10 20:30:16 +00:00
strictAssert ( conversation , 'Destination conversation cannot be created' ) ;
2020-11-20 17:30:45 +00:00
2020-09-09 02:25:05 +00:00
return {
type : Message . PRIVATE ,
2022-08-09 21:39:00 +00:00
id : conversation.id ,
2020-09-09 02:25:05 +00:00
} ;
} ;
2020-02-14 21:28:35 +00:00
// Note: We do very little in this function, since everything in handleDataMessage is
// inside a conversation-specific queue(). Any code here might run before an earlier
// message is processed in handleDataMessage().
2022-11-09 18:59:32 +00:00
async function onSentMessage ( event : SentEvent ) : Promise < void > {
2019-05-09 15:38:05 +00:00
const { data , confirm } = event ;
2015-06-01 21:08:21 +00:00
2021-07-09 19:36:10 +00:00
const source = window . textsecure . storage . user . getNumber ( ) ;
2021-09-10 02:38:11 +00:00
const sourceUuid = window . textsecure . storage . user . getUuid ( ) ? . toString ( ) ;
2021-07-09 19:36:10 +00:00
strictAssert ( source && sourceUuid , 'Missing user number and uuid' ) ;
2020-11-20 17:30:45 +00:00
const messageDescriptor = getMessageDescriptor ( {
. . . data ,
} ) ;
2019-05-09 15:38:05 +00:00
2021-07-02 19:21:24 +00:00
const { PROFILE_KEY_UPDATE } = Proto . DataMessage . Flags ;
2019-05-09 15:38:05 +00:00
// eslint-disable-next-line no-bitwise
const isProfileUpdate = Boolean ( data . message . flags & PROFILE_KEY_UPDATE ) ;
if ( isProfileUpdate ) {
2020-04-29 21:24:12 +00:00
return handleMessageSentProfileUpdate ( {
2019-05-09 15:38:05 +00:00
data ,
confirm ,
messageDescriptor ,
} ) ;
}
2020-07-10 18:28:49 +00:00
const message = createSentMessage ( data , messageDescriptor ) ;
2020-04-29 21:24:12 +00:00
2020-02-14 21:28:35 +00:00
if ( data . message . reaction ) {
2021-07-09 19:36:10 +00:00
strictAssert (
data . message . reaction . targetAuthorUuid ,
'Reaction without targetAuthorUuid'
) ;
const targetAuthorUuid = normalizeUuid (
data . message . reaction . targetAuthorUuid ,
'DataMessage.Reaction.targetAuthorUuid'
2020-11-02 22:49:07 +00:00
) ;
2021-10-29 23:19:44 +00:00
const { reaction , timestamp } = data . message ;
2022-01-04 15:27:16 +00:00
strictAssert (
reaction . targetTimestamp ,
'Reaction without targetAuthorUuid'
) ;
2021-04-07 17:04:42 +00:00
if ( ! isValidReactionEmoji ( reaction . emoji ) ) {
2021-09-17 18:27:53 +00:00
log . warn ( 'Received an invalid reaction emoji. Dropping it' ) ;
2021-04-07 17:04:42 +00:00
event . confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2021-04-07 17:04:42 +00:00
}
2021-09-17 18:27:53 +00:00
log . info ( 'Queuing sent reaction for' , reaction . targetTimestamp ) ;
2022-01-04 15:27:16 +00:00
const attributes : ReactionAttributesType = {
2020-01-17 22:23:19 +00:00
emoji : reaction.emoji ,
2023-01-11 22:54:06 +00:00
fromId : window.ConversationController.getOurConversationIdOrThrow ( ) ,
2020-01-17 22:23:19 +00:00
remove : reaction.remove ,
2023-01-11 22:54:06 +00:00
source : ReactionSource.FromSync ,
storyReactionMessage : message ,
2021-07-09 19:36:10 +00:00
targetAuthorUuid ,
2020-09-09 02:25:05 +00:00
targetTimestamp : reaction.targetTimestamp ,
2021-10-29 23:19:44 +00:00
timestamp ,
2022-01-04 15:27:16 +00:00
} ;
const reactionModel = Reactions . getSingleton ( ) . add ( attributes ) ;
2023-01-11 22:54:06 +00:00
drop ( Reactions . getSingleton ( ) . onReaction ( reactionModel ) ) ;
2019-09-26 19:56:31 +00:00
2020-02-14 21:28:35 +00:00
event . confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2020-04-29 21:24:12 +00:00
}
if ( data . message . delete ) {
const { delete : del } = data . message ;
2022-01-04 15:27:16 +00:00
strictAssert (
del . targetSentTimestamp ,
'Delete without targetSentTimestamp'
) ;
strictAssert ( data . serverTimestamp , 'Data has no serverTimestamp' ) ;
2021-09-17 18:27:53 +00:00
log . info ( 'Queuing sent DOE for' , del . targetSentTimestamp ) ;
2022-01-04 15:27:16 +00:00
const attributes : DeleteAttributesType = {
2020-04-29 21:24:12 +00:00
targetSentTimestamp : del.targetSentTimestamp ,
2021-07-09 19:36:10 +00:00
serverTimestamp : data.serverTimestamp ,
2022-01-04 15:27:16 +00:00
fromId : window.ConversationController.getOurConversationIdOrThrow ( ) ,
} ;
const deleteModel = Deletes . getSingleton ( ) . add ( attributes ) ;
2020-04-29 21:24:12 +00:00
// Note: We do not wait for completion here
2022-12-21 18:41:48 +00:00
void Deletes . getSingleton ( ) . onDelete ( deleteModel ) ;
2020-04-29 21:24:12 +00:00
confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2019-05-09 15:38:05 +00:00
}
2018-07-25 22:02:27 +00:00
2023-03-27 23:48:57 +00:00
if ( data . message . editedMessageTimestamp ) {
const { editedMessageTimestamp } = data . message ;
strictAssert ( editedMessageTimestamp , 'Edit missing targetSentTimestamp' ) ;
log . info ( 'Queuing sent edit for' , {
editedMessageTimestamp ,
sentAt : data.timestamp ,
} ) ;
const editAttributes : EditAttributesType = {
2023-04-20 16:31:59 +00:00
conversationId : message.attributes.conversationId ,
2023-03-27 23:48:57 +00:00
fromId : window.ConversationController.getOurConversationIdOrThrow ( ) ,
2023-04-20 16:31:59 +00:00
message : copyDataMessageIntoMessage ( data . message , message . attributes ) ,
2023-03-27 23:48:57 +00:00
targetSentTimestamp : editedMessageTimestamp ,
} ;
drop ( Edits . onEdit ( editAttributes ) ) ;
confirm ( ) ;
return ;
}
2020-12-09 22:04:34 +00:00
if ( handleGroupCallUpdateMessage ( data . message , messageDescriptor ) ) {
2021-05-24 21:30:56 +00:00
event . confirm ( ) ;
2022-11-09 18:59:32 +00:00
return ;
2020-12-09 22:04:34 +00:00
}
2020-02-14 21:28:35 +00:00
// Don't wait for handleDataMessage, as it has its own per-conversation queueing
2022-12-21 18:41:48 +00:00
void message . handleDataMessage ( data . message , event . confirm , {
2020-02-14 21:28:35 +00:00
data ,
} ) ;
2018-04-27 21:25:04 +00:00
}
2015-06-01 21:08:21 +00:00
2020-11-20 17:30:45 +00:00
type MessageDescriptor = {
type : 'private' | 'group' ;
id : string ;
} ;
function initIncomingMessage (
2021-07-09 19:36:10 +00:00
data : MessageEventData ,
2020-11-20 17:30:45 +00:00
descriptor : MessageDescriptor
) {
2022-09-15 19:17:15 +00:00
assertDev (
2021-03-04 21:44:57 +00:00
Boolean ( data . receivedAtCounter ) ,
` Did not receive receivedAtCounter for message: ${ data . timestamp } `
) ;
2022-07-13 00:37:21 +00:00
const partialMessage : MessageAttributesType = {
id : UUID.generate ( ) . toString ( ) ,
2022-07-01 00:52:03 +00:00
canReplyToStory : data.message.isStory
? data . message . canReplyToStory
: undefined ,
2020-09-09 02:25:05 +00:00
conversationId : descriptor.id ,
2021-08-12 18:15:55 +00:00
readStatus : ReadStatus.Unread ,
2022-07-01 00:52:03 +00:00
received_at : data.receivedAtCounter ,
received_at_ms : data.receivedAtDate ,
2022-04-22 18:35:14 +00:00
seenStatus : SeenStatus.Unseen ,
2022-07-01 00:52:03 +00:00
sent_at : data.timestamp ,
serverGuid : data.serverGuid ,
serverTimestamp : data.serverTimestamp ,
source : data.source ,
sourceDevice : data.sourceDevice ,
2022-08-04 00:10:05 +00:00
sourceUuid : data.sourceUuid ? UUID . cast ( data . sourceUuid ) : undefined ,
2021-07-09 19:36:10 +00:00
timestamp : data.timestamp ,
2022-07-01 00:52:03 +00:00
type : data . message . isStory ? 'story' : 'incoming' ,
unidentifiedDeliveryReceived : data.unidentifiedDeliveryReceived ,
2022-07-13 00:37:21 +00:00
} ;
return new window . Whisper . Message ( partialMessage ) ;
2018-04-27 21:25:04 +00:00
}
2018-02-24 01:40:02 +00:00
2020-12-09 22:04:34 +00:00
// Returns `false` if this message isn't a group call message.
function handleGroupCallUpdateMessage (
2021-07-09 19:36:10 +00:00
message : ProcessedDataMessage ,
2020-12-09 22:04:34 +00:00
messageDescriptor : MessageDescriptor
) : boolean {
if ( message . groupCallUpdate ) {
if ( message . groupV2 && messageDescriptor . type === Message . GROUP ) {
2021-08-19 01:04:38 +00:00
window . reduxActions . calling . peekNotConnectedGroupCall ( {
conversationId : messageDescriptor.id ,
} ) ;
2020-12-09 22:04:34 +00:00
return true ;
}
2021-09-17 18:27:53 +00:00
log . warn (
2020-12-09 22:04:34 +00:00
'Received a group call update for a conversation that is not a GV2 group. Ignoring that property and continuing.'
) ;
}
return false ;
}
2021-08-30 21:39:57 +00:00
async function unlinkAndDisconnect (
mode : RemoveAllConfiguration
) : Promise < void > {
2020-09-24 20:57:54 +00:00
window . Whisper . events . trigger ( 'unauthorized' ) ;
2018-02-24 01:40:02 +00:00
2021-09-17 18:27:53 +00:00
log . warn (
2021-09-15 18:44:27 +00:00
'unlinkAndDisconnect: Client is no longer authorized; ' +
'deleting local configuration'
) ;
2019-10-02 20:52:20 +00:00
if ( messageReceiver ) {
2021-09-17 18:27:53 +00:00
log . info ( 'unlinkAndDisconnect: logging out' ) ;
2021-07-28 21:37:09 +00:00
strictAssert ( server !== undefined , 'WebAPI not initialized' ) ;
server . unregisterRequestHandler ( messageReceiver ) ;
2021-09-15 18:44:27 +00:00
messageReceiver . stopProcessing ( ) ;
await server . logout ( ) ;
2019-10-02 20:52:20 +00:00
await window . waitForAllBatchers ( ) ;
2021-05-24 19:01:45 +00:00
}
2019-09-26 19:56:31 +00:00
2022-12-21 18:41:48 +00:00
void onEmpty ( ) ;
2019-02-19 20:10:26 +00:00
2023-04-11 03:54:43 +00:00
void Registration . remove ( ) ;
2019-02-20 01:32:44 +00:00
2019-10-02 20:52:20 +00:00
const NUMBER_ID_KEY = 'number_id' ;
2021-06-17 17:15:10 +00:00
const UUID_ID_KEY = 'uuid_id' ;
2023-02-09 23:42:50 +00:00
const PNI_KEY = 'pni' ;
2019-10-02 20:52:20 +00:00
const VERSION_KEY = 'version' ;
const LAST_PROCESSED_INDEX_KEY = 'attachmentMigration_lastProcessedIndex' ;
const IS_MIGRATION_COMPLETE_KEY = 'attachmentMigration_isComplete' ;
2018-07-27 16:34:47 +00:00
2020-09-24 20:57:54 +00:00
const previousNumberId = window . textsecure . storage . get ( NUMBER_ID_KEY ) ;
2021-06-17 17:15:10 +00:00
const previousUuidId = window . textsecure . storage . get ( UUID_ID_KEY ) ;
2023-02-09 23:42:50 +00:00
const previousPni = window . textsecure . storage . get ( PNI_KEY ) ;
2020-09-24 20:57:54 +00:00
const lastProcessedIndex = window . textsecure . storage . get (
LAST_PROCESSED_INDEX_KEY
) ;
const isMigrationComplete = window . textsecure . storage . get (
2019-10-02 20:52:20 +00:00
IS_MIGRATION_COMPLETE_KEY
) ;
2018-07-27 16:34:47 +00:00
2019-10-02 20:52:20 +00:00
try {
2021-09-27 17:31:34 +00:00
log . info ( ` unlinkAndDisconnect: removing configuration, mode ${ mode } ` ) ;
2021-08-30 21:39:57 +00:00
await window . textsecure . storage . protocol . removeAllConfiguration ( mode ) ;
2019-10-02 20:52:20 +00:00
2021-05-27 20:47:39 +00:00
// This was already done in the database with removeAllConfiguration; this does it
// for all the conversation models in memory.
window . getConversations ( ) . forEach ( conversation = > {
// eslint-disable-next-line no-param-reassign
delete conversation . attributes . senderKeyInfo ;
} ) ;
2023-02-09 23:42:50 +00:00
// These three bits of data are important to ensure that the app loads up
2019-10-02 20:52:20 +00:00
// the conversation list, instead of showing just the QR code screen.
2021-06-15 00:09:37 +00:00
if ( previousNumberId !== undefined ) {
await window . textsecure . storage . put ( NUMBER_ID_KEY , previousNumberId ) ;
}
2021-06-17 17:15:10 +00:00
if ( previousUuidId !== undefined ) {
await window . textsecure . storage . put ( UUID_ID_KEY , previousUuidId ) ;
}
2023-02-09 23:42:50 +00:00
if ( previousPni !== undefined ) {
await window . textsecure . storage . put ( PNI_KEY , previousPni ) ;
}
2019-10-02 20:52:20 +00:00
// These two are important to ensure we don't rip through every message
// in the database attempting to upgrade it after starting up again.
2020-10-08 00:46:52 +00:00
await window . textsecure . storage . put (
2019-10-02 20:52:20 +00:00
IS_MIGRATION_COMPLETE_KEY ,
isMigrationComplete || false
2018-07-27 16:34:47 +00:00
) ;
2021-06-15 00:09:37 +00:00
if ( lastProcessedIndex !== undefined ) {
await window . textsecure . storage . put (
LAST_PROCESSED_INDEX_KEY ,
lastProcessedIndex
) ;
} else {
await window . textsecure . storage . remove ( LAST_PROCESSED_INDEX_KEY ) ;
}
2020-10-08 00:46:52 +00:00
await window . textsecure . storage . put ( VERSION_KEY , window . getVersion ( ) ) ;
2018-05-25 01:50:49 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'unlinkAndDisconnect: Successfully cleared local configuration' ) ;
2019-10-02 20:52:20 +00:00
} catch ( eraseError ) {
2021-09-17 18:27:53 +00:00
log . error (
2021-09-15 18:44:27 +00:00
'unlinkAndDisconnect: Something went wrong clearing ' +
'local configuration' ,
2022-11-22 18:43:43 +00:00
Errors . toLogFormat ( eraseError )
2019-10-02 20:52:20 +00:00
) ;
2021-07-29 08:19:26 +00:00
} finally {
2023-04-11 03:54:43 +00:00
await Registration . markEverDone ( ) ;
2019-10-02 20:52:20 +00:00
}
}
2018-07-27 16:34:47 +00:00
2022-11-09 18:59:32 +00:00
function onError ( ev : ErrorEvent ) : void {
2019-10-02 20:52:20 +00:00
const { error } = ev ;
2021-09-17 18:27:53 +00:00
log . error ( 'background onError:' , Errors . toLogFormat ( error ) ) ;
2015-06-19 22:32:25 +00:00
2019-10-02 20:52:20 +00:00
if (
2021-09-22 00:58:03 +00:00
error instanceof HTTPError &&
2019-10-02 20:52:20 +00:00
( error . code === 401 || error . code === 403 )
) {
2022-12-21 18:41:48 +00:00
void unlinkAndDisconnect ( RemoveAllConfiguration . Full ) ;
2021-02-18 16:40:26 +00:00
return ;
2018-04-27 21:25:04 +00:00
}
2017-01-04 03:37:56 +00:00
2021-09-17 18:27:53 +00:00
log . warn ( 'background onError: Doing nothing with incoming error' ) ;
2021-02-18 16:40:26 +00:00
}
2019-09-26 19:56:31 +00:00
2022-11-09 18:59:32 +00:00
function onViewOnceOpenSync ( ev : ViewOnceOpenSyncEvent ) : void {
2019-09-26 19:56:31 +00:00
ev . confirm ( ) ;
2020-03-05 21:14:58 +00:00
const { source , sourceUuid , timestamp } = ev ;
2021-09-17 18:27:53 +00:00
log . info ( ` view once open sync ${ source } ${ timestamp } ` ) ;
2022-01-04 15:27:16 +00:00
strictAssert ( sourceUuid , 'ViewOnceOpen without sourceUuid' ) ;
strictAssert ( timestamp , 'ViewOnceOpen without timestamp' ) ;
2019-06-26 19:33:13 +00:00
2022-01-04 15:27:16 +00:00
const attributes : ViewOnceOpenSyncAttributesType = {
2019-06-26 19:33:13 +00:00
source ,
2020-03-05 21:14:58 +00:00
sourceUuid ,
2019-06-26 19:33:13 +00:00
timestamp ,
2022-01-04 15:27:16 +00:00
} ;
const sync = ViewOnceOpenSyncs . getSingleton ( ) . add ( attributes ) ;
2019-06-26 19:33:13 +00:00
2022-12-21 18:41:48 +00:00
void ViewOnceOpenSyncs . getSingleton ( ) . onSync ( sync ) ;
2019-06-26 19:33:13 +00:00
}
2022-11-09 18:59:32 +00:00
async function onFetchLatestSync ( ev : FetchLatestEvent ) : Promise < void > {
2020-07-07 00:56:56 +00:00
ev . confirm ( ) ;
const { eventType } = ev ;
2021-07-02 19:21:24 +00:00
const FETCH_LATEST_ENUM = Proto . SyncMessage . FetchLatest . Type ;
2020-07-07 00:56:56 +00:00
switch ( eventType ) {
2021-07-21 20:45:41 +00:00
case FETCH_LATEST_ENUM . LOCAL_PROFILE : {
2022-11-09 18:59:32 +00:00
log . info ( 'onFetchLatestSync: fetching latest local profile' ) ;
2021-09-10 02:38:11 +00:00
const ourUuid = window . textsecure . storage . user . getUuid ( ) ? . toString ( ) ;
2021-07-21 20:45:41 +00:00
const ourE164 = window . textsecure . storage . user . getNumber ( ) ;
2023-02-02 18:03:51 +00:00
await getProfile ( ourUuid , ourE164 ) ;
2020-07-07 00:56:56 +00:00
break ;
2021-07-21 20:45:41 +00:00
}
2020-07-07 00:56:56 +00:00
case FETCH_LATEST_ENUM . STORAGE_MANIFEST :
2021-09-17 18:27:53 +00:00
log . info ( 'onFetchLatestSync: fetching latest manifest' ) ;
2022-10-08 00:19:02 +00:00
await StorageService . runStorageServiceSyncJob ( ) ;
2020-07-07 00:56:56 +00:00
break ;
2021-11-30 16:29:57 +00:00
case FETCH_LATEST_ENUM . SUBSCRIPTION_STATUS :
log . info ( 'onFetchLatestSync: fetching latest subscription status' ) ;
strictAssert ( server , 'WebAPI not ready' ) ;
areWeASubscriberService . update ( window . storage , server ) ;
break ;
2020-07-07 00:56:56 +00:00
default :
2021-09-17 18:27:53 +00:00
log . info ( ` onFetchLatestSync: Unknown type encountered ${ eventType } ` ) ;
2020-07-07 00:56:56 +00:00
}
}
2021-07-09 19:36:10 +00:00
async function onKeysSync ( ev : KeysEvent ) {
2020-07-07 00:56:56 +00:00
ev . confirm ( ) ;
const { storageServiceKey } = ev ;
2022-09-14 21:40:44 +00:00
if ( storageServiceKey == null ) {
2021-09-17 18:27:53 +00:00
log . info ( 'onKeysSync: deleting window.storageKey' ) ;
2022-12-21 18:41:48 +00:00
await window . storage . remove ( 'storageKey' ) ;
2020-09-09 00:56:23 +00:00
}
2020-07-07 00:56:56 +00:00
if ( storageServiceKey ) {
2021-09-24 00:49:05 +00:00
const storageServiceKeyBase64 = Bytes . toBase64 ( storageServiceKey ) ;
2022-02-02 21:15:39 +00:00
if ( window . storage . get ( 'storageKey' ) === storageServiceKeyBase64 ) {
log . info (
"onKeysSync: storage service key didn't change, " +
'fetching manifest anyway'
) ;
} else {
log . info (
'onKeysSync: updated storage service key, erasing state and fetching'
) ;
await window . storage . put ( 'storageKey' , storageServiceKeyBase64 ) ;
2022-10-08 00:19:02 +00:00
await StorageService . eraseAllStorageServiceState ( {
2022-02-02 21:15:39 +00:00
keepUnknownFields : true ,
} ) ;
}
2020-07-07 00:56:56 +00:00
2022-10-08 00:19:02 +00:00
await StorageService . runStorageServiceSyncJob ( ) ;
2020-07-07 00:56:56 +00:00
}
}
2022-03-25 17:36:08 +00:00
2022-11-09 18:59:32 +00:00
function onMessageRequestResponse ( ev : MessageRequestResponseEvent ) : void {
2020-05-27 21:37:06 +00:00
ev . confirm ( ) ;
2023-04-15 00:52:50 +00:00
const { threadE164 , threadUuid , groupV2Id , messageRequestResponseType } =
ev ;
2020-05-27 21:37:06 +00:00
2021-09-17 18:27:53 +00:00
log . info ( 'onMessageRequestResponse' , {
2020-11-20 17:30:45 +00:00
threadE164 ,
threadUuid ,
groupV2Id : ` groupv2( ${ groupV2Id } ) ` ,
messageRequestResponseType ,
} ) ;
2020-05-27 21:37:06 +00:00
2022-01-04 15:27:16 +00:00
strictAssert (
messageRequestResponseType ,
'onMessageRequestResponse: missing type'
) ;
const attributes : MessageRequestAttributesType = {
2020-11-20 17:30:45 +00:00
threadE164 ,
threadUuid ,
groupV2Id ,
type : messageRequestResponseType ,
2022-01-04 15:27:16 +00:00
} ;
const sync = MessageRequests . getSingleton ( ) . add ( attributes ) ;
2020-05-27 21:37:06 +00:00
2022-12-21 18:41:48 +00:00
void MessageRequests . getSingleton ( ) . onResponse ( sync ) ;
2020-05-27 21:37:06 +00:00
}
2022-11-09 18:59:32 +00:00
function onReadReceipt ( event : Readonly < ReadEvent > ) : void {
2021-07-27 15:42:25 +00:00
onReadOrViewReceipt ( {
logTitle : 'read receipt' ,
event ,
type : MessageReceiptType . Read ,
} ) ;
}
function onViewReceipt ( event : Readonly < ViewEvent > ) : void {
onReadOrViewReceipt ( {
logTitle : 'view receipt' ,
event ,
type : MessageReceiptType . View ,
} ) ;
}
function onReadOrViewReceipt ( {
event ,
logTitle ,
type ,
} : Readonly < {
event : ReadEvent | ViewEvent ;
logTitle : string ;
type : MessageReceiptType . Read | MessageReceiptType . View ;
} > ) : void {
2022-08-15 21:53:33 +00:00
const {
envelopeTimestamp ,
timestamp ,
source ,
sourceUuid ,
sourceDevice ,
wasSentEncrypted ,
} = event . receipt ;
2022-12-05 22:46:54 +00:00
const { conversation : sourceConversation } =
window . ConversationController . maybeMergeContacts ( {
2022-08-09 21:39:00 +00:00
aci : sourceUuid ,
2021-07-20 20:17:25 +00:00
e164 : source ,
2022-01-20 22:44:25 +00:00
reason : ` onReadOrViewReceipt( ${ envelopeTimestamp } ) ` ,
2022-12-05 22:46:54 +00:00
} ) ;
2021-09-17 18:27:53 +00:00
log . info (
2021-07-27 15:42:25 +00:00
logTitle ,
2022-10-05 20:49:43 +00:00
` ${ sourceUuid || source } . ${ sourceDevice } ` ,
2020-08-06 17:28:56 +00:00
envelopeTimestamp ,
'for sent message' ,
timestamp
) ;
2018-04-27 21:25:04 +00:00
2021-07-27 15:42:25 +00:00
event . confirm ( ) ;
2019-09-26 19:56:31 +00:00
2022-01-04 15:27:16 +00:00
strictAssert (
isValidUuid ( sourceUuid ) ,
'onReadOrViewReceipt: Missing sourceUuid'
) ;
strictAssert ( sourceDevice , 'onReadOrViewReceipt: Missing sourceDevice' ) ;
const attributes : MessageReceiptAttributesType = {
2021-07-20 20:17:25 +00:00
messageSentAt : timestamp ,
receiptTimestamp : envelopeTimestamp ,
2023-01-11 22:54:06 +00:00
sourceConversationId : sourceConversation.id ,
2021-10-26 22:59:08 +00:00
sourceUuid ,
2021-07-20 20:17:25 +00:00
sourceDevice ,
2021-07-27 15:42:25 +00:00
type ,
2022-08-15 21:53:33 +00:00
wasSentEncrypted ,
2022-01-04 15:27:16 +00:00
} ;
const receipt = MessageReceipts . getSingleton ( ) . add ( attributes ) ;
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
2019-09-26 19:56:31 +00:00
// Note: We do not wait for completion here
2022-12-21 18:41:48 +00:00
void MessageReceipts . getSingleton ( ) . onReceipt ( receipt ) ;
2018-04-27 21:25:04 +00:00
}
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
2022-11-09 18:59:32 +00:00
function onReadSync ( ev : ReadSyncEvent ) : Promise < void > {
2020-08-06 17:28:56 +00:00
const { envelopeTimestamp , sender , senderUuid , timestamp } = ev . read ;
2021-07-09 19:36:10 +00:00
const readAt = envelopeTimestamp ;
2022-08-09 21:39:00 +00:00
const senderConversation = window . ConversationController . lookupOrCreate ( {
2020-08-06 17:28:56 +00:00
e164 : sender ,
uuid : senderUuid ,
2022-12-03 01:05:27 +00:00
reason : 'onReadSync' ,
2020-08-06 17:28:56 +00:00
} ) ;
2022-08-09 21:39:00 +00:00
const senderId = senderConversation ? . id ;
2020-08-06 17:28:56 +00:00
2021-09-17 18:27:53 +00:00
log . info (
2021-08-02 22:47:33 +00:00
'read sync' ,
sender ,
senderUuid ,
envelopeTimestamp ,
senderId ,
'for message' ,
timestamp
) ;
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
2022-01-04 15:27:16 +00:00
strictAssert ( senderId , 'onReadSync missing senderId' ) ;
strictAssert ( senderUuid , 'onReadSync missing senderUuid' ) ;
strictAssert ( timestamp , 'onReadSync missing timestamp' ) ;
const attributes : ReadSyncAttributesType = {
2021-08-02 22:47:33 +00:00
senderId ,
sender ,
senderUuid ,
timestamp ,
readAt ,
2022-01-04 15:27:16 +00:00
} ;
const receipt = ReadSyncs . getSingleton ( ) . add ( attributes ) ;
2021-07-30 20:39:41 +00:00
2021-08-02 22:47:33 +00:00
receipt . on ( 'remove' , ev . confirm ) ;
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
2021-08-02 22:47:33 +00:00
// Note: Here we wait, because we want read states to be in the database
// before we move on.
return ReadSyncs . getSingleton ( ) . onSync ( receipt ) ;
2018-04-27 21:25:04 +00:00
}
2017-07-25 01:43:35 +00:00
2022-11-09 18:59:32 +00:00
function onViewSync ( ev : ViewSyncEvent ) : Promise < void > {
2021-08-12 18:15:55 +00:00
const { envelopeTimestamp , senderE164 , senderUuid , timestamp } = ev . view ;
2022-08-09 21:39:00 +00:00
const senderConversation = window . ConversationController . lookupOrCreate ( {
2021-08-12 18:15:55 +00:00
e164 : senderE164 ,
uuid : senderUuid ,
2022-12-03 01:05:27 +00:00
reason : 'onViewSync' ,
2021-08-12 18:15:55 +00:00
} ) ;
2022-08-09 21:39:00 +00:00
const senderId = senderConversation ? . id ;
2021-08-12 18:15:55 +00:00
2021-09-17 18:27:53 +00:00
log . info (
2021-08-12 18:15:55 +00:00
'view sync' ,
senderE164 ,
senderUuid ,
envelopeTimestamp ,
senderId ,
'for message' ,
timestamp
) ;
2022-01-04 15:27:16 +00:00
strictAssert ( senderId , 'onViewSync missing senderId' ) ;
strictAssert ( senderUuid , 'onViewSync missing senderUuid' ) ;
strictAssert ( timestamp , 'onViewSync missing timestamp' ) ;
const attributes : ViewSyncAttributesType = {
2021-08-12 18:15:55 +00:00
senderId ,
senderE164 ,
senderUuid ,
timestamp ,
viewedAt : envelopeTimestamp ,
2022-01-04 15:27:16 +00:00
} ;
const receipt = ViewSyncs . getSingleton ( ) . add ( attributes ) ;
2021-08-12 18:15:55 +00:00
receipt . on ( 'remove' , ev . confirm ) ;
// Note: Here we wait, because we want viewed states to be in the database
// before we move on.
return ViewSyncs . getSingleton ( ) . onSync ( receipt ) ;
}
2022-11-09 18:59:32 +00:00
function onDeliveryReceipt ( ev : DeliveryEvent ) : void {
2018-05-25 01:50:49 +00:00
const { deliveryReceipt } = ev ;
2022-08-15 21:53:33 +00:00
const {
envelopeTimestamp ,
sourceUuid ,
source ,
sourceDevice ,
timestamp ,
wasSentEncrypted ,
} = deliveryReceipt ;
2015-12-09 22:43:53 +00:00
2019-09-26 19:56:31 +00:00
ev . confirm ( ) ;
2022-12-05 22:46:54 +00:00
const { conversation : sourceConversation } =
window . ConversationController . maybeMergeContacts ( {
2022-08-09 21:39:00 +00:00
aci : sourceUuid ,
2021-07-20 20:17:25 +00:00
e164 : source ,
2022-01-20 22:44:25 +00:00
reason : ` onDeliveryReceipt( ${ envelopeTimestamp } ) ` ,
2022-12-05 22:46:54 +00:00
} ) ;
2020-03-05 21:14:58 +00:00
2021-09-17 18:27:53 +00:00
log . info (
2020-08-06 17:28:56 +00:00
'delivery receipt from' ,
2022-10-05 20:49:43 +00:00
` ${ sourceUuid || source } . ${ sourceDevice } ` ,
2020-08-06 17:28:56 +00:00
envelopeTimestamp ,
'for sent message' ,
2022-10-05 20:49:43 +00:00
timestamp ,
` wasSentEncrypted= ${ wasSentEncrypted } `
2020-08-06 17:28:56 +00:00
) ;
2022-01-04 15:27:16 +00:00
strictAssert (
envelopeTimestamp ,
'onDeliveryReceipt: missing envelopeTimestamp'
) ;
strictAssert (
isValidUuid ( sourceUuid ) ,
'onDeliveryReceipt: missing valid sourceUuid'
) ;
strictAssert ( sourceDevice , 'onDeliveryReceipt: missing sourceDevice' ) ;
const attributes : MessageReceiptAttributesType = {
2021-07-20 20:17:25 +00:00
messageSentAt : timestamp ,
receiptTimestamp : envelopeTimestamp ,
2022-08-09 21:39:00 +00:00
sourceConversationId : sourceConversation?.id ,
2021-10-26 22:59:08 +00:00
sourceUuid ,
2021-07-20 20:17:25 +00:00
sourceDevice ,
type : MessageReceiptType . Delivery ,
2022-08-15 21:53:33 +00:00
wasSentEncrypted ,
2022-01-04 15:27:16 +00:00
} ;
const receipt = MessageReceipts . getSingleton ( ) . add ( attributes ) ;
2017-07-25 01:43:35 +00:00
2019-09-26 19:56:31 +00:00
// Note: We don't wait for completion here
2022-12-21 18:41:48 +00:00
void MessageReceipts . getSingleton ( ) . onReceipt ( receipt ) ;
2018-04-27 21:25:04 +00:00
}
2021-02-26 21:06:37 +00:00
}
window . startApp = startApp ;