Add an access to the user in ChatMember interface

This commit is contained in:
Victor 2021-07-08 15:46:41 +03:00
parent c8d461926b
commit 0ec2e32bc9
8 changed files with 24 additions and 10 deletions

View File

@ -265,10 +265,10 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
.orElse(new ArrayList<>())
.stream()
.map(member -> {
if (member instanceof ChatMemberAdministrator) {
return ((ChatMemberAdministrator) member).getUser().getId();
} else if (member instanceof ChatMemberOwner) {
return ((ChatMemberOwner) member).getUser().getId();
final String status = member.getStatus();
if (status.equals(ChatMemberOwner.STATUS)
|| status.equals(ChatMemberAdministrator.STATUS)) {
return member.getUser().getId();
}
return 0L;
})

View File

@ -2,6 +2,7 @@ package org.telegram.telegrambots.meta.api.objects.chatmember;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.api.objects.chatmember.serialization.ChatMemberDeserializer;
/**
@ -14,4 +15,5 @@ import org.telegram.telegrambots.meta.api.objects.chatmember.serialization.ChatM
@JsonDeserialize(using = ChatMemberDeserializer.class)
public interface ChatMember extends BotApiObject {
String getStatus();
User getUser();
}

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberAdministrator implements ChatMember {
public static final String STATUS = "administrator";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
private static final String CANBEEDITED_FIELD = "can_be_edited";
@ -46,7 +48,7 @@ public class ChatMemberAdministrator implements ChatMember {
* The member's status in the chat, always administrator
*/
@JsonProperty(STATUS_FIELD)
private final String status = "administrator";
private final String status = STATUS;
/**
* Information about the user
*/

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberBanned implements ChatMember {
public static final String STATUS = "kicked";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
private static final String UNTILDATE_FIELD = "until_date";
@ -34,7 +36,7 @@ public class ChatMemberBanned implements ChatMember {
* The member's status in the chat, always kicked
*/
@JsonProperty(STATUS_FIELD)
private final String status = "kicked";
private final String status = STATUS;
/**
* Information about the user
*/

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberLeft implements ChatMember {
public static final String STATUS = "left";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
@ -33,7 +35,7 @@ public class ChatMemberLeft implements ChatMember {
* The member's status in the chat, always left
*/
@JsonProperty(STATUS_FIELD)
private final String status = "left";
private final String status = STATUS;
/**
* Information about the user
*/

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberMember implements ChatMember {
public static final String STATUS = "member";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
@ -33,7 +35,7 @@ public class ChatMemberMember implements ChatMember {
* The member's status in the chat, always member
*/
@JsonProperty(STATUS_FIELD)
private final String status = "member";
private final String status = STATUS;
/**
* Information about the user
*/

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberOwner implements ChatMember {
public static final String STATUS = "creator";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
private static final String CUSTOMTITLE_FIELD = "custom_title";
@ -35,7 +37,7 @@ public class ChatMemberOwner implements ChatMember {
* The member's status in the chat, always creator
*/
@JsonProperty(STATUS_FIELD)
private final String status = "creator";
private final String status = STATUS;
/**
* Information about the user
*/

View File

@ -26,6 +26,8 @@ import org.telegram.telegrambots.meta.api.objects.User;
@AllArgsConstructor
@Builder
public class ChatMemberRestricted implements ChatMember {
public static final String STATUS = "restricted";
private static final String STATUS_FIELD = "status";
private static final String USER_FIELD = "user";
private static final String ISMEMBER_FIELD = "is_member";
@ -43,7 +45,7 @@ public class ChatMemberRestricted implements ChatMember {
* The member's status in the chat, always restricted
*/
@JsonProperty(STATUS_FIELD)
private final String status = "restricted";
private final String status = STATUS;
/**
* Information about the user
*/