should fix #2

This commit is contained in:
mrbesen 2020-12-02 19:57:37 +01:00
parent f6196f3a1f
commit 9dc407180d
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 16 additions and 16 deletions

View File

@ -63,7 +63,7 @@ public class TelegramAPI implements Runnable {
protected int fetchedUpdates = 0; protected int fetchedUpdates = 0;
protected long start = 0; protected long start = 0;
private LinkedList<TUser> users = new LinkedList<>(); private Map<Long, TUser> users = new TreeMap<>();
@Setter @Setter
private List<Long> admins = new LinkedList<>(); //required for feedback private List<Long> admins = new LinkedList<>(); //required for feedback
private CommandManager cmdmgr = new CommandManager(this); private CommandManager cmdmgr = new CommandManager(this);
@ -435,23 +435,26 @@ public class TelegramAPI implements Runnable {
} }
public TUser getUser(String name) { public TUser getUser(String name) {
for(TUser us : users) { for(TUser us : users.values()) {
if(us.getName().equals(name)) if(us.getName().equals(name))
return us; return us;
} }
return null; return null;
} }
public TUser getUser(int id) { public TUser getUser(long id, boolean createIfNotExitsts) {
for(TUser us : users) { TUser u = users.get(id);
if(us.getID() == id) if(u != null || !createIfNotExitsts)
return us; return u;
} u = new TUser(id, this);
TUser u = new TUser(id, this); users.put(id, u);
users.add(u);
return u; return u;
} }
public TUser getUser(long id) {
return getUser(id, true);
}
/** /**
* gets a user by id from the known user lists, * gets a user by id from the known user lists,
* if no user found, it creates a new User and adds it to the list. * if no user found, it creates a new User and adds it to the list.
@ -459,12 +462,12 @@ public class TelegramAPI implements Runnable {
* @return * @return
*/ */
public TUser getUser(JSONObject json) { public TUser getUser(JSONObject json) {
int id = json.getInt("id"); long id = json.getLong("id");
TUser user = getUser(id); TUser user = getUser(id, false);
if(user != null) if(user != null)
return user; return user;
user = new TUser(json, this); user = new TUser(json, this);
users.add(user); users.put(id, user);
return user; return user;
} }

View File

@ -16,7 +16,7 @@ import java.util.TreeMap;
public class FeedbackCommand implements JSONCommandHandler { public class FeedbackCommand implements JSONCommandHandler {
protected final TInlineKeyboardMarkup cancelMarkup = new TInlineKeyboardMarkup(1); protected final TInlineKeyboardMarkup cancelMarkup = TInlineKeyboardMarkup.makeSingleButton("❌ cancel", CANCELFEEDBACK);
protected final Map<Long, TMessage> awaitingFeedback = new TreeMap<>(); //maps users chat id -> message that said "please send feedback" TODO: make persistent? protected final Map<Long, TMessage> awaitingFeedback = new TreeMap<>(); //maps users chat id -> message that said "please send feedback" TODO: make persistent?
protected final Map<Long, Long[]> awnser = new TreeMap<>(); // chatid -> [chatid, messageid] to awnser to; next message from key will be fwd to value[0] and reply to value[1] protected final Map<Long, Long[]> awnser = new TreeMap<>(); // chatid -> [chatid, messageid] to awnser to; next message from key will be fwd to value[0] and reply to value[1]
protected final TelegramAPI api; protected final TelegramAPI api;
@ -27,9 +27,6 @@ public class FeedbackCommand implements JSONCommandHandler {
public FeedbackCommand(TelegramAPI api, List<Long> admins) { public FeedbackCommand(TelegramAPI api, List<Long> admins) {
this.api = api; this.api = api;
this.admins = (admins == null ? new LinkedList<>() : admins); this.admins = (admins == null ? new LinkedList<>() : admins);
//build markup
cancelMarkup.addCallbackButton("❌ cancel", CANCELFEEDBACK, 1);
} }
@Override @Override