mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
60 lines
2.5 KiB
Swift
60 lines
2.5 KiB
Swift
import Foundation
|
|
|
|
import Postbox
|
|
import SyncCore
|
|
import TelegramCore
|
|
import WidgetItems
|
|
|
|
public extension WidgetDataPeer.Message {
|
|
init(message: Message) {
|
|
var content: WidgetDataPeer.Message.Content = .text
|
|
for media in message.media {
|
|
switch media {
|
|
case _ as TelegramMediaImage:
|
|
content = .image(WidgetDataPeer.Message.Content.Image())
|
|
case let file as TelegramMediaFile:
|
|
var fileName = "file"
|
|
for attribute in file.attributes {
|
|
if case let .FileName(value) = attribute {
|
|
fileName = value
|
|
break
|
|
}
|
|
}
|
|
content = .file(WidgetDataPeer.Message.Content.File(name: fileName))
|
|
for attribute in file.attributes {
|
|
switch attribute {
|
|
case let .Sticker(altText, _, _):
|
|
content = .sticker(WidgetDataPeer.Message.Content.Sticker(altText: altText))
|
|
case let .Video(duration, _, flags):
|
|
if flags.contains(.instantRoundVideo) {
|
|
content = .videoMessage(WidgetDataPeer.Message.Content.VideoMessage(duration: Int32(duration)))
|
|
} else {
|
|
content = .video(WidgetDataPeer.Message.Content.Video())
|
|
}
|
|
case let .Audio(isVoice, duration, title, performer, _):
|
|
if isVoice {
|
|
content = .voiceMessage(WidgetDataPeer.Message.Content.VoiceMessage(duration: Int32(duration)))
|
|
} else {
|
|
content = .music(WidgetDataPeer.Message.Content.Music(artist: performer ?? "", title: title ?? "", duration: Int32(duration)))
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
case let action as TelegramMediaAction:
|
|
switch action.action {
|
|
case let .phoneCall(_, _, _, isVideo):
|
|
content = .call(WidgetDataPeer.Message.Content.Call(isVideo: isVideo))
|
|
default:
|
|
break
|
|
}
|
|
case _ as TelegramMediaMap:
|
|
content = .mapLocation(WidgetDataPeer.Message.Content.MapLocation())
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
self.init(text: message.text, content: content, timestamp: message.timestamp)
|
|
}
|
|
}
|