Redesigned UserStatusChangeProcessor to please @CyB3RC0nN0R s wishes

This commit is contained in:
delvh 2020-02-07 15:57:41 +01:00
parent f28d4e2e55
commit 337c74ded1
2 changed files with 5 additions and 8 deletions

View File

@ -1,11 +1,9 @@
package envoy.client.net; package envoy.client.net;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.data.User;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.UserStatusChangeEvent; import envoy.event.UserStatusChangeEvent;
@ -19,9 +17,10 @@ import envoy.event.UserStatusChangeEvent;
*/ */
public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent> { public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent> {
private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class.getSimpleName());
private Client client; private Client client;
private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class.getSimpleName());
/** /**
* @param client the {@link Client} who receives an * @param client the {@link Client} who receives an
* {@link UserStatusChangeEvent} * {@link UserStatusChangeEvent}
@ -32,9 +31,7 @@ public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent
@Override @Override
public void accept(UserStatusChangeEvent evt) { public void accept(UserStatusChangeEvent evt) {
logger.info("Received " + evt); logger.info("Received " + evt);
List<User> contacts = client.getContacts().getContacts(); client.getContacts().getContacts().stream().filter((user) -> user.getId() == evt.getId()).findFirst().get().setStatus(evt.get());
contacts.stream().filter((user) -> user.getId() == evt.getId()).findFirst().get().setStatus(evt.get());
EventBus.getInstance().dispatch(evt); EventBus.getInstance().dispatch(evt);
} }
} }

View File

@ -212,7 +212,7 @@ public class ChatWindow extends JFrame {
// Listen to theme changes // Listen to theme changes
EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get())); EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme((Theme) evt.get()));
// Listen to UserStatus changes // Listen to user status changes
EventBus.getInstance().register(UserStatusChangeEvent.class, (evt) -> { userList.revalidate(); userList.repaint(); }); EventBus.getInstance().register(UserStatusChangeEvent.class, (evt) -> { userList.revalidate(); userList.repaint(); });
// Listen to received messages // Listen to received messages