Replace UserStatusChangeProcessor with inline code in ChatScene
This commit is contained in:
parent
c228519d4b
commit
8a3ffec859
@ -141,7 +141,7 @@ public class Client implements Closeable {
|
|||||||
receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor());
|
receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor());
|
||||||
|
|
||||||
// Process user status changes
|
// Process user status changes
|
||||||
receiver.registerProcessor(UserStatusChangeEvent.class, new UserStatusChangeProcessor(localDB));
|
receiver.registerProcessor(UserStatusChangeEvent.class, eventBus::dispatch);
|
||||||
|
|
||||||
// Process message ID generation
|
// Process message ID generation
|
||||||
receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator);
|
receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator);
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package envoy.client.net;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import envoy.client.data.LocalDB;
|
|
||||||
import envoy.data.User;
|
|
||||||
import envoy.event.EventBus;
|
|
||||||
import envoy.event.UserStatusChangeEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Project: <strong>envoy-client</strong><br>
|
|
||||||
* File: <strong>UserStatusChangeProcessor.java</strong><br>
|
|
||||||
* Created: <strong>2 Feb 2020</strong><br>
|
|
||||||
*
|
|
||||||
* @author Leon Hofmeister
|
|
||||||
* @since Envoy Client v0.3-alpha
|
|
||||||
*/
|
|
||||||
public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent> {
|
|
||||||
|
|
||||||
private final LocalDB localDB;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param localDB the local database in which status updates will by applied
|
|
||||||
* @since Envoy Client v0.3-alpha
|
|
||||||
*/
|
|
||||||
public UserStatusChangeProcessor(LocalDB localDB) { this.localDB = localDB; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(UserStatusChangeEvent evt) {
|
|
||||||
localDB.getUsers().values().stream().filter(u -> u.getID() == evt.getID()).map(User.class::cast).findFirst().get().setStatus(evt.get());
|
|
||||||
EventBus.getInstance().dispatch(evt);
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,9 +22,7 @@ import envoy.client.net.WriteProxy;
|
|||||||
import envoy.client.ui.ContactListCell;
|
import envoy.client.ui.ContactListCell;
|
||||||
import envoy.client.ui.MessageListCell;
|
import envoy.client.ui.MessageListCell;
|
||||||
import envoy.client.ui.SceneContext;
|
import envoy.client.ui.SceneContext;
|
||||||
import envoy.data.Contact;
|
import envoy.data.*;
|
||||||
import envoy.data.Message;
|
|
||||||
import envoy.data.MessageBuilder;
|
|
||||||
import envoy.event.EventBus;
|
import envoy.event.EventBus;
|
||||||
import envoy.event.MessageStatusChangeEvent;
|
import envoy.event.MessageStatusChangeEvent;
|
||||||
import envoy.event.UserStatusChangeEvent;
|
import envoy.event.UserStatusChangeEvent;
|
||||||
@ -105,7 +103,16 @@ public final class ChatScene {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Listen to user status changes
|
// Listen to user status changes
|
||||||
eventBus.register(UserStatusChangeEvent.class, e -> Platform.runLater(userList::refresh));
|
eventBus.register(UserStatusChangeEvent.class, e ->
|
||||||
|
userList.getItems()
|
||||||
|
.stream()
|
||||||
|
.filter(c -> c.getID() == e.getID())
|
||||||
|
.findAny()
|
||||||
|
.ifPresent(u -> {
|
||||||
|
((User) u).setStatus(e.get());
|
||||||
|
Platform.runLater(userList::refresh);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// Listen to contacts changes
|
// Listen to contacts changes
|
||||||
eventBus.register(ContactOperationEvent.class, e -> {
|
eventBus.register(ContactOperationEvent.class, e -> {
|
||||||
|
Reference in New Issue
Block a user