mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
50 lines
1.8 KiB
Swift
50 lines
1.8 KiB
Swift
import Foundation
|
|
import SwiftSignalKit
|
|
import Postbox
|
|
import TelegramApi
|
|
|
|
import SyncCore
|
|
|
|
public enum NotificationTokenType {
|
|
case aps(encrypt: Bool)
|
|
case voip
|
|
}
|
|
|
|
func _internal_unregisterNotificationToken(account: Account, token: Data, type: NotificationTokenType, otherAccountUserIds: [PeerId.Id]) -> Signal<Never, NoError> {
|
|
let mappedType: Int32
|
|
switch type {
|
|
case .aps:
|
|
mappedType = 1
|
|
case .voip:
|
|
mappedType = 9
|
|
}
|
|
return account.network.request(Api.functions.account.unregisterDevice(tokenType: mappedType, token: hexString(token), otherUids: otherAccountUserIds.map({ $0._internalGetInt32Value() })))
|
|
|> retryRequest
|
|
|> ignoreValues
|
|
}
|
|
|
|
func _internal_registerNotificationToken(account: Account, token: Data, type: NotificationTokenType, sandbox: Bool, otherAccountUserIds: [PeerId.Id], excludeMutedChats: Bool) -> Signal<Never, NoError> {
|
|
return masterNotificationsKey(account: account, ignoreDisabled: false)
|
|
|> mapToSignal { masterKey -> Signal<Never, NoError> in
|
|
let mappedType: Int32
|
|
var keyData = Data()
|
|
switch type {
|
|
case let .aps(encrypt):
|
|
mappedType = 1
|
|
if encrypt {
|
|
keyData = masterKey.data
|
|
}
|
|
case .voip:
|
|
mappedType = 9
|
|
keyData = masterKey.data
|
|
}
|
|
var flags: Int32 = 0
|
|
if excludeMutedChats {
|
|
flags |= 1 << 0
|
|
}
|
|
return account.network.request(Api.functions.account.registerDevice(flags: flags, tokenType: mappedType, token: hexString(token), appSandbox: sandbox ? .boolTrue : .boolFalse, secret: Buffer(data: keyData), otherUids: otherAccountUserIds.map({ $0._internalGetInt32Value() })))
|
|
|> retryRequest
|
|
|> ignoreValues
|
|
}
|
|
}
|