Merge commit 'd554ad5a855819a91622a8a1cbcb568363de22d9'

This commit is contained in:
Peter 2019-03-14 14:03:19 +04:00
commit 4cf1c9184e
7 changed files with 202 additions and 65 deletions

View File

@ -105,6 +105,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1000708810] = { return Api.help.AppUpdate.parse_noAppUpdate($0) }
dict[-209337866] = { return Api.LangPackDifference.parse_langPackDifference($0) }
dict[-1590738760] = { return Api.WallPaperSettings.parse_wallPaperSettings($0) }
dict[1152191385] = { return Api.EmojiURL.parse_EmojiURL($0) }
dict[-791039645] = { return Api.channels.ChannelParticipant.parse_channelParticipant($0) }
dict[-1736378792] = { return Api.InputCheckPasswordSRP.parse_inputCheckPasswordEmpty($0) }
dict[-763367294] = { return Api.InputCheckPasswordSRP.parse_inputCheckPasswordSRP($0) }
@ -157,6 +158,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[1343122938] = { return Api.PrivacyKey.parse_privacyKeyChatInvite($0) }
dict[1030105979] = { return Api.PrivacyKey.parse_privacyKeyPhoneCall($0) }
dict[961092808] = { return Api.PrivacyKey.parse_privacyKeyPhoneP2P($0) }
dict[1777096355] = { return Api.PrivacyKey.parse_privacyKeyForwards($0) }
dict[-1777000467] = { return Api.PrivacyKey.parse_privacyKeyProfilePhoto($0) }
dict[522914557] = { return Api.Update.parse_updateNewMessage($0) }
dict[1318109142] = { return Api.Update.parse_updateMessageID($0) }
dict[-1576161051] = { return Api.Update.parse_updateDeleteMessages($0) }
@ -413,12 +416,14 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1107622874] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyChatInvite($0) }
dict[-88417185] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneCall($0) }
dict[-610373422] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneP2P($0) }
dict[-1529000952] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyForwards($0) }
dict[1461304012] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyProfilePhoto($0) }
dict[235081943] = { return Api.help.RecentMeUrls.parse_recentMeUrls($0) }
dict[-1606526075] = { return Api.ReplyMarkup.parse_replyKeyboardHide($0) }
dict[-200242528] = { return Api.ReplyMarkup.parse_replyKeyboardForceReply($0) }
dict[889353612] = { return Api.ReplyMarkup.parse_replyKeyboardMarkup($0) }
dict[1218642516] = { return Api.ReplyMarkup.parse_replyInlineMarkup($0) }
dict[2147310185] = { return Api.EmojiKeywordsDifference.parse_emojiKeywordsDifference($0) }
dict[1556570557] = { return Api.EmojiKeywordsDifference.parse_emojiKeywordsDifference($0) }
dict[1493171408] = { return Api.HighScore.parse_highScore($0) }
dict[-305282981] = { return Api.TopPeer.parse_topPeer($0) }
dict[986597452] = { return Api.contacts.Link.parse_link($0) }
@ -847,6 +852,8 @@ struct Api {
_1.serialize(buffer, boxed)
case let _1 as Api.WallPaperSettings:
_1.serialize(buffer, boxed)
case let _1 as Api.EmojiURL:
_1.serialize(buffer, boxed)
case let _1 as Api.channels.ChannelParticipant:
_1.serialize(buffer, boxed)
case let _1 as Api.InputCheckPasswordSRP:

View File

@ -2882,6 +2882,40 @@ extension Api {
}
}
}
enum EmojiURL: TypeConstructorDescription {
case EmojiURL(url: String)
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .EmojiURL(let url):
if boxed {
buffer.appendInt32(1152191385)
}
serializeString(url, buffer: buffer, boxed: false)
break
}
}
func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .EmojiURL(let url):
return ("EmojiURL", [("url", url)])
}
}
static func parse_EmojiURL(_ reader: BufferReader) -> EmojiURL? {
var _1: String?
_1 = parseString(reader)
let _c1 = _1 != nil
if _c1 {
return Api.EmojiURL.EmojiURL(url: _1!)
}
else {
return nil
}
}
}
enum InputCheckPasswordSRP: TypeConstructorDescription {
case inputCheckPasswordEmpty
@ -3678,6 +3712,8 @@ extension Api {
case privacyKeyChatInvite
case privacyKeyPhoneCall
case privacyKeyPhoneP2P
case privacyKeyForwards
case privacyKeyProfilePhoto
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
@ -3704,6 +3740,18 @@ extension Api {
buffer.appendInt32(961092808)
}
break
case .privacyKeyForwards:
if boxed {
buffer.appendInt32(1777096355)
}
break
case .privacyKeyProfilePhoto:
if boxed {
buffer.appendInt32(-1777000467)
}
break
}
}
@ -3718,6 +3766,10 @@ extension Api {
return ("privacyKeyPhoneCall", [])
case .privacyKeyPhoneP2P:
return ("privacyKeyPhoneP2P", [])
case .privacyKeyForwards:
return ("privacyKeyForwards", [])
case .privacyKeyProfilePhoto:
return ("privacyKeyProfilePhoto", [])
}
}
@ -3733,6 +3785,12 @@ extension Api {
static func parse_privacyKeyPhoneP2P(_ reader: BufferReader) -> PrivacyKey? {
return Api.PrivacyKey.privacyKeyPhoneP2P
}
static func parse_privacyKeyForwards(_ reader: BufferReader) -> PrivacyKey? {
return Api.PrivacyKey.privacyKeyForwards
}
static func parse_privacyKeyProfilePhoto(_ reader: BufferReader) -> PrivacyKey? {
return Api.PrivacyKey.privacyKeyProfilePhoto
}
}
enum Update: TypeConstructorDescription {
@ -10100,6 +10158,8 @@ extension Api {
case inputPrivacyKeyChatInvite
case inputPrivacyKeyPhoneCall
case inputPrivacyKeyPhoneP2P
case inputPrivacyKeyForwards
case inputPrivacyKeyProfilePhoto
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
@ -10126,6 +10186,18 @@ extension Api {
buffer.appendInt32(-610373422)
}
break
case .inputPrivacyKeyForwards:
if boxed {
buffer.appendInt32(-1529000952)
}
break
case .inputPrivacyKeyProfilePhoto:
if boxed {
buffer.appendInt32(1461304012)
}
break
}
}
@ -10140,6 +10212,10 @@ extension Api {
return ("inputPrivacyKeyPhoneCall", [])
case .inputPrivacyKeyPhoneP2P:
return ("inputPrivacyKeyPhoneP2P", [])
case .inputPrivacyKeyForwards:
return ("inputPrivacyKeyForwards", [])
case .inputPrivacyKeyProfilePhoto:
return ("inputPrivacyKeyProfilePhoto", [])
}
}
@ -10155,6 +10231,12 @@ extension Api {
static func parse_inputPrivacyKeyPhoneP2P(_ reader: BufferReader) -> InputPrivacyKey? {
return Api.InputPrivacyKey.inputPrivacyKeyPhoneP2P
}
static func parse_inputPrivacyKeyForwards(_ reader: BufferReader) -> InputPrivacyKey? {
return Api.InputPrivacyKey.inputPrivacyKeyForwards
}
static func parse_inputPrivacyKeyProfilePhoto(_ reader: BufferReader) -> InputPrivacyKey? {
return Api.InputPrivacyKey.inputPrivacyKeyProfilePhoto
}
}
enum ReplyMarkup: TypeConstructorDescription {
@ -10268,14 +10350,15 @@ extension Api {
}
enum EmojiKeywordsDifference: TypeConstructorDescription {
case emojiKeywordsDifference(fromVersion: Int32, version: Int32, keywords: [Api.EmojiKeyword])
case emojiKeywordsDifference(langCode: String, fromVersion: Int32, version: Int32, keywords: [Api.EmojiKeyword])
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .emojiKeywordsDifference(let fromVersion, let version, let keywords):
case .emojiKeywordsDifference(let langCode, let fromVersion, let version, let keywords):
if boxed {
buffer.appendInt32(2147310185)
buffer.appendInt32(1556570557)
}
serializeString(langCode, buffer: buffer, boxed: false)
serializeInt32(fromVersion, buffer: buffer, boxed: false)
serializeInt32(version, buffer: buffer, boxed: false)
buffer.appendInt32(481674261)
@ -10289,25 +10372,28 @@ extension Api {
func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .emojiKeywordsDifference(let fromVersion, let version, let keywords):
return ("emojiKeywordsDifference", [("fromVersion", fromVersion), ("version", version), ("keywords", keywords)])
case .emojiKeywordsDifference(let langCode, let fromVersion, let version, let keywords):
return ("emojiKeywordsDifference", [("langCode", langCode), ("fromVersion", fromVersion), ("version", version), ("keywords", keywords)])
}
}
static func parse_emojiKeywordsDifference(_ reader: BufferReader) -> EmojiKeywordsDifference? {
var _1: Int32?
_1 = reader.readInt32()
var _1: String?
_1 = parseString(reader)
var _2: Int32?
_2 = reader.readInt32()
var _3: [Api.EmojiKeyword]?
var _3: Int32?
_3 = reader.readInt32()
var _4: [Api.EmojiKeyword]?
if let _ = reader.readInt32() {
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.EmojiKeyword.self)
_4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.EmojiKeyword.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
if _c1 && _c2 && _c3 {
return Api.EmojiKeywordsDifference.emojiKeywordsDifference(fromVersion: _1!, version: _2!, keywords: _3!)
let _c4 = _4 != nil
if _c1 && _c2 && _c3 && _c4 {
return Api.EmojiKeywordsDifference.emojiKeywordsDifference(langCode: _1!, fromVersion: _2!, version: _3!, keywords: _4!)
}
else {
return nil

View File

@ -2875,6 +2875,20 @@ extension Api {
return result
})
}
static func getEmojiURL(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.EmojiURL>) {
let buffer = Buffer()
buffer.appendInt32(-709817306)
serializeString(langCode, buffer: buffer, boxed: false)
return (FunctionDescription(name: "messages.getEmojiURL", parameters: [("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiURL? in
let reader = BufferReader(buffer)
var result: Api.EmojiURL?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.EmojiURL
}
return result
})
}
}
struct channels {
static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {

View File

@ -11,7 +11,7 @@ public final class NotificationExceptionsList : Equatable {
public let peers: [PeerId: Peer]
public let settings: [PeerId: TelegramPeerNotificationSettings]
init(_ peers:[PeerId: Peer], _ settings: [PeerId : TelegramPeerNotificationSettings]) {
init(peers: [PeerId: Peer], settings: [PeerId: TelegramPeerNotificationSettings]) {
self.peers = peers
self.settings = settings
}
@ -21,7 +21,6 @@ public final class NotificationExceptionsList : Equatable {
}
}
public func notificationExceptionsList(network: Network) -> Signal<NotificationExceptionsList, NoError> {
return network.request(Api.functions.account.getNotifyExceptions(flags: 1 << 1, peer: nil)) |> retryRequest |> map { result in
switch result {
@ -62,9 +61,9 @@ public func notificationExceptionsList(network: Network) -> Signal<NotificationE
}
}
return NotificationExceptionsList(peers, settings)
return NotificationExceptionsList(peers: peers, settings: settings)
default:
return NotificationExceptionsList([:], [:])
return NotificationExceptionsList(peers: [:], settings: [:])
}
}
}

View File

@ -61,14 +61,18 @@ public struct AccountPrivacySettings: Equatable {
public let groupInvitations: SelectivePrivacySettings
public let voiceCalls: SelectivePrivacySettings
public let voiceCallsP2P: SelectivePrivacySettings
public let profilePhoto: SelectivePrivacySettings
public let forwards: SelectivePrivacySettings
public let accountRemovalTimeout: Int32
public init(presence: SelectivePrivacySettings, groupInvitations: SelectivePrivacySettings, voiceCalls: SelectivePrivacySettings, voiceCallsP2P: SelectivePrivacySettings, accountRemovalTimeout: Int32) {
public init(presence: SelectivePrivacySettings, groupInvitations: SelectivePrivacySettings, voiceCalls: SelectivePrivacySettings, voiceCallsP2P: SelectivePrivacySettings, profilePhoto: SelectivePrivacySettings, forwards: SelectivePrivacySettings, accountRemovalTimeout: Int32) {
self.presence = presence
self.groupInvitations = groupInvitations
self.voiceCalls = voiceCalls
self.voiceCallsP2P = voiceCallsP2P
self.profilePhoto = profilePhoto
self.forwards = forwards
self.accountRemovalTimeout = accountRemovalTimeout
}
@ -85,7 +89,12 @@ public struct AccountPrivacySettings: Equatable {
if lhs.voiceCallsP2P != rhs.voiceCallsP2P {
return false
}
if lhs.profilePhoto != rhs.profilePhoto {
return false
}
if lhs.forwards != rhs.forwards {
return false
}
if lhs.accountRemovalTimeout != rhs.accountRemovalTimeout {
return false
}

View File

@ -1,26 +1,26 @@
public func dataSizeString(_ size: Int, forceDecimal: Bool = false) -> String {
return dataSizeString(Int64(size), forceDecimal: forceDecimal)
public func dataSizeString(_ size: Int, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String {
return dataSizeString(Int64(size), forceDecimal: forceDecimal, decimalSeparator: decimalSeparator)
}
public func dataSizeString(_ size: Int64, forceDecimal: Bool = false) -> String {
public func dataSizeString(_ size: Int64, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String {
if size >= 1024 * 1024 * 1024 {
let remainder = (size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102)
let remainder = Int64((Double(size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102.4)).rounded(.down))
if remainder != 0 || forceDecimal {
return "\(size / (1024 * 1024 * 1024)),\(remainder) GB"
return "\(size / (1024 * 1024 * 1024))\(decimalSeparator)\(remainder) GB"
} else {
return "\(size / (1024 * 1024 * 1024)) GB"
}
} else if size >= 1024 * 1024 {
let remainder = (size % (1024 * 1024)) / (1024 * 102)
let remainder = Int64((Double(size % (1024 * 1024)) / (1024.0 * 102.4)).rounded(.down))
if remainder != 0 || forceDecimal {
return "\(size / (1024 * 1024)),\(remainder) MB"
return "\(size / (1024 * 1024))\(decimalSeparator)\(remainder) MB"
} else {
return "\(size / (1024 * 1024)) MB"
}
} else if size >= 1024 {
let remainder = (size % (1024)) / (102)
if remainder != 0 || forceDecimal {
return "\(size / 1024),\(remainder) KB"
return "\(size / 1024)\(decimalSeparator)\(remainder) KB"
} else {
return "\(size / 1024) KB"
}

View File

@ -12,10 +12,12 @@ public func requestAccountPrivacySettings(account: Account) -> Signal<AccountPri
let groupPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyChatInvite))
let voiceCallPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyPhoneCall))
let voiceCallP2P = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyPhoneP2P))
let profilePhotoPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyProfilePhoto))
let forwardPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyForwards))
let autoremoveTimeout = account.network.request(Api.functions.account.getAccountTTL())
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, autoremoveTimeout)
return combineLatest(lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, autoremoveTimeout)
|> retryRequest
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, autoremoveTimeout -> Signal<AccountPrivacySettings, NoError> in
|> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, autoremoveTimeout -> Signal<AccountPrivacySettings, NoError> in
let accountTimeoutSeconds: Int32
switch autoremoveTimeout {
case let .accountDaysTTL(days):
@ -27,6 +29,8 @@ public func requestAccountPrivacySettings(account: Account) -> Signal<AccountPri
let groupRules: [Api.PrivacyRule]
let voiceRules: [Api.PrivacyRule]
let voiceP2PRules: [Api.PrivacyRule]
let profilePhotoRules: [Api.PrivacyRule]
let forwardRules: [Api.PrivacyRule]
var apiUsers: [Api.User] = []
switch lastSeenPrivacy {
@ -53,6 +57,18 @@ public func requestAccountPrivacySettings(account: Account) -> Signal<AccountPri
voiceP2PRules = rules
}
switch profilePhotoPrivacy {
case let .privacyRules(rules, users):
apiUsers.append(contentsOf: users)
profilePhotoRules = rules
}
switch forwardPrivacy {
case let .privacyRules(rules, users):
apiUsers.append(contentsOf: users)
forwardRules = rules
}
let peers = apiUsers.map { TelegramUser(user: $0) }
return account.postbox.transaction { transaction -> AccountPrivacySettings in
@ -60,7 +76,7 @@ public func requestAccountPrivacySettings(account: Account) -> Signal<AccountPri
return updated
})
return AccountPrivacySettings(presence: SelectivePrivacySettings(apiRules: lastSeenRules), groupInvitations: SelectivePrivacySettings(apiRules: groupRules), voiceCalls: SelectivePrivacySettings(apiRules: voiceRules), voiceCallsP2P: SelectivePrivacySettings(apiRules: voiceP2PRules), accountRemovalTimeout: accountTimeoutSeconds)
return AccountPrivacySettings(presence: SelectivePrivacySettings(apiRules: lastSeenRules), groupInvitations: SelectivePrivacySettings(apiRules: groupRules), voiceCalls: SelectivePrivacySettings(apiRules: voiceRules), voiceCallsP2P: SelectivePrivacySettings(apiRules: voiceP2PRules), profilePhoto: SelectivePrivacySettings(apiRules: profilePhotoRules), forwards: SelectivePrivacySettings(apiRules: forwardRules), accountRemovalTimeout: accountTimeoutSeconds)
}
}
}
@ -78,6 +94,8 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
case groupInvitations
case voiceCalls
case voiceCallsP2P
case profilePhoto
case forwards
var apiKey: Api.InputPrivacyKey {
switch self {
@ -89,6 +107,10 @@ public enum UpdateSelectiveAccountPrivacySettingsType {
return .inputPrivacyKeyPhoneCall
case .voiceCallsP2P:
return .inputPrivacyKeyPhoneP2P
case .profilePhoto:
return .inputPrivacyKeyProfilePhoto
case .forwards:
return .inputPrivacyKeyForwards
}
}
}