From d66c8bd427d3230509e04e068b36d0229bbdeda2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 18 Jul 2016 16:00:59 -0700 Subject: [PATCH] Avoid deadlock while accepting new key (#17) Using description in log output crashes when the description is a media message, since printing media description uses a transaction within our existing transaction. Instead we'll use a simpler debugDescription for simple text building, like logging. // FREEBIE --- .clang-format | 10 +++------- src/Contacts/TSThread.m | 4 ++-- src/Messages/Interactions/TSMessage.m | 18 +++++++++++++++--- ...TSInvalidIdentityKeyReceivingErrorMessage.m | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.clang-format b/.clang-format index 0ef36b1e5..6d3ed1c24 100644 --- a/.clang-format +++ b/.clang-format @@ -1,14 +1,10 @@ --- -BasedOnStyle: Chromium -AlignTrailingComments: true -AlignConsecutiveAssignments: true -AllowShortIfStatementsOnASingleLine: false -BreakBeforeBraces: Attach +BasedOnStyle: WebKit +AllowShortFunctionsOnASingleLine: false BinPackArguments: false BinPackParameters: false ColumnLimit: 120 -IndentWidth: 4 -KeepEmptyLinesAtTheStartOfBlocks: false +IndentCaseLabels: true MaxEmptyLinesToKeep: 2 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true diff --git a/src/Contacts/TSThread.m b/src/Contacts/TSThread.m index 56c5a64c5..8be9329b1 100644 --- a/src/Contacts/TSThread.m +++ b/src/Contacts/TSThread.m @@ -21,7 +21,7 @@ @property (nonatomic, retain) NSDate *lastMessageDate; @property (nonatomic, copy) NSString *messageDraft; -- (TSInteraction *) lastInteraction; +- (TSInteraction *)lastInteraction; @end @@ -111,7 +111,7 @@ if (self.lastInteraction == nil) { return @""; } else { - return self.lastInteraction.description; + return [self lastInteraction].description; } } diff --git a/src/Messages/Interactions/TSMessage.m b/src/Messages/Interactions/TSMessage.m index 5cdc9c4f2..66f22342a 100644 --- a/src/Messages/Interactions/TSMessage.m +++ b/src/Messages/Interactions/TSMessage.m @@ -55,13 +55,25 @@ NSString *const TSAttachementsRelationshipEdgeName = @"TSAttachmentEdge"; return self; } -- (BOOL)hasAttachments { +- (BOOL)hasAttachments +{ return self.attachments ? (self.attachments.count > 0) : false; } -- (NSString *)description { +- (NSString *)debugDescription +{ if ([self hasAttachments]) { - NSString *attachmentId = self.attachments[0]; + NSString *attachmentId = self.attachments[0]; + return [NSString stringWithFormat:@"Media Message with attachmentId:%@", attachmentId]; + } else { + return [NSString stringWithFormat:@"Message with body:%@", self.body]; + } +} + +- (NSString *)description +{ + if ([self hasAttachments]) { + NSString *attachmentId = self.attachments[0]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId]; if (attachment) { return attachment.description; diff --git a/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m b/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m index 9005cf06c..f96613a41 100644 --- a/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m +++ b/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m @@ -69,7 +69,7 @@ NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) { TSInteraction *interaction = (TSInteraction *)object; - DDLogVerbose(@"Interaction type: %@", interaction.description); + DDLogVerbose(@"Interaction type: %@", interaction.debugDescription); if ([interaction isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) { TSInvalidIdentityKeyErrorMessage *invalidKeyMessage =