Stop polling upon deleting group chat.

Also don't create poller if thread has been deleted.
pull/49/head
Mikunj 6 years ago
parent c780023d63
commit f7039809a7

@ -321,6 +321,9 @@ static NSTimeInterval launchStartedAt;
// Loki - Observe messages received notifications // Loki - Observe messages received notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNewMessagesReceived:) name:NSNotification.newMessagesReceived object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNewMessagesReceived:) name:NSNotification.newMessagesReceived object:nil];
// Loki - Observe thread deletion notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleThreadDeleted:) name:NSNotification.threadDeleted object:nil];
OWSLogInfo(@"application: didFinishLaunchingWithOptions completed."); OWSLogInfo(@"application: didFinishLaunchingWithOptions completed.");
@ -1579,26 +1582,61 @@ static NSTimeInterval launchStartedAt;
- (void)createGroupChatPollersIfNeeded - (void)createGroupChatPollersIfNeeded
{ {
if (self.lokiPublicChatPoller == nil) { self.lokiPublicChatPoller = [[LKGroupChatPoller alloc] initForGroup:self.lokiPublicChat]; } // Make sure thread exists
__block TSGroupThread *thread;
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [TSGroupThread threadWithGroupId:[self.lokiPublicChat.id dataUsingEncoding:NSUTF8StringEncoding] transaction:transaction];
}];
if (thread != nil && self.lokiPublicChatPoller == nil) {
self.lokiPublicChatPoller = [[LKGroupChatPoller alloc] initForGroup:self.lokiPublicChat];
}
} }
- (void)createRSSFeedPollersIfNeeded - (void)createRSSFeedPollersIfNeeded
{ {
if (self.lokiNewsFeedPoller == nil) { self.lokiNewsFeedPoller = [[LKRSSFeedPoller alloc] initForFeed:self.lokiNewsFeed]; } // Make sure thread exists
__block TSGroupThread *lokiNewsFeedThread;
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *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]; } if (self.lokiMessengerUpdatesFeedPoller == nil) { self.lokiMessengerUpdatesFeedPoller = [[LKRSSFeedPoller alloc] initForFeed:self.lokiMessengerUpdatesFeed]; }
} }
- (void)startGroupChatPollersIfNeeded - (void)startGroupChatPollersIfNeeded
{ {
[self createGroupChatPollersIfNeeded]; [self createGroupChatPollersIfNeeded];
[self.lokiPublicChatPoller startIfNeeded]; if (self.lokiPublicChatPoller != nil) { [self.lokiPublicChatPoller startIfNeeded]; }
} }
- (void)startRSSFeedPollersIfNeeded - (void)startRSSFeedPollersIfNeeded
{ {
[self createRSSFeedPollersIfNeeded]; [self createRSSFeedPollersIfNeeded];
[self.lokiNewsFeedPoller startIfNeeded]; if (self.lokiNewsFeedPoller != nil) { [self.lokiNewsFeedPoller startIfNeeded]; }
[self.lokiMessengerUpdatesFeedPoller startIfNeeded]; if (self.lokiMessengerUpdatesFeedPoller != nil) { [self.lokiMessengerUpdatesFeedPoller startIfNeeded]; }
}
- (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) {
[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) {
[self.lokiNewsFeedPoller stop];
self.lokiNewsFeedPoller = nil;
}
} }
@end @end

@ -1413,6 +1413,8 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
- (void)deleteThread:(TSThread *)thread - (void)deleteThread:(TSThread *)thread
{ {
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
/* Loki: Orignal Code
=====================
if ([thread isKindOfClass:[TSGroupThread class]]) { if ([thread isKindOfClass:[TSGroupThread class]]) {
TSGroupThread *groupThread = (TSGroupThread *)thread; TSGroupThread *groupThread = (TSGroupThread *)thread;
if (groupThread.isLocalUserInGroup) { if (groupThread.isLocalUserInGroup) {
@ -1420,10 +1422,15 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
return; return;
} }
} }
*/
// Loki: For now hard delete all groups
[thread removeWithTransaction:transaction]; [thread removeWithTransaction:transaction];
}]; }];
// Loki - Post notification
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.threadDeleted object:nil userInfo:@{ @"threadId": thread.uniqueId }];
[self updateViewState]; [self updateViewState];
} }

@ -4,6 +4,7 @@ public extension Notification.Name {
public static let newMessagesReceived = Notification.Name("newMessagesReceived") public static let newMessagesReceived = Notification.Name("newMessagesReceived")
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged") public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged") public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged")
public static let threadDeleted = Notification.Name("threadDeleted")
} }
// MARK: - Obj-C // MARK: - Obj-C
@ -13,4 +14,5 @@ public extension Notification.Name {
@objc public static let newMessagesReceived = Notification.Name.newMessagesReceived.rawValue as NSString @objc public static let newMessagesReceived = Notification.Name.newMessagesReceived.rawValue as NSString
@objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString @objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString
@objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.rawValue as NSString @objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.rawValue as NSString
@objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString
} }

Loading…
Cancel
Save