diff --git a/library/src/main/java/com/pengrad/telegrambot/model/CallbackQuery.java b/library/src/main/java/com/pengrad/telegrambot/model/CallbackQuery.java index 9c96cd8e..71a3178e 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/CallbackQuery.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/CallbackQuery.java @@ -1,5 +1,7 @@ package com.pengrad.telegrambot.model; +import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; + import java.io.Serializable; /** @@ -11,7 +13,7 @@ public class CallbackQuery implements Serializable { private String id; private User from; - private Message message; + private MaybeInaccessibleMessage message; private String inline_message_id; private String chat_instance; private String data; @@ -25,10 +27,27 @@ public User from() { return from; } - public Message message() { + private MaybeInaccessibleMessage maybeInaccessibleMessage() { return message; } + /** + * @deprecated Use CallbackQuery#maybeInaccessibleMessage instead + */ + @Deprecated + public Message message() { + if (message instanceof Message) { + return (Message)message; + } + + Message result = new Message(); + result.setChat(message.chat()); + result.setMessageId(message.messageId()); + result.setDate(message.date()); + + return result; + } + public String inlineMessageId() { return inline_message_id; } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Chat.java b/library/src/main/java/com/pengrad/telegrambot/model/Chat.java index 330420d3..2508b267 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Chat.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Chat.java @@ -36,6 +36,10 @@ public enum Type { private ChatPhoto photo; private String[] active_usernames; private ReactionType[] available_reactions; + private Integer accent_color_id; + private String background_custom_emoji_id; + private Integer profile_accent_color_id; + private String profile_background_custom_emoji_id; private String emoji_status_custom_emoji_id; private Integer emoji_status_expiration_date; private String bio; @@ -52,6 +56,7 @@ public enum Type { private Integer slow_mode_delay; private Integer message_auto_delete_time; private Boolean has_protected_content; + private Boolean has_visible_history; private String sticker_set_name; private Boolean can_set_sticker_set; private Long linked_chat_id; @@ -106,6 +111,22 @@ public ReactionType[] availableReactions() { return available_reactions; } + public Integer accentColorId() { + return accent_color_id; + } + + public String backgroundCustomEmojiId() { + return background_custom_emoji_id; + } + + public Integer profileAccentColorId() { + return profile_accent_color_id; + } + + public String profileBackgroundCustomEmojiId() { + return profile_background_custom_emoji_id; + } + /** * @deprecated Use emojiStatusCustomEmojiId() instead */ @@ -177,6 +198,10 @@ public Boolean hasProtectedContent() { return has_protected_content != null && has_protected_content; } + public Boolean hasVisibleHistory() { + return has_visible_history != null && has_visible_history; + } + public String stickerSetName() { return sticker_set_name; } @@ -208,6 +233,10 @@ public boolean equals(Object o) { Objects.equals(photo, chat.photo) && Arrays.equals(active_usernames, chat.active_usernames) && Arrays.equals(available_reactions, chat.available_reactions) && + Objects.equals(accent_color_id, chat.accent_color_id) && + Objects.equals(background_custom_emoji_id, chat.background_custom_emoji_id) && + Objects.equals(profile_accent_color_id, chat.profile_accent_color_id) && + Objects.equals(profile_background_custom_emoji_id, chat.profile_background_custom_emoji_id) && Objects.equals(emoji_status_custom_emoji_id, chat.emoji_status_custom_emoji_id) && Objects.equals(emoji_status_expiration_date, chat.emoji_status_expiration_date) && Objects.equals(bio, chat.bio) && @@ -224,6 +253,7 @@ public boolean equals(Object o) { Objects.equals(slow_mode_delay, chat.slow_mode_delay) && Objects.equals(message_auto_delete_time, chat.message_auto_delete_time) && Objects.equals(has_protected_content, chat.has_protected_content) && + Objects.equals(has_visible_history, chat.has_visible_history) && Objects.equals(sticker_set_name, chat.sticker_set_name) && Objects.equals(can_set_sticker_set, chat.can_set_sticker_set) && Objects.equals(linked_chat_id, chat.linked_chat_id) && @@ -248,6 +278,10 @@ public String toString() { ", photo=" + photo + ", active_usernames=" + Arrays.toString(active_usernames) + ", available_reactions=" + Arrays.toString(available_reactions) + + ", accent_color_id=" + accent_color_id + + ", background_custom_emoji_id='" + background_custom_emoji_id + '\'' + + ", profile_accent_color_id=" + profile_accent_color_id + + ", profile_background_custom_emoji_id='" + profile_background_custom_emoji_id + '\'' + ", emoji_status_custom_emoji_id='" + emoji_status_custom_emoji_id + '\'' + ", emoji_status_expiration_date='" + emoji_status_expiration_date + '\'' + ", bio='" + bio + '\'' + @@ -264,6 +298,7 @@ public String toString() { ", slow_mode_delay=" + slow_mode_delay + ", message_auto_delete_time=" + message_auto_delete_time + ", has_protected_content=" + has_protected_content + + ", has_visible_history=" + has_visible_history + ", sticker_set_name='" + sticker_set_name + '\'' + ", can_set_sticker_set=" + can_set_sticker_set + ", linked_chat_id=" + linked_chat_id + diff --git a/library/src/main/java/com/pengrad/telegrambot/model/ExternalReplyInfo.java b/library/src/main/java/com/pengrad/telegrambot/model/ExternalReplyInfo.java new file mode 100644 index 00000000..5ee55e7d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/ExternalReplyInfo.java @@ -0,0 +1,174 @@ +package com.pengrad.telegrambot.model; + +import com.pengrad.telegrambot.model.giveaway.Giveaway; +import com.pengrad.telegrambot.model.giveaway.GiveawayWinners; +import com.pengrad.telegrambot.model.message.origin.MessageOrigin; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Objects; + + +public class ExternalReplyInfo implements Serializable { + private final static long serialVersionUID = 0L; + + private MessageOrigin origin; + private Chat chat; + private Integer message_id; + private LinkPreviewOptions link_preview_options; + private Animation animation; + private Audio audio; + private Document document; + private PhotoSize[] photo; + private Sticker sticker; + private Story story; + private Video video; + private VideoNote video_note; + private Voice voice; + private Boolean has_media_spoiler; + private Contact contact; + private Dice dice; + private Game game; + private Giveaway giveaway; + private GiveawayWinners giveaway_winners; + private Invoice invoice; + private Location location; + private Poll poll; + private Venue venue; + + public MessageOrigin origin() { + return origin; + } + + public Chat chat() { + return chat; + } + + public Integer messageId() { + return message_id; + } + + public LinkPreviewOptions linkPreviewOptions() { + return link_preview_options; + } + + public Animation animation() { + return animation; + } + + public Audio audio() { + return audio; + } + + public Document document() { + return document; + } + + public PhotoSize[] photo() { + return photo; + } + + public Sticker sticker() { + return sticker; + } + + public Story story() { + return story; + } + + public Video video() { + return video; + } + + public VideoNote videoNote() { + return video_note; + } + + public Voice voice() { + return voice; + } + + public Boolean hasMediaSpoiler() { + return has_media_spoiler; + } + + public Contact contact() { + return contact; + } + + public Dice dice() { + return dice; + } + + public Game game() { + return game; + } + + public Giveaway giveaway() { + return giveaway; + } + + public GiveawayWinners giveawayWinners() { + return giveaway_winners; + } + + public Invoice invoice() { + return invoice; + } + + public Location location() { + return location; + } + + public Poll poll() { + return poll; + } + + public Venue venue() { + return venue; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExternalReplyInfo that = (ExternalReplyInfo) o; + return Objects.equals(origin, that.origin) && Objects.equals(chat, that.chat) && Objects.equals(message_id, that.message_id) && Objects.equals(link_preview_options, that.link_preview_options) && Objects.equals(animation, that.animation) && Objects.equals(audio, that.audio) && Objects.equals(document, that.document) && Arrays.equals(photo, that.photo) && Objects.equals(sticker, that.sticker) && Objects.equals(story, that.story) && Objects.equals(video, that.video) && Objects.equals(video_note, that.video_note) && Objects.equals(voice, that.voice) && Objects.equals(has_media_spoiler, that.has_media_spoiler) && Objects.equals(contact, that.contact) && Objects.equals(dice, that.dice) && Objects.equals(game, that.game) && Objects.equals(giveaway, that.giveaway) && Objects.equals(giveaway_winners, that.giveaway_winners) && Objects.equals(invoice, that.invoice) && Objects.equals(location, that.location) && Objects.equals(poll, that.poll) && Objects.equals(venue, that.venue); + } + + @Override + public int hashCode() { + int result = Objects.hash(origin, chat, message_id, link_preview_options, animation, audio, document, sticker, story, video, video_note, voice, has_media_spoiler, contact, dice, game, giveaway, giveaway_winners, invoice, location, poll, venue); + result = 31 * result + Arrays.hashCode(photo); + return result; + } + + @Override + public String toString() { + return "ExternalReplyInfo{" + + "origin=" + origin + + ", chat=" + chat + + ", message_id=" + message_id + + ", link_preview_options=" + link_preview_options + + ", animation=" + animation + + ", audio=" + audio + + ", document=" + document + + ", photo=" + Arrays.toString(photo) + + ", sticker=" + sticker + + ", story=" + story + + ", video=" + video + + ", video_note=" + video_note + + ", voice=" + voice + + ", has_media_spoiler=" + has_media_spoiler + + ", contact=" + contact + + ", dice=" + dice + + ", game=" + game + + ", giveaway=" + giveaway + + ", giveaway_winners=" + giveaway_winners + + ", invoice=" + invoice + + ", location=" + location + + ", poll=" + poll + + ", venue=" + venue + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/LinkPreviewOptions.java b/library/src/main/java/com/pengrad/telegrambot/model/LinkPreviewOptions.java new file mode 100644 index 00000000..3eeae8c3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/LinkPreviewOptions.java @@ -0,0 +1,67 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; +import java.util.Objects; + +public class LinkPreviewOptions implements Serializable { + + private final static long serialVersionUID = 0L; + + + private Boolean is_disabled; + private String url; + private Boolean prefer_small_media; + private Boolean prefer_large_media; + private Boolean show_above_text; + + + public Boolean isDisabled() { + return is_disabled; + } + + public String url() { + return url; + } + + public Boolean preferSmallMedia() { + return prefer_small_media; + } + + public Boolean preferLargeMedia() { + return prefer_large_media; + } + + public Boolean showAboveText() { + return show_above_text; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LinkPreviewOptions that = (LinkPreviewOptions) o; + return Objects.equals(is_disabled, that.is_disabled) + && Objects.equals(url, that.url) + && Objects.equals(prefer_small_media, that.prefer_small_media) + && Objects.equals(prefer_large_media, that.prefer_large_media) + && Objects.equals(show_above_text, that.show_above_text); + } + + @Override + public int hashCode() { + return Objects.hash(is_disabled, url, prefer_small_media, prefer_large_media, show_above_text); + } + + @Override + public String toString() { + return "LinkPreviewOptions{" + + "is_disabled='" + is_disabled + "'," + + "url='" + url + "'," + + "prefer_small_media='" + prefer_small_media + "'," + + "prefer_large_media='" + prefer_large_media + "'," + + "show_above_text='" + show_above_text + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index d77479b7..8f3f7f2e 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -1,5 +1,7 @@ package com.pengrad.telegrambot.model; +import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; +import com.pengrad.telegrambot.model.message.origin.*; import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; import com.pengrad.telegrambot.passport.PassportData; @@ -11,24 +13,18 @@ * stas * 8/4/15. */ -public class Message implements Serializable { +public class Message extends MaybeInaccessibleMessage implements Serializable { private final static long serialVersionUID = 0L; - private Integer message_id; private Integer message_thread_id; private User from; private Chat sender_chat; - private Integer date; - private Chat chat; - private User forward_from; - private Chat forward_from_chat; - private Integer forward_from_message_id; - private String forward_signature; - private String forward_sender_name; - private Integer forward_date; + private MessageOrigin forward_origin; private Boolean is_topic_message; private Boolean is_automatic_forward; private Message reply_to_message; + private ExternalReplyInfo external_reply; + private TextQuote quote; private User via_bot; private Integer edit_date; private Boolean has_protected_content; @@ -38,6 +34,7 @@ public class Message implements Serializable { private String text; private MessageEntity[] entities; private MessageEntity[] caption_entities; + private LinkPreviewOptions link_preview_options; private Audio audio; private Document document; private Animation animation; @@ -64,11 +61,12 @@ public class Message implements Serializable { private MessageAutoDeleteTimerChanged message_auto_delete_timer_changed; private Long migrate_to_chat_id; private Long migrate_from_chat_id; - private Message pinned_message; + private MaybeInaccessibleMessage pinned_message; private Invoice invoice; private SuccessfulPayment successful_payment; private Story story; - private UserShared user_shared; + private UserShared user_shared; //@deprectated + private UsersShared users_shared; private ChatShared chat_shared; private String connected_website; private PassportData passport_data; @@ -88,10 +86,6 @@ public class Message implements Serializable { private InlineKeyboardMarkup reply_markup; private WebAppData web_app_data; - public Integer messageId() { - return message_id; - } - public Integer messageThreadId() { return message_thread_id; } @@ -104,40 +98,87 @@ public Chat senderChat() { return sender_chat; } - public Integer date() { - return date; - } - - public Chat chat() { - return chat; + private MessageOrigin forwardOrigin() { + return forward_origin; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public User forwardFrom() { - return forward_from; + if (forward_origin instanceof MessageOriginUser) { + return ((MessageOriginUser) forward_origin).senderUser(); + } + return null; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public Chat forwardFromChat() { - return forward_from_chat; + if (forward_origin instanceof MessageOriginChat) { + return ((MessageOriginChat) forward_origin).senderChat(); + } + + if (forward_origin instanceof MessageOriginChannel) { + return ((MessageOriginChannel) forward_origin).chat(); + } + + return null; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public Integer forwardFromMessageId() { - return forward_from_message_id; + if (forward_origin instanceof MessageOriginChannel) { + return ((MessageOriginChannel) forward_origin).messageId(); + } + + return null; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public String forwardSignature() { - return forward_signature; + if (forward_origin instanceof MessageOriginChat) { + return ((MessageOriginChat) forward_origin).authorSignature(); + } + + if (forward_origin instanceof MessageOriginChannel) { + return ((MessageOriginChannel) forward_origin).authorSignature(); + } + + return null; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public String forwardSenderName() { - return forward_sender_name; - } + if (forward_origin instanceof MessageOriginHiddenUser) { + return ((MessageOriginHiddenUser) forward_origin).senderUserName(); + } - public Boolean isTopicMessage() { - return is_topic_message != null && is_topic_message; + return null; } + /** + * @deprecated Use Message#forwardOrigin instead + */ + @Deprecated public Integer forwardDate() { - return forward_date; + return forward_origin.date(); + } + + public Boolean isTopicMessage() { + return is_topic_message != null && is_topic_message; } public Boolean isAutomaticForward() { @@ -147,6 +188,12 @@ public Boolean isAutomaticForward() { public Message replyToMessage() { return reply_to_message; } + public ExternalReplyInfo externalReply() { + return external_reply; + } + public TextQuote quote() { + return quote; + } public User viaBot() { return via_bot; @@ -185,6 +232,9 @@ public MessageEntity[] captionEntities() { return caption_entities; } + public LinkPreviewOptions linkPreviewOptions() { + return link_preview_options; + } public Audio audio() { return audio; } @@ -289,7 +339,7 @@ public Long migrateFromChatId() { return migrate_from_chat_id; } - public Message pinnedMessage() { + public MaybeInaccessibleMessage pinnedMessage() { return pinned_message; } @@ -305,10 +355,18 @@ public Story story() { return story; } + /** + * @deprecated Use usersShared instead + */ + @Deprecated public UserShared userShared() { return user_shared; } + public UsersShared usersShared() { + return users_shared; + } + public ChatShared chatShared() { return chat_shared; } @@ -377,6 +435,27 @@ public WebAppData webAppData() { return web_app_data; } + /** + * Only for backwards-compatibility with MaybeInaccessibleMessage + */ + void setChat(Chat chat) { + this.chat = chat; + } + + /** + * Only for backwards-compatibility with MaybeInaccessibleMessage + */ + void setMessageId(Integer messageId) { + this.message_id = messageId; + } + + /** + * Only for backwards-compatibility with MaybeInaccessibleMessage + */ + void setDate(Integer date) { + this.date = date; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -388,15 +467,12 @@ public boolean equals(Object o) { Objects.equals(sender_chat, message.sender_chat) && Objects.equals(date, message.date) && Objects.equals(chat, message.chat) && - Objects.equals(forward_from, message.forward_from) && - Objects.equals(forward_from_chat, message.forward_from_chat) && - Objects.equals(forward_from_message_id, message.forward_from_message_id) && - Objects.equals(forward_signature, message.forward_signature) && - Objects.equals(forward_sender_name, message.forward_sender_name) && - Objects.equals(forward_date, message.forward_date) && + Objects.equals(forward_origin, message.forward_origin) && Objects.equals(is_topic_message, message.is_topic_message) && Objects.equals(is_automatic_forward, message.is_automatic_forward) && Objects.equals(reply_to_message, message.reply_to_message) && + Objects.equals(external_reply, message.external_reply) && + Objects.equals(quote, message.quote) && Objects.equals(via_bot, message.via_bot) && Objects.equals(edit_date, message.edit_date) && Objects.equals(has_protected_content, message.has_protected_content) && @@ -406,6 +482,7 @@ public boolean equals(Object o) { Objects.equals(text, message.text) && Arrays.equals(entities, message.entities) && Arrays.equals(caption_entities, message.caption_entities) && + Objects.equals(link_preview_options, message.link_preview_options) && Objects.equals(audio, message.audio) && Objects.equals(document, message.document) && Objects.equals(animation, message.animation) && @@ -437,6 +514,7 @@ public boolean equals(Object o) { Objects.equals(successful_payment, message.successful_payment) && Objects.equals(story, message.story) && Objects.equals(user_shared, message.user_shared) && + Objects.equals(users_shared, message.users_shared) && Objects.equals(chat_shared, message.chat_shared) && Objects.equals(connected_website, message.connected_website) && Objects.equals(passport_data, message.passport_data) && @@ -470,15 +548,12 @@ public String toString() { ", sender_chat=" + sender_chat + ", date=" + date + ", chat=" + chat + - ", forward_from=" + forward_from + - ", forward_from_chat=" + forward_from_chat + - ", forward_from_message_id=" + forward_from_message_id + - ", forward_signature='" + forward_signature + '\'' + - ", forward_sender_name='" + forward_sender_name + '\'' + - ", forward_date=" + forward_date + + ", forward_origin=" + forward_origin + ", is_topic_message=" + is_topic_message + ", is_automatic_forward=" + is_automatic_forward + ", reply_to_message=" + reply_to_message + + ", external_reply=" + external_reply + + ", quote=" + quote + ", via_bot=" + via_bot + ", edit_date=" + edit_date + ", has_protected_content=" + has_protected_content+ @@ -488,6 +563,7 @@ public String toString() { ", text='" + text + '\'' + ", entities=" + Arrays.toString(entities) + ", caption_entities=" + Arrays.toString(caption_entities) + + ", link_preview_options=" + link_preview_options + ", audio=" + audio + ", document=" + document + ", animation=" + animation + @@ -519,6 +595,7 @@ public String toString() { ", successful_payment=" + successful_payment + ", story=" + story + ", user_shared=" + user_shared + + ", users_shared=" + users_shared + ", chat_shared=" + chat_shared + ", connected_website='" + connected_website + '\'' + ", passport_data=" + passport_data + diff --git a/library/src/main/java/com/pengrad/telegrambot/model/MessageEntity.java b/library/src/main/java/com/pengrad/telegrambot/model/MessageEntity.java index 473e91de..eeb2742c 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/MessageEntity.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/MessageEntity.java @@ -12,7 +12,7 @@ public class MessageEntity implements Serializable { public enum Type { mention, hashtag, cashtag, bot_command, url, email, phone_number, bold, italic, code, pre, text_link, - text_mention, underline, strikethrough, spoiler, custom_emoji + text_mention, underline, strikethrough, spoiler, custom_emoji, blockquote } private Type type; diff --git a/library/src/main/java/com/pengrad/telegrambot/model/TextQuote.java b/library/src/main/java/com/pengrad/telegrambot/model/TextQuote.java new file mode 100644 index 00000000..15c410ec --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/TextQuote.java @@ -0,0 +1,57 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Objects; + +public class TextQuote implements Serializable { + + private final static long serialVersionUID = 0L; + + private String text; + private MessageEntity[] entities; + private Integer position; + private Boolean is_manual; + + public String text() { + return text; + } + + public MessageEntity[] entities() { + return entities; + } + + public Integer position() { + return position; + } + + public Boolean isManual() { + return is_manual; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TextQuote textQuote = (TextQuote) o; + return Objects.equals(text, textQuote.text) && Arrays.equals(entities, textQuote.entities) && Objects.equals(position, textQuote.position) && Objects.equals(is_manual, textQuote.is_manual); + } + + @Override + public int hashCode() { + int result = Objects.hash(text, position, is_manual); + result = 31 * result + Arrays.hashCode(entities); + return result; + } + + @Override + public String toString() { + return "TextQuote{" + + "text='" + text + '\'' + + ", entities=" + Arrays.toString(entities) + + ", position=" + position + + ", is_manual=" + is_manual + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Update.java b/library/src/main/java/com/pengrad/telegrambot/model/Update.java index ff17a90d..049ce28f 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Update.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Update.java @@ -1,5 +1,8 @@ package com.pengrad.telegrambot.model; +import com.pengrad.telegrambot.model.chatboost.ChatBoostRemoved; +import com.pengrad.telegrambot.model.chatboost.ChatBoostUpdated; + import java.io.Serializable; import java.util.Objects; @@ -27,6 +30,8 @@ public class Update implements Serializable { private ChatJoinRequest chat_join_request; private MessageReactionUpdated message_reaction; private MessageReactionCountUpdated message_reaction_count; + private ChatBoostUpdated chat_boost; + private ChatBoostRemoved removed_chat_boost; public Integer updateId() { return update_id; @@ -96,6 +101,14 @@ public MessageReactionCountUpdated messageReactionCount() { return message_reaction_count; } + public ChatBoostUpdated chatBoost() { + return chat_boost; + } + + public ChatBoostRemoved removedChatBoost() { + return removed_chat_boost; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -117,7 +130,9 @@ public boolean equals(Object o) { Objects.equals(chat_member, update.chat_member) && Objects.equals(chat_join_request, update.chat_join_request) && Objects.equals(message_reaction, update.message_reaction) && - Objects.equals(message_reaction_count, update.message_reaction_count); + Objects.equals(message_reaction_count, update.message_reaction_count) && + Objects.equals(chat_boost, update.chat_boost) && + Objects.equals(removed_chat_boost, update.removed_chat_boost); } @Override @@ -145,6 +160,8 @@ public String toString() { ", chat_join_request=" + chat_join_request + ", message_reaction=" + message_reaction + ", message_reaction_count=" + message_reaction_count + + ", chat_boost=" + chat_boost + + ", removed_chat_boost=" + removed_chat_boost + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/UsersShared.java b/library/src/main/java/com/pengrad/telegrambot/model/UsersShared.java new file mode 100644 index 00000000..3e1d7853 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/UsersShared.java @@ -0,0 +1,43 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Objects; + +public class UsersShared implements Serializable { + private final static long serialVersionUID = 0L; + + private Integer request_id; + private Integer[] user_ids; + + public Integer requestId() { + return request_id; + } + + public Integer[] userIds() { + return user_ids; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UsersShared that = (UsersShared) o; + return Objects.equals(request_id, that.request_id) && Arrays.equals(user_ids, that.user_ids); + } + + @Override + public int hashCode() { + int result = Objects.hash(request_id); + result = 31 * result + Arrays.hashCode(user_ids); + return result; + } + + @Override + public String toString() { + return "UsersShared{" + + "request_id='" + request_id + '\'' + + ", user_ids='" + Arrays.toString(user_ids) + '\'' + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoost.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoost.java new file mode 100644 index 00000000..97bb9c83 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoost.java @@ -0,0 +1,55 @@ +package com.pengrad.telegrambot.model.chatboost; + +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSource; + +import java.util.Objects; + +public class ChatBoost { + + private String boost_id; + private Integer add_date; + private Integer expiration_date; + private ChatBoostSource source; + + public String boostId() { + return boost_id; + } + + public Integer addDate() { + return add_date; + } + + public Integer expirationDate() { + return expiration_date; + } + + public ChatBoostSource source() { + return source; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChatBoost chatBoost = (ChatBoost) o; + return Objects.equals(boost_id, chatBoost.boost_id) + && Objects.equals(add_date, chatBoost.add_date) + && Objects.equals(expiration_date, chatBoost.expiration_date) + && Objects.equals(source, chatBoost.source); + } + + @Override + public int hashCode() { + return boost_id != null ? boost_id.hashCode() : 0; + } + + @Override + public String toString() { + return "ChatBoost{" + + "boost_id='" + boost_id + '\'' + + ", add_date=" + add_date + + ", expiration_date=" + expiration_date + + ", source=" + source + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostRemoved.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostRemoved.java new file mode 100644 index 00000000..02f5bd0e --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostRemoved.java @@ -0,0 +1,56 @@ +package com.pengrad.telegrambot.model.chatboost; + +import com.pengrad.telegrambot.model.Chat; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSource; + +import java.util.Objects; + +public class ChatBoostRemoved { + + private Chat chat; + private String boost_id; + private Integer remove_date; + private ChatBoostSource source; + + public Chat chat() { + return chat; + } + + public String boostId() { + return boost_id; + } + + public Integer removeDate() { + return remove_date; + } + + public ChatBoostSource source() { + return source; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChatBoostRemoved that = (ChatBoostRemoved) o; + return Objects.equals(chat, that.chat) + && Objects.equals(boost_id, that.boost_id) + && Objects.equals(remove_date, that.remove_date) + && Objects.equals(source, that.source); + } + + @Override + public int hashCode() { + return boost_id != null ? boost_id.hashCode() : 0; + } + + @Override + public String toString() { + return "ChatBoostRemoved{" + + "chat=" + chat + + ", boost_id='" + boost_id + '\'' + + ", remove_date=" + remove_date + + ", source=" + source + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostUpdated.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostUpdated.java new file mode 100644 index 00000000..4779ba1e --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/ChatBoostUpdated.java @@ -0,0 +1,41 @@ +package com.pengrad.telegrambot.model.chatboost; + +import com.pengrad.telegrambot.model.Chat; + +import java.util.Objects; + +public class ChatBoostUpdated { + + private Chat chat; + private ChatBoost boost; + + public Chat chat() { + return chat; + } + + public ChatBoost boost() { + return boost; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChatBoostUpdated that = (ChatBoostUpdated) o; + return Objects.equals(chat, that.chat) + && Objects.equals(boost, that.boost); + } + + @Override + public int hashCode() { + return Objects.hash(chat, boost); + } + + @Override + public String toString() { + return "ChatBoostUpdated{" + + "chat=" + chat + + ", boost=" + boost + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSource.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSource.java new file mode 100644 index 00000000..cf733082 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSource.java @@ -0,0 +1,37 @@ +package com.pengrad.telegrambot.model.chatboost.source; + +import java.io.Serializable; +import java.util.Objects; + +import com.pengrad.telegrambot.model.User; + + +public class ChatBoostSource implements Serializable { + private final static long serialVersionUID = 0L; + + protected String source; + protected User user; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ChatBoostSource that = (ChatBoostSource) o; + return Objects.equals(source, that.source) + && Objects.equals(user, that.user); + } + + @Override + public int hashCode() { + return Objects.hash(source, user); + } + + @Override + public String toString() { + return "ChatBoostSource{" + + "source='" + source + "'," + + "user='" + user + "'" + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiftCode.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiftCode.java new file mode 100644 index 00000000..dbf2ea2a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiftCode.java @@ -0,0 +1,25 @@ +package com.pengrad.telegrambot.model.chatboost.source; + +import java.io.Serializable; +import java.util.Objects; + + +public class ChatBoostSourceGiftCode extends ChatBoostSource implements Serializable { + private final static long serialVersionUID = 0L; + + public final static String CHAT_BOOST_TYPE = "gift_code"; + + @Override + public int hashCode() { + return Objects.hash(source, user); + } + + @Override + public String toString() { + return "ChatBoostSourceGiftCode{" + + "source='" + source + "'," + + "user='" + user + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiveaway.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiveaway.java new file mode 100644 index 00000000..4679d7c3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourceGiveaway.java @@ -0,0 +1,37 @@ +package com.pengrad.telegrambot.model.chatboost.source; + +import java.io.Serializable; +import java.util.Objects; + + +public class ChatBoostSourceGiveaway extends ChatBoostSource implements Serializable { + private final static long serialVersionUID = 0L; + + public final static String CHAT_BOOST_TYPE = "giveaway"; + + private Integer giveaway_message_id; + private Boolean is_unclaimed; + + public Integer giveawayMessageId() { + return giveaway_message_id; + } + public Boolean isUnclaimed() { + return is_unclaimed != null && is_unclaimed; + } + + @Override + public int hashCode() { + return Objects.hash(source, user, giveaway_message_id, is_unclaimed); + } + + @Override + public String toString() { + return "ChatBoostSourceGiveaway{" + + "source='" + source + "'," + + "user='" + user + "'," + + "giveaway_message_id='" + giveaway_message_id + "'," + + "is_unclaimed='" + is_unclaimed + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourcePremium.java b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourcePremium.java new file mode 100644 index 00000000..dacba5ca --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/chatboost/source/ChatBoostSourcePremium.java @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.model.chatboost.source; + +import java.io.Serializable; +import java.util.Objects; + + +public class ChatBoostSourcePremium extends ChatBoostSource implements Serializable { + private final static long serialVersionUID = 0L; + + public final static String CHAT_BOOST_TYPE = "premium"; + + @Override + public int hashCode() { + return Objects.hash(source, user); + } + + @Override + public String toString() { + return "ChatBoostSourcePremium{" + + "source='" + source + "'," + + "user='" + user + "'" + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/giveaway/Giveaway.java b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/Giveaway.java new file mode 100644 index 00000000..7809bfee --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/Giveaway.java @@ -0,0 +1,83 @@ +package com.pengrad.telegrambot.model.giveaway; + +import com.pengrad.telegrambot.model.Chat; +import com.pengrad.telegrambot.model.LinkPreviewOptions; + +import java.io.Serializable; +import java.util.Objects; + +public class Giveaway implements Serializable { + + private final static long serialVersionUID = 0L; + + private Chat[] chats; + private Integer winners_selection_date; + private Integer winner_count; + private Boolean only_new_members; + private Boolean has_public_winners; + private String prize_description; + private String[] country_codes; + private Integer premium_subscription_month_count; + + + public Chat[] chats() { + return chats; + } + public Integer winnersSelectionDate() { + return winners_selection_date; + } + public Integer winnerCount() { + return winner_count; + } + public Boolean onlyNewMembers() { + return only_new_members; + } + public Boolean hasPublicWinners() { + return has_public_winners; + } + public String prizeDescription() { + return prize_description; + } + public String[] countryCodes() { + return country_codes; + } + public Integer premiumSubscriptionMonthCount() { + return premium_subscription_month_count; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Giveaway that = (Giveaway) o; + return Objects.equals(chats, that.chats) + && Objects.equals(winners_selection_date, that.winners_selection_date) + && Objects.equals(winner_count, that.winner_count) + && Objects.equals(only_new_members, that.only_new_members) + && Objects.equals(has_public_winners, that.has_public_winners) + && Objects.equals(prize_description, that.prize_description) + && Objects.equals(country_codes, that.country_codes) + && Objects.equals(premium_subscription_month_count, that.premium_subscription_month_count); + } + + @Override + public int hashCode() { + return Objects.hash(chats, winners_selection_date, winner_count, only_new_members, has_public_winners, prize_description, country_codes, premium_subscription_month_count); + } + + @Override + public String toString() { + return "Giveaway{" + + "chats='" + chats + "'," + + "winners_selection_date='" + winners_selection_date + "'," + + "winner_count='" + winner_count + "'," + + "only_new_members='" + only_new_members + "'," + + "has_public_winners='" + has_public_winners + "'," + + "prize_description='" + prize_description + "'," + + "country_codes='" + country_codes + "'," + + "premium_subscription_month_count='" + premium_subscription_month_count + "'" + + '}'; + } + + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayCompleted.java b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayCompleted.java new file mode 100644 index 00000000..215dbed9 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayCompleted.java @@ -0,0 +1,54 @@ +package com.pengrad.telegrambot.model.giveaway; + +import com.pengrad.telegrambot.model.Message; + +import java.io.Serializable; +import java.util.Objects; + +public class GiveawayCompleted implements Serializable { + + private final static long serialVersionUID = 0L; + + private Integer winner_count; + private Integer unclaimed_prize_count; + private Message giveaway_message; + + + public Integer winnerCount() { + return winner_count; + } + + public Integer unclaimedPrizeCount() { + return unclaimed_prize_count; + } + + public Message giveawayMessage() { + return giveaway_message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GiveawayCompleted that = (GiveawayCompleted) o; + return Objects.equals(winner_count, that.winner_count) + && Objects.equals(unclaimed_prize_count, that.unclaimed_prize_count) + && Objects.equals(giveaway_message, that.giveaway_message); + } + + @Override + public int hashCode() { + return Objects.hash(winner_count, unclaimed_prize_count, giveaway_message); + } + + @Override + public String toString() { + return "GiveawayCompleted{" + + "winner_count='" + winner_count + "'," + + "unclaimed_prize_count='" + unclaimed_prize_count + "'," + + "giveaway_message='" + giveaway_message + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayWinners.java b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayWinners.java new file mode 100644 index 00000000..f81b49bc --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/giveaway/GiveawayWinners.java @@ -0,0 +1,99 @@ +package com.pengrad.telegrambot.model.giveaway; + +import com.pengrad.telegrambot.model.Chat; +import com.pengrad.telegrambot.model.User; + +import java.io.Serializable; +import java.util.Objects; + +public class GiveawayWinners implements Serializable { + + private final static long serialVersionUID = 0L; + + private Chat chat; + private Integer giveaway_message_id; + private Integer winners_selection_date; + private Integer winner_count; + private User[] winners; + private Integer additional_chat_count; + private Integer premium_subscription_month_count; + private Integer unclaimed_prize_count; + private Boolean only_new_members; + private Boolean was_refunded; + private String prize_description; + + + public Chat chat() { + return chat; + } + public Integer giveawayMessageId() { + return giveaway_message_id; + } + public Integer winnersSelectionDate() { + return winners_selection_date; + } + public Integer winnerCount() { + return winner_count; + } + public User[] winners() { + return winners; + } + public Integer additionalChatCount() { + return additional_chat_count; + } + public Integer premiumSubscriptionMonthCount() { + return premium_subscription_month_count; + } + public Integer unclaimedPrizeCount() { + return unclaimed_prize_count; + } + public Boolean onlyNewMembers() { + return only_new_members; + } + public Boolean wasRefunded() { + return was_refunded; + } + public String prizeDescription() { + return prize_description; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GiveawayWinners that = (GiveawayWinners) o; + return Objects.equals(chat, that.chat) + && Objects.equals(winners_selection_date, that.winners_selection_date) + && Objects.equals(winner_count, that.winner_count) + && Objects.equals(winners, that.winners) + && Objects.equals(additional_chat_count, that.additional_chat_count) + && Objects.equals(premium_subscription_month_count, that.premium_subscription_month_count) + && Objects.equals(unclaimed_prize_count, that.unclaimed_prize_count) + && Objects.equals(only_new_members, that.only_new_members) + && Objects.equals(was_refunded, that.was_refunded) + && Objects.equals(prize_description, that.prize_description); + } + + @Override + public int hashCode() { + return Objects.hash(chat, winners_selection_date, winner_count, winners, additional_chat_count, premium_subscription_month_count, unclaimed_prize_count, only_new_members, was_refunded, prize_description); + } + + @Override + public String toString() { + return "GiveawayWinners{" + + "chat='" + chat + "'," + + "winners_selection_date='" + winners_selection_date + "'," + + "winner_count='" + winner_count + "'," + + "winners='" + winners + "'," + + "additional_chat_count='" + additional_chat_count + "'," + + "premium_subscription_month_count='" + premium_subscription_month_count + "'," + + "unclaimed_prize_count='" + unclaimed_prize_count + "'," + + "only_new_members='" + only_new_members + "'," + + "was_refunded='" + was_refunded + "'," + + "prize_description='" + prize_description + "'" + + '}'; + } + + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/InaccessibleMessage.java b/library/src/main/java/com/pengrad/telegrambot/model/message/InaccessibleMessage.java new file mode 100644 index 00000000..c887d988 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/InaccessibleMessage.java @@ -0,0 +1,15 @@ +package com.pengrad.telegrambot.model.message; + +public class InaccessibleMessage extends MaybeInaccessibleMessage { + + public static final Integer INACCESSIBLE_MESSAGE_DATE = 0; + + @Override + public String toString() { + return "InaccessibleMessage{" + + "chat=" + chat + + ", message_id=" + message_id + + ", date=" + date + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/MaybeInaccessibleMessage.java b/library/src/main/java/com/pengrad/telegrambot/model/message/MaybeInaccessibleMessage.java new file mode 100644 index 00000000..4dc9511c --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/MaybeInaccessibleMessage.java @@ -0,0 +1,48 @@ +package com.pengrad.telegrambot.model.message; + +import com.pengrad.telegrambot.model.Chat; + +import java.util.Objects; + +public class MaybeInaccessibleMessage { + + protected Chat chat; + protected Integer message_id; + protected Integer date; + + public Chat chat() { + return chat; + } + + public Integer messageId() { + return message_id; + } + + public Integer date() { + return date; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MaybeInaccessibleMessage that = (MaybeInaccessibleMessage) o; + return Objects.equals(chat, that.chat) + && Objects.equals(message_id, that.message_id) + && Objects.equals(date, that.date); + } + + @Override + public int hashCode() { + return Objects.hash(chat, message_id); + } + + @Override + public String toString() { + return "MaybeInaccessibleMessage{" + + "chat=" + chat + + ", message_id=" + message_id + + ", date=" + date + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOrigin.java b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOrigin.java new file mode 100644 index 00000000..443aabaf --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOrigin.java @@ -0,0 +1,42 @@ +package com.pengrad.telegrambot.model.message.origin; + +import java.io.Serializable; +import java.util.Objects; + +public class MessageOrigin implements Serializable { + private final static long serialVersionUID = 0L; + + protected String type; + protected Integer date; + + public String type() { + return type; + } + + public Integer date() { + return date; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MessageOrigin that = (MessageOrigin) o; + return Objects.equals(type, that.type) + && Objects.equals(date, that.date); + } + + @Override + public int hashCode() { + return Objects.hash(type, date); + } + + @Override + public String toString() { + return "MessageOrigin{" + + "type='" + type + "'," + + "date='" + date + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChannel.java b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChannel.java new file mode 100644 index 00000000..8a08b6b6 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChannel.java @@ -0,0 +1,56 @@ +package com.pengrad.telegrambot.model.message.origin; + +import com.pengrad.telegrambot.model.Chat; + +import java.util.Objects; + +public class MessageOriginChannel extends MessageOrigin { + + public static final String MESSAGE_ORIGIN_TYPE = "channel"; + + private Chat chat; + private Integer message_id; + + private String author_signature; + + public Chat chat() { + return chat; + } + + public Integer messageId() { + return message_id; + } + + public String authorSignature() { + return author_signature; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MessageOriginChannel that = (MessageOriginChannel) o; + return Objects.equals(type, that.type) + && Objects.equals(date, that.date) + && Objects.equals(chat, that.chat) + && Objects.equals(message_id, that.message_id) + && Objects.equals(author_signature, that.author_signature); + } + + @Override + public int hashCode() { + return Objects.hash(type, date, chat, message_id, author_signature); + } + + @Override + public String toString() { + return "MessageOriginChannel{" + + "type='" + type + "'," + + "date='" + date + "'," + + "chat='" + chat + "'," + + "message_id='" + message_id + "'," + + "author_signature='" + author_signature + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChat.java b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChat.java new file mode 100644 index 00000000..63acfe6d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginChat.java @@ -0,0 +1,48 @@ +package com.pengrad.telegrambot.model.message.origin; + +import com.pengrad.telegrambot.model.Chat; + +import java.util.Objects; + +public class MessageOriginChat extends MessageOrigin { + + public static final String MESSAGE_ORIGIN_TYPE = "chat"; + + private Chat sender_chat; + private String author_signature; + + public Chat senderChat() { + return sender_chat; + } + + public String authorSignature() { + return author_signature; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MessageOriginChat that = (MessageOriginChat) o; + return Objects.equals(type, that.type) + && Objects.equals(date, that.date) + && Objects.equals(sender_chat, that.sender_chat) + && Objects.equals(author_signature, that.author_signature); + } + + @Override + public int hashCode() { + return Objects.hash(type, date, sender_chat, author_signature); + } + + @Override + public String toString() { + return "MessageOriginChat{" + + "type='" + type + "'," + + "date='" + date + "'," + + "sender_chat='" + sender_chat + "'," + + "author_signature='" + author_signature + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginHiddenUser.java b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginHiddenUser.java new file mode 100644 index 00000000..3f205edb --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginHiddenUser.java @@ -0,0 +1,39 @@ +package com.pengrad.telegrambot.model.message.origin; + +import java.util.Objects; + +public class MessageOriginHiddenUser extends MessageOrigin { + + public static final String MESSAGE_ORIGIN_TYPE = "hidden_user"; + + private String sender_user_name; + + public String senderUserName() { + return sender_user_name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MessageOriginHiddenUser that = (MessageOriginHiddenUser) o; + return Objects.equals(type, that.type) + && Objects.equals(date, that.date) + && Objects.equals(sender_user_name, that.sender_user_name); + } + + @Override + public int hashCode() { + return Objects.hash(type, date, sender_user_name); + } + + @Override + public String toString() { + return "MessageOriginHiddenUser{" + + "type='" + type + "'," + + "date='" + date + "'," + + "sender_user_name='" + sender_user_name + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginUser.java b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginUser.java new file mode 100644 index 00000000..8f7f7462 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/message/origin/MessageOriginUser.java @@ -0,0 +1,41 @@ +package com.pengrad.telegrambot.model.message.origin; + +import com.pengrad.telegrambot.model.User; + +import java.util.Objects; + +public class MessageOriginUser extends MessageOrigin { + + public static final String MESSAGE_ORIGIN_TYPE = "user"; + + private User sender_user; + + public User senderUser() { + return sender_user; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MessageOriginUser that = (MessageOriginUser) o; + return Objects.equals(type, that.type) + && Objects.equals(date, that.date) + && Objects.equals(sender_user, that.sender_user); + } + + @Override + public int hashCode() { + return Objects.hash(type, date, sender_user); + } + + @Override + public String toString() { + return "MessageOriginUser{" + + "type='" + type + "'," + + "date='" + date + "'," + + "sender_user='" + sender_user + "'" + + '}'; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InputTextMessageContent.java b/library/src/main/java/com/pengrad/telegrambot/model/request/InputTextMessageContent.java index b8c480af..0a6edd43 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/InputTextMessageContent.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/InputTextMessageContent.java @@ -1,6 +1,8 @@ package com.pengrad.telegrambot.model.request; +import com.pengrad.telegrambot.model.LinkPreviewOptions; import com.pengrad.telegrambot.model.MessageEntity; +import com.pengrad.telegrambot.request.EditMessageText; import java.io.Serializable; @@ -13,6 +15,7 @@ public class InputTextMessageContent extends InputMessageContent implements Seri private String message_text; private String parse_mode; + private LinkPreviewOptions link_preview_options; private Boolean disable_web_page_preview; private MessageEntity[] entities; @@ -30,6 +33,14 @@ public InputTextMessageContent entities(MessageEntity... entities) { return this; } + public InputTextMessageContent linkPreviewOptions(LinkPreviewOptions linkPreviewOptions) { + this.link_preview_options = linkPreviewOptions; + return this; + } + + /* + @deprecated Use linkPreviewOptions instead + */ public InputTextMessageContent disableWebPagePreview(Boolean disableWebPagePreview) { this.disable_web_page_preview = disableWebPagePreview; return this; diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButton.java b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButton.java index 4143c068..e51d1fa4 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButton.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButton.java @@ -15,7 +15,8 @@ public class KeyboardButton implements Serializable { private boolean request_contact; private boolean request_location; private KeyboardButtonPollType request_poll; - private KeyboardButtonRequestUser request_user; + private KeyboardButtonRequestUsers request_users; + private KeyboardButtonRequestUser request_user; // @deprecated private KeyboardButtonRequestChat request_chat; private WebAppInfo web_app; @@ -38,11 +39,20 @@ public KeyboardButton requestPoll(KeyboardButtonPollType poll) { return this; } + /** + * @deprecated Use reqyestUsers instead + */ + @Deprecated public KeyboardButton requestUser(KeyboardButtonRequestUser user) { this.request_user = user; return this; } + public KeyboardButton requestUsers(KeyboardButtonRequestUsers users) { + this.request_users = users; + return this; + } + public KeyboardButton requestChat(KeyboardButtonRequestChat chat) { this.request_chat = chat; return this; diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUser.java b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUser.java index 5e8d46fd..934d9e90 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUser.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUser.java @@ -2,6 +2,10 @@ import java.io.Serializable; +/** + * @deprecated Use KeyboardButtonRequestUsers instead + */ +@Deprecated public class KeyboardButtonRequestUser implements Serializable { private final static long serialVersionUID = 0L; diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUsers.java b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUsers.java new file mode 100644 index 00000000..ffa418f5 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButtonRequestUsers.java @@ -0,0 +1,32 @@ +package com.pengrad.telegrambot.model.request; + +import java.io.Serializable; + +public class KeyboardButtonRequestUsers implements Serializable { + private final static long serialVersionUID = 0L; + + private Integer request_id; + private Boolean user_is_bot; + private Boolean user_is_premium; + private Integer max_quantity; + + public KeyboardButtonRequestUsers(Integer requestId) { + this.request_id = requestId; + } + + public KeyboardButtonRequestUsers userIsBot(Boolean userIsBot) { + this.user_is_bot = userIsBot; + return this; + } + + public KeyboardButtonRequestUsers userIsPremium(Boolean userIsPremium) { + this.user_is_premium = userIsPremium; + return this; + } + + public KeyboardButtonRequestUsers maxQuantity(Integer maxQuantity) { + this.max_quantity = maxQuantity; + return this; + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/ReplyParameters.java b/library/src/main/java/com/pengrad/telegrambot/model/request/ReplyParameters.java new file mode 100644 index 00000000..aa36fad0 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/ReplyParameters.java @@ -0,0 +1,52 @@ +package com.pengrad.telegrambot.model.request; + +import com.pengrad.telegrambot.model.MessageEntity; + +import java.io.Serializable; + +public class ReplyParameters implements Serializable { + + private final static long serialVersionUID = 0L; + + private Integer message_id; + private Object chat_id; + private Boolean allow_sending_without_reply; + private String quote; + private String quote_parse_mode; + private MessageEntity[] quote_entities; + private Integer quote_position; + + public ReplyParameters(Integer messageId) { + this.message_id = messageId; + } + + public ReplyParameters(Integer messageId, Object chatId) { + this.message_id = messageId; + this.chat_id = chatId; + } + + public ReplyParameters allowSendingWithoutReply(Boolean allowSendingWithoutReply) { + this.allow_sending_without_reply = allowSendingWithoutReply; + return this; + } + + public ReplyParameters quote(String quote) { + this.quote = quote; + return this; + } + + public ReplyParameters quoteParseMode(ParseMode parseMode) { + this.quote_parse_mode = parseMode.name(); + return this; + } + + public ReplyParameters quoteEntities(MessageEntity[] quoteEntities) { + this.quote_entities = quoteEntities; + return this; + } + + public ReplyParameters quotePosition(Integer quotePosition) { + this.quote_position = quotePosition; + return this; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/AbstractSendRequest.java b/library/src/main/java/com/pengrad/telegrambot/request/AbstractSendRequest.java index 7cc01a97..af7afd43 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/AbstractSendRequest.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/AbstractSendRequest.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.request; +import com.pengrad.telegrambot.model.request.ReplyParameters; import com.pengrad.telegrambot.model.request.Keyboard; import com.pengrad.telegrambot.response.SendResponse; @@ -22,10 +23,20 @@ public T disableNotification(boolean disableNotification) { return add("disable_notification", disableNotification); } + public T replyParameters(ReplyParameters replyParameters) { + return add("reply_parameters", replyParameters); + } + + /* + @deprecated Use replyParameters instead + */ public T replyToMessageId(int replyToMessageId) { return add("reply_to_message_id", replyToMessageId); } + /* + @deprecated Use replyParameters instead + */ public T allowSendingWithoutReply(boolean allowSendingWithoutReply) { return add("allow_sending_without_reply", allowSendingWithoutReply); } @@ -37,4 +48,5 @@ public T replyMarkup(Keyboard replyMarkup) { public T protectContent(boolean protectContent) { return add("protect_content", protectContent); } + } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessage.java b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessage.java index ba8a19a7..a4e74616 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessage.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessage.java @@ -1,6 +1,7 @@ package com.pengrad.telegrambot.request; import com.pengrad.telegrambot.model.MessageEntity; +import com.pengrad.telegrambot.model.request.ReplyParameters; import com.pengrad.telegrambot.model.request.Keyboard; import com.pengrad.telegrambot.model.request.ParseMode; import com.pengrad.telegrambot.response.MessageIdResponse; @@ -32,14 +33,20 @@ public CopyMessage captionEntities(MessageEntity... entities) { return add("caption_entities", entities); } - public CopyMessage disableNotification(boolean disableNotification) { - return add("disable_notification", disableNotification); + public CopyMessage replyParameters(ReplyParameters replyParameters) { + return add("reply_parameters", replyParameters); } + /* + @deprecated Use replyParameters instead + */ public CopyMessage allowSendingWithoutReply(boolean allowSendingWithoutReply) { return add("allow_sending_without_reply", allowSendingWithoutReply); } + /* + @deprecated Use replyParameters instead + */ public CopyMessage replyToMessageId(int replyToMessageId) { return add("reply_to_message_id", replyToMessageId); } @@ -48,4 +55,11 @@ public CopyMessage replyMarkup(Keyboard replyMarkup) { return add("reply_markup", replyMarkup); } + public CopyMessage disableNotification(boolean disableNotification) { + return add("disable_notification", disableNotification); + } + public CopyMessage protectContent(boolean protectContent) { + return add("protect_content", protectContent); + } + } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java new file mode 100644 index 00000000..7bdd2471 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.java @@ -0,0 +1,28 @@ +package com.pengrad.telegrambot.request; + +import com.pengrad.telegrambot.response.MessageIdsResponse; + + +public class CopyMessages extends BaseRequest { + + public CopyMessages(Object chatId, Object fromChatId, int[] messageIds) { + super(MessageIdsResponse.class); + add("chat_id", chatId).add("from_chat_id", fromChatId).add("message_ids", messageIds); + } + + public CopyMessages messageThreadId(Integer messageThreadId) { + return add("message_thread_id", messageThreadId); + } + + public CopyMessages removeCaption(boolean removeCaption) { + return add("remove_caption", removeCaption); + } + + public CopyMessages disableNotification(boolean disableNotification) { + return add("disable_notification", disableNotification); + } + public CopyMessages protectContent(boolean protectContent) { + return add("protect_content", protectContent); + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessages.java b/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessages.java new file mode 100644 index 00000000..4899817d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessages.java @@ -0,0 +1,11 @@ +package com.pengrad.telegrambot.request; + +import com.pengrad.telegrambot.response.BaseResponse; + +public class DeleteMessages extends BaseRequest { + + public DeleteMessages(Object chatId, int[] messageIds) { + super(BaseResponse.class); + add("chat_id", chatId).add("message_ids", messageIds); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/EditMessageText.java b/library/src/main/java/com/pengrad/telegrambot/request/EditMessageText.java index a8461a13..977210b2 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/EditMessageText.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/EditMessageText.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.request; +import com.pengrad.telegrambot.model.LinkPreviewOptions; import com.pengrad.telegrambot.model.MessageEntity; import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; import com.pengrad.telegrambot.model.request.ParseMode; @@ -30,6 +31,13 @@ public EditMessageText entities(MessageEntity... entities) { return add("entities", entities); } + public EditMessageText linkPreviewOptions(LinkPreviewOptions linkPreviewOptions) { + return add("link_preview_options", linkPreviewOptions); + } + + /* + @deprecated Use linkPreviewOptions instead + */ public EditMessageText disableWebPagePreview(boolean disableWebPagePreview) { return add("disable_web_page_preview", disableWebPagePreview); } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessage.java b/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessage.java index 319ec817..671251e1 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessage.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessage.java @@ -20,4 +20,8 @@ public ForwardMessage messageThreadId(Integer messageThreadId) { public ForwardMessage disableNotification(boolean disableNotification) { return add("disable_notification", disableNotification); } + public ForwardMessage protectContent(boolean protectContent) { + return add("protect_content", protectContent); + } + } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessages.java b/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessages.java new file mode 100644 index 00000000..3a348b39 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/ForwardMessages.java @@ -0,0 +1,22 @@ +package com.pengrad.telegrambot.request; + +import com.pengrad.telegrambot.response.MessageIdsResponse; + +public class ForwardMessages extends BaseRequest { + + public ForwardMessages(Object chatId, Object fromChatId, int[] messageIds) { + super(MessageIdsResponse.class); + add("chat_id", chatId).add("from_chat_id", fromChatId).add("message_ids", messageIds); + } + + public ForwardMessages messageThreadId(Integer messageThreadId) { + return add("message_thread_id", messageThreadId); + } + public ForwardMessages disableNotification(boolean disableNotification) { + return add("disable_notification", disableNotification); + } + public ForwardMessages protectContent(boolean protectContent) { + return add("protect_content", protectContent); + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/GetUserChatBoosts.java b/library/src/main/java/com/pengrad/telegrambot/request/GetUserChatBoosts.java new file mode 100644 index 00000000..ef80de77 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/GetUserChatBoosts.java @@ -0,0 +1,11 @@ +package com.pengrad.telegrambot.request; + +import com.pengrad.telegrambot.response.UserChatBoostsResponse; + +public class GetUserChatBoosts extends BaseRequest { + + public GetUserChatBoosts(Object chatId, Integer userId) { + super(UserChatBoostsResponse.class); + add("chat_id", chatId).add("user_id", userId); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/PinChatMessage.java b/library/src/main/java/com/pengrad/telegrambot/request/PinChatMessage.java index 2857c95b..1abe826d 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/PinChatMessage.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/PinChatMessage.java @@ -16,4 +16,5 @@ public PinChatMessage(Object chatId, int messageId) { public PinChatMessage disableNotification(boolean disableNotification) { return add("disable_notification", disableNotification); } + } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SendMediaGroup.java b/library/src/main/java/com/pengrad/telegrambot/request/SendMediaGroup.java index 607dad76..e8a64c62 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/SendMediaGroup.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/SendMediaGroup.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.request; +import com.pengrad.telegrambot.model.request.ReplyParameters; import com.pengrad.telegrambot.model.request.InputMedia; import com.pengrad.telegrambot.response.MessagesResponse; @@ -34,18 +35,31 @@ public SendMediaGroup messageThreadId(Integer messageThreadId) { return add("message_thread_id", messageThreadId); } - public SendMediaGroup disableNotification(boolean disableNotification) { - return add("disable_notification", disableNotification); + public SendMediaGroup replyParameters(ReplyParameters replyParameters) { + return add("reply_parameters", replyParameters); } + /* + @deprecated Use replyParameters instead + */ public SendMediaGroup replyToMessageId(int replyToMessageId) { return add("reply_to_message_id", replyToMessageId); } + /* + @deprecated Use replyParameters instead + */ public SendMediaGroup allowSendingWithoutReply(boolean allowSendingWithoutReply) { return add("allow_sending_without_reply", allowSendingWithoutReply); } + public SendMediaGroup disableNotification(boolean disableNotification) { + return add("disable_notification", disableNotification); + } + public SendMediaGroup protectContent(boolean protectContent) { + return add("protect_content", protectContent); + } + @Override public boolean isMultipart() { return isMultipart; diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SendMessage.java b/library/src/main/java/com/pengrad/telegrambot/request/SendMessage.java index 170126ec..02272972 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/SendMessage.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/SendMessage.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.request; +import com.pengrad.telegrambot.model.LinkPreviewOptions; import com.pengrad.telegrambot.model.MessageEntity; import com.pengrad.telegrambot.model.request.ParseMode; @@ -22,6 +23,13 @@ public SendMessage entities(MessageEntity... entities) { return add("entities", entities); } + public SendMessage linkPreviewOptions(LinkPreviewOptions linkPreviewOptions) { + return add("link_preview_options", linkPreviewOptions); + } + + /* + @deprecated Use linkPreviewOptions instead + */ public SendMessage disableWebPagePreview(boolean disableWebPagePreview) { return add("disable_web_page_preview", disableWebPagePreview); } diff --git a/library/src/main/java/com/pengrad/telegrambot/response/MessageIdsResponse.java b/library/src/main/java/com/pengrad/telegrambot/response/MessageIdsResponse.java new file mode 100644 index 00000000..c10b50bf --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/MessageIdsResponse.java @@ -0,0 +1,25 @@ +package com.pengrad.telegrambot.response; + +import com.pengrad.telegrambot.model.MessageId; + +import java.util.Arrays; + +/** + * Stas Parshin + * 06 November 2020 + */ +public class MessageIdsResponse extends BaseResponse { + + private MessageId[] result; + + public MessageId[] result() { + return result; + } + + @Override + public String toString() { + return "MessageIdsResponse{" + + "result=" + Arrays.toString(result) + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java b/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java new file mode 100644 index 00000000..999fbc84 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.java @@ -0,0 +1,21 @@ +package com.pengrad.telegrambot.response; + +import com.pengrad.telegrambot.model.chatboost.ChatBoost; + +import java.util.Arrays; + +public class UserChatBoostsResponse extends BaseResponse { + + private ChatBoost[] boosts; + + public ChatBoost[] boosts() { + return boosts; + } + + @Override + public String toString() { + return "UserChatBoostsResponse{" + + "boosts=" + Arrays.toString(boosts) + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java index 6520ed59..f5a6555f 100644 --- a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java +++ b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java @@ -3,7 +3,13 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSource; +import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; +import com.pengrad.telegrambot.model.message.origin.MessageOrigin; import com.pengrad.telegrambot.model.reaction.ReactionType; +import com.pengrad.telegrambot.utility.gson.ChatBoostSourceTypeAdapter; +import com.pengrad.telegrambot.utility.gson.MaybeInaccessibleMessageTypeAdapter; +import com.pengrad.telegrambot.utility.gson.MessageOriginTypeAdapter; import com.pengrad.telegrambot.utility.gson.ReactionTypeAdapter; import java.io.ByteArrayOutputStream; @@ -20,8 +26,11 @@ public class BotUtils { private BotUtils() {} public static final Gson GSON = new GsonBuilder() - .registerTypeAdapter(ReactionType.class, new ReactionTypeAdapter()) - .create(); + .registerTypeAdapter(ReactionType.class, new ReactionTypeAdapter()) + .registerTypeAdapter(MessageOrigin.class, new MessageOriginTypeAdapter()) + .registerTypeAdapter(ChatBoostSource.class, new ChatBoostSourceTypeAdapter()) + .registerTypeAdapter(MaybeInaccessibleMessage.class, new MaybeInaccessibleMessageTypeAdapter()) + .create(); public static Update parseUpdate(String update) { return GSON.fromJson(update, Update.class); diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/gson/ChatBoostSourceTypeAdapter.java b/library/src/main/java/com/pengrad/telegrambot/utility/gson/ChatBoostSourceTypeAdapter.java new file mode 100644 index 00000000..72a8cb4b --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/utility/gson/ChatBoostSourceTypeAdapter.java @@ -0,0 +1,28 @@ +package com.pengrad.telegrambot.utility.gson; + +import com.google.gson.*; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSource; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSourceGiftCode; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSourceGiveaway; +import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSourcePremium; + +import java.lang.reflect.Type; + +public class ChatBoostSourceTypeAdapter implements JsonDeserializer { + + @Override + public ChatBoostSource deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject object = element.getAsJsonObject(); + String discriminator = object.getAsJsonPrimitive("source").getAsString(); + + if (ChatBoostSourceGiftCode.CHAT_BOOST_TYPE.equals(discriminator)) { + return context.deserialize(object, ChatBoostSourceGiftCode.class); + } else if (ChatBoostSourceGiveaway.CHAT_BOOST_TYPE.equals(discriminator)) { + return context.deserialize(object, ChatBoostSourceGiveaway.class); + } else if (ChatBoostSourcePremium.CHAT_BOOST_TYPE.equals(discriminator)) { + return context.deserialize(object, ChatBoostSourcePremium.class); + } + + return context.deserialize(object, ChatBoostSource.class); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/gson/MaybeInaccessibleMessageTypeAdapter.java b/library/src/main/java/com/pengrad/telegrambot/utility/gson/MaybeInaccessibleMessageTypeAdapter.java new file mode 100644 index 00000000..f8d359f2 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/utility/gson/MaybeInaccessibleMessageTypeAdapter.java @@ -0,0 +1,23 @@ +package com.pengrad.telegrambot.utility.gson; + +import com.google.gson.*; +import com.pengrad.telegrambot.model.Message; +import com.pengrad.telegrambot.model.message.InaccessibleMessage; +import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; + +import java.lang.reflect.Type; + +public class MaybeInaccessibleMessageTypeAdapter implements JsonDeserializer { + + @Override + public MaybeInaccessibleMessage deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject object = element.getAsJsonObject(); + JsonPrimitive discriminator = object.getAsJsonPrimitive("date"); + + if (!discriminator.isJsonNull() && discriminator.getAsInt() != InaccessibleMessage.INACCESSIBLE_MESSAGE_DATE) { + return context.deserialize(object, Message.class); + } else { + return context.deserialize(object, InaccessibleMessage.class); + } + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/gson/MessageOriginTypeAdapter.java b/library/src/main/java/com/pengrad/telegrambot/utility/gson/MessageOriginTypeAdapter.java new file mode 100644 index 00000000..41ea690e --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/utility/gson/MessageOriginTypeAdapter.java @@ -0,0 +1,27 @@ +package com.pengrad.telegrambot.utility.gson; + +import com.google.gson.*; +import com.pengrad.telegrambot.model.message.origin.*; + +import java.lang.reflect.Type; + +public class MessageOriginTypeAdapter implements JsonDeserializer { + + @Override + public MessageOrigin deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject object = element.getAsJsonObject(); + String discriminator = object.getAsJsonPrimitive("type").getAsString(); + + if (MessageOriginChannel.MESSAGE_ORIGIN_TYPE.equals(discriminator)) { + return context.deserialize(object, MessageOriginChannel.class); + } else if (MessageOriginChat.MESSAGE_ORIGIN_TYPE.equals(discriminator)) { + return context.deserialize(object, MessageOriginChat.class); + } else if (MessageOriginHiddenUser.MESSAGE_ORIGIN_TYPE.equals(discriminator)) { + return context.deserialize(object, MessageOriginHiddenUser.class); + } else if (MessageOriginUser.MESSAGE_ORIGIN_TYPE.equals(discriminator)) { + return context.deserialize(object, MessageOriginUser.class); + } + + return context.deserialize(object, MessageOrigin.class); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/gson/ReactionTypeAdapter.java b/library/src/main/java/com/pengrad/telegrambot/utility/gson/ReactionTypeAdapter.java index f96f2928..69aff521 100644 --- a/library/src/main/java/com/pengrad/telegrambot/utility/gson/ReactionTypeAdapter.java +++ b/library/src/main/java/com/pengrad/telegrambot/utility/gson/ReactionTypeAdapter.java @@ -20,6 +20,6 @@ public ReactionType deserialize(JsonElement element, Type type, JsonDeserializat return context.deserialize(object, ReactionTypeCustomEmoji.class); } - throw new JsonParseException("Unknown ReactionType type: " + discriminator); + return context.deserialize(object, ReactionType.class); } } diff --git a/library/src/test/java/com/pengrad/telegrambot/ModelTest.java b/library/src/test/java/com/pengrad/telegrambot/ModelTest.java index a8463d4e..f247e540 100644 --- a/library/src/test/java/com/pengrad/telegrambot/ModelTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/ModelTest.java @@ -1,6 +1,8 @@ package com.pengrad.telegrambot; import com.pengrad.telegrambot.model.*; +import com.pengrad.telegrambot.model.Message; +import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; import com.pengrad.telegrambot.model.request.InlineKeyboardButton; import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; import com.pengrad.telegrambot.passport.Credentials; @@ -61,7 +63,7 @@ public void testEquals() throws ReflectiveOperationException { f.set(callbackQuery, "2"); Message message = Message.class.getDeclaredConstructor().newInstance(); - f = Message.class.getDeclaredField("message_id"); + f = MaybeInaccessibleMessage.class.getDeclaredField("message_id"); f.setAccessible(true); f.set(message, 11); @@ -87,6 +89,9 @@ public void testEquals() throws ReflectiveOperationException { verifierApi.withIgnoredFields("general_forum_topic_unhidden"); verifierApi.withIgnoredFields("story"); } + if (c == ExternalReplyInfo.class) { + verifierApi.withIgnoredFields("story"); + } verifierApi.verify(); } diff --git a/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java b/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java index bbf295f0..9d5390d0 100644 --- a/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java @@ -37,7 +37,6 @@ public static void checkTextMessage(Message message) { assertNull(message.isAutomaticForward()); assertNull(message.hasMediaSpoiler()); assertNull(message.messageAutoDeleteTimerChanged()); - assertNull(message.userShared()); assertNull(message.chatShared()); assertNull(message.proximityAlertTriggered()); assertNull(message.forumTopicCreated());