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
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package fileid
|
|
|
|
import (
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/constant"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
// FromDocument creates FileID from tg.Document.
|
|
func FromDocument(doc *tg.Document) FileID {
|
|
fileID := FileID{
|
|
Type: DocumentAsFile,
|
|
DC: doc.DCID,
|
|
ID: doc.ID,
|
|
AccessHash: doc.AccessHash,
|
|
FileReference: doc.FileReference,
|
|
}
|
|
for _, attr := range doc.Attributes {
|
|
switch attr := attr.(type) {
|
|
case *tg.DocumentAttributeAnimated:
|
|
fileID.Type = Animation
|
|
case *tg.DocumentAttributeSticker:
|
|
fileID.Type = Sticker
|
|
case *tg.DocumentAttributeVideo:
|
|
fileID.Type = Video
|
|
if attr.RoundMessage {
|
|
fileID.Type = VideoNote
|
|
}
|
|
case *tg.DocumentAttributeAudio:
|
|
fileID.Type = Audio
|
|
if attr.Voice {
|
|
fileID.Type = Voice
|
|
}
|
|
}
|
|
}
|
|
return fileID
|
|
}
|
|
|
|
// FromPhoto creates FileID from tg.Photo.
|
|
func FromPhoto(photo *tg.Photo, thumbType rune) FileID {
|
|
return FileID{
|
|
Type: Photo,
|
|
DC: photo.DCID,
|
|
ID: photo.ID,
|
|
AccessHash: photo.AccessHash,
|
|
FileReference: photo.FileReference,
|
|
PhotoSizeSource: PhotoSizeSource{
|
|
Type: PhotoSizeSourceThumbnail,
|
|
FileType: Photo,
|
|
ThumbnailType: thumbType,
|
|
},
|
|
}
|
|
}
|
|
|
|
// ChatPhoto is interface for user profile photo and chat photo structures.
|
|
type ChatPhoto interface {
|
|
GetDCID() int
|
|
GetPhotoID() int64
|
|
}
|
|
|
|
var _ = []ChatPhoto{
|
|
(*tg.ChatPhoto)(nil),
|
|
(*tg.UserProfilePhoto)(nil),
|
|
}
|
|
|
|
// FromChatPhoto creates new FileID from ChatPhoto.
|
|
func FromChatPhoto(id constant.TDLibPeerID, accessHash int64, photo ChatPhoto, big bool) FileID {
|
|
typ := PhotoSizeSourceDialogPhotoSmall
|
|
if big {
|
|
typ = PhotoSizeSourceDialogPhotoBig
|
|
}
|
|
return FileID{
|
|
Type: ProfilePhoto,
|
|
DC: photo.GetDCID(),
|
|
ID: photo.GetPhotoID(),
|
|
PhotoSizeSource: PhotoSizeSource{
|
|
Type: typ,
|
|
DialogID: id,
|
|
DialogAccessHash: accessHash,
|
|
},
|
|
}
|
|
}
|