From ca0a0c07fc23291f5e6b5b2d73a979dc8d76a0a4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 7 Feb 2023 15:37:17 +0100 Subject: [PATCH] add models for Chat States + manager --- .../conversations/android/xmpp/Managers.java | 2 ++ .../xmpp/manager/ChatStateManager.java | 23 +++++++++++++++++++ .../android/xmpp/model/state/Active.java | 11 +++++++++ .../model/state/ChatStateNotification.java | 10 ++++++++ .../android/xmpp/model/state/Composing.java | 11 +++++++++ .../android/xmpp/model/state/Gone.java | 11 +++++++++ .../android/xmpp/model/state/Inactive.java | 11 +++++++++ .../android/xmpp/model/state/Paused.java | 11 +++++++++ .../xmpp/model/state/package-info.java | 5 ++++ .../xmpp/processor/MessageProcessor.java | 7 ++++++ 10 files changed, 102 insertions(+) create mode 100644 src/main/java/im/conversations/android/xmpp/manager/ChatStateManager.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/Active.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/ChatStateNotification.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/Composing.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/Gone.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/Inactive.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/Paused.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/state/package-info.java diff --git a/src/main/java/im/conversations/android/xmpp/Managers.java b/src/main/java/im/conversations/android/xmpp/Managers.java index 121a444d2..41d7a8a4d 100644 --- a/src/main/java/im/conversations/android/xmpp/Managers.java +++ b/src/main/java/im/conversations/android/xmpp/Managers.java @@ -9,6 +9,7 @@ import im.conversations.android.xmpp.manager.AxolotlManager; import im.conversations.android.xmpp.manager.BlockingManager; import im.conversations.android.xmpp.manager.BookmarkManager; import im.conversations.android.xmpp.manager.CarbonsManager; +import im.conversations.android.xmpp.manager.ChatStateManager; import im.conversations.android.xmpp.manager.DiscoManager; import im.conversations.android.xmpp.manager.NickManager; import im.conversations.android.xmpp.manager.PepManager; @@ -29,6 +30,7 @@ public final class Managers { .put(BlockingManager.class, new BlockingManager(context, connection)) .put(BookmarkManager.class, new BookmarkManager(context, connection)) .put(CarbonsManager.class, new CarbonsManager(context, connection)) + .put(ChatStateManager.class, new ChatStateManager(context, connection)) .put(DiscoManager.class, new DiscoManager(context, connection)) .put(NickManager.class, new NickManager(context, connection)) .put(PepManager.class, new PepManager(context, connection)) diff --git a/src/main/java/im/conversations/android/xmpp/manager/ChatStateManager.java b/src/main/java/im/conversations/android/xmpp/manager/ChatStateManager.java new file mode 100644 index 000000000..aad83570a --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/manager/ChatStateManager.java @@ -0,0 +1,23 @@ +package im.conversations.android.xmpp.manager; + +import android.content.Context; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.siacs.conversations.xmpp.Jid; +import im.conversations.android.xmpp.XmppConnection; +import im.conversations.android.xmpp.model.state.ChatStateNotification; + +public class ChatStateManager extends AbstractManager{ + + private static final Logger LOGGER = LoggerFactory.getLogger(ChatStateManager.class); + + public ChatStateManager(Context context, XmppConnection connection) { + super(context, connection); + } + + public void handle(final Jid from, final ChatStateNotification chatState) { + LOGGER.info("Received {} from {}", chatState, from); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/Active.java b/src/main/java/im/conversations/android/xmpp/model/state/Active.java new file mode 100644 index 000000000..8053b014b --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/Active.java @@ -0,0 +1,11 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.annotation.XmlElement; + +@XmlElement +public class Active extends ChatStateNotification { + + protected Active() { + super(Active.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/ChatStateNotification.java b/src/main/java/im/conversations/android/xmpp/model/state/ChatStateNotification.java new file mode 100644 index 000000000..93c1c4d49 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/ChatStateNotification.java @@ -0,0 +1,10 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.xmpp.model.Extension; + +public abstract class ChatStateNotification extends Extension { + + protected ChatStateNotification(Class clazz) { + super(clazz); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/Composing.java b/src/main/java/im/conversations/android/xmpp/model/state/Composing.java new file mode 100644 index 000000000..e85dd9e5b --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/Composing.java @@ -0,0 +1,11 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.annotation.XmlElement; + +@XmlElement +public class Composing extends ChatStateNotification { + + protected Composing() { + super(Composing.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/Gone.java b/src/main/java/im/conversations/android/xmpp/model/state/Gone.java new file mode 100644 index 000000000..41b5a3fb6 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/Gone.java @@ -0,0 +1,11 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.annotation.XmlElement; + +@XmlElement +public class Gone extends ChatStateNotification { + + protected Gone() { + super(Gone.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/Inactive.java b/src/main/java/im/conversations/android/xmpp/model/state/Inactive.java new file mode 100644 index 000000000..a20b6f670 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/Inactive.java @@ -0,0 +1,11 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.annotation.XmlElement; + +@XmlElement +public class Inactive extends ChatStateNotification { + + protected Inactive() { + super(Inactive.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/Paused.java b/src/main/java/im/conversations/android/xmpp/model/state/Paused.java new file mode 100644 index 000000000..82e1bbcd6 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/Paused.java @@ -0,0 +1,11 @@ +package im.conversations.android.xmpp.model.state; + +import im.conversations.android.annotation.XmlElement; + +@XmlElement +public class Paused extends ChatStateNotification { + + protected Paused() { + super(Paused.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/state/package-info.java b/src/main/java/im/conversations/android/xmpp/model/state/package-info.java new file mode 100644 index 000000000..681ddf7e3 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/state/package-info.java @@ -0,0 +1,5 @@ +@XmlPackage(namespace = Namespace.CHAT_STATES) +package im.conversations.android.xmpp.model.state; + +import eu.siacs.conversations.xml.Namespace; +import im.conversations.android.annotation.XmlPackage; \ No newline at end of file diff --git a/src/main/java/im/conversations/android/xmpp/processor/MessageProcessor.java b/src/main/java/im/conversations/android/xmpp/processor/MessageProcessor.java index 85de45bc6..373284446 100644 --- a/src/main/java/im/conversations/android/xmpp/processor/MessageProcessor.java +++ b/src/main/java/im/conversations/android/xmpp/processor/MessageProcessor.java @@ -4,6 +4,7 @@ import android.content.Context; import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.manager.CarbonsManager; +import im.conversations.android.xmpp.manager.ChatStateManager; import im.conversations.android.xmpp.manager.PubSubManager; import im.conversations.android.xmpp.manager.ReceiptManager; import im.conversations.android.xmpp.model.DeliveryReceiptRequest; @@ -11,6 +12,8 @@ import im.conversations.android.xmpp.model.carbons.Received; import im.conversations.android.xmpp.model.carbons.Sent; import im.conversations.android.xmpp.model.pubsub.event.Event; import im.conversations.android.xmpp.model.stanza.Message; +import im.conversations.android.xmpp.model.state.ChatStateNotification; + import java.util.function.Consumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +61,10 @@ public class MessageProcessor extends XmppConnection.Delegate implements Consume if (isRealtimeProcessor()) { final var requests = message.getExtensions(DeliveryReceiptRequest.class); getManager(ReceiptManager.class).received(from, id, requests); + final var chatState = message.getExtension(ChatStateNotification.class); + if (chatState != null) { + getManager(ChatStateManager.class).handle(from, chatState); + } } // TODO parse chat states