Home telegram-gif
Post
Cancel

telegram-gif

Gif in Chat

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
ChatMessageInteractiveMediaNode

TransformImageNode

GalleryController

GalleryPagerNode
func replaceItems()

GalleryItemNode

UniversalVideoGalleryItem

UniversalVideoNode

func galleryItemForEntry()

GalleryMessageHistoryView

UniversalMediaPlayer.MediaPlayerNode

DisplayLinkDispatcher

updatedStatusSignal
updateImageSignal

updatedVideoNodeReadySignal:
strongSelf.insertSubnode(videoNode, aboveSubnode: strongSelf.imageNode)

updatedPlayerStatusSignal
updatedFetchControls

let blurSourceImage = thumbnailImage ?? fullSizeImage
1
DataJSON.dataJSON(data: bet fail)

GifPaneSearchContentNode

1
func paneGifSearchForQuery

enum ChatPresentationInputQueryResult

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
case stickers([FoundStickerItem])
case hashtags([String])
case mentions([Peer])
case commands([PeerCommand])
case emojis([(String, String)], NSRange)
case contextRequestResult(Peer?, ChatContextResultCollection?)


extension ChatContextResultCollection {
    convenience init(apiResults: Api.messages.BotResults, botId: PeerId, peerId: PeerId, query: String, geoPoint: (Double, Double)?) {
        switch apiResults {
            case let .botResults(flags, queryId, nextOffset, switchPm, results, cacheTime, _):
                var switchPeer: ChatContextResultSwitchPeer?
                if let switchPm = switchPm {
                    switchPeer = ChatContextResultSwitchPeer(apiSwitchPeer: switchPm)
                }
                let parsedResults = results.map({ ChatContextResult(apiResult: $0, queryId: queryId) })
                /*.filter({ result in
                    switch result {
                        case .internalReference:
                            return false
                        default:
                            return true
                    }
                })*/
                self.init(botId: botId, peerId: peerId, query: query, geoPoint: geoPoint, queryId: queryId, nextOffset: nextOffset, presentation: (flags & (1 << 0) != 0) ? .media : .list, switchPeer: switchPeer, results: parsedResults, cacheTimeout: cacheTime)
        }
    }
}

class ChatContextResultCollection

1
2
3
4
5
6
7
8
9
10
public let botId: PeerId
public let peerId: PeerId
public let query: String
public let geoPoint: (Double, Double)?
public let queryId: Int64
public let nextOffset: String?
public let presentation: ChatContextResultCollectionPresentation
public let switchPeer: ChatContextResultSwitchPeer?
public let results: [ChatContextResult]
public let cacheTimeout: Int32

enum ChatContextResult

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
case externalReference(queryId: Int64, id: String, type: String, title: String?, description: String?, url: String?, content: TelegramMediaWebFile?, thumbnail: TelegramMediaWebFile?, message: ChatContextResultMessage)

case internalReference(queryId: Int64, id: String, type: String, title: String?, description: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, message: ChatContextResultMessage)


public var queryId: Int64 {
    switch self {
        case let .externalReference(queryId, _, _, _, _, _, _, _, _):
            return queryId
        case let .internalReference(queryId, _, _, _, _, _, _, _):
            return queryId
    }
}
public var id: String {
    switch self {
        case let .externalReference(_, id, _, _, _, _, _, _, _):
            return id
        case let .internalReference(_, id, _, _, _, _, _, _):
            return id
    }
}
public var type: String {
    switch self {
        case let .externalReference(_, _, type, _, _, _, _, _, _):
            return type
        case let .internalReference(_, _, type, _, _, _, _, _):
            return type
    }
}
public var title: String? {
    switch self {
        case let .externalReference(_, _, _, title, _, _, _, _, _):
            return title
        case let .internalReference(_, _, _, title, _, _, _, _):
            return title
    }
}
public var description: String? {
    switch self {
        case let .externalReference(_, _, _, _, description, _, _, _, _):
            return description
        case let .internalReference(_, _, _, _, description, _, _, _):
            return description
    }
}
public var message: ChatContextResultMessage {
    switch self {
        case let .externalReference(_, _, _, _, _, _, _, _, message):
            return message
        case let .internalReference(_, _, _, _, _, _, _, message):
            return message
    }
}


