Merge pull request #750 from addo37/fix-poll-user
Fix handling of poll updates without user information
This commit is contained in:
commit
cdfd49e9b5
@ -465,6 +465,10 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
|||||||
|
|
||||||
Update addUser(Update update) {
|
Update addUser(Update update) {
|
||||||
User endUser = AbilityUtils.getUser(update);
|
User endUser = AbilityUtils.getUser(update);
|
||||||
|
if (endUser.equals(EMPTY_USER)) {
|
||||||
|
// Can't add an empty user, return the update as is
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
users().compute(endUser.getId(), (id, user) -> {
|
users().compute(endUser.getId(), (id, user) -> {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
@ -25,6 +25,10 @@ public enum Flag implements Predicate<Update> {
|
|||||||
EDITED_MESSAGE(Update::hasEditedMessage),
|
EDITED_MESSAGE(Update::hasEditedMessage),
|
||||||
INLINE_QUERY(Update::hasInlineQuery),
|
INLINE_QUERY(Update::hasInlineQuery),
|
||||||
CHOSEN_INLINE_QUERY(Update::hasChosenInlineQuery),
|
CHOSEN_INLINE_QUERY(Update::hasChosenInlineQuery),
|
||||||
|
SHIPPING_QUERY(Update::hasShippingQuery),
|
||||||
|
PRECHECKOUT_QUERY(Update::hasPreCheckoutQuery),
|
||||||
|
POLL(Update::hasPoll),
|
||||||
|
POLL_ANSWER(Update::hasPollAnswer),
|
||||||
|
|
||||||
// Message Flags
|
// Message Flags
|
||||||
REPLY(upd -> MESSAGE.test(upd) && upd.getMessage().isReply()),
|
REPLY(upd -> MESSAGE.test(upd) && upd.getMessage().isReply()),
|
||||||
|
@ -24,6 +24,8 @@ import static org.telegram.abilitybots.api.objects.Flag.*;
|
|||||||
* Helper and utility methods
|
* Helper and utility methods
|
||||||
*/
|
*/
|
||||||
public final class AbilityUtils {
|
public final class AbilityUtils {
|
||||||
|
public static User EMPTY_USER = new User();
|
||||||
|
|
||||||
private AbilityUtils() {
|
private AbilityUtils() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -69,6 +71,14 @@ public final class AbilityUtils {
|
|||||||
return update.getEditedMessage().getFrom();
|
return update.getEditedMessage().getFrom();
|
||||||
} else if (CHOSEN_INLINE_QUERY.test(update)) {
|
} else if (CHOSEN_INLINE_QUERY.test(update)) {
|
||||||
return update.getChosenInlineQuery().getFrom();
|
return update.getChosenInlineQuery().getFrom();
|
||||||
|
} else if (SHIPPING_QUERY.test(update)) {
|
||||||
|
return update.getShippingQuery().getFrom();
|
||||||
|
} else if (PRECHECKOUT_QUERY.test(update)) {
|
||||||
|
return update.getPreCheckoutQuery().getFrom();
|
||||||
|
} else if (POLL_ANSWER.test(update)) {
|
||||||
|
return update.getPollAnswer().getUser();
|
||||||
|
} else if (POLL.test(update)) {
|
||||||
|
return EMPTY_USER;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Could not retrieve originating user from update");
|
throw new IllegalStateException("Could not retrieve originating user from update");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user