Added support for server-provided search bot usernames

This commit is contained in:
Ilya Laktyushin
2018-12-07 22:59:33 +04:00
parent 37c7241974
commit 6372091ab5
7 changed files with 87 additions and 10 deletions

View File

@@ -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 = "<group>"; };
0962E66E21B6147600245FD9 /* AppConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConfiguration.swift; sourceTree = "<group>"; };
0962E67421B6437600245FD9 /* SplitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitTest.swift; sourceTree = "<group>"; };
0962E68021BAA20E00245FD9 /* SearchBotsConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBotsConfiguration.swift; sourceTree = "<group>"; };
9F06830F21A40DEC001D8EDB /* NotificationExceptionsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationExceptionsList.swift; sourceTree = "<group>"; };
9FC8ADAA206BBFF10094F7B4 /* RecentWebSessions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentWebSessions.swift; sourceTree = "<group>"; };
C205FEA71EB3B75900455808 /* ExportMessageLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExportMessageLink.swift; sourceTree = "<group>"; };
@@ -1255,6 +1257,7 @@
D026099D20C695AF006C34AC /* Wallpapers.swift */,
D051DB13215EC5A300F30F92 /* AppChangelogState.swift */,
0962E66E21B6147600245FD9 /* AppConfiguration.swift */,
0962E68021BAA20E00245FD9 /* SearchBotsConfiguration.swift */,
);
name = Settings;
sourceTree = "<group>";
@@ -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 */,

View File

@@ -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
}()

View File

@@ -61,6 +61,8 @@ func managedConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<V
})
updateLimitsConfiguration(transaction: transaction, configuration: LimitsConfiguration(maxGroupMemberCount: config.chatSizeMax, maxSupergroupMemberCount: config.megagroupSizeMax, maxMessageForwardBatchSize: config.forwardedCountMax, maxSavedGifCount: config.savedGifsLimit, maxRecentStickerCount: config.stickersRecentLimit, maxMessageEditingInterval: config.editTimeLimit, maxMediaCaptionLength: config.captionLengthMax, canRemoveIncomingMessagesInPrivateChats: (config.flags & (1 << 6)) != 0))
updateSearchBotsConfiguration(transaction: transaction, configuration: SearchBotsConfiguration(imageBotUsername: config.imgSearchUsername, gifBotUsername: config.gifSearchUsername, venueBotUsername: config.venueSearchUsername))
let (primary, secondary) = getLocalization(transaction)
var invalidateLocalization = false

View File

@@ -74,12 +74,7 @@ func managedSynchronizeAppLogEventsOperations(postbox: Postbox, network: Network
let tag: PeerOperationLogTag = OperationLogTags.SynchronizeAppLogEvents
let helper = Atomic<ManagedSynchronizeAppLogEventsOperationsHelper>(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)

View File

@@ -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 {

View File

@@ -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):

View File

@@ -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)
}
}