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()) {
|
if (client.isOnline()) {
|
||||||
try {
|
try {
|
||||||
if(!searchField.getText().isEmpty()) {
|
if(!searchField.getText().isEmpty()) {
|
||||||
client.sendEvent(new ContactsRequest(searchField.getText()));
|
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender()));
|
||||||
} else {
|
} else {
|
||||||
contactsModel.clear();
|
contactsModel.clear();
|
||||||
revalidate();
|
revalidate();
|
||||||
@ -279,7 +279,7 @@ public class ChatWindow extends JFrame {
|
|||||||
if (client.isOnline()) {
|
if (client.isOnline()) {
|
||||||
try {
|
try {
|
||||||
if(!searchField.getText().isEmpty()) {
|
if(!searchField.getText().isEmpty()) {
|
||||||
client.sendEvent(new ContactsRequest(searchField.getText()));
|
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender()));
|
||||||
}
|
}
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
@ -401,18 +401,6 @@ public class ChatWindow extends JFrame {
|
|||||||
contactsModel.clear();
|
contactsModel.clear();
|
||||||
final java.util.List<User> contacts = ((SearchResultEvent) evt).get();
|
final java.util.List<User> contacts = ((SearchResultEvent) evt).get();
|
||||||
logger.info("Received contact search result " + contacts);
|
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);
|
contacts.forEach(contactsModel::add);
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
@ -427,13 +415,10 @@ public class ChatWindow extends JFrame {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Not finished LocalDB update of contact list
|
// Update LocalDB
|
||||||
// Add this user to the chats
|
userListModel.addElement(contact);
|
||||||
// userListModel.addElement(contact);
|
localDb.getUsers().put(contact.getName(), contact);
|
||||||
// Check if user exists in local DB
|
localDb.getChats().add(new Chat(contact));
|
||||||
// if (localDb.getChats().stream().filter(c -> c.getRecipient().getId() ==
|
|
||||||
// contact.getId()).count() == 0)
|
|
||||||
// localDb.getChats().add(new Chat(contact));
|
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
|
Reference in New Issue
Block a user