From a23c19389cd613be9acc88b210114adfcc2fc693 Mon Sep 17 00:00:00 2001 From: DinoLeung Date: Sat, 26 Aug 2023 20:50:35 +0930 Subject: [PATCH] updated message class --- lib/src/teledart/model/message.dart | 2 ++ lib/src/telegram/model.dart | 2 ++ lib/src/telegram/model.g.dart | 30 ++++++++++++++++++++ lib/src/telegram/models/chat_shared.dart | 36 ++++++++++++++++++++++++ lib/src/telegram/models/message.dart | 4 +++ lib/src/telegram/models/user_shared.dart | 36 ++++++++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 lib/src/telegram/models/chat_shared.dart create mode 100644 lib/src/telegram/models/user_shared.dart diff --git a/lib/src/teledart/model/message.dart b/lib/src/teledart/model/message.dart index bd9a70e..851955f 100644 --- a/lib/src/teledart/model/message.dart +++ b/lib/src/teledart/model/message.dart @@ -88,6 +88,8 @@ class TeleDartMessage extends Message { pinnedMessage: message.pinnedMessage, invoice: message.invoice, successfulPayment: message.successfulPayment, + userShared: message.userShared, + chatShared: message.chatShared, connectedWebsite: message.connectedWebsite, writeAccessAllowed: message.writeAccessAllowed, passportData: message.passportData, diff --git a/lib/src/telegram/model.dart b/lib/src/telegram/model.dart index b1a3a23..0b196c1 100644 --- a/lib/src/telegram/model.dart +++ b/lib/src/telegram/model.dart @@ -48,6 +48,7 @@ part 'models/chat_member_updated.dart'; part 'models/chat_member.dart'; part 'models/chat_permissions.dart'; part 'models/chat_photo.dart'; +part 'models/chat_shared.dart'; part 'models/chat.dart'; part 'models/chosen_inline_result.dart'; part 'models/contact.dart'; @@ -152,6 +153,7 @@ part 'models/sticker.dart'; part 'models/successful_payment.dart'; part 'models/update.dart'; part 'models/user_profile_photos.dart'; +part 'models/user_shared.dart'; part 'models/user.dart'; part 'models/venue.dart'; part 'models/video_note.dart'; diff --git a/lib/src/telegram/model.g.dart b/lib/src/telegram/model.g.dart index 60a6870..91170f3 100644 --- a/lib/src/telegram/model.g.dart +++ b/lib/src/telegram/model.g.dart @@ -624,6 +624,17 @@ Map _$ChatPhotoToJson(ChatPhoto instance) => { 'big_file_unique_id': instance.bigFileUniqueId, }; +ChatShared _$ChatSharedFromJson(Map json) => ChatShared( + requestId: json['request_id'] as int, + userId: json['user_id'] as int, + ); + +Map _$ChatSharedToJson(ChatShared instance) => + { + 'request_id': instance.requestId, + 'user_id': instance.userId, + }; + Chat _$ChatFromJson(Map json) => Chat( id: json['id'] as int, type: json['type'] as String, @@ -2996,6 +3007,12 @@ Message _$MessageFromJson(Map json) => Message( ? null : SuccessfulPayment.fromJson( json['successful_payment'] as Map), + userShared: json['user_shared'] == null + ? null + : UserShared.fromJson(json['user_shared'] as Map), + chatShared: json['chat_shared'] == null + ? null + : ChatShared.fromJson(json['chat_shared'] as Map), connectedWebsite: json['connected_website'] as String?, writeAccessAllowed: json['write_access_allowed'] == null ? null @@ -3126,6 +3143,8 @@ Map _$MessageToJson(Message instance) { writeNotNull('pinned_message', instance.pinnedMessage?.toJson()); writeNotNull('invoice', instance.invoice?.toJson()); writeNotNull('successful_payment', instance.successfulPayment?.toJson()); + writeNotNull('user_shared', instance.userShared?.toJson()); + writeNotNull('chat_shared', instance.chatShared?.toJson()); writeNotNull('connected_website', instance.connectedWebsite); writeNotNull('write_access_allowed', instance.writeAccessAllowed?.toJson()); writeNotNull('passport_data', instance.passportData?.toJson()); @@ -3961,6 +3980,17 @@ Map _$UserProfilePhotosToJson(UserProfilePhotos instance) => .toList(), }; +UserShared _$UserSharedFromJson(Map json) => UserShared( + requestId: json['request_id'] as int, + userId: json['user_id'] as int, + ); + +Map _$UserSharedToJson(UserShared instance) => + { + 'request_id': instance.requestId, + 'user_id': instance.userId, + }; + User _$UserFromJson(Map json) => User( id: json['id'] as int, isBot: json['is_bot'] as bool, diff --git a/lib/src/telegram/models/chat_shared.dart b/lib/src/telegram/models/chat_shared.dart new file mode 100644 index 0000000..324de73 --- /dev/null +++ b/lib/src/telegram/models/chat_shared.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 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 chat whose identifier was +/// shared with the bot using a [KeyboardButtonRequestChat] button. +/// +/// https://core.telegram.org/bots/api#chatshared +@JsonSerializable(fieldRename: FieldRename.snake) +class ChatShared { + int requestId; + int userId; + ChatShared({ + required this.requestId, + required this.userId, + }); + factory ChatShared.fromJson(Map json) => + _$ChatSharedFromJson(json); + Map toJson() => _$ChatSharedToJson(this); +} diff --git a/lib/src/telegram/models/message.dart b/lib/src/telegram/models/message.dart index 7776498..22893d7 100644 --- a/lib/src/telegram/models/message.dart +++ b/lib/src/telegram/models/message.dart @@ -76,6 +76,8 @@ class Message { Message? pinnedMessage; Invoice? invoice; SuccessfulPayment? successfulPayment; + UserShared? userShared; + ChatShared? chatShared; String? connectedWebsite; WriteAccessAllowed? writeAccessAllowed; PassportData? passportData; @@ -147,6 +149,8 @@ class Message { this.pinnedMessage, this.invoice, this.successfulPayment, + this.userShared, + this.chatShared, this.connectedWebsite, this.writeAccessAllowed, this.passportData, diff --git a/lib/src/telegram/models/user_shared.dart b/lib/src/telegram/models/user_shared.dart new file mode 100644 index 0000000..c59f8cb --- /dev/null +++ b/lib/src/telegram/models/user_shared.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 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 user whose identifier was +/// shared with the bot using a [KeyboardButtonRequestUser] button. +/// +/// https://core.telegram.org/bots/api#usershared +@JsonSerializable(fieldRename: FieldRename.snake) +class UserShared { + int requestId; + int userId; + UserShared({ + required this.requestId, + required this.userId, + }); + factory UserShared.fromJson(Map json) => + _$UserSharedFromJson(json); + Map toJson() => _$UserSharedToJson(this); +}