mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
32 lines
1.0 KiB
Swift
32 lines
1.0 KiB
Swift
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
import TelegramApiMac
|
|
#else
|
|
import Postbox
|
|
import TelegramApi
|
|
import SwiftSignalKit
|
|
#endif
|
|
|
|
public func exportMessageLink(account: Account, peerId: PeerId, messageId: MessageId) -> Signal<String?, NoError> {
|
|
return account.postbox.transaction { transaction -> Peer? in
|
|
return transaction.getPeer(peerId)
|
|
}
|
|
|> mapToSignal { peer -> Signal<String?, NoError> in
|
|
if let peer = peer, let input = apiInputChannel(peer) {
|
|
return account.network.request(Api.functions.channels.exportMessageLink(channel: input, id: messageId.id, grouped: .boolTrue)) |> mapError { _ in return }
|
|
|> map { res in
|
|
switch res {
|
|
case let .exportedMessageLink(link, _):
|
|
return link
|
|
}
|
|
} |> `catch` { _ -> Signal<String?, NoError> in
|
|
return .single(nil)
|
|
}
|
|
} else {
|
|
return .single(nil)
|
|
}
|
|
}
|
|
}
|