mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-17 04:32:04 +01:00
Merge branch '4.1'
Conflicts: smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java
This commit is contained in:
commit
2079ba6bd6
4 changed files with 48 additions and 35 deletions
|
@ -22,7 +22,7 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
@ -37,10 +37,9 @@ import org.jxmpp.jid.Jid;
|
||||||
* @see Roster#getGroup(String)
|
* @see Roster#getGroup(String)
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class RosterGroup {
|
public class RosterGroup extends Manager {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final XMPPConnection connection;
|
|
||||||
private final Set<RosterEntry> entries;
|
private final Set<RosterEntry> entries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,8 +49,8 @@ public class RosterGroup {
|
||||||
* @param connection the connection the group belongs to.
|
* @param connection the connection the group belongs to.
|
||||||
*/
|
*/
|
||||||
RosterGroup(String name, XMPPConnection connection) {
|
RosterGroup(String name, XMPPConnection connection) {
|
||||||
|
super(connection);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.connection = connection;
|
|
||||||
entries = new LinkedHashSet<RosterEntry>();
|
entries = new LinkedHashSet<RosterEntry>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ public class RosterGroup {
|
||||||
item.removeGroupName(this.name);
|
item.removeGroupName(this.name);
|
||||||
item.addGroupName(name);
|
item.addGroupName(name);
|
||||||
packet.addRosterItem(item);
|
packet.addRosterItem(item);
|
||||||
connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +170,6 @@ public class RosterGroup {
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void addEntry(RosterEntry entry) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void addEntry(RosterEntry entry) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
PacketCollector collector = null;
|
|
||||||
// Only add the entry if it isn't already in the list.
|
// Only add the entry if it isn't already in the list.
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
if (!entries.contains(entry)) {
|
if (!entries.contains(entry)) {
|
||||||
|
@ -181,12 +179,9 @@ public class RosterGroup {
|
||||||
item.addGroupName(getName());
|
item.addGroupName(getName());
|
||||||
packet.addRosterItem(item);
|
packet.addRosterItem(item);
|
||||||
// Wait up to a certain number of seconds for a reply from the server.
|
// Wait up to a certain number of seconds for a reply from the server.
|
||||||
collector = connection.createPacketCollectorAndSend(packet);
|
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collector != null) {
|
|
||||||
collector.nextResultOrThrow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,7 +198,6 @@ public class RosterGroup {
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void removeEntry(RosterEntry entry) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void removeEntry(RosterEntry entry) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
PacketCollector collector = null;
|
|
||||||
// Only remove the entry if it's in the entry list.
|
// Only remove the entry if it's in the entry list.
|
||||||
// Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
|
// Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
|
||||||
// to take place the entry will exist in the group until a packet is received from the
|
// to take place the entry will exist in the group until a packet is received from the
|
||||||
|
@ -216,12 +210,9 @@ public class RosterGroup {
|
||||||
item.removeGroupName(this.getName());
|
item.removeGroupName(this.getName());
|
||||||
packet.addRosterItem(item);
|
packet.addRosterItem(item);
|
||||||
// Wait up to a certain number of seconds for a reply from the server.
|
// Wait up to a certain number of seconds for a reply from the server.
|
||||||
collector = connection.createPacketCollectorAndSend(packet);
|
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collector != null) {
|
|
||||||
collector.nextResultOrThrow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEntryLocal(RosterEntry entry) {
|
void addEntryLocal(RosterEntry entry) {
|
||||||
|
|
|
@ -41,6 +41,8 @@ import org.jivesoftware.smack.filter.AndFilter;
|
||||||
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
||||||
import org.jivesoftware.smack.filter.OrFilter;
|
import org.jivesoftware.smack.filter.OrFilter;
|
||||||
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
import org.jivesoftware.smack.filter.StanzaTypeFilter;
|
||||||
|
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||||
|
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||||
import org.jivesoftware.smack.packet.DefaultExtensionElement;
|
import org.jivesoftware.smack.packet.DefaultExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
@ -141,8 +143,6 @@ public class AgentSession {
|
||||||
|
|
||||||
// Create a filter to listen for packets we're interested in.
|
// Create a filter to listen for packets we're interested in.
|
||||||
OrFilter filter = new OrFilter(
|
OrFilter filter = new OrFilter(
|
||||||
new StanzaTypeFilter(OfferRequestProvider.OfferRequestPacket.class),
|
|
||||||
new StanzaTypeFilter(OfferRevokeProvider.OfferRevokePacket.class),
|
|
||||||
new StanzaTypeFilter(Presence.class),
|
new StanzaTypeFilter(Presence.class),
|
||||||
new StanzaTypeFilter(Message.class));
|
new StanzaTypeFilter(Message.class));
|
||||||
|
|
||||||
|
@ -157,6 +157,37 @@ public class AgentSession {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
connection.addAsyncStanzaListener(packetListener, filter);
|
connection.addAsyncStanzaListener(packetListener, filter);
|
||||||
|
|
||||||
|
connection.registerIQRequestHandler(new AbstractIqRequestHandler(
|
||||||
|
OfferRequestProvider.OfferRequestPacket.ELEMENT,
|
||||||
|
OfferRequestProvider.OfferRequestPacket.NAMESPACE, IQ.Type.set,
|
||||||
|
Mode.async) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IQ handleIQRequest(IQ iqRequest) {
|
||||||
|
// Acknowledge the IQ set.
|
||||||
|
IQ reply = IQ.createResultIQ(iqRequest);
|
||||||
|
|
||||||
|
fireOfferRequestEvent((OfferRequestProvider.OfferRequestPacket) iqRequest);
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connection.registerIQRequestHandler(new AbstractIqRequestHandler(
|
||||||
|
OfferRevokeProvider.OfferRevokePacket.ELEMENT,
|
||||||
|
OfferRevokeProvider.OfferRevokePacket.NAMESPACE, IQ.Type.set,
|
||||||
|
Mode.async) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IQ handleIQRequest(IQ iqRequest) {
|
||||||
|
// Acknowledge the IQ set.
|
||||||
|
IQ reply = IQ.createResultIQ(iqRequest);
|
||||||
|
|
||||||
|
fireOfferRevokeEvent((OfferRevokeProvider.OfferRevokePacket) iqRequest);
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Create the agent associated to this session
|
// Create the agent associated to this session
|
||||||
agent = new Agent(connection, workgroupJID);
|
agent = new Agent(connection, workgroupJID);
|
||||||
}
|
}
|
||||||
|
@ -704,15 +735,8 @@ public class AgentSession {
|
||||||
|
|
||||||
// PacketListener Implementation.
|
// PacketListener Implementation.
|
||||||
|
|
||||||
private void handlePacket(Stanza packet) throws NotConnectedException, InterruptedException {
|
private void handlePacket(Stanza packet) {
|
||||||
if (packet instanceof OfferRequestProvider.OfferRequestPacket) {
|
if (packet instanceof Presence) {
|
||||||
// Acknowledge the IQ set.
|
|
||||||
IQ reply = IQ.createResultIQ((IQ) packet);
|
|
||||||
connection.sendStanza(reply);
|
|
||||||
|
|
||||||
fireOfferRequestEvent((OfferRequestProvider.OfferRequestPacket)packet);
|
|
||||||
}
|
|
||||||
else if (packet instanceof Presence) {
|
|
||||||
Presence presence = (Presence)packet;
|
Presence presence = (Presence)packet;
|
||||||
|
|
||||||
// The workgroup can send us a number of different presence packets. We
|
// The workgroup can send us a number of different presence packets. We
|
||||||
|
@ -794,13 +818,6 @@ public class AgentSession {
|
||||||
message.getFrom(), metaData);
|
message.getFrom(), metaData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (packet instanceof OfferRevokeProvider.OfferRevokePacket) {
|
|
||||||
// Acknowledge the IQ set.
|
|
||||||
IQ reply = IQ.createResultIQ((OfferRevokeProvider.OfferRevokePacket) packet);
|
|
||||||
connection.sendStanza(reply);
|
|
||||||
|
|
||||||
fireOfferRevokeEvent((OfferRevokeProvider.OfferRevokePacket)packet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -111,6 +111,9 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
||||||
|
|
||||||
public static class OfferRequestPacket extends IQ {
|
public static class OfferRequestPacket extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "offer";
|
||||||
|
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
|
||||||
|
|
||||||
private int timeout;
|
private int timeout;
|
||||||
private Jid userID;
|
private Jid userID;
|
||||||
private Jid userJID;
|
private Jid userJID;
|
||||||
|
@ -121,7 +124,7 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
||||||
public OfferRequestPacket(Jid userJID, Jid userID, int timeout, Map<String, List<String>> metaData,
|
public OfferRequestPacket(Jid userJID, Jid userID, int timeout, Map<String, List<String>> metaData,
|
||||||
String sessionID, OfferContent content)
|
String sessionID, OfferContent content)
|
||||||
{
|
{
|
||||||
super("offer", "http://jabber.org/protocol/workgroup");
|
super(ELEMENT, NAMESPACE);
|
||||||
this.userJID = userJID;
|
this.userJID = userJID;
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
|
|
@ -69,13 +69,15 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
|
||||||
|
|
||||||
public class OfferRevokePacket extends IQ {
|
public class OfferRevokePacket extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "offer-revoke";
|
||||||
|
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
|
||||||
private Jid userJID;
|
private Jid userJID;
|
||||||
private Jid userID;
|
private Jid userID;
|
||||||
private String sessionID;
|
private String sessionID;
|
||||||
private String reason;
|
private String reason;
|
||||||
|
|
||||||
public OfferRevokePacket (Jid userJID, Jid userID, String cause, String sessionID) {
|
public OfferRevokePacket (Jid userJID, Jid userID, String cause, String sessionID) {
|
||||||
super("offer-revoke", "http://jabber.org/protocol/workgroup");
|
super(ELEMENT, NAMESPACE);
|
||||||
this.userJID = userJID;
|
this.userJID = userJID;
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
this.reason = cause;
|
this.reason = cause;
|
||||||
|
|
Loading…
Reference in a new issue