1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-31 17:25:58 +01:00

pep: cleanup pep users API

Use EntityBareJid just as its done within PepManager. There is no need
for AsyncButOrdered in the PEP user managers, as PepManager already
takes care of that. Also the message carrying the PEP event should
always be the last parameter of the callbacks, as it is the least
important piece of information.
This commit is contained in:
Florian Schmaus 2020-04-13 12:14:32 +02:00
parent 32ae0d8826
commit 7c2f9e3603
10 changed files with 44 additions and 62 deletions

View file

@ -19,8 +19,8 @@ package org.jivesoftware.smackx.geoloc;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
public interface GeoLocationListener {
void onGeoLocationUpdated(BareJid jid, GeoLocation geoLocation, Message message);
void onGeoLocationUpdated(EntityBareJid jid, GeoLocation geoLocation, Message message);
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez 2019 Florian Schmaus
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez 2019-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.AsyncButOrdered;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.NoResponseException;
@ -43,7 +42,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProviderManager;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.Jid;
@ -73,7 +71,6 @@ public final class GeoLocationManager extends Manager {
private static boolean ENABLE_USER_LOCATION_NOTIFICATIONS_BY_DEFAULT = true;
private final Set<GeoLocationListener> geoLocationListeners = new CopyOnWriteArraySet<>();
private final AsyncButOrdered<BareJid> asyncButOrdered = new AsyncButOrdered<BareJid>();
private final ServiceDiscoveryManager serviceDiscoveryManager;
private final PepManager pepManager;
@ -116,17 +113,14 @@ public final class GeoLocationManager extends Manager {
return;
}
final BareJid contact = from.asBareJid();
asyncButOrdered.performAsyncButOrdered(contact, () -> {
ItemsExtension itemsExtension = (ItemsExtension) event.getEvent();
List<ExtensionElement> items = itemsExtension.getExtensions();
@SuppressWarnings("unchecked")
PayloadItem<GeoLocation> payload = (PayloadItem<GeoLocation>) items.get(0);
GeoLocation geoLocation = payload.getPayload();
for (GeoLocationListener listener : geoLocationListeners) {
listener.onGeoLocationUpdated(contact, geoLocation, message);
listener.onGeoLocationUpdated(from, geoLocation, message);
}
});
}
});
serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2018 Paul Schaub.
* Copyright 2018 Paul Schaub, 2020 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,9 +20,10 @@ import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.mood.element.MoodElement;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
public interface MoodListener {
void onMoodUpdated(BareJid jid, Message message, MoodElement moodElement);
void onMoodUpdated(EntityBareJid from, MoodElement moodElement, Message message);
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2018 Paul Schaub.
* Copyright 2018 Paul Schaub, 2020 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,12 +16,11 @@
*/
package org.jivesoftware.smackx.mood;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.AsyncButOrdered;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
@ -42,7 +41,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubException;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
/**
@ -72,8 +70,7 @@ public final class MoodManager extends Manager {
private static final Map<XMPPConnection, MoodManager> INSTANCES = new WeakHashMap<>();
private final Set<MoodListener> moodListeners = new HashSet<>();
private final AsyncButOrdered<BareJid> asyncButOrdered = new AsyncButOrdered<>();
private final Set<MoodListener> moodListeners = new CopyOnWriteArraySet<>();
private PubSubManager pubSubManager;
private MoodManager(XMPPConnection connection) {
@ -86,22 +83,16 @@ public final class MoodManager extends Manager {
return;
}
final BareJid contact = from.asBareJid();
asyncButOrdered.performAsyncButOrdered(contact, new Runnable() {
@Override
public void run() {
ItemsExtension items = (ItemsExtension) event.getExtensions().get(0);
PayloadItem<?> payload = (PayloadItem<?>) items.getItems().get(0);
MoodElement mood = (MoodElement) payload.getPayload();
for (MoodListener listener : moodListeners) {
listener.onMoodUpdated(contact, message, mood);
listener.onMoodUpdated(from, mood, message);
}
}
});
}
});
}
public static synchronized MoodManager getInstanceFor(XMPPConnection connection) {
MoodManager manager = INSTANCES.get(connection);
@ -170,11 +161,11 @@ public final class MoodManager extends Manager {
message.addExtension(element);
}
public synchronized void addMoodListener(MoodListener listener) {
public void addMoodListener(MoodListener listener) {
moodListeners.add(listener);
}
public synchronized void removeMoodListener(MoodListener listener) {
public void removeMoodListener(MoodListener listener) {
moodListeners.remove(listener);
}
}

View file

@ -135,6 +135,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
*
* @return List of {@link Item}, {@link RetractItem}, or null
*/
// TODO: Shouldn't this return List<Item>? Why is RetractItem not a subtype of item?
public List<? extends NamedElement> getItems() {
return items;
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Aditya Borikar.
* Copyright 2019 Aditya Borikar, 2020 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,9 +20,10 @@ import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
public interface UserTuneListener {
void onUserTuneUpdated(BareJid jid, Message message, UserTuneElement userTuneElement);
void onUserTuneUpdated(EntityBareJid jid, UserTuneElement userTuneElement, Message message);
}

View file

@ -22,7 +22,6 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.AsyncButOrdered;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
@ -41,7 +40,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
/**
@ -70,7 +68,6 @@ public final class UserTuneManager extends Manager {
private static boolean ENABLE_USER_TUNE_NOTIFICATIONS_BY_DEFAULT = true;
private final Set<UserTuneListener> userTuneListeners = new CopyOnWriteArraySet<>();
private final AsyncButOrdered<BareJid> asyncButOrdered = new AsyncButOrdered<>();
private final ServiceDiscoveryManager serviceDiscoveryManager;
private final PepManager pepManager;
@ -93,8 +90,6 @@ public final class UserTuneManager extends Manager {
return;
}
final BareJid contact = from.asBareJid();
asyncButOrdered.performAsyncButOrdered(contact, () -> {
ItemsExtension itemsExtension = (ItemsExtension) event.getEvent();
List<ExtensionElement> items = itemsExtension.getExtensions();
@SuppressWarnings("unchecked")
@ -102,9 +97,8 @@ public final class UserTuneManager extends Manager {
UserTuneElement tune = payload.getPayload();
for (UserTuneListener listener : userTuneListeners) {
listener.onUserTuneUpdated(contact, message, tune);
listener.onUserTuneUpdated(from, tune, message);
}
});
}
});
serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);

View file

@ -35,7 +35,7 @@ import org.igniterealtime.smack.inttest.annotations.AfterClass;
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil;
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.util.XmppDateTime;
public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest {
@ -82,7 +82,7 @@ public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest {
final GeoLocationListener geoLocationListener = new GeoLocationListener() {
@Override
public void onGeoLocationUpdated(BareJid jid, GeoLocation geoLocation, Message message) {
public void onGeoLocationUpdated(EntityBareJid jid, GeoLocation geoLocation, Message message) {
if (geoLocation.equals(geoLocation1)) {
geoLocationReceived.signal();
}

View file

@ -43,7 +43,7 @@ public class MoodIntegrationTest extends AbstractSmackIntegrationTest {
final SimpleResultSyncPoint moodReceived = new SimpleResultSyncPoint();
final MoodListener moodListener = (jid, message, moodElement) -> {
final MoodListener moodListener = (jid, moodElement, message) -> {
if (moodElement.getMood() == Mood.satisfied) {
moodReceived.signal();
}

View file

@ -31,7 +31,7 @@ import org.igniterealtime.smack.inttest.annotations.AfterClass;
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil;
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest {
@ -63,7 +63,7 @@ public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest {
final UserTuneListener userTuneListener = new UserTuneListener() {
@Override
public void onUserTuneUpdated(BareJid jid, Message message, UserTuneElement userTuneElement) {
public void onUserTuneUpdated(EntityBareJid jid, UserTuneElement userTuneElement, Message message) {
if (userTuneElement.equals(userTuneElement1)) {
userTuneReceived.signal();
}