Fix threading issue & unnecessary updating

pull/16/head
Niels Andriesse 6 years ago
parent 180c86a940
commit 81d5adc8c8

@ -407,7 +407,7 @@ typedef enum : NSUInteger {
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleThreadFriendRequestStatusChangedNotification:) selector:@selector(handleThreadFriendRequestStatusChangedNotification:)
name:@"threadFriendRequestStatusChanged" name:NSNotification.threadFriendRequestStatusChanged
object:nil]; object:nil];
} }
@ -474,7 +474,12 @@ typedef enum : NSUInteger {
- (void)handleThreadFriendRequestStatusChangedNotification:(NSNotification *)notification - (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]; [self.thread reload];
// Update UI
[self.viewItems.lastObject clearCachedLayoutState]; // Presumably a cell with a friend request view [self.viewItems.lastObject clearCachedLayoutState]; // Presumably a cell with a friend request view
[self resetContentAndLayout]; [self resetContentAndLayout];
[self updateInputToolbar]; [self updateInputToolbar];

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

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

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

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

Loading…
Cancel
Save