From 99e8aa5803db90d4486665f5df2b55629f02eefd Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 12 Sep 2019 10:06:42 +1000 Subject: [PATCH] Clean --- Signal/src/AppDelegate.m | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 7bf576d2e..24377aef7 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1582,12 +1582,11 @@ static NSTimeInterval launchStartedAt; - (void)createGroupChatPollersIfNeeded { - // Make sure thread exists + // Only create the group chat pollers if their threads aren't deleted __block TSGroupThread *thread; - [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { thread = [TSGroupThread threadWithGroupId:[self.lokiPublicChat.id dataUsingEncoding:NSUTF8StringEncoding] transaction:transaction]; }]; - if (thread != nil && self.lokiPublicChatPoller == nil) { self.lokiPublicChatPoller = [[LKGroupChatPoller alloc] initForGroup:self.lokiPublicChat]; } @@ -1595,17 +1594,18 @@ static NSTimeInterval launchStartedAt; - (void)createRSSFeedPollersIfNeeded { - // Make sure thread exists + // Only create the RSS feed pollers if their threads aren't deleted __block TSGroupThread *lokiNewsFeedThread; - [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { lokiNewsFeedThread = [TSGroupThread threadWithGroupId:[self.lokiNewsFeed.id dataUsingEncoding:NSUTF8StringEncoding] transaction:transaction]; }]; if (lokiNewsFeedThread != nil && self.lokiNewsFeedPoller == nil) { self.lokiNewsFeedPoller = [[LKRSSFeedPoller alloc] initForFeed:self.lokiNewsFeed]; } - - // We don't need to check thread for this as it's never deletable - if (self.lokiMessengerUpdatesFeedPoller == nil) { self.lokiMessengerUpdatesFeedPoller = [[LKRSSFeedPoller alloc] initForFeed:self.lokiMessengerUpdatesFeed]; } + // The user can't delete the Loki Messenger Updates RSS feed + if (self.lokiMessengerUpdatesFeedPoller == nil) { + self.lokiMessengerUpdatesFeedPoller = [[LKRSSFeedPoller alloc] initForFeed:self.lokiMessengerUpdatesFeed]; + } } - (void)startGroupChatPollersIfNeeded @@ -1623,17 +1623,13 @@ static NSTimeInterval launchStartedAt; - (void)handleThreadDeleted:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; - NSString *threadId = (NSString *)userInfo[@"threadId"]; - if (threadId == nil) { return; } - - // Check if public chat was deleted - if ([threadId isEqualToString:[TSGroupThread threadIdFromGroupId:[self.lokiPublicChat.id dataUsingEncoding:NSUTF8StringEncoding]]] && self.lokiPublicChatPoller != nil) { + NSString *threadID = (NSString *)userInfo[@"threadId"]; + if (threadID == nil) { return; } + if ([threadID isEqualToString:[TSGroupThread threadIdFromGroupId:[self.lokiPublicChat.id dataUsingEncoding:NSUTF8StringEncoding]]] && self.lokiPublicChatPoller != nil) { [self.lokiPublicChatPoller stop]; self.lokiPublicChatPoller = nil; } - - // Check if news feed was deleted - if ([threadId isEqualToString:[TSGroupThread threadIdFromGroupId:[self.lokiNewsFeed.id dataUsingEncoding:NSUTF8StringEncoding]]] && self.lokiNewsFeedPoller != nil) { + if ([threadID isEqualToString:[TSGroupThread threadIdFromGroupId:[self.lokiNewsFeed.id dataUsingEncoding:NSUTF8StringEncoding]]] && self.lokiNewsFeedPoller != nil) { [self.lokiNewsFeedPoller stop]; self.lokiNewsFeedPoller = nil; }