Updated client
* Updated ContactsRequest constructor to work with new versin of this event. *Implemented LocalDB updates when adding a contact and display it immediately, so you can chat directly.
This commit is contained in:
parent
48a64b08f9
commit
128d5bec4a
@ -262,7 +262,7 @@ public class ChatWindow extends JFrame {
|
||||
if (client.isOnline()) {
|
||||
try {
|
||||
if(!searchField.getText().isEmpty()) {
|
||||
client.sendEvent(new ContactsRequest(searchField.getText()));
|
||||
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender()));
|
||||
} else {
|
||||
contactsModel.clear();
|
||||
revalidate();
|
||||
@ -279,7 +279,7 @@ public class ChatWindow extends JFrame {
|
||||
if (client.isOnline()) {
|
||||
try {
|
||||
if(!searchField.getText().isEmpty()) {
|
||||
client.sendEvent(new ContactsRequest(searchField.getText()));
|
||||
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender()));
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
@ -401,18 +401,6 @@ public class ChatWindow extends JFrame {
|
||||
contactsModel.clear();
|
||||
final java.util.List<User> contacts = ((SearchResultEvent) evt).get();
|
||||
logger.info("Received contact search result " + contacts);
|
||||
|
||||
// // Checks whether a contact received from the server as search result already
|
||||
// // exists in the contacts of this client. if so, it does not get added to the
|
||||
// // contactsModel, and so can not be added to the contacts.
|
||||
// for (int i = 0; i < contacts.size(); i++) {
|
||||
// for (int j = 0; j < localDb.getUsers().size(); j++) {
|
||||
// if (!(contacts.get(i).getId() ==
|
||||
// localDb.getUsers().get(contacts.get(i).getName()).getId())) {
|
||||
// contactsModel.add(contacts.get(i));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
contacts.forEach(contactsModel::add);
|
||||
revalidate();
|
||||
repaint();
|
||||
@ -427,13 +415,10 @@ public class ChatWindow extends JFrame {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// TODO: Not finished LocalDB update of contact list
|
||||
// Add this user to the chats
|
||||
// userListModel.addElement(contact);
|
||||
// Check if user exists in local DB
|
||||
// if (localDb.getChats().stream().filter(c -> c.getRecipient().getId() ==
|
||||
// contact.getId()).count() == 0)
|
||||
// localDb.getChats().add(new Chat(contact));
|
||||
// Update LocalDB
|
||||
userListModel.addElement(contact);
|
||||
localDb.getUsers().put(contact.getName(), contact);
|
||||
localDb.getChats().add(new Chat(contact));
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
|
Reference in New Issue
Block a user