This commit is contained in:
rubenlagus 2021-01-02 18:06:05 +01:00 committed by Ruben Bermudez
parent 451bdce90b
commit 6342d1ff4e
2 changed files with 52 additions and 4 deletions

View File

@ -27,7 +27,7 @@ public class ChatMember implements BotApiObject {
private static final String STATUS_FIELD = "status"; private static final String STATUS_FIELD = "status";
private static final String UNTILDATE_FIELD = "until_date"; private static final String UNTILDATE_FIELD = "until_date";
private static final String CANBEEDITED_FIELD = "can_be_edited"; private static final String CANBEEDITED_FIELD = "can_be_edited";
private static final String CANCHANGEINFORMATION_FIELD = "can_change_information"; private static final String CANCHANGEINFO_FIELD = "can_change_info";
private static final String CANPOSTMESSAGES_FIELD = "can_post_messages"; private static final String CANPOSTMESSAGES_FIELD = "can_post_messages";
private static final String CANEDITMESSAGES_FIELD = "can_edit_messages"; private static final String CANEDITMESSAGES_FIELD = "can_edit_messages";
private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages"; private static final String CANDELETEMESSAGES_FIELD = "can_delete_messages";
@ -52,8 +52,8 @@ public class ChatMember implements BotApiObject {
private Integer untilDate; ///< Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time private Integer untilDate; ///< Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
@JsonProperty(CANBEEDITED_FIELD) @JsonProperty(CANBEEDITED_FIELD)
private Boolean canBeEdited; ///< Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user private Boolean canBeEdited; ///< Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
@JsonProperty(CANCHANGEINFORMATION_FIELD) @JsonProperty(CANCHANGEINFO_FIELD)
private Boolean canChangeInformation; ///< Optional. Administrators and restricted only. True, if the administrator can change the chat title, photo and other settings private Boolean canChangeInfo; ///< Optional. Administrators and restricted only. True, if the administrator can change the chat title, photo and other settings
@JsonProperty(CANPOSTMESSAGES_FIELD) @JsonProperty(CANPOSTMESSAGES_FIELD)
private Boolean canPostMessages; ///< Optional. Administrators only. True, if the administrator can post in the channel, channels only private Boolean canPostMessages; ///< Optional. Administrators only. True, if the administrator can post in the channel, channels only
@JsonProperty(CANEDITMESSAGES_FIELD) @JsonProperty(CANEDITMESSAGES_FIELD)
@ -79,7 +79,7 @@ public class ChatMember implements BotApiObject {
@JsonProperty(CAN_SEND_POLLS_FIELD) @JsonProperty(CAN_SEND_POLLS_FIELD)
private Boolean canSendPolls; ///< Optional. Restricted only. True, if the user is allowed to send polls. private Boolean canSendPolls; ///< Optional. Restricted only. True, if the user is allowed to send polls.
@JsonProperty(ISMEMBER_FIELD) @JsonProperty(ISMEMBER_FIELD)
private Boolean isMemberField; ///< True, if the user is a member of the chat at the moment of the request. For example, it can be false for the chat creator or for a restricted user. private Boolean isMember; ///< True, if the user is a member of the chat at the moment of the request. For example, it can be false for the chat creator or for a restricted user.
@JsonProperty(CUSTOMTITLE_FIELD) @JsonProperty(CUSTOMTITLE_FIELD)
private String customTitle; ///< Optional. Owner and administrators only. Custom title for this user private String customTitle; ///< Optional. Owner and administrators only. Custom title for this user
@JsonProperty(ISANONYMOUS_FIELD) @JsonProperty(ISANONYMOUS_FIELD)

View File

@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands; import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands;
import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatMember;
import org.telegram.telegrambots.meta.api.methods.updates.Close; import org.telegram.telegrambots.meta.api.methods.updates.Close;
import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates;
import org.telegram.telegrambots.meta.api.methods.updates.LogOut; import org.telegram.telegrambots.meta.api.methods.updates.LogOut;
@ -13,6 +14,7 @@ import org.telegram.telegrambots.meta.api.objects.ApiResponse;
import org.telegram.telegrambots.meta.api.objects.Audio; import org.telegram.telegrambots.meta.api.objects.Audio;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery; import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Chat; import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.ChatMember;
import org.telegram.telegrambots.meta.api.objects.Document; import org.telegram.telegrambots.meta.api.objects.Document;
import org.telegram.telegrambots.meta.api.objects.EntityType; import org.telegram.telegrambots.meta.api.objects.EntityType;
import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Message;
@ -164,6 +166,52 @@ class TestDeserialization {
assertTrue(response); assertTrue(response);
} }
@Test
void TestDeserializationChatMember() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": {\n" +
" \"user\": {\n" +
" \"id\": 1111111,\n" +
" \"is_bot\": true,\n" +
" \"first_name\": \"MyTesting\",\n" +
" \"username\": \"MyTestingUsername\"\n" +
" },\n" +
" \"status\": \"restricted\",\n" +
" \"until_date\": 0,\n" +
" \"can_send_messages\": false,\n" +
" \"can_send_media_messages\": false,\n" +
" \"can_send_polls\": false,\n" +
" \"can_send_other_messages\": false,\n" +
" \"can_add_web_page_previews\": false,\n" +
" \"can_change_info\": false,\n" +
" \"can_invite_users\": false,\n" +
" \"can_pin_messages\": false,\n" +
" \"is_member\": true\n" +
" }\n" +
"}";
ChatMember response = new GetChatMember().deserializeResponse(updateText);
assertNotNull(response);
assertNotNull(response.getUser());
assertEquals(1111111, response.getUser().getId());
assertTrue(response.getUser().getIsBot());
assertEquals("MyTesting", response.getUser().getFirstName());
assertEquals("MyTestingUsername", response.getUser().getUserName());
assertEquals("restricted", response.getStatus());
assertEquals(0, response.getUntilDate());
assertFalse(response.getCanSendMessages());
assertFalse(response.getCanSendMediaMessages());
assertFalse(response.getCanSendPolls());
assertFalse(response.getCanSendOtherMessages());
assertFalse(response.getCanAddWebPagePreviews());
assertFalse(response.getCanChangeInfo());
assertFalse(response.getCanInviteUsers());
assertFalse(response.getCanPinMessages());
assertTrue(response.getIsMember());
}
@Test @Test
void TestDeserializationLogoutMethod() throws Exception { void TestDeserializationLogoutMethod() throws Exception {
String updateText = "{\"ok\":true,\"result\": true}"; String updateText = "{\"ok\":true,\"result\": true}";