From be625d8f961b37c10b9ca6f04205ddb2aaa91c18 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 7 Mar 2017 01:36:35 +0300 Subject: [PATCH] no message --- .tx/config | 23 +++++++++ TelegramUI.xcodeproj/project.pbxproj | 4 ++ TelegramUI/ChatHistoryListNode.swift | 26 +++++++++- ...hatMessageThrottledProcessingManager.swift | 49 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 .tx/config create mode 100644 TelegramUI/ChatMessageThrottledProcessingManager.swift diff --git a/.tx/config b/.tx/config new file mode 100644 index 0000000000..9fbe69c828 --- /dev/null +++ b/.tx/config @@ -0,0 +1,23 @@ +[main] +host = https://www.transifex.com + +[iphone-1.descriptiontxt] +file_filter = translations/iphone-1.descriptiontxt/.txt +source_lang = en +type = TXT + +[iphone-1.infopliststrings] +file_filter = translations/iphone-1.infopliststrings/.strings +source_lang = en +type = STRINGS + +[iphone-1.localizablestrings_1] +file_filter = translations/iphone-1.localizablestrings_1/.strings +source_lang = en +type = STRINGS + +[iphone-1.localizablestrings] +file_filter = translations/iphone-1.localizablestrings/.strings +source_lang = en +type = STRINGS + diff --git a/TelegramUI.xcodeproj/project.pbxproj b/TelegramUI.xcodeproj/project.pbxproj index e044f669f3..04f8453533 100644 --- a/TelegramUI.xcodeproj/project.pbxproj +++ b/TelegramUI.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ D00C7CE91E379B820080C3D5 /* ChatSecretAutoremoveTimerActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00C7CE81E379B820080C3D5 /* ChatSecretAutoremoveTimerActionSheet.swift */; }; D00C7CF71E37BF680080C3D5 /* SecretChatKeyVisualization.h in Headers */ = {isa = PBXBuildFile; fileRef = D00C7CF51E37BF680080C3D5 /* SecretChatKeyVisualization.h */; }; D00C7CF81E37BF680080C3D5 /* SecretChatKeyVisualization.m in Sources */ = {isa = PBXBuildFile; fileRef = D00C7CF61E37BF680080C3D5 /* SecretChatKeyVisualization.m */; }; + D00D34371E6E14E30057B307 /* ChatMessageThrottledProcessingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00D34361E6E14E30057B307 /* ChatMessageThrottledProcessingManager.swift */; }; D00DBBDD1E65650800DB5485 /* ChatReportPeerTitlePanelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00DBBDC1E65650800DB5485 /* ChatReportPeerTitlePanelNode.swift */; }; D00E15261DDBD4E700ACF65C /* LegacyCamera.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00E15251DDBD4E700ACF65C /* LegacyCamera.swift */; }; D0105D5A1D80B957008755D8 /* ChatChannelSubscriberInputPanelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0105D591D80B957008755D8 /* ChatChannelSubscriberInputPanelNode.swift */; }; @@ -500,6 +501,7 @@ D00C7CE81E379B820080C3D5 /* ChatSecretAutoremoveTimerActionSheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatSecretAutoremoveTimerActionSheet.swift; sourceTree = ""; }; D00C7CF51E37BF680080C3D5 /* SecretChatKeyVisualization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecretChatKeyVisualization.h; sourceTree = ""; }; D00C7CF61E37BF680080C3D5 /* SecretChatKeyVisualization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecretChatKeyVisualization.m; sourceTree = ""; }; + D00D34361E6E14E30057B307 /* ChatMessageThrottledProcessingManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatMessageThrottledProcessingManager.swift; sourceTree = ""; }; D00DBBDC1E65650800DB5485 /* ChatReportPeerTitlePanelNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatReportPeerTitlePanelNode.swift; sourceTree = ""; }; D00E15251DDBD4E700ACF65C /* LegacyCamera.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyCamera.swift; sourceTree = ""; }; D0105D591D80B957008755D8 /* ChatChannelSubscriberInputPanelNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatChannelSubscriberInputPanelNode.swift; sourceTree = ""; }; @@ -1754,6 +1756,7 @@ D0DE77261D932627002B8809 /* ChatHistoryNode.swift */, D0E7A1BC1D8C246D00C37A6F /* ChatHistoryListNode.swift */, D02BE0701D91814C000889C2 /* ChatHistoryGridNode.swift */, + D00D34361E6E14E30057B307 /* ChatMessageThrottledProcessingManager.swift */, D0DE772C1D934DCB002B8809 /* List Items */, D02BE0751D9190CD000889C2 /* Grid Items */, ); @@ -2663,6 +2666,7 @@ D0528E631E65BECA00E2FEF5 /* UserInfoController.swift in Sources */, D0F69E751D6B8C340046BCD6 /* ContactsPeerItem.swift in Sources */, D01B27991E39144C0022A4C0 /* ItemListController.swift in Sources */, + D00D34371E6E14E30057B307 /* ChatMessageThrottledProcessingManager.swift in Sources */, D0561DE11E57153000E6B9E9 /* ItemListActivityTextItem.swift in Sources */, D0F69DD61D6B8A2D0046BCD6 /* AlertController.swift in Sources */, D00370301DA43077004308D3 /* ItemListItem.swift in Sources */, diff --git a/TelegramUI/ChatHistoryListNode.swift b/TelegramUI/ChatHistoryListNode.swift index 29263b0e15..11e666a393 100644 --- a/TelegramUI/ChatHistoryListNode.swift +++ b/TelegramUI/ChatHistoryListNode.swift @@ -210,6 +210,8 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { private let galleryHiddenMesageAndMediaDisposable = MetaDisposable() + private let messageProcessingManager = ChatMessageThrottledProcessingManager() + public init(account: Account, peerId: PeerId, tagMask: MessageTags?, messageId: MessageId?, controllerInteraction: ChatControllerInteraction, mode: ChatHistoryListMode = .bubbles) { self.account = account self.peerId = peerId @@ -223,6 +225,10 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { //self.debugInfo = true + self.messageProcessingManager.process = { [weak account] messageIds in + account?.viewTracker.updatedViewCountMessageIds(messageIds: messageIds) + } + self.preloadPages = false switch self.mode { case .bubbles: @@ -346,7 +352,25 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { if let strongSelf = self { if let historyView = (opaqueTransactionState as? ChatHistoryTransactionOpaqueState)?.historyView { if let visible = displayedRange.visibleRange { - if let messageIndex = maxIncomingMessageIndexForEntries(historyView.filteredEntries, indexRange: (historyView.filteredEntries.count - 1 - visible.lastIndex, historyView.filteredEntries.count - 1 - visible.firstIndex)) { + let indexRange = (historyView.filteredEntries.count - 1 - visible.lastIndex, historyView.filteredEntries.count - 1 - visible.firstIndex) + + var messageIdsWithViewCount: [MessageId] = [] + for i in (indexRange.0 ... indexRange.1) { + if case let .MessageEntry(message, _) = historyView.filteredEntries[i] { + inner: for attribute in message.attributes { + if attribute is ViewCountMessageAttribute { + messageIdsWithViewCount.append(message.id) + break inner + } + } + } + } + + if !messageIdsWithViewCount.isEmpty { + strongSelf.messageProcessingManager.add(messageIdsWithViewCount) + } + + if let messageIndex = maxIncomingMessageIndexForEntries(historyView.filteredEntries, indexRange: indexRange) { strongSelf.updateMaxVisibleReadIncomingMessageIndex(messageIndex) } } diff --git a/TelegramUI/ChatMessageThrottledProcessingManager.swift b/TelegramUI/ChatMessageThrottledProcessingManager.swift new file mode 100644 index 0000000000..713c3a865c --- /dev/null +++ b/TelegramUI/ChatMessageThrottledProcessingManager.swift @@ -0,0 +1,49 @@ +import Foundation +import Postbox +import SwiftSignalKit + +final class ChatMessageThrottledProcessingManager { + private let queue = Queue(target: Queue.concurrentBackgroundQueue()) + + var process: ((Set) -> Void)? + + private var timer: SwiftSignalKit.Timer? + private var processed = Set() + private var buffer = Set() + + func setProcess(process: @escaping (Set) -> Void) { + self.queue.async { + self.process = process + } + } + + func add(_ messageIds: [MessageId]) { + self.queue.async { + for id in messageIds { + if !self.processed.contains(id) { + self.processed.insert(id) + self.buffer.insert(id) + } + } + + if self.timer == nil { + var completionImpl: (() -> Void)? + let timer = SwiftSignalKit.Timer(timeout: 1.0, repeat: false, completion: { + completionImpl?() + }, queue: self.queue) + completionImpl = { [weak self, weak timer] in + if let strongSelf = self { + if let timer = timer, strongSelf.timer === timer { + strongSelf.timer = nil + } + let buffer = strongSelf.buffer + strongSelf.buffer.removeAll() + strongSelf.process?(buffer) + } + } + self.timer = timer + timer.start() + } + } + } +}