Requesting unread messages an assigning them to the right chat element.
This commit is contained in:
parent
78f9f4c883
commit
aeb138334e
@ -137,7 +137,7 @@ public class Client {
|
|||||||
private User getUser(String name) {
|
private User getUser(String name) {
|
||||||
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
||||||
WebTarget target = client.target(String
|
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();
|
Response response = target.request("application/xml").get();
|
||||||
Users users = response.readEntity(Users.class);
|
Users users = response.readEntity(Users.class);
|
||||||
System.out.println("Response code: " + response.getStatus());
|
System.out.println("Response code: " + response.getStatus());
|
||||||
@ -146,6 +146,18 @@ public class Client {
|
|||||||
return users.getUser().get(0);
|
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
|
* @return the sender object that represents this client
|
||||||
* @since Envoy 0.1
|
* @since Envoy 0.1
|
||||||
|
@ -20,11 +20,13 @@ import javax.swing.JTextArea;
|
|||||||
import javax.swing.JTextPane;
|
import javax.swing.JTextPane;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.Timer;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
import envoy.client.Chat;
|
import envoy.client.Chat;
|
||||||
import envoy.client.Client;
|
import envoy.client.Client;
|
||||||
import envoy.schema.Message;
|
import envoy.schema.Message;
|
||||||
|
import envoy.schema.Messages;
|
||||||
import envoy.schema.User;
|
import envoy.schema.User;
|
||||||
import envoy.schema.Users;
|
import envoy.schema.Users;
|
||||||
|
|
||||||
@ -228,6 +230,19 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
|
|
||||||
loadUserList(userList);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user