extension ChatContextResult {
    init(apiResult: Api.BotInlineResult, queryId: Int64) {
        switch apiResult {
            case let .botInlineResult(_, id, type, title, description, url, thumb, content, sendMessage):
                self = .externalReference(queryId: queryId, id: id, type: type, title: title, description: description, url: url, content: content.flatMap(TelegramMediaWebFile.init), thumbnail: thumb.flatMap(TelegramMediaWebFile.init), message: ChatContextResultMessage(apiMessage: sendMessage))
            case let .botInlineMediaResult(_, id, type, photo, document, title, description, sendMessage):
                var image: TelegramMediaImage?
                var file: TelegramMediaFile?
                if let photo = photo, let parsedImage = telegramMediaImageFromApiPhoto(photo) {
                    image = parsedImage
                }
                if let document = document, let parsedFile = telegramMediaFileFromApiDocument(document) {
                    file = parsedFile
                }
                self = .internalReference(queryId: queryId, id: id, type: type, title: title, description: description, image: image, file: file, message: ChatContextResultMessage(apiMessage: sendMessage))
        }
    }
}

funcrequestContextResults

1
public static func getInlineBotResults(flags: Int32, bot: Api.InputUser, peer: Api.InputPeer, geoPoint: Api.InputGeoPoint?, query: String, offset: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.BotResults>)

enum BotResults

1
case botResults(flags: Int32, queryId: Int64, nextOffset: String?, switchPm: Api.InlineBotSwitchPM?, results: [Api.BotInlineResult], cacheTime: Int32, users: [Api.User])

enum Api.BotInlineResult

1
2
3
case botInlineMediaResult(flags: Int32, id: String, type: String, photo: Api.Photo?, document: Api.Document?, title: String?, description: String?, sendMessage: Api.BotInlineMessage)

case botInlineResult(flags: Int32, id: String, type: String, title: String?, description: String?, url: String?, thumb: Api.WebDocument?, content: Api.WebDocument?, sendMessage: Api.BotInlineMessage)

enum Api.WebDocument

1
2
3
case webDocumentNoProxy(url: String, size: Int32, mimeType: String, attributes: [Api.DocumentAttribute])
 
case webDocument(url: String, accessHash: Int64, size: Int32, mimeType: String, attributes: [Api.DocumentAttribute])

enum Api.Document

1
2
case documentEmpty(id: Int64)
case document(flags: Int32, id: Int64, accessHash: Int64, fileReference: Buffer, date: Int32, mimeType: String, size: Int32, thumbs: [Api.PhotoSize]?, dcId: Int32, attributes: [Api.DocumentAttribute])

TelegramMediaWebFile

1
2
3
4
5
6
7
8
9
10
extension TelegramMediaWebFile {
    convenience init(_ document: Api.WebDocument) {
        switch document {
            case let .webDocument(data):
                self.init(resource: WebFileReferenceMediaResource(url: data.url, size: data.size, accessHash: data.accessHash), mimeType: data.mimeType, size: data.size, attributes: telegramMediaFileAttributesFromApiAttributes(data.attributes))
            case let .webDocumentNoProxy(url, size, mimeType, attributes):
                self.init(resource: HttpReferenceMediaResource(url: url, size: Int(size)), mimeType: mimeType, size: size, attributes: telegramMediaFileAttributesFromApiAttributes(attributes))
        }
    }
}

Api.Photo

TelegramMediaImage

1
func telegramMediaImageFromApiPhoto

TelegramMediaFile

1
func telegramMediaFileFromApiDocument

enum ChatPresentationInputQueryResult

1
2
3
4
5
6
case stickers([FoundStickerItem])
case hashtags([String])
case mentions([Peer])
case commands([PeerCommand])
case emojis([(String, String)], NSRange)
case contextRequestResult(Peer?, ChatContextResultCollection?)

resolvePeerByName -> BotResults[Api.BotInlineResult] -> [ChatContextResult] -> ChatContextResultCollection -> ChatPresentationInputQueryResult -> [FileMediaReference]

typealias FileMediaReference = MediaReference**

This post is licensed under CC BY 4.0 by the author.