Process messages in a single transaction (wherever possible).

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 6fce2c26b7
commit fa353259c3

@ -2598,7 +2598,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
handler:^(UIAlertAction *_Nonnull action) {
OWSAttachmentsProcessor *processor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentPointer:attachmentPointer
networkManager:self.networkManager];
networkManager:self.networkManager
storageManager:self.storageManager];
[processor fetchAttachmentsForMessage:message
storageManager:self.storageManager
success:^(TSAttachmentStream *_Nonnull attachmentStream) {

@ -48,27 +48,27 @@ NS_ASSUME_NONNULL_BEGIN
OWSIncomingSentMessageTranscript *transcript = self.incomingSentMessageTranscript;
DDLogDebug(@"%@ Recording transcript: %@", self.tag, transcript);
TSThread *thread = [transcript threadWithTransaction:transaction];
if (transcript.isEndSessionMessage) {
DDLogInfo(@"%@ EndSession was sent to recipient: %@.", self.tag, transcript.recipientId);
// NOTE: We dispatch_sync() here.
dispatch_sync([OWSDispatch sessionStoreQueue], ^{
dispatch_async([OWSDispatch sessionStoreQueue], ^{
[self.storageManager deleteAllSessionsForContact:transcript.recipientId];
});
[[[TSInfoMessage alloc] initWithTimestamp:transcript.timestamp
inThread:transcript.thread
inThread:thread
messageType:TSInfoMessageTypeSessionDidEnd] saveWithTransaction:transaction];
// Don't continue processing lest we print a bubble for the session reset.
return;
}
TSThread *thread = transcript.thread;
OWSAttachmentsProcessor *attachmentsProcessor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:transcript.attachmentPointerProtos
timestamp:transcript.timestamp
relay:transcript.relay
thread:thread
networkManager:self.networkManager
storageManager:self.storageManager
transaction:transaction];
// TODO group updates. Currently desktop doesn't support group updates, so not a problem yet.

@ -34,13 +34,15 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
relay:(nullable NSString *)relay
thread:(TSThread *)thread
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
transaction:(YapDatabaseReadWriteTransaction *)transaction NS_DESIGNATED_INITIALIZER;
/*
* Retry fetching failed attachment download
*/
- (instancetype)initWithAttachmentPointer:(TSAttachmentPointer *)attachmentPointer
networkManager:(TSNetworkManager *)networkManager NS_DESIGNATED_INITIALIZER;
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager NS_DESIGNATED_INITIALIZER;
- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message
storageManager:(TSStorageManager *)storageManager

@ -32,6 +32,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
@interface OWSAttachmentsProcessor ()
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) NSArray<TSAttachmentPointer *> *supportedAttachmentPointers;
@end
@ -40,6 +41,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
- (instancetype)initWithAttachmentPointer:(TSAttachmentPointer *)attachmentPointer
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
{
self = [super init];
if (!self) {
@ -47,6 +49,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
_networkManager = networkManager;
_storageManager = storageManager;
_supportedAttachmentPointers = @[ attachmentPointer ];
_supportedAttachmentIds = @[ attachmentPointer.uniqueId ];
@ -59,6 +62,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
relay:(nullable NSString *)relay
thread:(TSThread *)thread
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
self = [super init];
@ -67,6 +71,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
_networkManager = networkManager;
_storageManager = storageManager;
NSMutableArray<NSString *> *attachmentIds = [NSMutableArray new];
NSMutableArray<TSAttachmentPointer *> *supportedAttachmentPointers = [NSMutableArray new];

@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@class OWSSignalServiceProtosDataMessage;
@class OWSSignalServiceProtosAttachmentPointer;
@class TSThread;
@class YapDatabaseReadWriteTransaction;
/**
* Represents notification of a message sent on our behalf from another device.
@ -23,7 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) uint64_t timestamp;
@property (nonatomic, readonly) uint64_t expirationStartedAt;
@property (nonatomic, readonly) uint32_t expirationDuration;
@property (nonatomic, readonly) TSThread *thread;
@property (nonatomic, readonly) BOOL isGroupUpdate;
@property (nonatomic, readonly) BOOL isExpirationTimerUpdate;
@property (nonatomic, readonly) BOOL isEndSessionMessage;
@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSString *body;
@property (nonatomic, readonly) NSArray<OWSSignalServiceProtosAttachmentPointer *> *attachmentPointerProtos;
- (TSThread *)threadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
@end
NS_ASSUME_NONNULL_END

@ -3,16 +3,14 @@
//
#import "OWSIncomingSentMessageTranscript.h"
#import "OWSAttachmentsProcessor.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSMessagesManager.h"
#import "TSOutgoingMessage.h"
#import "TSThread.h"
// Thread finding imports
#import "TSContactThread.h"
#import "TSGroupModel.h"
#import "TSGroupThread.h"
#import "TSMessagesManager.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import "TSThread.h"
NS_ASSUME_NONNULL_BEGIN
@ -49,12 +47,12 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (TSThread *)thread
- (TSThread *)threadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
if (self.dataMessage.hasGroup) {
return [TSGroupThread getOrCreateThreadWithGroupIdData:self.dataMessage.group.id];
return [TSGroupThread getOrCreateThreadWithGroupIdData:self.dataMessage.group.id transaction:transaction];
} else {
return [TSContactThread getOrCreateThreadWithContactId:self.recipientId];
return [TSContactThread getOrCreateThreadWithContactId:self.recipientId transaction:transaction];
}
}

@ -1187,6 +1187,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
encryptionException = exception;
}
});
if (encryptionException) {
DDLogInfo(@"%@ Exception during encryption: %@", self.tag, encryptionException);
@throw encryptionException;

@ -678,6 +678,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:envelope.relay
thread:groupThread
networkManager:self.networkManager
storageManager:self.storageManager
transaction:transaction];
if (!attachmentsProcessor.hasSupportedAttachments) {
@ -713,6 +714,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:envelope.relay
thread:thread
networkManager:self.networkManager
storageManager:self.storageManager
transaction:transaction];
if (!attachmentsProcessor.hasSupportedAttachments) {
DDLogWarn(@"%@ received unsupported media envelope", self.tag);

Loading…
Cancel
Save