Skip to content

Commit

Permalink
implemeted message origin classees
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Apr 6, 2024
1 parent 64f8e11 commit 4050fe4
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/src/telegram/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ part 'models/menu_button.dart';
part 'models/message_auto_delete_timer_changed.dart';
part 'models/message_entity.dart';
part 'models/message_id.dart';
part 'models/message_origin_channel.dart';
part 'models/message_origin_chat.dart';
part 'models/message_origin_hidden_user.dart';
part 'models/message_origin_user.dart';
part 'models/message_origin.dart';
part 'models/message_reaction_count_updated.dart';
part 'models/message_reaction_updated.dart';
Expand Down
98 changes: 91 additions & 7 deletions lib/src/telegram/model.g.dart

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

54 changes: 54 additions & 0 deletions lib/src/telegram/models/message_origin_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

part of '../model.dart';

/// The message was originally sent to a channel chat.
///
/// https://core.telegram.org/bots/api#messageoriginchannel
@JsonSerializable(fieldRename: FieldRename.snake)
class MessageOriginChannel implements MessageOrigin {
@override
MessageOriginType type;
@override
int date;
Chat chat;
int messageId;
String? authorSignature;

MessageOriginChannel({
required this.type,
required this.date,
required this.chat,
required this.messageId,
this.authorSignature,
});

@override
@JsonKey(includeFromJson: false, includeToJson: false)
DateTime get date_ =>
TimeHelper.toDateTime(date);
@override
set date_(DateTime dateTime) =>
date = TimeHelper.toUnixTime(dateTime);

factory MessageOriginChannel.fromJson(Map<String, dynamic> json) =>
_$MessageOriginChannelFromJson(json);
@override
Map<String, dynamic> toJson() => _$MessageOriginChannelToJson(this);
}
52 changes: 52 additions & 0 deletions lib/src/telegram/models/message_origin_chat.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

part of '../model.dart';

/// The message was originally sent on behalf of a chat to a group chat.
///
/// https://core.telegram.org/bots/api#messageoriginchat
@JsonSerializable(fieldRename: FieldRename.snake)
class MessageOriginChat implements MessageOrigin {
@override
MessageOriginType type;
@override
int date;
Chat senderChat;
String? authorSignature;

MessageOriginChat({
required this.type,
required this.date,
required this.senderChat,
this.authorSignature,
});

@override
@JsonKey(includeFromJson: false, includeToJson: false)
DateTime get date_ =>
TimeHelper.toDateTime(date);
@override
set date_(DateTime dateTime) =>
date = TimeHelper.toUnixTime(dateTime);

factory MessageOriginChat.fromJson(Map<String, dynamic> json) =>
_$MessageOriginChatFromJson(json);
@override
Map<String, dynamic> toJson() => _$MessageOriginChatToJson(this);
}
50 changes: 50 additions & 0 deletions lib/src/telegram/models/message_origin_hidden_user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

part of '../model.dart';

/// The message was originally sent by an unknown user.
///
/// https://core.telegram.org/bots/api#messageoriginhiddenuser
@JsonSerializable(fieldRename: FieldRename.snake)
class MessageOriginHiddenUser implements MessageOrigin {
@override
MessageOriginType type;
@override
int date;
String senderUserName;

MessageOriginHiddenUser({
required this.type,
required this.date,
required this.senderUserName,
});

@override
@JsonKey(includeFromJson: false, includeToJson: false)
DateTime get date_ =>
TimeHelper.toDateTime(date);
@override
set date_(DateTime dateTime) =>
date = TimeHelper.toUnixTime(dateTime);

factory MessageOriginHiddenUser.fromJson(Map<String, dynamic> json) =>
_$MessageOriginHiddenUserFromJson(json);
@override
Map<String, dynamic> toJson() => _$MessageOriginHiddenUserToJson(this);
}
50 changes: 50 additions & 0 deletions lib/src/telegram/models/message_origin_user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

part of '../model.dart';

/// The message was originally sent by a known user.
///
/// https://core.telegram.org/bots/api#messageoriginuser
@JsonSerializable(fieldRename: FieldRename.snake)
class MessageOriginUser implements MessageOrigin {
@override
MessageOriginType type;
@override
int date;
User senderUser;

MessageOriginUser({
required this.type,
required this.date,
required this.senderUser,
});

@override
@JsonKey(includeFromJson: false, includeToJson: false)
DateTime get date_ =>
TimeHelper.toDateTime(date);
@override
set date_(DateTime dateTime) =>
date = TimeHelper.toUnixTime(dateTime);

factory MessageOriginUser.fromJson(Map<String, dynamic> json) =>
_$MessageOriginUserFromJson(json);
@override
Map<String, dynamic> toJson() => _$MessageOriginUserToJson(this);
}

0 comments on commit 4050fe4

Please sign in to comment.