Home telegram - media
Post
Cancel

telegram - media

Media

protocol Media

1
2
3
4
5
var id: MediaId? { get }
var peerIds: [PeerId] { get }
func isLikelyToBeUpdated() -> Bool
func isEqual(to other: Media) -> Bool
func isSemanticallyEqual(to other: Media) -> Bool

struct MediaId

1
2
3
4
typealias Namespace = Int32
typealias Id = Int64
let namespace: Namespace
let id: Id

MediaReference

enum MediaReference

1
2
3
4
5
case standalone(media: T)
case message(message: MessageReference, media: T)
case webPage(webPage: WebpageReference, media: T)
case stickerPack(stickerPack: StickerPackReference, media: T)
case savedGif(media: T)

enum AnyMediaReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
case standalone(media: Media)
case message(message: MessageReference, media: Media)
case webPage(webPage: WebpageReference, media: Media)
case stickerPack(stickerPack: StickerPackReference, media: Media)
case savedGif(media: Media)

public var partial: PartialMediaReference? {
    switch self {
        case .standalone:
            return nil
        case let .message(message, _):
            return .message(message: message)
        case let .webPage(webPage, _):
            return .webPage(webPage: webPage)
        case let .stickerPack(stickerPack, _):
            return .stickerPack(stickerPack: stickerPack)
        case .savedGif:
            return .savedGif
    }
}

public func concrete<T: Media>(_ type: T.Type) -> MediaReference<T>? {
    switch self {
        case let .standalone(media):
            if let media = media as? T {
                return .standalone(media: media)
            }
        case let .message(message, media):
            if let media = media as? T {
                return .message(message: message, media: media)
            }
        case let .webPage(webPage, media):
            if let media = media as? T {
                return .webPage(webPage: webPage, media: media)
            }
        case let .stickerPack(stickerPack, media):
            if let media = media as? T {
                return .stickerPack(stickerPack: stickerPack, media: media)
            }
        case let .savedGif(media):
            if let media = media as? T {
                return .savedGif(media: media)
            }
    }
    return nil
}

public func resourceReference(_ resource: MediaResource) -> MediaResourceReference {
    return .media(media: self, resource: resource)
}

enum PartialMediaReference

1
2
3
4
case message(message: MessageReference)
case webPage(webPage: WebpageReference)
case stickerPack(stickerPack: StickerPackReference)
case savedGif

MessageReference

struct MessageReference

1
let content: MessageReferenceContent

enum MessageReferenceContent

1
2
3
case none

case message(peer: PeerReference, id: MessageId, timestamp: Int32, incoming: Bool, secret: Bool)

enum PeerReference

1
2
3
case user(id: Int32, accessHash: Int64)
case group(id: Int32)
case channel(id: Int32, accessHash: Int64)

WebpageReference

enum WebpageReference

1
let content: WebpageReferenceContent

enum WebpageReferenceContent

1
2
case none
case webPage(id: Int64, url: String)

StickerPackReference

enum StickerPackReference

1
2
3
case id(id: Int64, accessHash: Int64)
case name(String)
case animatedEmoji

TelegramMediaImage

class TelegramMediaImage: Media

1
2
3
4
5
6
7
8
9
10
public let imageId: MediaId
// a image media has several representations
public let representations: [TelegramMediaImageRepresentation]
public let immediateThumbnailData: Data?
public let reference: TelegramMediaImageReference?
public let partialReference: PartialMediaReference?
public let peerIds: [PeerId] = []
public var id: MediaId? {
    return self.imageId
}

TelegramMediaImageRepresentation

1
2
public let dimensions: CGSize
public let resource: TelegramMediaResource

enum TelegramMediaImageReference

1
case cloud(imageId: Int64, accessHash: Int64, fileReference: Data?)

TelegramMediaFile

class TelegramMediaFile: Media

1
2
3
4
5
6
7
8
9
10
11
12
public let fileId: MediaId
public let partialReference: PartialMediaReference?
public let resource: TelegramMediaResource
public let previewRepresentations: [TelegramMediaImageRepresentation]
public let immediateThumbnailData: Data?
public let mimeType: String
public let size: Int?
public let attributes: [TelegramMediaFileAttribute]
public let peerIds: [PeerId] = []
public var id: MediaId? {
    return self.fileId
}

enum TelegramMediaFileAttribute

1
2
3
4
5
6
7
case FileName(fileName: String)
case Sticker(displayText: String, packReference: StickerPackReference?, maskData: StickerMaskCoords?)
case ImageSize(size: CGSize)
case Animated
case Video(duration: Int, size: CGSize, flags: TelegramMediaVideoFlags)
case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?)
case HasLinkedStickers

struct TelegramMediaVideoFlags

1
2
public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0)
public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1)
This post is licensed under CC BY 4.0 by the author.