7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
106 lines
2.8 KiB
Go
106 lines
2.8 KiB
Go
package fileid
|
|
|
|
import "go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
|
|
// AsInputWebFileLocation converts file ID to tg.InputWebFileLocationClass.
|
|
func (f FileID) AsInputWebFileLocation() (tg.InputWebFileLocationClass, bool) {
|
|
if f.URL == "" {
|
|
return nil, false
|
|
}
|
|
|
|
return &tg.InputWebFileLocation{
|
|
URL: f.URL,
|
|
AccessHash: f.AccessHash,
|
|
}, true
|
|
}
|
|
|
|
func (f FileID) asPhotoLocation() (tg.InputFileLocationClass, bool) {
|
|
switch src := f.PhotoSizeSource; src.Type {
|
|
case PhotoSizeSourceLegacy:
|
|
case PhotoSizeSourceThumbnail:
|
|
switch src.FileType {
|
|
case Photo, Thumbnail:
|
|
return &tg.InputPhotoFileLocation{
|
|
ID: f.ID,
|
|
AccessHash: f.AccessHash,
|
|
FileReference: f.FileReference,
|
|
ThumbSize: string(f.PhotoSizeSource.ThumbnailType),
|
|
}, true
|
|
}
|
|
case PhotoSizeSourceDialogPhotoSmall,
|
|
PhotoSizeSourceDialogPhotoBig:
|
|
return &tg.InputPeerPhotoFileLocation{
|
|
Big: src.Type == PhotoSizeSourceDialogPhotoBig,
|
|
Peer: src.dialogPeer(),
|
|
PhotoID: f.ID,
|
|
}, true
|
|
case PhotoSizeSourceStickerSetThumbnail:
|
|
case PhotoSizeSourceFullLegacy:
|
|
return &tg.InputPhotoLegacyFileLocation{
|
|
ID: f.ID,
|
|
AccessHash: f.AccessHash,
|
|
FileReference: f.FileReference,
|
|
VolumeID: f.PhotoSizeSource.VolumeID,
|
|
LocalID: f.PhotoSizeSource.LocalID,
|
|
Secret: f.PhotoSizeSource.Secret,
|
|
}, true
|
|
case PhotoSizeSourceDialogPhotoSmallLegacy,
|
|
PhotoSizeSourceDialogPhotoBigLegacy:
|
|
return &tg.InputPeerPhotoFileLocationLegacy{
|
|
Big: src.Type == PhotoSizeSourceDialogPhotoBigLegacy,
|
|
Peer: src.dialogPeer(),
|
|
VolumeID: f.PhotoSizeSource.VolumeID,
|
|
LocalID: f.PhotoSizeSource.LocalID,
|
|
}, true
|
|
case PhotoSizeSourceStickerSetThumbnailLegacy:
|
|
return &tg.InputStickerSetThumbLegacy{
|
|
Stickerset: f.PhotoSizeSource.stickerSet(),
|
|
VolumeID: f.PhotoSizeSource.VolumeID,
|
|
LocalID: f.PhotoSizeSource.LocalID,
|
|
}, true
|
|
case PhotoSizeSourceStickerSetThumbnailVersion:
|
|
return &tg.InputStickerSetThumb{
|
|
Stickerset: f.PhotoSizeSource.stickerSet(),
|
|
ThumbVersion: int(f.PhotoSizeSource.StickerVersion),
|
|
}, true
|
|
}
|
|
|
|
return nil, false
|
|
}
|
|
|
|
// AsInputFileLocation converts file ID to tg.InputFileLocationClass.
|
|
func (f FileID) AsInputFileLocation() (tg.InputFileLocationClass, bool) {
|
|
switch f.Type {
|
|
case Thumbnail, ProfilePhoto, Photo:
|
|
return f.asPhotoLocation()
|
|
case Encrypted:
|
|
return &tg.InputEncryptedFileLocation{
|
|
ID: f.ID,
|
|
AccessHash: f.AccessHash,
|
|
}, true
|
|
case SecureRaw,
|
|
Secure:
|
|
return &tg.InputSecureFileLocation{
|
|
ID: f.ID,
|
|
AccessHash: f.AccessHash,
|
|
}, true
|
|
case Video,
|
|
Voice,
|
|
Document,
|
|
Sticker,
|
|
Audio,
|
|
Animation,
|
|
VideoNote,
|
|
Background,
|
|
DocumentAsFile:
|
|
return &tg.InputDocumentFileLocation{
|
|
ID: f.ID,
|
|
AccessHash: f.AccessHash,
|
|
FileReference: f.FileReference,
|
|
ThumbSize: "", // ?
|
|
}, true
|
|
}
|
|
|
|
return nil, false
|
|
}
|