Add 'is ud' property to outgoing messages.

This commit is contained in:
Matthew Chen 2018-10-10 10:27:29 -04:00
parent cba8c67983
commit a6eed30127
5 changed files with 18 additions and 10 deletions

View File

@ -4249,7 +4249,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
contactShare:nil];
[message saveWithTransaction:transaction];
[message updateWithFakeMessageState:TSOutgoingMessageStateSent transaction:transaction];
[message updateWithSentRecipient:recipientId transaction:transaction];
[message updateWithSentRecipient:recipientId wasSentByUD:NO transaction:transaction];
[message updateWithDeliveredRecipient:recipientId deliveryTimestamp:timestamp transaction:transaction];
[message updateWithReadRecipientId:recipientId
readTimestamp:timestamp.unsignedLongLongValue

View File

@ -62,6 +62,8 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
// This property should only be set if state == .sent.
@property (atomic, nullable, readonly) NSNumber *readTimestamp;
@property (atomic, readonly) BOOL wasSentByUD;
@end
#pragma mark -
@ -167,7 +169,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
#pragma mark - Update With... Methods
// This method is used to record a successful send to one recipient.
- (void)updateWithSentRecipient:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithSentRecipient:(NSString *)recipientId
wasSentByUD:(BOOL)wasSentByUD
transaction:(YapDatabaseReadWriteTransaction *)transaction;
// This method is used to record a skipped send to one recipient.
- (void)updateWithSkippedRecipient:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction;

View File

@ -60,6 +60,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
@property (atomic) OWSOutgoingMessageRecipientState state;
@property (atomic, nullable) NSNumber *deliveryTimestamp;
@property (atomic, nullable) NSNumber *readTimestamp;
@property (atomic) BOOL wasSentByUD;
@end
@ -637,8 +638,9 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}];
}
- (void)updateWithSentRecipient:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction
{
- (void)updateWithSentRecipient:(NSString *)recipientId
wasSentByUD:(BOOL)wasSentByUD
transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSAssertDebug(recipientId.length > 0);
OWSAssertDebug(transaction);
@ -651,6 +653,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return;
}
recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.wasSentByUD |= wasSentByUD;
}];
}

View File

@ -1001,7 +1001,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messages:deviceMessages
timeStamp:message.timestamp
unidentifiedAccess:messageSend.unidentifiedAccess];
OWSWebSocketType webSocketType = (isUDSend ? OWSWebSocketTypeUD : OWSWebSocketTypeDefault);
BOOL canMakeWebsocketRequests = ([TSSocketManager.shared canMakeRequestsOfType:webSocketType] &&
!messageSend.hasWebsocketSendFailed);
@ -1009,7 +1008,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[TSSocketManager.shared makeRequest:request
webSocketType:webSocketType
success:^(id _Nullable responseObject) {
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages];
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:isUDSend];
}
failure:^(NSInteger statusCode, NSData *_Nullable responseData, NSError *error) {
dispatch_async([OWSDispatch sendingQueue], ^{
@ -1038,7 +1037,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} else {
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages];
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:isUDSend];
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
@ -1069,7 +1068,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (void)messageSendDidSucceed:(OWSMessageSend *)messageSend
deviceMessages:(NSArray<NSDictionary *> *)deviceMessages
{
wasSentByUD:(BOOL)wasSentByUD {
OWSAssertDebug(messageSend);
OWSAssertDebug(deviceMessages);
@ -1091,7 +1090,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
dispatch_async([OWSDispatch sendingQueue], ^{
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[messageSend.message updateWithSentRecipient:messageSend.recipient.uniqueId transaction:transaction];
[messageSend.message updateWithSentRecipient:messageSend.recipient.uniqueId
wasSentByUD:wasSentByUD
transaction:transaction];
// If we've just delivered a message to a user, we know they
// have a valid Signal account.

View File

@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
quotedMessage:nil
contactShare:nil];
[self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[message updateWithSentRecipient:self.contactId transaction:transaction];
[message updateWithSentRecipient:self.contactId wasSentByUD:NO transaction:transaction];
XCTAssertTrue([message shouldStartExpireTimerWithTransaction:transaction]);
}];
}