Added ReceivedGroupMessageProcessor
Receiving groupMessages works now properly(only if online)
This commit is contained in:
parent
ee79ef1c66
commit
a8b35418d3
@ -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,6 +88,7 @@ public final class ChatScene {
|
||||
// Listen to received messages
|
||||
eventBus.register(MessageCreationEvent.class, e -> {
|
||||
final var message = e.get();
|
||||
if (message.getClass().equals(Message.class)) {
|
||||
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
||||
chat.getMessages().add(message);
|
||||
|
||||
@ -95,6 +96,15 @@ public final class ChatScene {
|
||||
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