Skip to content

Commit

Permalink
Merge branch '4.1'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Flowdalic committed May 27, 2015
2 parents 1d1ea5d + 7a3ca4f commit 2079ba6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Set;

import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
Expand All @@ -37,10 +37,9 @@
* @see Roster#getGroup(String)
* @author Matt Tucker
*/
public class RosterGroup {
public class RosterGroup extends Manager {

private final String name;
private final XMPPConnection connection;
private final Set<RosterEntry> entries;

/**
Expand All @@ -50,8 +49,8 @@ public class RosterGroup {
* @param connection the connection the group belongs to.
*/
RosterGroup(String name, XMPPConnection connection) {
super(connection);
this.name = name;
this.connection = connection;
entries = new LinkedHashSet<RosterEntry>();
}

Expand Down Expand Up @@ -85,7 +84,7 @@ public void setName(String name) throws NotConnectedException, NoResponseExcepti
item.removeGroupName(this.name);
item.addGroupName(name);
packet.addRosterItem(item);
connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
}
}
}
Expand Down Expand Up @@ -171,7 +170,6 @@ public boolean contains(Jid user) {
* @throws 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.
synchronized (entries) {
if (!entries.contains(entry)) {
Expand All @@ -181,12 +179,9 @@ public void addEntry(RosterEntry entry) throws NoResponseException, XMPPErrorExc
item.addGroupName(getName());
packet.addRosterItem(item);
// 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();
}
}

/**
Expand All @@ -203,7 +198,6 @@ public void addEntry(RosterEntry entry) throws NoResponseException, XMPPErrorExc
* @throws 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.
// 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
Expand All @@ -216,12 +210,9 @@ public void removeEntry(RosterEntry entry) throws NoResponseException, XMPPError
item.removeGroupName(this.getName());
packet.addRosterItem(item);
// 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) {
Expand Down
Expand Up @@ -41,6 +41,8 @@
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.OrFilter;
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.IQ;
import org.jivesoftware.smack.packet.Message;
Expand Down Expand Up @@ -141,8 +143,6 @@ public AgentSession(Jid workgroupJID, XMPPConnection connection) {

// Create a filter to listen for packets we're interested in.
OrFilter filter = new OrFilter(
new StanzaTypeFilter(OfferRequestProvider.OfferRequestPacket.class),
new StanzaTypeFilter(OfferRevokeProvider.OfferRevokePacket.class),
new StanzaTypeFilter(Presence.class),
new StanzaTypeFilter(Message.class));

Expand All @@ -157,6 +157,37 @@ public void processPacket(Stanza packet) {
}
};
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
agent = new Agent(connection, workgroupJID);
}
Expand Down Expand Up @@ -704,15 +735,8 @@ private void fireQueueUsersEvent(WorkgroupQueue queue, WorkgroupQueue.Status sta

// PacketListener Implementation.

private void handlePacket(Stanza packet) throws NotConnectedException, InterruptedException {
if (packet instanceof OfferRequestProvider.OfferRequestPacket) {
// Acknowledge the IQ set.
IQ reply = IQ.createResultIQ((IQ) packet);
connection.sendStanza(reply);

fireOfferRequestEvent((OfferRequestProvider.OfferRequestPacket)packet);
}
else if (packet instanceof Presence) {
private void handlePacket(Stanza packet) {
if (packet instanceof Presence) {
Presence presence = (Presence)packet;

// The workgroup can send us a number of different presence packets. We
Expand Down Expand Up @@ -794,13 +818,6 @@ else if (packet instanceof Message) {
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);
}
}

/**
Expand Down
Expand Up @@ -111,6 +111,9 @@ else if (eventType == XmlPullParser.END_TAG) {

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 Jid userID;
private Jid userJID;
Expand All @@ -121,7 +124,7 @@ public static class OfferRequestPacket extends IQ {
public OfferRequestPacket(Jid userJID, Jid userID, int timeout, Map<String, List<String>> metaData,
String sessionID, OfferContent content)
{
super("offer", "http://jabber.org/protocol/workgroup");
super(ELEMENT, NAMESPACE);
this.userJID = userJID;
this.userID = userID;
this.timeout = timeout;
Expand Down
Expand Up @@ -69,13 +69,15 @@ else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals(

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 userID;
private String sessionID;
private String reason;

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.userID = userID;
this.reason = cause;
Expand Down

0 comments on commit 2079ba6

Please sign in to comment.