From 5daff3620e5367d06f9fb0ec7f5b2781c2432979 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 26 Sep 2020 12:10:22 +0200 Subject: [PATCH] Update UI on user status change --- client/src/main/java/envoy/client/data/LocalDB.java | 5 +++++ .../java/envoy/client/ui/controller/ChatScene.java | 11 ++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index eb3cfd5..a06c063 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -222,6 +222,11 @@ public final class LocalDB implements EventListener { this.getMessage(evt.getID()).ifPresent(msg -> msg.getMemberStatuses().replace(evt.getMemberID(), evt.get())); } + @Event(priority = 150) + private void onUserStatusChange(UserStatusChange evt) { + this.getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast).ifPresent(u -> u.setStatus(evt.get())); + } + @Event(priority = 150) private void onGroupResize(GroupResize evt) { getChat(evt.getGroupID()).map(Chat::getRecipient).map(Group.class::cast).ifPresent(evt::apply); } diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 2bd678c..c77438f 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -253,15 +253,8 @@ public final class ChatScene implements EventListener, Restorable { .ifPresent(msg -> Platform.runLater(messageList::refresh)); } - @Event - private void onUserStatusChange(UserStatusChange evt) { - chats.getSource() - .stream() - .filter(c -> c.getRecipient().getID() == evt.getID()) - .findAny() - .map(Chat::getRecipient) - .ifPresent(u -> ((User) u).setStatus(evt.get())); - } + @Event(eventType = UserStatusChange.class) + private void onUserStatusChange() { Platform.runLater(chatList::refresh); } @Event private void onContactOperation(ContactOperation operation) {