diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index a2f8d58cf1..bde01674a8 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 0962E66D21B5C56F00245FD9 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0962E66C21B5C56F00245FD9 /* JSON.swift */; }; 0962E66F21B6147600245FD9 /* AppConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0962E66E21B6147600245FD9 /* AppConfiguration.swift */; }; 0962E67521B6437600245FD9 /* SplitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0962E67421B6437600245FD9 /* SplitTest.swift */; }; + 0962E68121BAA20E00245FD9 /* SearchBotsConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0962E68021BAA20E00245FD9 /* SearchBotsConfiguration.swift */; }; 9F06831021A40DEC001D8EDB /* NotificationExceptionsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06830F21A40DEC001D8EDB /* NotificationExceptionsList.swift */; }; 9F06831121A40DEC001D8EDB /* NotificationExceptionsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06830F21A40DEC001D8EDB /* NotificationExceptionsList.swift */; }; 9F10CE8B20613C78002DD61A /* SecretApiLayer73.swift in Sources */ = {isa = PBXBuildFile; fileRef = D018EDFF2044939F00CBB130 /* SecretApiLayer73.swift */; }; @@ -788,6 +789,7 @@ 0962E66C21B5C56F00245FD9 /* JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; 0962E66E21B6147600245FD9 /* AppConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConfiguration.swift; sourceTree = ""; }; 0962E67421B6437600245FD9 /* SplitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitTest.swift; sourceTree = ""; }; + 0962E68021BAA20E00245FD9 /* SearchBotsConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBotsConfiguration.swift; sourceTree = ""; }; 9F06830F21A40DEC001D8EDB /* NotificationExceptionsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationExceptionsList.swift; sourceTree = ""; }; 9FC8ADAA206BBFF10094F7B4 /* RecentWebSessions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentWebSessions.swift; sourceTree = ""; }; C205FEA71EB3B75900455808 /* ExportMessageLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExportMessageLink.swift; sourceTree = ""; }; @@ -1255,6 +1257,7 @@ D026099D20C695AF006C34AC /* Wallpapers.swift */, D051DB13215EC5A300F30F92 /* AppChangelogState.swift */, 0962E66E21B6147600245FD9 /* AppConfiguration.swift */, + 0962E68021BAA20E00245FD9 /* SearchBotsConfiguration.swift */, ); name = Settings; sourceTree = ""; @@ -2294,6 +2297,7 @@ C2366C891E4F40480097CCFF /* SupportPeerId.swift in Sources */, D0AF32351FAE8C6B0097362B /* MultipeerManager.swift in Sources */, D05A32E11E6F0982002760B4 /* UpdatedAccountPrivacySettings.swift in Sources */, + 0962E68121BAA20E00245FD9 /* SearchBotsConfiguration.swift in Sources */, D003702B1DA42586004308D3 /* PhoneNumber.swift in Sources */, D00BDA1C1EE5952A00C64C5E /* TelegramChannelBannedRights.swift in Sources */, D03B0CF91D62250800955575 /* TelegramMediaMap.swift in Sources */, diff --git a/TelegramCore/AccountManager.swift b/TelegramCore/AccountManager.swift index e75421650e..26f223667a 100644 --- a/TelegramCore/AccountManager.swift +++ b/TelegramCore/AccountManager.swift @@ -123,7 +123,7 @@ private var declaredEncodables: Void = { declareEncodable(AppChangelogState.self, f: { AppChangelogState(decoder: $0) }) declareEncodable(AppConfiguration.self, f: { AppConfiguration(decoder: $0) }) declareEncodable(JSON.self, f: { JSON(decoder: $0) }) - + declareEncodable(SearchBotsConfiguration.self, f: { SearchBotsConfiguration(decoder: $0) }) return }() diff --git a/TelegramCore/ManagedConfigurationUpdates.swift b/TelegramCore/ManagedConfigurationUpdates.swift index f858532d47..2286319da6 100644 --- a/TelegramCore/ManagedConfigurationUpdates.swift +++ b/TelegramCore/ManagedConfigurationUpdates.swift @@ -61,6 +61,8 @@ func managedConfigurationUpdates(postbox: Postbox, network: Network) -> Signal(value: ManagedSynchronizeAppLogEventsOperationsHelper()) - - let peerId = PeerId(namespace: 0, id: 0) - let _ = (postbox.transaction({ t in - t.operationLogRemoveAllEntries(peerId: peerId, tag: tag) - })).start() - + let disposable = postbox.mergedOperationLogView(tag: tag, limit: 50).start(next: { view in let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(PeerMergedOperationLogEntry, MetaDisposable)]) in return helper.update(view.entries) diff --git a/TelegramCore/Namespaces.swift b/TelegramCore/Namespaces.swift index fdc54f48e9..fa208f1b40 100644 --- a/TelegramCore/Namespaces.swift +++ b/TelegramCore/Namespaces.swift @@ -150,6 +150,7 @@ private enum PreferencesKeyValues: Int32 { case appChangelogState = 12 case localizationListState = 13 case appConfiguration = 14 + case searchBotsConfiguration = 15 } public func applicationSpecificPreferencesKey(_ value: Int32) -> ValueBoxKey { @@ -242,6 +243,12 @@ public struct PreferencesKeys { key.setInt32(0, value: PreferencesKeyValues.appConfiguration.rawValue) return key }() + + public static let searchBotsConfiguration: ValueBoxKey = { + let key = ValueBoxKey(length: 4) + key.setInt32(0, value: PreferencesKeyValues.searchBotsConfiguration.rawValue) + return key + }() } private enum SharedDataKeyValues: Int32 { diff --git a/TelegramCore/OutgoingMessageWithChatContextResult.swift b/TelegramCore/OutgoingMessageWithChatContextResult.swift index 039320b151..fa59eee7af 100644 --- a/TelegramCore/OutgoingMessageWithChatContextResult.swift +++ b/TelegramCore/OutgoingMessageWithChatContextResult.swift @@ -12,10 +12,12 @@ private func aspectFitSize(_ size: CGSize, to: CGSize) -> CGSize { return CGSize(width: floor(size.width * scale), height: floor(size.height * scale)) } -public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: ChatContextResultCollection, result: ChatContextResult) -> EnqueueMessage? { +public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: ChatContextResultCollection, result: ChatContextResult, includeViaBot: Bool = true) -> EnqueueMessage? { var attributes: [MessageAttribute] = [] - attributes.append(OutgoingChatContextResultMessageAttribute(queryId: result.queryId, id: result.id)) - attributes.append(InlineBotMessageAttribute(peerId: results.botId, title: nil)) + if includeViaBot { + attributes.append(OutgoingChatContextResultMessageAttribute(queryId: result.queryId, id: result.id)) + attributes.append(InlineBotMessageAttribute(peerId: results.botId, title: nil)) + } switch result.message { case let .auto(caption, entities, replyMarkup): diff --git a/TelegramCore/SearchBotsConfiguration.swift b/TelegramCore/SearchBotsConfiguration.swift new file mode 100644 index 0000000000..31d41bac83 --- /dev/null +++ b/TelegramCore/SearchBotsConfiguration.swift @@ -0,0 +1,67 @@ +import Foundation +#if os(macOS) +import PostboxMac +#else +import Postbox +#endif + +public struct SearchBotsConfiguration: Equatable, PreferencesEntry { + public let imageBotUsername: String? + public let gifBotUsername: String? + public let venueBotUsername: String? + + public static var defaultValue: SearchBotsConfiguration { + return SearchBotsConfiguration(imageBotUsername: "bing", gifBotUsername: "gif", venueBotUsername: "foursquare") + } + + init(imageBotUsername: String?, gifBotUsername: String?, venueBotUsername: String?) { + self.imageBotUsername = imageBotUsername + self.gifBotUsername = gifBotUsername + self.venueBotUsername = venueBotUsername + } + + public init(decoder: PostboxDecoder) { + self.imageBotUsername = decoder.decodeOptionalStringForKey("img") + self.gifBotUsername = decoder.decodeOptionalStringForKey("gif") + self.venueBotUsername = decoder.decodeOptionalStringForKey("venue") + } + + public func encode(_ encoder: PostboxEncoder) { + if let imageBotUsername = self.imageBotUsername { + encoder.encodeString(imageBotUsername, forKey: "img") + } else { + encoder.encodeNil(forKey: "img") + } + if let gifBotUsername = self.gifBotUsername { + encoder.encodeString(gifBotUsername, forKey: "gif") + } else { + encoder.encodeNil(forKey: "gif") + } + if let venueBotUsername = self.venueBotUsername { + encoder.encodeString(venueBotUsername, forKey: "venue") + } else { + encoder.encodeNil(forKey: "venue") + } + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? SearchBotsConfiguration else { + return false + } + return self == to + } +} + +public func currentSearchBotsConfiguration(transaction: Transaction) -> SearchBotsConfiguration { + if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration) as? SearchBotsConfiguration { + return entry + } else { + return SearchBotsConfiguration.defaultValue + } +} + +func updateSearchBotsConfiguration(transaction: Transaction, configuration: SearchBotsConfiguration) { + if !currentSearchBotsConfiguration(transaction: transaction).isEqual(to: configuration) { + transaction.setPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration, value: configuration) + } +}