move gotd fork into repo. (#111)
- 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
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
// Video creates new VideoDocumentBuilder to create video attachment.
|
||||
func (u *UploadedDocumentBuilder) Video() *VideoDocumentBuilder {
|
||||
b := u
|
||||
if u.doc.MimeType == "" {
|
||||
b = u.MIME(DefaultVideoMIME)
|
||||
}
|
||||
return &VideoDocumentBuilder{
|
||||
doc: b,
|
||||
attr: tg.DocumentAttributeVideo{},
|
||||
}
|
||||
}
|
||||
|
||||
// RoundVideo creates new VideoDocumentBuilder to create round video attachment.
|
||||
func (u *UploadedDocumentBuilder) RoundVideo() *VideoDocumentBuilder {
|
||||
return u.Video().Round()
|
||||
}
|
||||
|
||||
// VideoDocumentBuilder is a Video media option.
|
||||
type VideoDocumentBuilder struct {
|
||||
doc *UploadedDocumentBuilder
|
||||
attr tg.DocumentAttributeVideo
|
||||
}
|
||||
|
||||
// Round sets flag to mark this video as round.
|
||||
func (u *VideoDocumentBuilder) Round() *VideoDocumentBuilder {
|
||||
u.attr.RoundMessage = true
|
||||
return u
|
||||
}
|
||||
|
||||
// SupportsStreaming sets flag to mark this video as which supports streaming.
|
||||
func (u *VideoDocumentBuilder) SupportsStreaming() *VideoDocumentBuilder {
|
||||
u.attr.SupportsStreaming = true
|
||||
return u
|
||||
}
|
||||
|
||||
// Resolution sets resolution of this video.
|
||||
func (u *VideoDocumentBuilder) Resolution(w, h int) *VideoDocumentBuilder {
|
||||
u.attr.W = w
|
||||
u.attr.H = h
|
||||
return u
|
||||
}
|
||||
|
||||
// Duration sets duration of video file.
|
||||
func (u *VideoDocumentBuilder) Duration(duration time.Duration) *VideoDocumentBuilder {
|
||||
u.attr.Duration = duration.Seconds()
|
||||
return u
|
||||
}
|
||||
|
||||
// DurationSeconds sets duration in seconds.
|
||||
//
|
||||
// Deprecated: Use Duration instead. Telegram now supports fractional seconds.
|
||||
func (u *VideoDocumentBuilder) DurationSeconds(duration int) *VideoDocumentBuilder {
|
||||
u.attr.Duration = float64(duration)
|
||||
return u
|
||||
}
|
||||
|
||||
// apply implements MediaOption.
|
||||
func (u *VideoDocumentBuilder) apply(ctx context.Context, b *multiMediaBuilder) error {
|
||||
return u.doc.Attributes(&u.attr).apply(ctx, b)
|
||||
}
|
||||
|
||||
// applyMulti implements MultiMediaOption.
|
||||
func (u *VideoDocumentBuilder) applyMulti(ctx context.Context, b *multiMediaBuilder) error {
|
||||
return u.doc.Attributes(&u.attr).applyMulti(ctx, b)
|
||||
}
|
||||
|
||||
// Video adds video attachment.
|
||||
func Video(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder {
|
||||
// TODO(tdakkota): better MIME and attributes building.
|
||||
return UploadedDocument(file, caption...).Video()
|
||||
}
|
||||
|
||||
// RoundVideo adds round video attachment.
|
||||
func RoundVideo(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder {
|
||||
return UploadedDocument(file, caption...).RoundVideo()
|
||||
}
|
||||
|
||||
// Video sends video.
|
||||
func (b *Builder) Video(
|
||||
ctx context.Context,
|
||||
file tg.InputFileClass, caption ...StyledTextOption,
|
||||
) (tg.UpdatesClass, error) {
|
||||
return b.Media(ctx, Video(file, caption...))
|
||||
}
|
||||
|
||||
// RoundVideo sends round video.
|
||||
func (b *Builder) RoundVideo(
|
||||
ctx context.Context,
|
||||
file tg.InputFileClass, caption ...StyledTextOption,
|
||||
) (tg.UpdatesClass, error) {
|
||||
return b.Media(ctx, RoundVideo(file, caption...))
|
||||
}
|
||||
Reference in New Issue
Block a user