From c58a4a73d3fc01ffd27bdcb2455e6708b611e719 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 9 Nov 2019 09:38:10 +0100 Subject: [PATCH] Extracted updateUserStates method, fixed localDB initialization --- src/main/java/envoy/client/Config.java | 1 + src/main/java/envoy/client/ui/ChatWindow.java | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/envoy/client/Config.java b/src/main/java/envoy/client/Config.java index 1d107ca..0da3cf1 100644 --- a/src/main/java/envoy/client/Config.java +++ b/src/main/java/envoy/client/Config.java @@ -53,6 +53,7 @@ public class Config { case "-db": localDB = new File(args[++i]); } + if (localDB == null) localDB = new File(".\\localDB"); } /** diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 4ac1a6c..490308d 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -275,19 +275,17 @@ public class ChatWindow extends JFrame { client.addUnreadMessagesToLocalDB(localDB); client.clearUnreadMessagesSync(); - for (int i = 0; i < userList.getModel().getSize(); i++) { - for (int j = 0; j < localDB.getChats().size(); j++) { - if(userList.getModel().getElementAt(i).getID() == localDB.getChats().get(j).getRecipient().getID()) { - userList.getModel().getElementAt(i).setStatus(localDB.getChats().get(j).getRecipient().getStatus()); - } - } - - } + updateUserStates(); contentPane.revalidate(); contentPane.repaint(); - userList.revalidate(); - userList.repaint(); }).start(); } + + private void updateUserStates() { + for (int i = 0; i < userList.getModel().getSize(); i++) + for (int j = 0; j < localDB.getChats().size(); j++) + if (userList.getModel().getElementAt(i).getID() == localDB.getChats().get(j).getRecipient().getID()) + userList.getModel().getElementAt(i).setStatus(localDB.getChats().get(j).getRecipient().getStatus()); + } } \ No newline at end of file