mirror of https://github.com/oxen-io/session-ios
				
				
				
			Update background polling for SSKs
							parent
							
								
									f11f289f9d
								
							
						
					
					
						commit
						a8b53f6cf3
					
				| @ -0,0 +1,28 @@ | ||||
| import PromiseKit | ||||
| 
 | ||||
| @objc(LKBackgroundPoller) | ||||
| public final class BackgroundPoller : NSObject { | ||||
| 
 | ||||
|     private override init() { } | ||||
| 
 | ||||
|     @objc(pollWithCompletionHandler:) | ||||
|     public static func poll(completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { | ||||
|         var promises: [Promise<Void>] = [] | ||||
|         promises.append(AppEnvironment.shared.messageFetcherJob.run()) // FIXME: It'd be nicer to just use Poller directly | ||||
|         promises.append(contentsOf: ClosedGroupPoller().pollOnce()) | ||||
|         var openGroups: [String:PublicChat] = [:] | ||||
|         Storage.read { transaction in | ||||
|             openGroups = LokiDatabaseUtilities.getAllPublicChats(in: transaction) | ||||
|         } | ||||
|         openGroups.values.forEach { openGroup in | ||||
|             let poller = PublicChatPoller(for: openGroup) | ||||
|             poller.stop() | ||||
|             promises.append(poller.pollForNewMessages()) | ||||
|         } | ||||
|         when(resolved: promises).done { _ in | ||||
|             completionHandler(.newData) | ||||
|         }.catch { _ in | ||||
|             completionHandler(.failed) | ||||
|         } | ||||
|     } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in New Issue