mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-06 13:12:49 +00:00
Various improvements
This commit is contained in:
@@ -49,7 +49,7 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
|
||||
case .messageActionScreenshotTaken:
|
||||
return TelegramMediaAction(action: .historyScreenshot)
|
||||
case let .messageActionCustomAction(message):
|
||||
return TelegramMediaAction(action: .customText(text: message, entities: []))
|
||||
return TelegramMediaAction(action: .customText(text: message, entities: [], additionalAttributes: nil))
|
||||
case let .messageActionBotAllowed(flags, domain, app):
|
||||
if let domain = domain {
|
||||
return TelegramMediaAction(action: .botDomainAccessGranted(domain: domain))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Postbox
|
||||
import Foundation
|
||||
|
||||
public enum PhoneCallDiscardReason: Int32 {
|
||||
case missed = 0
|
||||
@@ -73,6 +74,18 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct CustomTextAttributes: Equatable {
|
||||
public var attributes: [(NSRange, NSAttributedString.Key, Any)]
|
||||
|
||||
public init(attributes: [(NSRange, NSAttributedString.Key, Any)]) {
|
||||
self.attributes = attributes
|
||||
}
|
||||
|
||||
public static func ==(lhs: CustomTextAttributes, rhs: CustomTextAttributes) -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
case unknown
|
||||
case groupCreated(title: String)
|
||||
case addedMembers(peerIds: [PeerId])
|
||||
@@ -89,7 +102,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case gameScore(gameId: Int64, score: Int32)
|
||||
case phoneCall(callId: Int64, discardReason: PhoneCallDiscardReason?, duration: Int32?, isVideo: Bool)
|
||||
case paymentSent(currency: String, totalAmount: Int64, invoiceSlug: String?, isRecurringInit: Bool, isRecurringUsed: Bool)
|
||||
case customText(text: String, entities: [MessageTextEntity])
|
||||
case customText(text: String, entities: [MessageTextEntity], additionalAttributes: CustomTextAttributes?)
|
||||
case botDomainAccessGranted(domain: String)
|
||||
case botAppAccessGranted(appName: String?, type: BotSendMessageAccessGrantedType?)
|
||||
case botSentSecureValues(types: [SentSecureValueType])
|
||||
@@ -152,7 +165,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case 15:
|
||||
self = .paymentSent(currency: decoder.decodeStringForKey("currency", orElse: ""), totalAmount: decoder.decodeInt64ForKey("ta", orElse: 0), invoiceSlug: decoder.decodeOptionalStringForKey("invoiceSlug"), isRecurringInit: decoder.decodeBoolForKey("isRecurringInit", orElse: false), isRecurringUsed: decoder.decodeBoolForKey("isRecurringUsed", orElse: false))
|
||||
case 16:
|
||||
self = .customText(text: decoder.decodeStringForKey("text", orElse: ""), entities: decoder.decodeObjectArrayWithDecoderForKey("ent"))
|
||||
self = .customText(text: decoder.decodeStringForKey("text", orElse: ""), entities: decoder.decodeObjectArrayWithDecoderForKey("ent"), additionalAttributes: nil)
|
||||
case 17:
|
||||
self = .botDomainAccessGranted(domain: decoder.decodeStringForKey("do", orElse: ""))
|
||||
case 18:
|
||||
@@ -298,7 +311,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
encoder.encodeNil(forKey: "d")
|
||||
}
|
||||
encoder.encodeInt32(isVideo ? 1 : 0, forKey: "vc")
|
||||
case let .customText(text, entities):
|
||||
case let .customText(text, entities, _):
|
||||
encoder.encodeInt32(16, forKey: "_rawValue")
|
||||
encoder.encodeString(text, forKey: "text")
|
||||
encoder.encodeObjectArray(entities, forKey: "ent")
|
||||
|
||||
@@ -87,7 +87,10 @@ public enum AdminLogEventAction {
|
||||
case pinTopic(prevInfo: EngineMessageHistoryThread.Info?, newInfo: EngineMessageHistoryThread.Info?)
|
||||
case toggleForum(isForum: Bool)
|
||||
case toggleAntiSpam(isEnabled: Bool)
|
||||
case changeNameColor(prev: PeerNameColor, new: PeerNameColor)
|
||||
case changeNameColor(prevColor: PeerNameColor, prevIcon: Int64?, newColor: PeerNameColor, newIcon: Int64?)
|
||||
case changeProfileColor(prevColor: PeerNameColor?, prevIcon: Int64?, newColor: PeerNameColor?, newIcon: Int64?)
|
||||
case changeWallpaper(prev: TelegramWallpaper?, new: TelegramWallpaper?)
|
||||
case changeStatus(prev: PeerEmojiStatus?, new: PeerEmojiStatus?)
|
||||
}
|
||||
|
||||
public enum ChannelAdminLogEventError {
|
||||
@@ -348,22 +351,69 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
|
||||
case let .channelAdminLogEventActionToggleAntiSpam(newValue):
|
||||
action = .toggleAntiSpam(isEnabled: newValue == .boolTrue)
|
||||
case let .channelAdminLogEventActionChangePeerColor(prevValue, newValue):
|
||||
let _ = prevValue
|
||||
let _ = newValue
|
||||
action = nil
|
||||
// action = .changeNameColor(prev: PeerNameColor(rawValue: prevValue), new: PeerNameColor(rawValue: newValue))
|
||||
var prevColorIndex: Int32
|
||||
var prevEmojiId: Int64?
|
||||
switch prevValue {
|
||||
case let .peerColor(_, color, backgroundEmojiIdValue):
|
||||
prevColorIndex = color ?? 0
|
||||
prevEmojiId = backgroundEmojiIdValue
|
||||
}
|
||||
|
||||
var newColorIndex: Int32
|
||||
var newEmojiId: Int64?
|
||||
switch newValue {
|
||||
case let .peerColor(_, color, backgroundEmojiIdValue):
|
||||
newColorIndex = color ?? 0
|
||||
newEmojiId = backgroundEmojiIdValue
|
||||
}
|
||||
|
||||
action = .changeNameColor(prevColor: PeerNameColor(rawValue: prevColorIndex), prevIcon: prevEmojiId, newColor: PeerNameColor(rawValue: newColorIndex), newIcon: newEmojiId)
|
||||
case let .channelAdminLogEventActionChangeProfilePeerColor(prevValue, newValue):
|
||||
let _ = prevValue
|
||||
let _ = newValue
|
||||
action = nil
|
||||
var prevColorIndex: Int32?
|
||||
var prevEmojiId: Int64?
|
||||
switch prevValue {
|
||||
case let .peerColor(_, color, backgroundEmojiIdValue):
|
||||
prevColorIndex = color
|
||||
prevEmojiId = backgroundEmojiIdValue
|
||||
}
|
||||
|
||||
var newColorIndex: Int32?
|
||||
var newEmojiId: Int64?
|
||||
switch newValue {
|
||||
case let .peerColor(_, color, backgroundEmojiIdValue):
|
||||
newColorIndex = color
|
||||
newEmojiId = backgroundEmojiIdValue
|
||||
}
|
||||
|
||||
action = .changeProfileColor(prevColor: prevColorIndex.flatMap(PeerNameColor.init(rawValue:)), prevIcon: prevEmojiId, newColor: newColorIndex.flatMap(PeerNameColor.init(rawValue:)), newIcon: newEmojiId)
|
||||
case let .channelAdminLogEventActionChangeWallpaper(prevValue, newValue):
|
||||
let _ = prevValue
|
||||
let _ = newValue
|
||||
action = nil
|
||||
let prev: TelegramWallpaper?
|
||||
if case let .wallPaperNoFile(_, _, settings) = prevValue {
|
||||
if settings == nil {
|
||||
prev = nil
|
||||
} else if case let .wallPaperSettings(flags, _, _, _, _, _, _, _) = settings, flags == 0 {
|
||||
prev = nil
|
||||
} else {
|
||||
prev = TelegramWallpaper(apiWallpaper: prevValue)
|
||||
}
|
||||
} else {
|
||||
prev = TelegramWallpaper(apiWallpaper: prevValue)
|
||||
}
|
||||
let new: TelegramWallpaper?
|
||||
if case let .wallPaperNoFile(_, _, settings) = newValue {
|
||||
if settings == nil {
|
||||
new = nil
|
||||
} else if case let .wallPaperSettings(flags, _, _, _, _, _, _, _) = settings, flags == 0 {
|
||||
new = nil
|
||||
} else {
|
||||
new = TelegramWallpaper(apiWallpaper: newValue)
|
||||
}
|
||||
} else {
|
||||
new = TelegramWallpaper(apiWallpaper: newValue)
|
||||
}
|
||||
action = .changeWallpaper(prev: prev, new: new)
|
||||
case let .channelAdminLogEventActionChangeEmojiStatus(prevValue, newValue):
|
||||
let _ = prevValue
|
||||
let _ = newValue
|
||||
action = nil
|
||||
action = .changeStatus(prev: PeerEmojiStatus(apiStatus: prevValue), new: PeerEmojiStatus(apiStatus: newValue))
|
||||
}
|
||||
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
|
||||
if let action = action {
|
||||
|
||||
@@ -718,6 +718,14 @@ public extension TelegramEngine {
|
||||
return _internal_updatePeerNameColorAndEmoji(account: self.account, peerId: peerId, nameColor: nameColor, backgroundEmojiId: backgroundEmojiId, profileColor: profileColor, profileBackgroundEmojiId: profileBackgroundEmojiId)
|
||||
}
|
||||
|
||||
public func updatePeerNameColor(peerId: EnginePeer.Id, nameColor: PeerNameColor, backgroundEmojiId: Int64?) -> Signal<Void, UpdatePeerNameColorAndEmojiError> {
|
||||
return _internal_updatePeerNameColor(account: self.account, peerId: peerId, nameColor: nameColor, backgroundEmojiId: backgroundEmojiId)
|
||||
}
|
||||
|
||||
public func updatePeerProfileColor(peerId: EnginePeer.Id, profileColor: PeerNameColor?, profileBackgroundEmojiId: Int64?) -> Signal<Void, UpdatePeerNameColorAndEmojiError> {
|
||||
return _internal_updatePeerProfileColor(account: self.account, peerId: peerId, profileColor: profileColor, profileBackgroundEmojiId: profileBackgroundEmojiId)
|
||||
}
|
||||
|
||||
public func updatePeerEmojiStatus(peerId: EnginePeer.Id, fileId: Int64?, expirationDate: Int32?) -> Signal<Never, UpdatePeerEmojiStatusError> {
|
||||
return _internal_updatePeerEmojiStatus(account: self.account, peerId: peerId, fileId: fileId, expirationDate: expirationDate)
|
||||
}
|
||||
|
||||
@@ -98,15 +98,21 @@ func _internal_updatePeerNameColorAndEmoji(account: Account, peerId: EnginePeer.
|
||||
return account.postbox.transaction { transaction -> Signal<Void, UpdatePeerNameColorAndEmojiError> in
|
||||
if let peer = transaction.getPeer(peerId) {
|
||||
if let peer = peer as? TelegramChannel, let inputChannel = apiInputChannel(peer) {
|
||||
let flagsReplies: Int32 = (1 << 0) | (1 << 2)
|
||||
var flagsReplies: Int32 = (1 << 2)
|
||||
if backgroundEmojiId != nil {
|
||||
flagsReplies |= 1 << 0
|
||||
}
|
||||
|
||||
var flagsProfile: Int32 = (1 << 0) | (1 << 1)
|
||||
var flagsProfile: Int32 = (1 << 1)
|
||||
if profileBackgroundEmojiId != nil {
|
||||
flagsProfile |= 1 << 0
|
||||
}
|
||||
if profileColor != nil {
|
||||
flagsProfile |= (1 << 2)
|
||||
}
|
||||
|
||||
return combineLatest(
|
||||
account.network.request(Api.functions.channels.updateColor(flags: flagsReplies, channel: inputChannel, color: nameColor.rawValue, backgroundEmojiId: backgroundEmojiId ?? 0))
|
||||
account.network.request(Api.functions.channels.updateColor(flags: flagsReplies, channel: inputChannel, color: nameColor.rawValue, backgroundEmojiId: backgroundEmojiId))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<Api.Updates?, MTRpcError> in
|
||||
if error.errorDescription.hasPrefix("CHAT_NOT_MODIFIED") {
|
||||
@@ -115,7 +121,7 @@ func _internal_updatePeerNameColorAndEmoji(account: Account, peerId: EnginePeer.
|
||||
return .fail(error)
|
||||
}
|
||||
},
|
||||
account.network.request(Api.functions.channels.updateColor(flags: flagsProfile, channel: inputChannel, color: profileColor?.rawValue, backgroundEmojiId: profileBackgroundEmojiId ?? 0))
|
||||
account.network.request(Api.functions.channels.updateColor(flags: flagsProfile, channel: inputChannel, color: profileColor?.rawValue, backgroundEmojiId: profileBackgroundEmojiId))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<Api.Updates?, MTRpcError> in
|
||||
if error.errorDescription.hasPrefix("CHAT_NOT_MODIFIED") {
|
||||
@@ -162,6 +168,105 @@ func _internal_updatePeerNameColorAndEmoji(account: Account, peerId: EnginePeer.
|
||||
|> switchToLatest
|
||||
}
|
||||
|
||||
func _internal_updatePeerNameColor(account: Account, peerId: EnginePeer.Id, nameColor: PeerNameColor, backgroundEmojiId: Int64?) -> Signal<Void, UpdatePeerNameColorAndEmojiError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, UpdatePeerNameColorAndEmojiError> in
|
||||
if let peer = transaction.getPeer(peerId) {
|
||||
if let peer = peer as? TelegramChannel, let inputChannel = apiInputChannel(peer) {
|
||||
var flagsReplies: Int32 = (1 << 2)
|
||||
if backgroundEmojiId != nil {
|
||||
flagsReplies |= 1 << 0
|
||||
}
|
||||
|
||||
return account.network.request(Api.functions.channels.updateColor(flags: flagsReplies, channel: inputChannel, color: nameColor.rawValue, backgroundEmojiId: backgroundEmojiId))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<Api.Updates?, MTRpcError> in
|
||||
if error.errorDescription.hasPrefix("CHAT_NOT_MODIFIED") {
|
||||
return .single(nil)
|
||||
} else {
|
||||
return .fail(error)
|
||||
}
|
||||
}
|
||||
|> mapError { error -> UpdatePeerNameColorAndEmojiError in
|
||||
if error.errorDescription.hasPrefix("BOOSTS_REQUIRED") {
|
||||
return .channelBoostRequired
|
||||
}
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { repliesResult -> Signal<Void, UpdatePeerNameColorAndEmojiError> in
|
||||
if let repliesResult = repliesResult {
|
||||
account.stateManager.addUpdates(repliesResult)
|
||||
}
|
||||
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
if let repliesResult = repliesResult, let apiChat = apiUpdatesGroups(repliesResult).first {
|
||||
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [apiChat], users: [])
|
||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
|
||||
}
|
||||
}
|
||||
|> mapError { _ -> UpdatePeerNameColorAndEmojiError in }
|
||||
}
|
||||
} else {
|
||||
return .fail(.generic)
|
||||
}
|
||||
} else {
|
||||
return .fail(.generic)
|
||||
}
|
||||
}
|
||||
|> castError(UpdatePeerNameColorAndEmojiError.self)
|
||||
|> switchToLatest
|
||||
}
|
||||
|
||||
func _internal_updatePeerProfileColor(account: Account, peerId: EnginePeer.Id, profileColor: PeerNameColor?, profileBackgroundEmojiId: Int64?) -> Signal<Void, UpdatePeerNameColorAndEmojiError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, UpdatePeerNameColorAndEmojiError> in
|
||||
if let peer = transaction.getPeer(peerId) {
|
||||
if let peer = peer as? TelegramChannel, let inputChannel = apiInputChannel(peer) {
|
||||
var flagsProfile: Int32 = (1 << 1)
|
||||
if profileBackgroundEmojiId != nil {
|
||||
flagsProfile |= 1 << 0
|
||||
}
|
||||
if profileColor != nil {
|
||||
flagsProfile |= (1 << 2)
|
||||
}
|
||||
|
||||
return account.network.request(Api.functions.channels.updateColor(flags: flagsProfile, channel: inputChannel, color: profileColor?.rawValue, backgroundEmojiId: profileBackgroundEmojiId))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<Api.Updates?, MTRpcError> in
|
||||
if error.errorDescription.hasPrefix("CHAT_NOT_MODIFIED") {
|
||||
return .single(nil)
|
||||
} else {
|
||||
return .fail(error)
|
||||
}
|
||||
}
|
||||
|> mapError { error -> UpdatePeerNameColorAndEmojiError in
|
||||
if error.errorDescription.hasPrefix("BOOSTS_REQUIRED") {
|
||||
return .channelBoostRequired
|
||||
}
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { profileResult -> Signal<Void, UpdatePeerNameColorAndEmojiError> in
|
||||
if let profileResult = profileResult {
|
||||
account.stateManager.addUpdates(profileResult)
|
||||
}
|
||||
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
if let profileResult = profileResult, let apiChat = apiUpdatesGroups(profileResult).first {
|
||||
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [apiChat], users: [])
|
||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
|
||||
}
|
||||
}
|
||||
|> mapError { _ -> UpdatePeerNameColorAndEmojiError in }
|
||||
}
|
||||
} else {
|
||||
return .fail(.generic)
|
||||
}
|
||||
} else {
|
||||
return .fail(.generic)
|
||||
}
|
||||
}
|
||||
|> castError(UpdatePeerNameColorAndEmojiError.self)
|
||||
|> switchToLatest
|
||||
}
|
||||
|
||||
public enum UpdatePeerEmojiStatusError {
|
||||
case generic
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user