Added ReceivedGroupMessageProcessor
Receiving groupMessages works now properly(only if online)
This commit is contained in:
parent
8826d0c3d3
commit
7a11b556d9
@ -139,6 +139,9 @@ public class Client implements Closeable {
|
||||
final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor();
|
||||
final MessageStatusChangeEventProcessor messageStatusChangeEventProcessor = new MessageStatusChangeEventProcessor();
|
||||
|
||||
// TODO: Define a cache
|
||||
receiver.registerProcessor(GroupMessage.class, new ReceivedGroupMessageProcessor());
|
||||
|
||||
receiver.registerProcessor(Message.class, receivedMessageProcessor);
|
||||
|
||||
// Relay cached unread messages
|
||||
|
@ -0,0 +1,33 @@
|
||||
package envoy.client.net;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import envoy.client.event.MessageCreationEvent;
|
||||
import envoy.data.GroupMessage;
|
||||
import envoy.data.Message.MessageStatus;
|
||||
import envoy.event.EventBus;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>ReceivedGroupMessageProcessor.java</strong><br>
|
||||
* Created: <strong>13.06.2020</strong><br>
|
||||
*
|
||||
* @author Maximilian Käfer
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
public class ReceivedGroupMessageProcessor implements Consumer<GroupMessage> {
|
||||
|
||||
private static final Logger logger = EnvoyLog.getLogger(ReceivedGroupMessageProcessor.class);
|
||||
|
||||
@Override
|
||||
public void accept(GroupMessage groupMessage) {
|
||||
if (groupMessage.getStatus() == MessageStatus.WAITING || groupMessage.getStatus() == MessageStatus.READ)
|
||||
logger.warning("The groupMessage has the unexpected status " + groupMessage.getStatus());
|
||||
|
||||
// Dispatch event
|
||||
EventBus.getInstance().dispatch(new MessageCreationEvent(groupMessage));
|
||||
}
|
||||
|
||||
}
|
@ -88,13 +88,23 @@ public final class ChatScene {
|
||||
// Listen to received messages
|
||||
eventBus.register(MessageCreationEvent.class, e -> {
|
||||
final var message = e.get();
|
||||
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
||||
chat.getMessages().add(message);
|
||||
if (message.getClass().equals(Message.class)) {
|
||||
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
||||
chat.getMessages().add(message);
|
||||
|
||||
// Update UI if in current chat
|
||||
if (chat == currentChat)
|
||||
Platform.runLater(messageList::refresh);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
localDB.getChat(message.getRecipientID()).ifPresent(chat -> {
|
||||
chat.getMessages().add(message);
|
||||
|
||||
// Update UI if in current chat
|
||||
if (chat == currentChat)
|
||||
Platform.runLater(messageList::refresh);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Listen to message status changes
|
||||
|
Reference in New Issue
Block a user