add models for Chat States + manager

This commit is contained in:
Daniel Gultsch 2023-02-07 15:37:17 +01:00
parent bed6b07bdd
commit ca0a0c07fc
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
10 changed files with 102 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import im.conversations.android.xmpp.manager.AxolotlManager;
import im.conversations.android.xmpp.manager.BlockingManager; import im.conversations.android.xmpp.manager.BlockingManager;
import im.conversations.android.xmpp.manager.BookmarkManager; import im.conversations.android.xmpp.manager.BookmarkManager;
import im.conversations.android.xmpp.manager.CarbonsManager; 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.DiscoManager;
import im.conversations.android.xmpp.manager.NickManager; import im.conversations.android.xmpp.manager.NickManager;
import im.conversations.android.xmpp.manager.PepManager; import im.conversations.android.xmpp.manager.PepManager;
@ -29,6 +30,7 @@ public final class Managers {
.put(BlockingManager.class, new BlockingManager(context, connection)) .put(BlockingManager.class, new BlockingManager(context, connection))
.put(BookmarkManager.class, new BookmarkManager(context, connection)) .put(BookmarkManager.class, new BookmarkManager(context, connection))
.put(CarbonsManager.class, new CarbonsManager(context, connection)) .put(CarbonsManager.class, new CarbonsManager(context, connection))
.put(ChatStateManager.class, new ChatStateManager(context, connection))
.put(DiscoManager.class, new DiscoManager(context, connection)) .put(DiscoManager.class, new DiscoManager(context, connection))
.put(NickManager.class, new NickManager(context, connection)) .put(NickManager.class, new NickManager(context, connection))
.put(PepManager.class, new PepManager(context, connection)) .put(PepManager.class, new PepManager(context, connection))

View file

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

View file

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

View file

@ -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<? extends Extension> clazz) {
super(clazz);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,6 +4,7 @@ import android.content.Context;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.XmppConnection;
import im.conversations.android.xmpp.manager.CarbonsManager; 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.PubSubManager;
import im.conversations.android.xmpp.manager.ReceiptManager; import im.conversations.android.xmpp.manager.ReceiptManager;
import im.conversations.android.xmpp.model.DeliveryReceiptRequest; 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.carbons.Sent;
import im.conversations.android.xmpp.model.pubsub.event.Event; import im.conversations.android.xmpp.model.pubsub.event.Event;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import im.conversations.android.xmpp.model.state.ChatStateNotification;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -58,6 +61,10 @@ public class MessageProcessor extends XmppConnection.Delegate implements Consume
if (isRealtimeProcessor()) { if (isRealtimeProcessor()) {
final var requests = message.getExtensions(DeliveryReceiptRequest.class); final var requests = message.getExtensions(DeliveryReceiptRequest.class);
getManager(ReceiptManager.class).received(from, id, requests); 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 // TODO parse chat states