Skip to content

Commit

Permalink
Merge #300: Typo and Headers to InputFile
Browse files Browse the repository at this point in the history
Fix typo
  • Loading branch information
HeySreelal authored Oct 23, 2024
2 parents 86b183e + 259ff2c commit df8b610
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.26.5

- Fixed in `ReactionTypeCustomEmoji.customEmojiId`

# 1.26.4

- Added `LocalFile` class.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/telegram/models/reaction_type_custom_emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ class ReactionTypeCustomEmoji implements ReactionType {
final ReactionTypeType type = ReactionTypeType.customEmoji;

/// Custom emoji identifier
final String customEmoji;
final String customEmojiId;

/// Constructs a [ReactionTypeCustomEmoji] object
const ReactionTypeCustomEmoji({
required this.customEmoji,
required this.customEmojiId,
});

/// Converts a [ReactionTypeCustomEmoji] object to JSON object
@override
Map<String, dynamic> toJson() {
return {
'type': type.value,
'custom_emoji': customEmoji,
'custom_emoji_id': customEmojiId,
};
}

/// Creates a [ReactionTypeCustomEmoji] object from JSON object
factory ReactionTypeCustomEmoji.fromJson(Map<String, dynamic> json) {
return ReactionTypeCustomEmoji(
customEmoji: json['custom_emoji']!,
customEmojiId: json['custom_emoji_id']!,
);
}
}
2 changes: 2 additions & 0 deletions lib/src/televerse/api/raw_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class RawAPI {
e.field: LocalFile(
e.file.getBytes(),
fileName: e.name,
headers: e.file.headers,
contentType: e.file.mimeType,
),
};
}).toList();
Expand Down
22 changes: 21 additions & 1 deletion lib/src/televerse/models/input_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,37 @@ class InputFile {
/// The bytes of the file.
final Uint8List? bytes;

/// Mime Type of the File
final String? mimeType;

/// Additional headers
final Map<String, List<String>>? headers;

/// Private constructor for [InputFile].
const InputFile._({
this.fileId,
this.url,
this.bytes,
this.name,
this.headers,
this.mimeType,
});

/// Creates a new [InputFile] using a local file.
factory InputFile.fromFile(
io.File file, {
String? name,
String? mimeType,
Map<String, List<String>>? headers,
}) {
if (!file.existsSync()) {
throw TeleverseException.fileDoesNotExist(file.path);
}
return InputFile._(
bytes: file.readAsBytesSync(),
name: name ?? file.filename,
mimeType: mimeType,
headers: headers,
);
}

Expand All @@ -70,9 +82,17 @@ class InputFile {
);

/// Creates a new [InputFile] using the bytes of the file.
factory InputFile.fromBytes(Uint8List bytes, {String? name}) => InputFile._(
factory InputFile.fromBytes(
Uint8List bytes, {
String? name,
String? mimeType,
Map<String, List<String>>? headers,
}) =>
InputFile._(
bytes: bytes,
name: name,
mimeType: mimeType,
headers: headers,
);

/// Returns the type of the [InputFile].
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: televerse
description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.10!
version: 1.26.4
version: 1.26.5
homepage: https://televerse.xooniverse.com
repository: https://github.com/xooniverse/televerse
topics:
Expand Down

0 comments on commit df8b610

Please sign in to comment.