Skip to content

Commit

Permalink
updated input media multipart post
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Aug 27, 2023
1 parent 78d4e38 commit fecbd34
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/src/telegram/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ part 'models/input_media_audio.dart';
part 'models/input_media_document.dart';
part 'models/input_media_photo.dart';
part 'models/input_media_video.dart';
part 'models/input_media_with_thumbnail.dart';
part 'models/input_media.dart';
part 'models/input_message_content.dart';
part 'models/input_sticker.dart';
Expand Down
42 changes: 38 additions & 4 deletions lib/src/telegram/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 38 additions & 3 deletions lib/src/telegram/models/input_media_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ part of '../model.dart';
///
/// https://core.telegram.org/bots/api#inputmediaanimation
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaAnimation implements InputMedia {
class InputMediaAnimation implements InputMediaWithThumbnail {
@override
String type;
@override
Expand All @@ -33,12 +33,17 @@ class InputMediaAnimation implements InputMedia {
String? parseMode;
@override
List<MessageEntity>? captionEntities;
dynamic thumbnail; // InputFile or String
@override
String? thumbnail;
int? width;
int? height;
int? duration;
bool? hasSpoiler;

@override
@JsonKey(includeFromJson: false, includeToJson: false)
MultipartFile? thumbnailFile;

InputMediaAnimation(
{this.type = InputMedia.typeAnimation,
required this.media,
Expand All @@ -49,7 +54,37 @@ class InputMediaAnimation implements InputMedia {
this.width,
this.height,
this.duration,
this.hasSpoiler});
this.hasSpoiler,
this.thumbnailFile,
});

// Factory to create InputMediaAnimation with thumbnail file
factory InputMediaAnimation.withThumbnailFile({
required io.File thumbnail,
required String media,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
int? width,
int? height,
int? duration,
bool? hasSpoiler,
}) =>
InputMediaAnimation(
type: InputMedia.typeAnimation,
media: media,
thumbnail: 'attach://${thumbnail.path}',
thumbnailFile: MultipartFile(
thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(),
filename: thumbnail.path.split('/').last),
caption: caption,
parseMode: parseMode,
captionEntities: captionEntities,
width: width,
height: height,
duration: duration,
hasSpoiler: hasSpoiler,
);

@JsonKey(includeFromJson: false, includeToJson: false)
Duration? get duration_ =>
Expand Down
36 changes: 34 additions & 2 deletions lib/src/telegram/models/input_media_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ part of '../model.dart';
///
/// https://core.telegram.org/bots/api#inputmediaaudio
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaAudio implements InputMedia {
class InputMediaAudio implements InputMediaWithThumbnail {
@override
String type;
@override
Expand All @@ -33,11 +33,16 @@ class InputMediaAudio implements InputMedia {
String? parseMode;
@override
List<MessageEntity>? captionEntities;
dynamic thumbnail; // InputFile or String
@override
String? thumbnail;
int? duration;
String? performer;
String? title;

@override
@JsonKey(includeFromJson: false, includeToJson: false)
MultipartFile? thumbnailFile;

InputMediaAudio({
this.type = InputMedia.typeAudio,
required this.media,
Expand All @@ -48,8 +53,35 @@ class InputMediaAudio implements InputMedia {
this.duration,
this.performer,
this.title,
this.thumbnailFile,
});

// Factory to create InputMediaAudio with thumbnail file
factory InputMediaAudio.withThumbnailFile({
required io.File thumbnail,
required String media,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
int? duration,
String? performer,
String? title,
}) =>
InputMediaAudio(
type: InputMedia.typeAudio,
media: media,
thumbnail: 'attach://${thumbnail.path}',
thumbnailFile: MultipartFile(
thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(),
filename: thumbnail.path.split('/').last),
caption: caption,
parseMode: parseMode,
captionEntities: captionEntities,
duration: duration,
performer: performer,
title: title,
);

@JsonKey(includeFromJson: false, includeToJson: false)
Duration? get duration_ =>
duration == null ? null : TimeHelper.toDuration(duration!);
Expand Down
34 changes: 32 additions & 2 deletions lib/src/telegram/models/input_media_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ part of '../model.dart';
///
/// https://core.telegram.org/bots/api#inputmediadocument
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaDocument implements InputMedia {
class InputMediaDocument implements InputMediaWithThumbnail {
@override
String type;
@override
Expand All @@ -33,8 +33,14 @@ class InputMediaDocument implements InputMedia {
String? parseMode;
@override
List<MessageEntity>? captionEntities;
dynamic thumbnail; // InputFile or String
@override
String? thumbnail;
bool? disableContentTypeDetection;

@override
@JsonKey(includeFromJson: false, includeToJson: false)
MultipartFile? thumbnailFile;

InputMediaDocument({
this.type = InputMedia.typeDocument,
required this.media,
Expand All @@ -43,7 +49,31 @@ class InputMediaDocument implements InputMedia {
this.parseMode,
this.captionEntities,
this.disableContentTypeDetection,
this.thumbnailFile,
});

// Factory to create InputMediaDocument with thumbnail file
factory InputMediaDocument.withThumbnailFile({
required io.File thumbnail,
required String media,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
bool? disableContentTypeDetection,
}) =>
InputMediaDocument(
type: InputMedia.typeDocument,
media: media,
thumbnail: 'attach://${thumbnail.path}',
thumbnailFile: MultipartFile(
thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(),
filename: thumbnail.path.split('/').last),
caption: caption,
parseMode: parseMode,
captionEntities: captionEntities,
disableContentTypeDetection: disableContentTypeDetection,
);

factory InputMediaDocument.fromJson(Map<String, dynamic> json) =>
_$InputMediaDocumentFromJson(json);
@override
Expand Down
40 changes: 38 additions & 2 deletions lib/src/telegram/models/input_media_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ part of '../model.dart';
///
/// https://core.telegram.org/bots/api#inputmediavideo
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaVideo implements InputMedia {
class InputMediaVideo implements InputMediaWithThumbnail {
@override
String type;
@override
Expand All @@ -33,13 +33,18 @@ class InputMediaVideo implements InputMedia {
String? parseMode;
@override
List<MessageEntity>? captionEntities;
dynamic thumbnail; // InputFile or String
@override
String? thumbnail;
int? width;
int? height;
int? duration;
bool? supportsStreaming;
bool? hasSpoiler;

@override
@JsonKey(includeFromJson: false, includeToJson: false)
MultipartFile? thumbnailFile;

InputMediaVideo({
this.type = InputMedia.typeVideo,
required this.media,
Expand All @@ -52,8 +57,39 @@ class InputMediaVideo implements InputMedia {
this.duration,
this.supportsStreaming,
this.hasSpoiler,
this.thumbnailFile,
});

// Factory to create InputMediaVideo with thumbnail file
factory InputMediaVideo.withThumbnailFile({
required io.File thumbnail,
required String media,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
int? width,
int? height,
int? duration,
bool? supportsStreaming,
bool? hasSpoiler,
}) =>
InputMediaVideo(
type: InputMedia.typeVideo,
media: media,
thumbnail: 'attach://${thumbnail.path}',
thumbnailFile: MultipartFile(
thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(),
filename: thumbnail.path.split('/').last),
caption: caption,
parseMode: parseMode,
captionEntities: captionEntities,
width: width,
height: height,
duration: duration,
supportsStreaming: supportsStreaming,
hasSpoiler: hasSpoiler,
);

@JsonKey(includeFromJson: false, includeToJson: false)
Duration? get duration_ =>
duration == null ? null : TimeHelper.toDuration(duration!);
Expand Down
Loading

0 comments on commit fecbd34

Please sign in to comment.