should fix #2
This commit is contained in:
parent
f6196f3a1f
commit
9dc407180d
|
@ -63,7 +63,7 @@ public class TelegramAPI implements Runnable {
|
|||
protected int fetchedUpdates = 0;
|
||||
protected long start = 0;
|
||||
|
||||
private LinkedList<TUser> users = new LinkedList<>();
|
||||
private Map<Long, TUser> users = new TreeMap<>();
|
||||
@Setter
|
||||
private List<Long> admins = new LinkedList<>(); //required for feedback
|
||||
private CommandManager cmdmgr = new CommandManager(this);
|
||||
|
@ -435,23 +435,26 @@ public class TelegramAPI implements Runnable {
|
|||
}
|
||||
|
||||
public TUser getUser(String name) {
|
||||
for(TUser us : users) {
|
||||
for(TUser us : users.values()) {
|
||||
if(us.getName().equals(name))
|
||||
return us;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TUser getUser(int id) {
|
||||
for(TUser us : users) {
|
||||
if(us.getID() == id)
|
||||
return us;
|
||||
}
|
||||
TUser u = new TUser(id, this);
|
||||
users.add(u);
|
||||
public TUser getUser(long id, boolean createIfNotExitsts) {
|
||||
TUser u = users.get(id);
|
||||
if(u != null || !createIfNotExitsts)
|
||||
return u;
|
||||
u = new TUser(id, this);
|
||||
users.put(id, u);
|
||||
return u;
|
||||
}
|
||||
|
||||
public TUser getUser(long id) {
|
||||
return getUser(id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -459,12 +462,12 @@ public class TelegramAPI implements Runnable {
|
|||
* @return
|
||||
*/
|
||||
public TUser getUser(JSONObject json) {
|
||||
int id = json.getInt("id");
|
||||
TUser user = getUser(id);
|
||||
long id = json.getLong("id");
|
||||
TUser user = getUser(id, false);
|
||||
if(user != null)
|
||||
return user;
|
||||
user = new TUser(json, this);
|
||||
users.add(user);
|
||||
users.put(id, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.TreeMap;
|
|||
|
||||
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, 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;
|
||||
|
@ -27,9 +27,6 @@ public class FeedbackCommand implements JSONCommandHandler {
|
|||
public FeedbackCommand(TelegramAPI api, List<Long> admins) {
|
||||
this.api = api;
|
||||
this.admins = (admins == null ? new LinkedList<>() : admins);
|
||||
|
||||
//build markup
|
||||
cancelMarkup.addCallbackButton("❌ cancel", CANCELFEEDBACK, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue