Fix threading issue & unnecessary updating

This commit is contained in:
Niels Andriesse 2019-05-20 10:40:39 +10:00
parent 180c86a940
commit 81d5adc8c8
5 changed files with 21 additions and 13 deletions

View File

@ -407,7 +407,7 @@ typedef enum : NSUInteger {
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleThreadFriendRequestStatusChangedNotification:)
name:@"threadFriendRequestStatusChanged"
name:NSNotification.threadFriendRequestStatusChanged
object:nil];
}
@ -474,7 +474,12 @@ typedef enum : NSUInteger {
- (void)handleThreadFriendRequestStatusChangedNotification:(NSNotification *)notification
{
// Check thread
NSString *threadID = (NSString *)notification.object;
if (![threadID isEqualToString:self.thread.uniqueId]) { return; }
// Ensure thread instance is up to date
[self.thread reload];
// Update UI
[self.viewItems.lastObject clearCachedLayoutState]; // Presumably a cell with a friend request view
[self resetContentAndLayout];
[self updateInputToolbar];

View File

@ -703,12 +703,15 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
self.friendRequestStatus = friendRequestStatus;
if (transaction == nil) {
[self save];
[self.dbReadWriteConnection flushTransactionsWithCompletionQueue:dispatch_get_main_queue() completionBlock:^{
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.threadFriendRequestStatusChanged object:self.uniqueId];
}];
} else {
[self saveWithTransaction:transaction];
[transaction.connection flushTransactionsWithCompletionQueue:dispatch_get_main_queue() completionBlock:^{
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.threadFriendRequestStatusChanged object:self.uniqueId];
}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[NSNotificationCenter.defaultCenter postNotificationName:@"threadFriendRequestStatusChanged" object:self.uniqueId];
});
}
- (BOOL)hasPendingFriendRequest

View File

@ -1,4 +1,8 @@
extension Notification.Name {
static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
public extension Notification.Name {
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
}
@objc public extension NSNotification {
@objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString // Obj-C
}

View File

@ -1,10 +1,6 @@
@objc public extension SSKProtoPrekeyBundleMessage {
private var accountManager: TSAccountManager {
return TSAccountManager.sharedInstance()
}
@objc public class func builder(fromPreKeyBundle preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder {
let builder = self.builder()
@ -19,7 +15,7 @@
}
@objc public func createPreKeyBundle(withTransaction transaction: YapDatabaseReadWriteTransaction) -> PreKeyBundle? {
let registrationId = accountManager.getOrGenerateRegistrationId(transaction)
let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId(transaction)
return PreKeyBundle(registrationId: Int32(registrationId),
deviceId: Int32(deviceID),
preKeyId: Int32(prekeyID),

View File

@ -3,11 +3,11 @@
@implementation OWSEphemeralMessage
- (BOOL)shouldBeSaved { return NO; }
+ (OWSEphemeralMessage *)createEmptyOutgoingMessageInThread:(TSThread *)thread {
return [[OWSEphemeralMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new]
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
}
- (BOOL)shouldBeSaved { return NO; }
@end