mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 19:09:56 +00:00
69 lines
2.6 KiB
Swift
69 lines
2.6 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
import MtProtoKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
import MtProtoKitDynamic
|
|
#endif
|
|
|
|
public func requestEditMessage(account: Account, messageId: MessageId, text: String, entities:TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false) -> Signal<Bool, NoError> {
|
|
return account.postbox.modify { modifier -> (Peer?, SimpleDictionary<PeerId, Peer>) in
|
|
var peers:SimpleDictionary<PeerId, Peer> = SimpleDictionary()
|
|
|
|
if let entities = entities {
|
|
for peerId in entities.associatedPeerIds {
|
|
if let peer = modifier.getPeer(peerId) {
|
|
peers[peer.id] = peer
|
|
}
|
|
}
|
|
}
|
|
return (modifier.getPeer(messageId.peerId), peers)
|
|
}
|
|
|> take(1)
|
|
|> mapToSignal { peer, associatedPeers in
|
|
if let peer = peer, let inputPeer = apiInputPeer(peer) {
|
|
|
|
var flags:Int32 = (1 << 11)
|
|
|
|
|
|
var apiEntities:[Api.MessageEntity]?
|
|
if let entities = entities {
|
|
apiEntities = apiTextAttributeEntities(entities, associatedPeers: associatedPeers)
|
|
flags |= Int32(1 << 3)
|
|
}
|
|
|
|
if disableUrlPreview {
|
|
flags |= Int32(1 << 1)
|
|
}
|
|
|
|
return account.network.request(Api.functions.messages.editMessage(flags: flags, peer: inputPeer, id: messageId.id, message: text, replyMarkup: nil, entities: apiEntities))
|
|
|> map { result -> Api.Updates? in
|
|
return result
|
|
}
|
|
|> `catch` { error -> Signal<Api.Updates?, MTRpcError> in
|
|
if error.errorDescription == "MESSAGE_NOT_MODIFIED" {
|
|
return .single(nil)
|
|
} else {
|
|
return .fail(error)
|
|
}
|
|
}
|
|
|> mapError { _ -> NoError in
|
|
return NoError()
|
|
}
|
|
|> mapToSignal { result -> Signal<Bool, NoError> in
|
|
if let result = result {
|
|
account.stateManager.addUpdates(result)
|
|
return .single(true)
|
|
} else {
|
|
return .single(false)
|
|
}
|
|
}
|
|
} else {
|
|
return .single(false)
|
|
}
|
|
}
|
|
}
|