mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			32 lines
		
	
	
		
			867 B
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			32 lines
		
	
	
		
			867 B
		
	
	
	
		
			Swift
		
	
 | 
						|
final class ThreadUpdateBatcher {
 | 
						|
    private var threadIDs: Set<String> = []
 | 
						|
 | 
						|
    private lazy var timer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { [weak self] _ in self?.touch() }
 | 
						|
 | 
						|
    static let shared = ThreadUpdateBatcher()
 | 
						|
 | 
						|
    private init() {
 | 
						|
        DispatchQueue.main.async {
 | 
						|
            SessionUtilitiesKit.touch(self.timer)
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    deinit { timer.invalidate() }
 | 
						|
 | 
						|
    func touch(_ threadID: String) {
 | 
						|
        threadIDs.insert(threadID)
 | 
						|
    }
 | 
						|
 | 
						|
    @objc private func touch() {
 | 
						|
        let threadIDs = self.threadIDs
 | 
						|
        self.threadIDs.removeAll()
 | 
						|
        Storage.write { transaction in
 | 
						|
            for threadID in threadIDs {
 | 
						|
                guard let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) else { return }
 | 
						|
                thread.touch(with: transaction)
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |