mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Update API
This commit is contained in:
@@ -30,19 +30,46 @@ public enum UpdateAboutError {
|
||||
|
||||
func _internal_updateAbout(account: Account, about: String?) -> Signal<Void, UpdateAboutError> {
|
||||
return account.network.request(Api.functions.account.updateProfile(flags: about == nil ? 0 : (1 << 2), firstName: nil, lastName: nil, about: about))
|
||||
|> mapError { _ -> UpdateAboutError in
|
||||
return .generic
|
||||
|> mapError { _ -> UpdateAboutError in
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { apiUser -> Signal<Void, UpdateAboutError> in
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
transaction.updatePeerCachedData(peerIds: Set([account.peerId]), update: { _, current in
|
||||
if let current = current as? CachedUserData {
|
||||
return current.withUpdatedAbout(about)
|
||||
} else {
|
||||
return current
|
||||
}
|
||||
})
|
||||
}
|
||||
|> castError(UpdateAboutError.self)
|
||||
}
|
||||
}
|
||||
|
||||
public enum UpdateNameColorAndEmojiError {
|
||||
case generic
|
||||
}
|
||||
|
||||
func _internal_updateNameColorAndEmoji(account: Account, nameColor: PeerNameColor, backgroundEmojiId: Int64?) -> Signal<Void, UpdateNameColorAndEmojiError> {
|
||||
let flags: Int32 = (1 << 0)
|
||||
return account.postbox.loadedPeerWithId(account.peerId)
|
||||
|> castError(UpdateNameColorAndEmojiError.self)
|
||||
|> mapToSignal { accountPeer -> Signal<Void, UpdateNameColorAndEmojiError> in
|
||||
guard let accountPeer = accountPeer as? TelegramUser else {
|
||||
return .fail(.generic)
|
||||
}
|
||||
return account.network.request(Api.functions.account.updateColor(flags: flags, color: nameColor.rawValue, backgroundEmojiId: backgroundEmojiId ?? 0))
|
||||
|> mapError { _ -> UpdateNameColorAndEmojiError in
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { apiUser -> Signal<Void, UpdateNameColorAndEmojiError> in
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
updatePeersCustom(transaction: transaction, peers: [accountPeer.withUpdatedNameColor(nameColor).withUpdatedBackgroundEmojiId(backgroundEmojiId)], update: { _, updated in
|
||||
return updated
|
||||
})
|
||||
}
|
||||
|> castError(UpdateNameColorAndEmojiError.self)
|
||||
}
|
||||
|> mapToSignal { apiUser -> Signal<Void, UpdateAboutError> in
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
transaction.updatePeerCachedData(peerIds: Set([account.peerId]), update: { _, current in
|
||||
if let current = current as? CachedUserData {
|
||||
return current.withUpdatedAbout(about)
|
||||
} else {
|
||||
return current
|
||||
}
|
||||
})
|
||||
}
|
||||
|> castError(UpdateAboutError.self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user