-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
591 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes the paid media to be sent. | ||
/// Currently, it can be one of [InputPaidMediaPhoto] or [InputPaidMediaVideo]. | ||
sealed class InputPaidMedia { | ||
/// Type of the media. | ||
InputPaidMediaType get type; | ||
|
||
/// File to send. | ||
/// Pass a file_id to send a file that exists on the Telegram servers (recommended), | ||
/// pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>” | ||
/// to upload a new one using multipart/form-data under <file_attach_name> name. | ||
final InputFile media; | ||
|
||
/// Creates a new [InputPaidMedia] object from JSON. | ||
const InputPaidMedia(this.media); | ||
|
||
/// Converts an [InputPaidMedia] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes paid media. | ||
/// Currently, it can be one of [PaidMediaPreview], [PaidMediaPhoto], [PaidMediaVideo]. | ||
abstract class PaidMedia { | ||
/// Type of the paid media. | ||
PaidMediaType get type; | ||
|
||
/// Creates a new [PaidMedia] object. | ||
/// This method decides which [PaidMedia] subclass to use based on the [type] field. | ||
static PaidMedia fromJson(Map<String, dynamic> json) { | ||
return switch (json['type']) { | ||
'preview' => PaidMediaPreview.fromJson(json), | ||
'photo' => PaidMediaPhoto.fromJson(json), | ||
'video' => PaidMediaVideo.fromJson(json), | ||
_ => throw ArgumentError('Invalid paid media type') | ||
}; | ||
} | ||
|
||
/// Creates a new [PaidMedia] object from JSON. | ||
const PaidMedia(); | ||
|
||
/// Converts a [PaidMedia] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
part of 'models.dart'; | ||
|
||
/// The paid media to send is a photo. | ||
class InputPaidMediaPhoto implements InputPaidMedia { | ||
@override | ||
InputPaidMediaType get type => InputPaidMediaType.photo; | ||
|
||
/// File to send. | ||
/// Pass a file_id to send a file that exists on the Telegram servers (recommended), | ||
/// pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>” | ||
/// to upload a new one using multipart/form-data under <file_attach_name> name. | ||
@override | ||
final InputFile media; | ||
|
||
/// Constructs a [InputPaidMediaPhoto] object. | ||
const InputPaidMediaPhoto({ | ||
required this.media, | ||
}); | ||
|
||
/// Converts a [InputPaidMediaPhoto] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type, | ||
'media': media.getValue('media'), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
part of 'models.dart'; | ||
|
||
/// The paid media to send is a video. | ||
class InputPaidMediaVideo implements InputPaidMedia { | ||
@override | ||
InputPaidMediaType get type => InputPaidMediaType.video; | ||
|
||
/// File to send. | ||
/// Pass a file_id to send a file that exists on the Telegram servers (recommended), | ||
/// pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>” | ||
/// to upload a new one using multipart/form-data under <file_attach_name> name. | ||
@override | ||
final InputFile media; | ||
|
||
/// Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. | ||
final InputFile? thumbnail; | ||
|
||
/// Optional. Video width. | ||
final int? width; | ||
|
||
/// Optional. Video height. | ||
final int? height; | ||
|
||
/// Optional. Video duration in seconds. | ||
final int? duration; | ||
|
||
/// Optional. Pass True if the uploaded video is suitable for streaming. | ||
final bool? supportsStreaming; | ||
|
||
/// Constructs a [InputPaidMediaVideo] object. | ||
const InputPaidMediaVideo({ | ||
required this.media, | ||
this.thumbnail, | ||
this.width, | ||
this.height, | ||
this.duration, | ||
this.supportsStreaming, | ||
}); | ||
|
||
/// Converts a [InputPaidMediaVideo] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type, | ||
'media': media.getValue('media'), | ||
'thumbnail': thumbnail?.getValue('thumbnail'), | ||
'width': width, | ||
'height': height, | ||
'duration': duration, | ||
'supports_streaming': supportsStreaming, | ||
}..removeWhere(_nullFilter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.