do not parse presences from account

This commit is contained in:
Daniel Gultsch 2023-02-17 14:14:52 +01:00
parent bf9b0b18f9
commit a1e97461f9
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -1,6 +1,10 @@
package im.conversations.android.xmpp.processor; package im.conversations.android.xmpp.processor;
import android.content.Context; import android.content.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import im.conversations.android.database.model.PresenceShow; import im.conversations.android.database.model.PresenceShow;
import im.conversations.android.database.model.PresenceType; import im.conversations.android.database.model.PresenceType;
import im.conversations.android.xmpp.Entity; import im.conversations.android.xmpp.Entity;
@ -11,6 +15,8 @@ import java.util.function.Consumer;
public class PresenceProcessor extends XmppConnection.Delegate implements Consumer<Presence> { public class PresenceProcessor extends XmppConnection.Delegate implements Consumer<Presence> {
private static final Logger LOGGER = LoggerFactory.getLogger(PresenceProcessor.class);
public PresenceProcessor(final Context context, final XmppConnection connection) { public PresenceProcessor(final Context context, final XmppConnection connection) {
super(context, connection); super(context, connection);
} }
@ -19,20 +25,24 @@ public class PresenceProcessor extends XmppConnection.Delegate implements Consum
public void accept(final Presence presencePacket) { public void accept(final Presence presencePacket) {
final var from = presencePacket.getFrom(); final var from = presencePacket.getFrom();
final var address = from == null ? null : from.asBareJid(); final var address = from == null ? null : from.asBareJid();
final var resource = from == null ? null : from.getResourceOrEmpty(); if (address == null) {
LOGGER.warn("Received presence from account (from=null). This is unusual.");
return;
}
final var resource = from.getResourceOrEmpty();
final var typeAttribute = presencePacket.getAttribute("type"); final var typeAttribute = presencePacket.getAttribute("type");
final PresenceType type; final PresenceType type;
try { try {
type = PresenceType.of(typeAttribute); type = PresenceType.of(typeAttribute);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
// log we dont parse presence of type $type LOGGER.warn("Received presence of type '{}' from {}", typeAttribute, from);
return; return;
} }
final var show = PresenceShow.of(presencePacket.findChildContent("show")); final var show = PresenceShow.of(presencePacket.findChildContent("show"));
final var status = presencePacket.findChildContent("status"); final var status = presencePacket.findChildContent("status");
getDatabase().presenceDao().set(getAccount(), address, resource, type, show, status); getDatabase().presenceDao().set(getAccount(), address, resource, type, show, status);
// TODO store presence info // TODO store presence info (vCard + muc#user stuff + occupantId)
// TODO do this only for contacts? // TODO do this only for contacts?
fetchCapabilities(presencePacket); fetchCapabilities(presencePacket);