mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
feat(Event): 2.6.5: Récupération des posts après changement de discussion
This commit is contained in:
parent
48da92717b
commit
1732a63a4a
3 changed files with 44 additions and 12 deletions
|
|
@ -278,6 +278,7 @@ public class ChatController implements Initializable {
|
||||||
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans la discussion avec " + contactSelected.getLogin());
|
Post postSys = new Post("system", loginTextField.getText(), "Bienvenue dans la discussion avec " + contactSelected.getLogin());
|
||||||
postsObservableList.clear();
|
postsObservableList.clear();
|
||||||
postsObservableList.add(postSys);
|
postsObservableList.add(postSys);
|
||||||
|
client.sendListPostEvent(0, contactSelected.getLogin());
|
||||||
postListView.refresh();
|
postListView.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,16 @@ public class ChatClient extends ClientTCP {
|
||||||
sendEvent(authEvent);
|
sendEvent(authEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendListPostEvent(long since, String select) {
|
||||||
|
Event listPostEvent = new Event(
|
||||||
|
Event.LIST_POSTS,
|
||||||
|
new JSONObject()
|
||||||
|
.put("since", since)
|
||||||
|
.put("select", select)
|
||||||
|
);
|
||||||
|
sendEvent(listPostEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveLoop() {
|
public void receiveLoop() {
|
||||||
|
|
|
||||||
|
|
@ -250,13 +250,33 @@ public class ChatServer {
|
||||||
doMessage(event.getContent());
|
doMessage(event.getContent());
|
||||||
LOGGER.info("Receiving message");
|
LOGGER.info("Receiving message");
|
||||||
return true;
|
return true;
|
||||||
|
} else if (event.getType().equals(Event.LIST_POSTS)) {
|
||||||
|
doListPost(event.getContent());
|
||||||
|
LOGGER.info("Sending Posts");
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warning("Unhandled event type: " + event.getType());
|
LOGGER.warning("Unhandled event type: " + event.getType());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doListPost(JSONObject content) throws JSONException, IllegalStateException {
|
||||||
|
|
||||||
|
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||||
|
if (!contactMap.containsKey(content.getString("select"))) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
for (Post post: postVector.getPostsSince(content.getLong("since"))) {
|
||||||
|
if (post.getTo().equals(content.getString("select")) ||
|
||||||
|
post.getFrom().equals(content.getString("select"))) {
|
||||||
|
sendEventToContact(contactMap.getContact(user.getLogin()), new Event(Event.POST, post.toJsonObject()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void doMessage(JSONObject content) throws JSONException, IllegalStateException {
|
private void doMessage(JSONObject content) throws JSONException, IllegalStateException {
|
||||||
|
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||||
if (content.getString("to").equals(user.getLogin()) || !contactMap.containsKey(content.getString("to"))) {
|
if (content.getString("to").equals(user.getLogin()) || !contactMap.containsKey(content.getString("to"))) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -273,6 +293,7 @@ public class ChatServer {
|
||||||
LOGGER.info("Fin de doMessage");
|
LOGGER.info("Fin de doMessage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void doListContact(JSONObject content) throws JSONException, IllegalStateException {
|
private void doListContact(JSONObject content) throws JSONException, IllegalStateException {
|
||||||
for (Contact contact: contactMap.values()) {
|
for (Contact contact: contactMap.values()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue