|
|
@ -42,20 +42,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
// The debug logs can be more verbose than the analytics events.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// In this case `descriptionForEnvelope` is valuable enough to
|
|
|
|
|
|
|
|
// log but too dangerous to include in the analytics event.
|
|
|
|
|
|
|
|
#define OWSProdErrorWEnvelope(__analyticsEventName, __envelope) \
|
|
|
|
|
|
|
|
{ \
|
|
|
|
|
|
|
|
DDLogError(@"%s:%d %@: %@", \
|
|
|
|
|
|
|
|
__PRETTY_FUNCTION__, \
|
|
|
|
|
|
|
|
__LINE__, \
|
|
|
|
|
|
|
|
__analyticsEventName, \
|
|
|
|
|
|
|
|
[self descriptionForEnvelope:__envelope]); \
|
|
|
|
|
|
|
|
OWSProdError(__analyticsEventName) \
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface TSMessagesManager ()
|
|
|
|
@interface TSMessagesManager ()
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) id<OWSCallMessageHandler> callMessageHandler;
|
|
|
|
@property (nonatomic, readonly) id<OWSCallMessageHandler> callMessageHandler;
|
|
|
@ -278,6 +264,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
completion:(nullable MessageManagerCompletionBlock)completionHandler
|
|
|
|
completion:(nullable MessageManagerCompletionBlock)completionHandler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
OWSAssert([TSAccountManager isRegistered]);
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that completionHandler is called on the main thread,
|
|
|
|
// Ensure that completionHandler is called on the main thread,
|
|
|
|
// and handle the nil case.
|
|
|
|
// and handle the nil case.
|
|
|
@ -366,6 +353,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
- (void)handleDeliveryReceipt:(OWSSignalServiceProtosEnvelope *)envelope
|
|
|
|
- (void)handleDeliveryReceipt:(OWSSignalServiceProtosEnvelope *)envelope
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
TSInteraction *interaction =
|
|
|
|
TSInteraction *interaction =
|
|
|
|
[TSInteraction interactionForTimestamp:envelope.timestamp withTransaction:transaction];
|
|
|
|
[TSInteraction interactionForTimestamp:envelope.timestamp withTransaction:transaction];
|
|
|
@ -380,6 +368,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
completion:(void (^)(NSError *_Nullable error))completion
|
|
|
|
completion:(void (^)(NSError *_Nullable error))completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
|
|
@synchronized(self) {
|
|
|
|
@synchronized(self) {
|
|
|
|
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
|
|
|
TSStorageManager *storageManager = [TSStorageManager sharedManager];
|
|
|
|
NSString *recipientId = messageEnvelope.source;
|
|
|
|
NSString *recipientId = messageEnvelope.source;
|
|
|
@ -511,7 +500,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
DDLogInfo(@"%@ handling dataMessage: %@", self.tag, [self descriptionForDataMessage:dataMessage]);
|
|
|
|
DDLogInfo(@"%@ handling dataMessage: %@", self.tag, [self descriptionForDataMessage:dataMessage]);
|
|
|
|
[self handleIncomingEnvelope:envelope withDataMessage:dataMessage];
|
|
|
|
[self handleIncomingEnvelope:envelope withDataMessage:dataMessage];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DDLogWarn(@"%@ Ignoring envelope with neither DataMessage nor Content.", self.tag);
|
|
|
|
OWSProdInfoWEnvelope([OWSAnalyticsEvents messageManagerErrorEnvelopeNoActionablePayload], envelope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -591,7 +580,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
} else if (callMessage.hasBusy) {
|
|
|
|
} else if (callMessage.hasBusy) {
|
|
|
|
[self.callMessageHandler receivedBusy:callMessage.busy fromCallerId:incomingEnvelope.source];
|
|
|
|
[self.callMessageHandler receivedBusy:callMessage.busy fromCallerId:incomingEnvelope.source];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DDLogWarn(@"%@ Ignoring Received CallMessage without actionable content: %@", self.tag, callMessage);
|
|
|
|
OWSProdInfoWEnvelope([OWSAnalyticsEvents messageManagerErrorCallMessageNoActionablePayload], incomingEnvelope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -600,6 +589,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
TSGroupThread *groupThread = [TSGroupThread getOrCreateThreadWithGroupIdData:dataMessage.group.id];
|
|
|
|
TSGroupThread *groupThread = [TSGroupThread getOrCreateThreadWithGroupIdData:dataMessage.group.id];
|
|
|
|
|
|
|
|
OWSAssert(groupThread);
|
|
|
|
OWSAttachmentsProcessor *attachmentsProcessor =
|
|
|
|
OWSAttachmentsProcessor *attachmentsProcessor =
|
|
|
|
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:@[ dataMessage.group.avatar ]
|
|
|
|
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:@[ dataMessage.group.avatar ]
|
|
|
|
timestamp:envelope.timestamp
|
|
|
|
timestamp:envelope.timestamp
|
|
|
@ -628,6 +618,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
TSThread *thread = [self threadForEnvelope:envelope dataMessage:dataMessage];
|
|
|
|
TSThread *thread = [self threadForEnvelope:envelope dataMessage:dataMessage];
|
|
|
|
|
|
|
|
OWSAssert(thread);
|
|
|
|
OWSAttachmentsProcessor *attachmentsProcessor =
|
|
|
|
OWSAttachmentsProcessor *attachmentsProcessor =
|
|
|
|
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:dataMessage.attachments
|
|
|
|
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:dataMessage.attachments
|
|
|
|
timestamp:envelope.timestamp
|
|
|
|
timestamp:envelope.timestamp
|
|
|
@ -665,6 +656,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage
|
|
|
|
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OWSAssert([TSAccountManager isRegistered]);
|
|
|
|
|
|
|
|
NSString *localNumber = [TSAccountManager localNumber];
|
|
|
|
|
|
|
|
if (![localNumber isEqualToString:messageEnvelope.source]) {
|
|
|
|
|
|
|
|
// Sync messages should only come from linked devices.
|
|
|
|
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorSyncMessageFromUnknownSource], messageEnvelope);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (syncMessage.hasSent) {
|
|
|
|
if (syncMessage.hasSent) {
|
|
|
|
OWSIncomingSentMessageTranscript *transcript =
|
|
|
|
OWSIncomingSentMessageTranscript *transcript =
|
|
|
|
[[OWSIncomingSentMessageTranscript alloc] initWithProto:syncMessage.sent relay:messageEnvelope.relay];
|
|
|
|
[[OWSIncomingSentMessageTranscript alloc] initWithProto:syncMessage.sent relay:messageEnvelope.relay];
|
|
|
@ -777,6 +777,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
enabled:NO
|
|
|
|
enabled:NO
|
|
|
|
durationSeconds:OWSDisappearingMessagesConfigurationDefaultExpirationDuration];
|
|
|
|
durationSeconds:OWSDisappearingMessagesConfigurationDefaultExpirationDuration];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAssert(disappearingMessagesConfiguration);
|
|
|
|
[disappearingMessagesConfiguration save];
|
|
|
|
[disappearingMessagesConfiguration save];
|
|
|
|
NSString *name = [self.contactsManager displayNameForPhoneIdentifier:envelope.source];
|
|
|
|
NSString *name = [self.contactsManager displayNameForPhoneIdentifier:envelope.source];
|
|
|
|
OWSDisappearingConfigurationUpdateInfoMessage *message =
|
|
|
|
OWSDisappearingConfigurationUpdateInfoMessage *message =
|
|
|
@ -798,6 +799,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert(gThread);
|
|
|
|
OWSAssert(gThread);
|
|
|
|
|
|
|
|
OWSAssert(gThread.groupModel);
|
|
|
|
OWSAssert(message);
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
|
|
if (gThread.groupModel.groupImage) {
|
|
|
|
if (gThread.groupModel.groupImage) {
|
|
|
@ -1023,30 +1025,30 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
__block TSErrorMessage *errorMessage;
|
|
|
|
__block TSErrorMessage *errorMessage;
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
if ([exception.name isEqualToString:NoSessionException]) {
|
|
|
|
if ([exception.name isEqualToString:NoSessionException]) {
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_no_session", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorNoSession], envelope);
|
|
|
|
errorMessage = [TSErrorMessage missingSessionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
errorMessage = [TSErrorMessage missingSessionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
} else if ([exception.name isEqualToString:InvalidKeyException]) {
|
|
|
|
} else if ([exception.name isEqualToString:InvalidKeyException]) {
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_invalid_key", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorInvalidKey], envelope);
|
|
|
|
errorMessage = [TSErrorMessage invalidKeyExceptionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
errorMessage = [TSErrorMessage invalidKeyExceptionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
} else if ([exception.name isEqualToString:InvalidKeyIdException]) {
|
|
|
|
} else if ([exception.name isEqualToString:InvalidKeyIdException]) {
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_invalid_key_id", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorInvalidKeyId], envelope);
|
|
|
|
errorMessage = [TSErrorMessage invalidKeyExceptionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
errorMessage = [TSErrorMessage invalidKeyExceptionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
} else if ([exception.name isEqualToString:DuplicateMessageException]) {
|
|
|
|
} else if ([exception.name isEqualToString:DuplicateMessageException]) {
|
|
|
|
// Duplicate messages are dismissed
|
|
|
|
// Duplicate messages are dismissed
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if ([exception.name isEqualToString:InvalidVersionException]) {
|
|
|
|
} else if ([exception.name isEqualToString:InvalidVersionException]) {
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_invalid_message_version", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorInvalidMessageVersion], envelope);
|
|
|
|
errorMessage = [TSErrorMessage invalidVersionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
errorMessage = [TSErrorMessage invalidVersionWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
} else if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
|
|
|
|
} else if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
|
|
|
|
// Should no longer get here, since we now record the new identity for incoming messages.
|
|
|
|
// Should no longer get here, since we now record the new identity for incoming messages.
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_untrusted_identity_key_exception", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorUntrustedIdentityKeyException], envelope);
|
|
|
|
OWSFail(@"%@ Failed to trust identity on incoming message from: %@.%d",
|
|
|
|
OWSFail(@"%@ Failed to trust identity on incoming message from: %@.%d",
|
|
|
|
self.tag,
|
|
|
|
self.tag,
|
|
|
|
envelope.source,
|
|
|
|
envelope.source,
|
|
|
|
envelope.sourceDevice);
|
|
|
|
envelope.sourceDevice);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
OWSProdErrorWEnvelope(@"message_manager_error_corrupt_message", envelope);
|
|
|
|
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorCorruptMessage], envelope);
|
|
|
|
errorMessage = [TSErrorMessage corruptedMessageWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
errorMessage = [TSErrorMessage corruptedMessageWithEnvelope:envelope withTransaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|