Added ReceivedGroupMessageProcessor

Receiving groupMessages works now properly(only if online)
This commit is contained in:
DieGurke 2020-06-13 10:40:47 +02:00
parent ee79ef1c66
commit a8b35418d3
3 changed files with 49 additions and 3 deletions

View File

@ -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

View File

@ -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&auml;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));
}
}

View File

@ -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