1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Make Workgroup JID an EntityBareJid in smackx.workgroup

This commit is contained in:
Florian Schmaus 2018-04-18 08:48:52 +02:00
parent 96046a063a
commit 5fbf2ce75a
8 changed files with 38 additions and 33 deletions

View file

@ -28,6 +28,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.workgroup.packet.AgentInfo; import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups; import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
/** /**
@ -37,7 +38,7 @@ import org.jxmpp.jid.Jid;
*/ */
public class Agent { public class Agent {
private XMPPConnection connection; private XMPPConnection connection;
private Jid workgroupJID; private final EntityBareJid workgroupJID;
public static Collection<String> getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { public static Collection<String> getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
AgentWorkgroups request = new AgentWorkgroups(agentJID); AgentWorkgroups request = new AgentWorkgroups(agentJID);
@ -49,7 +50,7 @@ public class Agent {
/** /**
* Constructs an Agent. * Constructs an Agent.
*/ */
Agent(XMPPConnection connection, Jid workgroupJID) { Agent(XMPPConnection connection, EntityBareJid workgroupJID) {
this.connection = connection; this.connection = connection;
this.workgroupJID = workgroupJID; this.workgroupJID = workgroupJID;
} }

View file

@ -58,7 +58,7 @@ public class AgentRoster {
private static final int EVENT_PRESENCE_CHANGED = 2; private static final int EVENT_PRESENCE_CHANGED = 2;
private final XMPPConnection connection; private final XMPPConnection connection;
private final Jid workgroupJID; private final EntityBareJid workgroupJID;
private final List<EntityBareJid> entries = new ArrayList<>(); private final List<EntityBareJid> entries = new ArrayList<>();
private final List<AgentRosterListener> listeners = new ArrayList<>(); private final List<AgentRosterListener> listeners = new ArrayList<>();
private final Map<Jid, Map<Resourcepart, Presence>> presenceMap = new HashMap<>(); private final Map<Jid, Map<Resourcepart, Presence>> presenceMap = new HashMap<>();
@ -73,7 +73,7 @@ public class AgentRoster {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
AgentRoster(XMPPConnection connection, Jid workgroupJID) throws NotConnectedException, InterruptedException { AgentRoster(XMPPConnection connection, EntityBareJid workgroupJID) throws NotConnectedException, InterruptedException {
this.connection = connection; this.connection = connection;
this.workgroupJID = workgroupJID; this.workgroupJID = workgroupJID;
// Listen for any roster packets. // Listen for any roster packets.
@ -292,7 +292,6 @@ public class AgentRoster {
/** /**
* Listens for all presence packets and processes them. * Listens for all presence packets and processes them.
*/ */
@SuppressWarnings("EqualsIncompatibleType")
private class PresencePacketListener implements StanzaListener { private class PresencePacketListener implements StanzaListener {
@Override @Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {

View file

@ -76,6 +76,8 @@ import org.jivesoftware.smackx.workgroup.settings.GenericSettings;
import org.jivesoftware.smackx.workgroup.settings.SearchSettings; import org.jivesoftware.smackx.workgroup.settings.SearchSettings;
import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.Form;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.stringprep.XmppStringprepException;
@ -96,7 +98,7 @@ public class AgentSession {
private final XMPPConnection connection; private final XMPPConnection connection;
private final Jid workgroupJID; private final EntityBareJid workgroupJID;
private boolean online = false; private boolean online = false;
private Presence.Mode presenceMode; private Presence.Mode presenceMode;
@ -124,7 +126,7 @@ public class AgentSession {
* authentication. * authentication.
* @param workgroupJID the fully qualified JID of the workgroup. * @param workgroupJID the fully qualified JID of the workgroup.
*/ */
public AgentSession(Jid workgroupJID, XMPPConnection connection) { public AgentSession(EntityBareJid workgroupJID, XMPPConnection connection) {
// Login must have been done before passing in connection. // Login must have been done before passing in connection.
if (!connection.isAuthenticated()) { if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must login to server before creating workgroup."); throw new IllegalStateException("Must login to server before creating workgroup.");
@ -502,9 +504,9 @@ public class AgentSession {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public void dequeueUser(String userID) throws XMPPException, NotConnectedException, InterruptedException { public void dequeueUser(EntityJid userID) throws XMPPException, NotConnectedException, InterruptedException {
// todo: this method simply won't work right now. // todo: this method simply won't work right now.
DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID); DepartQueuePacket departPacket = new DepartQueuePacket(workgroupJID, userID);
// PENDING // PENDING
this.connection.sendStanza(departPacket); this.connection.sendStanza(departPacket);

View file

@ -25,12 +25,13 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smackx.workgroup.packet.Transcript; import org.jivesoftware.smackx.workgroup.packet.Transcript;
import org.jivesoftware.smackx.workgroup.packet.Transcripts; import org.jivesoftware.smackx.workgroup.packet.Transcripts;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
/** /**
* A TranscriptManager helps to retrieve the full conversation transcript of a given session * A TranscriptManager helps to retrieve the full conversation transcript of a given session
* {@link #getTranscript(Jid, String)} or to retrieve a list with the summary of all the * {@link #getTranscript(EntityBareJid, String)} or to retrieve a list with the summary of all the
* conversations that a user had {@link #getTranscripts(Jid, Jid)}. * conversations that a user had {@link #getTranscripts(EntityBareJid, Jid)}.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
@ -52,7 +53,7 @@ public class TranscriptManager {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public Transcript getTranscript(Jid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { public Transcript getTranscript(EntityBareJid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Transcript request = new Transcript(sessionID); Transcript request = new Transcript(sessionID);
request.setTo(workgroupJID); request.setTo(workgroupJID);
Transcript response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); Transcript response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
@ -71,7 +72,7 @@ public class TranscriptManager {
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
*/ */
public Transcripts getTranscripts(Jid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { public Transcripts getTranscripts(EntityBareJid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Transcripts request = new Transcripts(userID); Transcripts request = new Transcripts(userID);
request.setTo(workgroupJID); request.setTo(workgroupJID);
Transcripts response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); Transcripts response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();

View file

@ -28,7 +28,9 @@ import java.util.TimeZone;
import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jxmpp.jid.EntityBareJid;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -56,14 +58,14 @@ public class AgentStatus implements ExtensionElement {
*/ */
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private String workgroupJID; private EntityBareJid workgroupJID;
private final List<ChatInfo> currentChats = new ArrayList<>(); private final List<ChatInfo> currentChats = new ArrayList<>();
private int maxChats = -1; private int maxChats = -1;
AgentStatus() { AgentStatus() {
} }
public String getWorkgroupJID() { public EntityBareJid getWorkgroupJID() {
return workgroupJID; return workgroupJID;
} }
@ -238,7 +240,7 @@ public class AgentStatus implements ExtensionElement {
public AgentStatus parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { public AgentStatus parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
AgentStatus agentStatus = new AgentStatus(); AgentStatus agentStatus = new AgentStatus();
agentStatus.workgroupJID = parser.getAttributeValue("", "jid"); agentStatus.workgroupJID = ParserUtils.getBareJidAttribute(parser);
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -19,7 +19,8 @@ package org.jivesoftware.smackx.workgroup.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityJid;
/** /**
* A IQ stanza used to depart a workgroup queue. There are two cases for issuing a depart * A IQ stanza used to depart a workgroup queue. There are two cases for issuing a depart
@ -34,18 +35,14 @@ import org.jxmpp.jid.Jid;
*/ */
public class DepartQueuePacket extends IQ { public class DepartQueuePacket extends IQ {
private Jid user; private final EntityJid user;
private DepartQueuePacket() {
super("depart-queue", "http://jabber.org/protocol/workgroup");
}
/** /**
* Creates a depart queue request stanza to the specified workgroup. * Creates a depart queue request stanza to the specified workgroup.
* *
* @param workgroup the workgroup to depart. * @param workgroup the workgroup to depart.
*/ */
public DepartQueuePacket(Jid workgroup) { public DepartQueuePacket(EntityBareJid workgroup) {
this(workgroup, null); this(workgroup, null);
} }
@ -56,8 +53,8 @@ public class DepartQueuePacket extends IQ {
* @param workgroup the workgroup to depart. * @param workgroup the workgroup to depart.
* @param user the user to make depart from the queue. * @param user the user to make depart from the queue.
*/ */
public DepartQueuePacket(Jid workgroup, Jid user) { public DepartQueuePacket(EntityBareJid workgroup, EntityJid user) {
this(); super("depart-queue", "http://jabber.org/protocol/workgroup");
this.user = user; this.user = user;
setTo(workgroup); setTo(workgroup);

View file

@ -21,7 +21,9 @@ import java.io.IOException;
import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jxmpp.jid.EntityBareJid;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -41,13 +43,13 @@ public class WorkgroupInformation implements ExtensionElement {
*/ */
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private final String workgroupJID; private final EntityBareJid workgroupJID;
public WorkgroupInformation(String workgroupJID) { public WorkgroupInformation(EntityBareJid workgroupJID) {
this.workgroupJID = workgroupJID; this.workgroupJID = workgroupJID;
} }
public String getWorkgroupJID() { public EntityBareJid getWorkgroupJID() {
return workgroupJID; return workgroupJID;
} }
@ -83,7 +85,7 @@ public class WorkgroupInformation implements ExtensionElement {
public WorkgroupInformation parse(XmlPullParser parser, public WorkgroupInformation parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException, int initialDepth) throws XmlPullParserException,
IOException { IOException {
String workgroupJID = parser.getAttributeValue("", "jid"); EntityBareJid workgroupJID = ParserUtils.getBareJidAttribute(parser);
// since this is a start and end tag, and we arrive on the start, this should guarantee // since this is a start and end tag, and we arrive on the start, this should guarantee
// we leave on the end // we leave on the end

View file

@ -61,6 +61,7 @@ import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityJid; import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -77,7 +78,7 @@ import org.jxmpp.jid.Jid;
*/ */
public class Workgroup { public class Workgroup {
private final Jid workgroupJID; private final EntityBareJid workgroupJID;
private final XMPPConnection connection; private final XMPPConnection connection;
private boolean inQueue; private boolean inQueue;
private final CopyOnWriteArraySet<WorkgroupInvitationListener> invitationListeners; private final CopyOnWriteArraySet<WorkgroupInvitationListener> invitationListeners;
@ -96,7 +97,7 @@ public class Workgroup {
* @param connection an XMPP connection which must have already undergone a * @param connection an XMPP connection which must have already undergone a
* successful login. * successful login.
*/ */
public Workgroup(Jid workgroupJID, XMPPConnection connection) { public Workgroup(EntityBareJid workgroupJID, XMPPConnection connection) {
// Login must have been done before passing in connection. // Login must have been done before passing in connection.
if (!connection.isAuthenticated()) { if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must login to server before creating workgroup."); throw new IllegalStateException("Must login to server before creating workgroup.");
@ -163,7 +164,7 @@ public class Workgroup {
* *
* @return the name of the workgroup. * @return the name of the workgroup.
*/ */
public Jid getWorkgroupJID() { public EntityBareJid getWorkgroupJID() {
return workgroupJID; return workgroupJID;
} }
@ -569,7 +570,7 @@ public class Workgroup {
private final Jid userID; private final Jid userID;
private final DataForm form; private final DataForm form;
private JoinQueuePacket(Jid workgroup, Form answerForm, Jid userID) { private JoinQueuePacket(EntityBareJid workgroup, Form answerForm, Jid userID) {
super("join-queue", "http://jabber.org/protocol/workgroup"); super("join-queue", "http://jabber.org/protocol/workgroup");
this.userID = userID; this.userID = userID;