|
|
|
@ -219,6 +219,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)throws_processEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
plaintextData:(NSData *_Nullable)plaintextData
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
|
if (!envelope) {
|
|
|
|
@ -261,7 +262,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
OWSFailDebug(@"missing decrypted data for envelope: %@", [self descriptionForEnvelope:envelope]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self throws_handleEnvelope:envelope plaintextData:plaintextData transaction:transaction];
|
|
|
|
|
[self throws_handleEnvelope:envelope
|
|
|
|
|
plaintextData:plaintextData
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
break;
|
|
|
|
|
case SSKProtoEnvelopeTypeReceipt:
|
|
|
|
|
OWSAssertDebug(!plaintextData);
|
|
|
|
@ -352,6 +356,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)throws_handleEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
plaintextData:(NSData *)plaintextData
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
|
if (!envelope) {
|
|
|
|
@ -406,7 +411,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
[[OWSDeviceManager sharedManager] setHasReceivedSyncMessage];
|
|
|
|
|
} else if (contentProto.dataMessage) {
|
|
|
|
|
[self handleIncomingEnvelope:envelope withDataMessage:contentProto.dataMessage transaction:transaction];
|
|
|
|
|
[self handleIncomingEnvelope:envelope
|
|
|
|
|
withDataMessage:contentProto.dataMessage
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
} else if (contentProto.callMessage) {
|
|
|
|
|
[self handleIncomingEnvelope:envelope withCallMessage:contentProto.callMessage];
|
|
|
|
|
} else if (contentProto.nullMessage) {
|
|
|
|
@ -427,7 +435,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}
|
|
|
|
|
OWSLogInfo(@"handling message: <DataMessage: %@ />", [self descriptionForDataMessage:dataMessageProto]);
|
|
|
|
|
|
|
|
|
|
[self handleIncomingEnvelope:envelope withDataMessage:dataMessageProto transaction:transaction];
|
|
|
|
|
[self handleIncomingEnvelope:envelope
|
|
|
|
|
withDataMessage:dataMessageProto
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
} else {
|
|
|
|
|
OWSProdInfoWEnvelope([OWSAnalyticsEvents messageManagerErrorEnvelopeNoActionablePayload], envelope);
|
|
|
|
|
}
|
|
|
|
@ -435,6 +446,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)handleIncomingEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
withDataMessage:(SSKProtoDataMessage *)dataMessage
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
|
if (!envelope) {
|
|
|
|
@ -517,9 +529,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
} else if ((dataMessage.flags & SSKProtoDataMessageFlagsProfileKeyUpdate) != 0) {
|
|
|
|
|
[self handleProfileKeyMessageWithEnvelope:envelope dataMessage:dataMessage];
|
|
|
|
|
} else if (dataMessage.attachments.count > 0) {
|
|
|
|
|
[self handleReceivedMediaWithEnvelope:envelope dataMessage:dataMessage transaction:transaction];
|
|
|
|
|
[self handleReceivedMediaWithEnvelope:envelope
|
|
|
|
|
dataMessage:dataMessage
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
} else {
|
|
|
|
|
[self handleReceivedTextMessageWithEnvelope:envelope dataMessage:dataMessage transaction:transaction];
|
|
|
|
|
[self handleReceivedTextMessageWithEnvelope:envelope
|
|
|
|
|
dataMessage:dataMessage
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
|
|
|
|
|
if ([self isDataMessageGroupAvatarUpdate:dataMessage]) {
|
|
|
|
|
OWSLogVerbose(@"Data message had group avatar attachment");
|
|
|
|
@ -528,18 +546,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send delivery receipts for "valid data" messages received via UD.
|
|
|
|
|
BOOL wasReceivedByUD = [self wasReceivedByUD:envelope];
|
|
|
|
|
if (wasReceivedByUD) {
|
|
|
|
|
[self.outgoingReceiptManager enqueueDeliveryReceiptForEnvelope:envelope];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)wasReceivedByUD:(SSKProtoEnvelope *)envelope
|
|
|
|
|
{
|
|
|
|
|
return (
|
|
|
|
|
envelope.type == SSKProtoEnvelopeTypeUnidentifiedSender && (!envelope.hasSource || envelope.source.length < 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)sendGroupInfoRequest:(NSData *)groupId
|
|
|
|
|
envelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
@ -702,6 +713,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)handleReceivedMediaWithEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
dataMessage:(SSKProtoDataMessage *)dataMessage
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
|
if (!envelope) {
|
|
|
|
@ -734,6 +746,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
TSIncomingMessage *_Nullable createdMessage = [self handleReceivedEnvelope:envelope
|
|
|
|
|
withDataMessage:dataMessage
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
attachmentIds:attachmentsProcessor.attachmentIds
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
|
|
|
|
@ -983,6 +996,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)handleReceivedTextMessageWithEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
dataMessage:(SSKProtoDataMessage *)dataMessage
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
|
if (!envelope) {
|
|
|
|
@ -998,7 +1012,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self handleReceivedEnvelope:envelope withDataMessage:dataMessage attachmentIds:@[] transaction:transaction];
|
|
|
|
|
[self handleReceivedEnvelope:envelope
|
|
|
|
|
withDataMessage:dataMessage
|
|
|
|
|
wasReceivedByUD:wasReceivedByUD
|
|
|
|
|
attachmentIds:@[]
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)sendGroupUpdateForThread:(TSGroupThread *)gThread message:(TSOutgoingMessage *)message
|
|
|
|
@ -1106,6 +1124,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (TSIncomingMessage *_Nullable)handleReceivedEnvelope:(SSKProtoEnvelope *)envelope
|
|
|
|
|
withDataMessage:(SSKProtoDataMessage *)dataMessage
|
|
|
|
|
wasReceivedByUD:(BOOL)wasReceivedByUD
|
|
|
|
|
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
|
{
|
|
|
|
@ -1127,7 +1146,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
NSData *groupId = dataMessage.group ? dataMessage.group.id : nil;
|
|
|
|
|
OWSContact *_Nullable contact = [OWSContacts contactForDataMessage:dataMessage transaction:transaction];
|
|
|
|
|
NSNumber *_Nullable serverTimestamp = (envelope.hasServerTimestamp ? @(envelope.serverTimestamp) : nil);
|
|
|
|
|
BOOL wasReceivedByUD = [self wasReceivedByUD:envelope];
|
|
|
|
|
|
|
|
|
|
if (dataMessage.group.type == SSKProtoGroupContextTypeRequestInfo) {
|
|
|
|
|
[self handleGroupInfoRequest:envelope dataMessage:dataMessage transaction:transaction];
|
|
|
|
|