Requesting unread messages an assigning them to the right chat element.

This commit is contained in:
Maxi 2019-10-19 15:09:32 +02:00
parent 8751bd8781
commit 0ed71e63a3
2 changed files with 28 additions and 1 deletions

View File

@ -137,7 +137,7 @@ public class Client {
private User getUser(String name) {
javax.ws.rs.client.Client client = ClientBuilder.newClient();
WebTarget target = client.target(String
.format("%s:%d/envoy-server/rest/user/sender?name=" + name, config.getServer(), config.getPort()));
.format("%s:%d/envoy-server/rest/user/sender?name=%s", config.getServer(), config.getPort(), name));
Response response = target.request("application/xml").get();
Users users = response.readEntity(Users.class);
System.out.println("Response code: " + response.getStatus());
@ -146,6 +146,18 @@ public class Client {
return users.getUser().get(0);
}
public Messages getUnreadMessages(long userId) {
javax.ws.rs.client.Client client = ClientBuilder.newClient();
WebTarget target = client.target(String
.format("%s:%d/envoy-server/rest/message/receive?userId=%d", config.getServer(), config.getPort(), userId));
Response response = target.request("application/xml").get();
Messages unreadMessages = response.readEntity(Messages.class);
System.out.println("Response code: " + response.getStatus());
response.close();
client.close();
return unreadMessages;
}
/**
* @return the sender object that represents this client
* @since Envoy 0.1

View File

@ -20,11 +20,13 @@ import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import envoy.client.Chat;
import envoy.client.Client;
import envoy.schema.Message;
import envoy.schema.Messages;
import envoy.schema.User;
import envoy.schema.Users;
@ -228,6 +230,19 @@ public class ChatWindow extends JFrame {
contentPane.revalidate();
loadUserList(userList);
new Timer(5000, (evt) -> {
Messages unreadMessages = client.getUnreadMessages(client.getSender().getID());
System.out.println(unreadMessages.getMessage().get(0));
for (int i = 0; i < unreadMessages.getMessage().size(); i++) {
for (int j = 0; j < partnerChatList.size(); j++) {
if(partnerChatList.get(j).getRecipient().getID() == unreadMessages.getMessage().get(i).getMetaData().getSender()) {
partnerChatList.get(j).appendMessage(unreadMessages.getMessage().get(i));
}
}
}
}).start();
contentPane.revalidate();
}
/**