mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge commit 'f11c45070e5e533f6f4077cc9f7708afd443538b' into HEAD
This commit is contained in:
@@ -64,6 +64,9 @@ extension TelegramUser {
|
||||
if (flags & (1 << 28)) != 0 {
|
||||
userFlags.insert(.isPremium)
|
||||
}
|
||||
if (flags2 & (1 << 2)) != 0 {
|
||||
userFlags.insert(.isCloseFriend)
|
||||
}
|
||||
|
||||
var botInfo: BotUserInfo?
|
||||
if (flags & (1 << 14)) != 0 {
|
||||
@@ -96,7 +99,7 @@ extension TelegramUser {
|
||||
|
||||
static func merge(_ lhs: TelegramUser?, rhs: Api.User) -> TelegramUser? {
|
||||
switch rhs {
|
||||
case let .user(flags, _, _, rhsAccessHash, _, _, _, _, photo, _, _, restrictionReason, botInlinePlaceholder, _, emojiStatus, _):
|
||||
case let .user(flags, flags2, _, rhsAccessHash, _, _, _, _, photo, _, _, restrictionReason, botInlinePlaceholder, _, emojiStatus, _):
|
||||
let isMin = (flags & (1 << 20)) != 0
|
||||
if !isMin {
|
||||
return TelegramUser(user: rhs)
|
||||
@@ -129,6 +132,9 @@ extension TelegramUser {
|
||||
if (flags & (1 << 28)) != 0 {
|
||||
userFlags.insert(.isPremium)
|
||||
}
|
||||
if (flags2 & (1 << 2)) != 0 {
|
||||
userFlags.insert(.isCloseFriend)
|
||||
}
|
||||
|
||||
var botInfo: BotUserInfo?
|
||||
if (flags & (1 << 14)) != 0 {
|
||||
|
||||
@@ -16,6 +16,7 @@ public struct UserInfoFlags: OptionSet {
|
||||
public static let isScam = UserInfoFlags(rawValue: (1 << 2))
|
||||
public static let isFake = UserInfoFlags(rawValue: (1 << 3))
|
||||
public static let isPremium = UserInfoFlags(rawValue: (1 << 4))
|
||||
public static let isCloseFriend = UserInfoFlags(rawValue: (1 << 5))
|
||||
}
|
||||
|
||||
public struct BotUserInfoFlags: OptionSet {
|
||||
@@ -351,4 +352,8 @@ public final class TelegramUser: Peer, Equatable {
|
||||
public func withUpdatedEmojiStatus(_ emojiStatus: PeerEmojiStatus?) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags, emojiStatus: emojiStatus, usernames: self.usernames)
|
||||
}
|
||||
|
||||
public func withUpdatedFlags(_ flags: UserInfoFlags) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags, emojiStatus: emojiStatus, usernames: self.usernames)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
import TelegramApi
|
||||
import MtProtoKit
|
||||
|
||||
public func _internal_updateCloseFriends(account: Account, peerIds: [EnginePeer.Id]) -> Signal<Never, NoError> {
|
||||
let ids: [Int64] = peerIds.map { $0.id._internalGetInt64Value() }
|
||||
return account.network.request(Api.functions.contacts.editCloseFriends(id: ids))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||
return account.postbox.transaction { transaction in
|
||||
let contactPeerIds = transaction.getContactPeerIds()
|
||||
var updatedPeers: [Peer] = []
|
||||
for peerId in contactPeerIds {
|
||||
if let peer = transaction.getPeer(peerId) as? TelegramUser {
|
||||
if peerIds.contains(peerId) {
|
||||
var updatedFlags = peer.flags
|
||||
updatedFlags.insert(.isCloseFriend)
|
||||
let updatedPeer = peer.withUpdatedFlags(updatedFlags)
|
||||
updatedPeers.append(updatedPeer)
|
||||
} else if peer.flags.contains(.isCloseFriend) {
|
||||
var updatedFlags = peer.flags
|
||||
updatedFlags.remove(.isCloseFriend)
|
||||
let updatedPeer = peer.withUpdatedFlags(updatedFlags)
|
||||
updatedPeers.append(updatedPeer)
|
||||
}
|
||||
}
|
||||
}
|
||||
updatePeers(transaction: transaction, peers: updatedPeers, update: { _, updated in
|
||||
return updated
|
||||
})
|
||||
}
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
@@ -44,5 +44,9 @@ public extension TelegramEngine {
|
||||
public func updateSelectiveAccountPrivacySettings(type: UpdateSelectiveAccountPrivacySettingsType, settings: SelectivePrivacySettings) -> Signal<Void, NoError> {
|
||||
return _internal_updateSelectiveAccountPrivacySettings(account: self.account, type: type, settings: settings)
|
||||
}
|
||||
|
||||
public func updateCloseFriends(peerIds: [EnginePeer.Id]) -> Signal<Never, NoError> {
|
||||
return _internal_updateCloseFriends(account: self.account, peerIds: peerIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user