diff --git a/lib/src/teledart/model/message.dart b/lib/src/teledart/model/message.dart index 8c4058e..0fd8016 100644 --- a/lib/src/teledart/model/message.dart +++ b/lib/src/teledart/model/message.dart @@ -46,6 +46,7 @@ class TeleDartMessage extends Message { isAutomaticForward: message.isAutomaticForward, replyToMessage: message.replyToMessage, externalReply: message.externalReply, + quote: message.quote, viaBot: message.viaBot, editDate: message.editDate, hasProtectedContent: message.hasProtectedContent, diff --git a/lib/src/telegram/model.dart b/lib/src/telegram/model.dart index 4b04c7b..bccd008 100644 --- a/lib/src/telegram/model.dart +++ b/lib/src/telegram/model.dart @@ -176,6 +176,7 @@ part 'models/sticker.dart'; part 'models/story.dart'; part 'models/successful_payment.dart'; part 'models/switch_inline_query_chosen_chat.dart'; +part 'models/text_quote.dart'; part 'models/update.dart'; part 'models/user_profile_photos.dart'; part 'models/user_shared.dart'; diff --git a/lib/src/telegram/model.g.dart b/lib/src/telegram/model.g.dart index 3c6c844..e6a20e1 100644 --- a/lib/src/telegram/model.g.dart +++ b/lib/src/telegram/model.g.dart @@ -3576,6 +3576,9 @@ Message _$MessageFromJson(Map json) => Message( ? null : ExternalReplyInfo.fromJson( json['external_reply'] as Map), + quote: json['quote'] == null + ? null + : TextQuote.fromJson(json['quote'] as Map), viaBot: json['via_bot'] == null ? null : User.fromJson(json['via_bot'] as Map), @@ -3759,6 +3762,7 @@ Map _$MessageToJson(Message instance) { writeNotNull('is_automatic_forward', instance.isAutomaticForward); writeNotNull('reply_to_message', instance.replyToMessage?.toJson()); writeNotNull('external_reply', instance.externalReply?.toJson()); + writeNotNull('quote', instance.quote?.toJson()); writeNotNull('via_bot', instance.viaBot?.toJson()); writeNotNull('edit_date', instance.editDate); writeNotNull('has_protected_content', instance.hasProtectedContent); @@ -4732,6 +4736,32 @@ Map _$SwitchInlineQueryChosenChatToJson( return val; } +TextQuote _$TextQuoteFromJson(Map json) => TextQuote( + text: json['text'] as String, + entities: (json['entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + position: json['position'] as int, + isManual: json['is_manual'] as bool?, + ); + +Map _$TextQuoteToJson(TextQuote instance) { + final val = { + 'text': instance.text, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('entities', instance.entities?.map((e) => e.toJson()).toList()); + val['position'] = instance.position; + writeNotNull('is_manual', instance.isManual); + return val; +} + Update _$UpdateFromJson(Map json) => Update( updateId: json['update_id'] as int, message: json['message'] == null diff --git a/lib/src/telegram/models/message.dart b/lib/src/telegram/models/message.dart index af6726b..6457fd2 100644 --- a/lib/src/telegram/models/message.dart +++ b/lib/src/telegram/models/message.dart @@ -34,6 +34,7 @@ class Message { bool? isAutomaticForward; Message? replyToMessage; ExternalReplyInfo? externalReply; + TextQuote? quote; User? viaBot; int? editDate; bool? hasProtectedContent; @@ -104,6 +105,7 @@ class Message { this.isAutomaticForward, this.replyToMessage, this.externalReply, + this.quote, this.viaBot, this.editDate, this.hasProtectedContent, diff --git a/lib/src/telegram/models/text_quote.dart b/lib/src/telegram/models/text_quote.dart new file mode 100644 index 0000000..610e153 --- /dev/null +++ b/lib/src/telegram/models/text_quote.dart @@ -0,0 +1,42 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2024 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object contains information about the quoted part of a message +/// that is replied to by the given message. +/// +/// https://core.telegram.org/bots/api#textquote +@JsonSerializable(fieldRename: FieldRename.snake) +class TextQuote { + String text; + List? entities; + int position; + bool? isManual; + + TextQuote({ + required this.text, + this.entities, + required this.position, + this.isManual, + }); + + factory TextQuote.fromJson(Map json) => + _$TextQuoteFromJson(json); + Map toJson() => _$TextQuoteToJson(this); +}