mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Register IQ request handler for Offer(Request|Revoke) IQs
Fixes SMACK-664.
This commit is contained in:
parent
35317a19bd
commit
6632345efc
3 changed files with 43 additions and 20 deletions
|
@ -41,6 +41,8 @@ import org.jivesoftware.smack.filter.AndFilter;
|
|||
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;
|
||||
|
@ -142,8 +144,6 @@ public class AgentSession {
|
|||
|
||||
// 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));
|
||||
|
||||
|
@ -158,6 +158,37 @@ public class AgentSession {
|
|||
}
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
@ -689,15 +720,8 @@ public class AgentSession {
|
|||
|
||||
// PacketListener Implementation.
|
||||
|
||||
private void handlePacket(Stanza packet) throws NotConnectedException {
|
||||
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
|
||||
|
@ -779,13 +803,6 @@ public class AgentSession {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,6 +112,9 @@ public class OfferRequestProvider extends IQProvider<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 String userID;
|
||||
private String userJID;
|
||||
|
@ -122,7 +125,7 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
|||
public OfferRequestPacket(String userJID, String 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;
|
||||
|
|
|
@ -67,13 +67,16 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
|
|||
|
||||
public class OfferRevokePacket extends IQ {
|
||||
|
||||
public static final String ELEMENT = "offer-revoke";
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
|
||||
|
||||
private String userJID;
|
||||
private String userID;
|
||||
private String sessionID;
|
||||
private String reason;
|
||||
|
||||
public OfferRevokePacket (String userJID, String 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;
|
||||
|
|
Loading…
Reference in a new issue