mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +01:00
Make Agent an EntityBareJid in smackx.workgroup
This commit is contained in:
parent
f69cd55970
commit
96046a063a
7 changed files with 55 additions and 49 deletions
|
@ -38,6 +38,7 @@ import org.jivesoftware.smack.packet.Stanza;
|
||||||
import org.jivesoftware.smackx.workgroup.packet.AgentStatus;
|
import org.jivesoftware.smackx.workgroup.packet.AgentStatus;
|
||||||
import org.jivesoftware.smackx.workgroup.packet.AgentStatusRequest;
|
import org.jivesoftware.smackx.workgroup.packet.AgentStatusRequest;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
import org.jxmpp.jid.EntityFullJid;
|
import org.jxmpp.jid.EntityFullJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
|
@ -58,7 +59,7 @@ public class AgentRoster {
|
||||||
|
|
||||||
private final XMPPConnection connection;
|
private final XMPPConnection connection;
|
||||||
private final Jid workgroupJID;
|
private final Jid workgroupJID;
|
||||||
private final List<String> 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<>();
|
||||||
// The roster is marked as initialized when at least a single roster packet
|
// The roster is marked as initialized when at least a single roster packet
|
||||||
|
@ -113,8 +114,7 @@ public class AgentRoster {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
|
|
||||||
// Fire events for the existing entries and presences in the roster
|
// Fire events for the existing entries and presences in the roster
|
||||||
for (Iterator<String> it = getAgents().iterator(); it.hasNext();) {
|
for (EntityBareJid jid : getAgents()) {
|
||||||
String jid = it.next();
|
|
||||||
// Check again in case the agent is no longer in the roster (highly unlikely
|
// Check again in case the agent is no longer in the roster (highly unlikely
|
||||||
// but possible)
|
// but possible)
|
||||||
if (entries.contains(jid)) {
|
if (entries.contains(jid)) {
|
||||||
|
@ -167,10 +167,10 @@ public class AgentRoster {
|
||||||
*
|
*
|
||||||
* @return all entries in the roster.
|
* @return all entries in the roster.
|
||||||
*/
|
*/
|
||||||
public Set<String> getAgents() {
|
public Set<EntityBareJid> getAgents() {
|
||||||
Set<String> agents = new HashSet<>();
|
Set<EntityBareJid> agents = new HashSet<>();
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator<String> i = entries.iterator(); i.hasNext();) {
|
for (Iterator<EntityBareJid> i = entries.iterator(); i.hasNext();) {
|
||||||
agents.add(i.next());
|
agents.add(i.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,14 +185,13 @@ public class AgentRoster {
|
||||||
* or "user@domain/resource").
|
* or "user@domain/resource").
|
||||||
* @return true if the XMPP address is an agent in the workgroup.
|
* @return true if the XMPP address is an agent in the workgroup.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("EqualsIncompatibleType")
|
|
||||||
public boolean contains(Jid jid) {
|
public boolean contains(Jid jid) {
|
||||||
if (jid == null) {
|
if (jid == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator<String> i = entries.iterator(); i.hasNext();) {
|
for (Iterator<EntityBareJid> i = entries.iterator(); i.hasNext();) {
|
||||||
String entry = i.next();
|
EntityBareJid entry = i.next();
|
||||||
if (entry.equals(jid)) {
|
if (entry.equals(jid)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -278,10 +277,10 @@ public class AgentRoster {
|
||||||
for (int i = 0; i < listeners.length; i++) {
|
for (int i = 0; i < listeners.length; i++) {
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case EVENT_AGENT_ADDED:
|
case EVENT_AGENT_ADDED:
|
||||||
listeners[i].agentAdded((String) eventObject);
|
listeners[i].agentAdded((EntityBareJid) eventObject);
|
||||||
break;
|
break;
|
||||||
case EVENT_AGENT_REMOVED:
|
case EVENT_AGENT_REMOVED:
|
||||||
listeners[i].agentRemoved((String) eventObject);
|
listeners[i].agentRemoved((EntityBareJid) eventObject);
|
||||||
break;
|
break;
|
||||||
case EVENT_PRESENCE_CHANGED:
|
case EVENT_PRESENCE_CHANGED:
|
||||||
listeners[i].presenceChanged((Presence) eventObject);
|
listeners[i].presenceChanged((Presence) eventObject);
|
||||||
|
@ -335,8 +334,8 @@ public class AgentRoster {
|
||||||
}
|
}
|
||||||
// Fire an event.
|
// Fire an event.
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator<String> i = entries.iterator(); i.hasNext();) {
|
for (Iterator<EntityBareJid> i = entries.iterator(); i.hasNext();) {
|
||||||
String entry = i.next();
|
EntityBareJid entry = i.next();
|
||||||
if (entry.equals(key.asEntityBareJidIfPossible())) {
|
if (entry.equals(key.asEntityBareJidIfPossible())) {
|
||||||
fireEvent(EVENT_PRESENCE_CHANGED, packet);
|
fireEvent(EVENT_PRESENCE_CHANGED, packet);
|
||||||
}
|
}
|
||||||
|
@ -356,8 +355,7 @@ public class AgentRoster {
|
||||||
}
|
}
|
||||||
// Fire an event.
|
// Fire an event.
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator<String> i = entries.iterator(); i.hasNext();) {
|
for (EntityBareJid entry : entries) {
|
||||||
String entry = i.next();
|
|
||||||
if (entry.equals(key.asEntityBareJidIfPossible())) {
|
if (entry.equals(key.asEntityBareJidIfPossible())) {
|
||||||
fireEvent(EVENT_PRESENCE_CHANGED, packet);
|
fireEvent(EVENT_PRESENCE_CHANGED, packet);
|
||||||
}
|
}
|
||||||
|
@ -378,19 +376,12 @@ public class AgentRoster {
|
||||||
AgentStatusRequest statusRequest = (AgentStatusRequest) packet;
|
AgentStatusRequest statusRequest = (AgentStatusRequest) packet;
|
||||||
for (Iterator<AgentStatusRequest.Item> i = statusRequest.getAgents().iterator(); i.hasNext();) {
|
for (Iterator<AgentStatusRequest.Item> i = statusRequest.getAgents().iterator(); i.hasNext();) {
|
||||||
AgentStatusRequest.Item item = i.next();
|
AgentStatusRequest.Item item = i.next();
|
||||||
String agentJID = item.getJID();
|
EntityBareJid agentJID = item.getJID();
|
||||||
if ("remove".equals(item.getType())) {
|
if ("remove".equals(item.getType())) {
|
||||||
|
|
||||||
// Removing the user from the roster, so remove any presence information
|
// Removing the user from the roster, so remove any presence information
|
||||||
// about them.
|
// about them.
|
||||||
Jid agentJid;
|
presenceMap.remove(agentJID.asBareJid());
|
||||||
try {
|
|
||||||
agentJid = JidCreate.from(agentJID);
|
|
||||||
}
|
|
||||||
catch (XmppStringprepException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
presenceMap.remove(agentJid.asBareJid());
|
|
||||||
// Fire event for roster listeners.
|
// Fire event for roster listeners.
|
||||||
fireEvent(EVENT_AGENT_REMOVED, agentJID);
|
fireEvent(EVENT_AGENT_REMOVED, agentJID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,17 @@ package org.jivesoftware.smackx.workgroup.agent;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Agent roster listener.
|
* Agent roster listener.
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public interface AgentRosterListener {
|
public interface AgentRosterListener {
|
||||||
|
|
||||||
void agentAdded(String jid);
|
void agentAdded(EntityBareJid jid);
|
||||||
|
|
||||||
void agentRemoved(String jid);
|
void agentRemoved(EntityBareJid jid);
|
||||||
|
|
||||||
void presenceChanged(Presence presence);
|
void presenceChanged(Presence presence);
|
||||||
}
|
}
|
||||||
|
|
|
@ -891,7 +891,7 @@ public class AgentSession {
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public AgentChatHistory getAgentHistory(String jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException {
|
public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException {
|
||||||
AgentChatHistory request;
|
AgentChatHistory request;
|
||||||
if (startDate != null) {
|
if (startDate != null) {
|
||||||
request = new AgentChatHistory(jid, maxSessions, startDate);
|
request = new AgentChatHistory(jid, maxSessions, startDate);
|
||||||
|
@ -1015,7 +1015,7 @@ public class AgentSession {
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void sendRoomInvitation(RoomInvitation.Type type, Jid invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
|
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
|
||||||
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
|
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
|
||||||
iq.setType(IQ.Type.set);
|
iq.setType(IQ.Type.set);
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx.workgroup.agent;
|
package org.jivesoftware.smackx.workgroup.agent;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
|
import org.jxmpp.jid.EntityJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request sent by an agent to invite another agent or user.
|
* Request sent by an agent to invite another agent or user.
|
||||||
*
|
*
|
||||||
|
@ -24,21 +27,21 @@ package org.jivesoftware.smackx.workgroup.agent;
|
||||||
*/
|
*/
|
||||||
public class InvitationRequest extends OfferContent {
|
public class InvitationRequest extends OfferContent {
|
||||||
|
|
||||||
private final String inviter;
|
private final EntityJid inviter;
|
||||||
private final String room;
|
private final EntityBareJid room;
|
||||||
private final String reason;
|
private final String reason;
|
||||||
|
|
||||||
public InvitationRequest(String inviter, String room, String reason) {
|
public InvitationRequest(EntityJid inviter, EntityBareJid room, String reason) {
|
||||||
this.inviter = inviter;
|
this.inviter = inviter;
|
||||||
this.room = room;
|
this.room = room;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInviter() {
|
public EntityJid getInviter() {
|
||||||
return inviter;
|
return inviter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoom() {
|
public EntityBareJid getRoom() {
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -45,20 +46,20 @@ public class AgentChatHistory extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
private String agentJID;
|
private EntityBareJid agentJID;
|
||||||
private int maxSessions;
|
private int maxSessions;
|
||||||
private long startDate;
|
private long startDate;
|
||||||
|
|
||||||
private final List<AgentChatSession> agentChatSessions = new ArrayList<>();
|
private final List<AgentChatSession> agentChatSessions = new ArrayList<>();
|
||||||
|
|
||||||
public AgentChatHistory(String agentJID, int maxSessions, Date startDate) {
|
public AgentChatHistory(EntityBareJid agentJID, int maxSessions, Date startDate) {
|
||||||
this();
|
this();
|
||||||
this.agentJID = agentJID;
|
this.agentJID = agentJID;
|
||||||
this.maxSessions = maxSessions;
|
this.maxSessions = maxSessions;
|
||||||
this.startDate = startDate.getTime();
|
this.startDate = startDate.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AgentChatHistory(String agentJID, int maxSessions) {
|
public AgentChatHistory(EntityBareJid agentJID, int maxSessions) {
|
||||||
this();
|
this();
|
||||||
this.agentJID = agentJID;
|
this.agentJID = agentJID;
|
||||||
this.maxSessions = maxSessions;
|
this.maxSessions = maxSessions;
|
||||||
|
|
|
@ -25,7 +25,9 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -90,17 +92,17 @@ public class AgentStatusRequest extends IQ {
|
||||||
|
|
||||||
public static class Item {
|
public static class Item {
|
||||||
|
|
||||||
private final String jid;
|
private final EntityBareJid jid;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public Item(String jid, String type, String name) {
|
public Item(EntityBareJid jid, String type, String name) {
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJID() {
|
public EntityBareJid getJID() {
|
||||||
return jid;
|
return jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +141,7 @@ public class AgentStatusRequest extends IQ {
|
||||||
private Item parseAgent(XmlPullParser parser) throws XmlPullParserException, IOException {
|
private Item parseAgent(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
|
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
String jid = parser.getAttributeValue("", "jid");
|
EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
|
||||||
String type = parser.getAttributeValue("", "type");
|
String type = parser.getAttributeValue("", "type");
|
||||||
String name = null;
|
String name = null;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
|
|
@ -25,6 +25,10 @@ import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
|
import org.jxmpp.jid.EntityJid;
|
||||||
|
import org.jxmpp.jid.Jid;
|
||||||
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -53,11 +57,11 @@ public class RoomInvitation implements ExtensionElement {
|
||||||
* JID of the entity being invited. The entity could be another agent, user , a queue or a workgroup. In
|
* JID of the entity being invited. The entity could be another agent, user , a queue or a workgroup. In
|
||||||
* the case of a queue or a workgroup the server will select the best agent to invite.
|
* the case of a queue or a workgroup the server will select the best agent to invite.
|
||||||
*/
|
*/
|
||||||
private String invitee;
|
private Jid invitee;
|
||||||
/**
|
/**
|
||||||
* Full JID of the user that sent the invitation.
|
* Full JID of the user that sent the invitation.
|
||||||
*/
|
*/
|
||||||
private String inviter;
|
private EntityJid inviter;
|
||||||
/**
|
/**
|
||||||
* ID of the session that originated the initial user request.
|
* ID of the session that originated the initial user request.
|
||||||
*/
|
*/
|
||||||
|
@ -65,13 +69,13 @@ public class RoomInvitation implements ExtensionElement {
|
||||||
/**
|
/**
|
||||||
* JID of the room to join if offer is accepted.
|
* JID of the room to join if offer is accepted.
|
||||||
*/
|
*/
|
||||||
private String room;
|
private EntityBareJid room;
|
||||||
/**
|
/**
|
||||||
* Text provided by the inviter explaining the reason why the invitee is invited.
|
* Text provided by the inviter explaining the reason why the invitee is invited.
|
||||||
*/
|
*/
|
||||||
private String reason;
|
private String reason;
|
||||||
|
|
||||||
public RoomInvitation(Type type, String invitee, String sessionID, String reason) {
|
public RoomInvitation(Type type, Jid invitee, String sessionID, String reason) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.invitee = invitee;
|
this.invitee = invitee;
|
||||||
this.sessionID = sessionID;
|
this.sessionID = sessionID;
|
||||||
|
@ -91,11 +95,11 @@ public class RoomInvitation implements ExtensionElement {
|
||||||
return NAMESPACE;
|
return NAMESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInviter() {
|
public EntityJid getInviter() {
|
||||||
return inviter;
|
return inviter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoom() {
|
public EntityBareJid getRoom() {
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,16 +183,19 @@ public class RoomInvitation implements ExtensionElement {
|
||||||
invitation.sessionID = parser.getAttributeValue("", "id");
|
invitation.sessionID = parser.getAttributeValue("", "id");
|
||||||
}
|
}
|
||||||
else if ("invitee".equals(elementName)) {
|
else if ("invitee".equals(elementName)) {
|
||||||
invitation.invitee = parser.nextText();
|
String inviteeString = parser.nextText();
|
||||||
|
invitation.invitee = JidCreate.from(inviteeString);
|
||||||
}
|
}
|
||||||
else if ("inviter".equals(elementName)) {
|
else if ("inviter".equals(elementName)) {
|
||||||
invitation.inviter = parser.nextText();
|
String inviterString = parser.nextText();
|
||||||
|
invitation.inviter = JidCreate.entityFrom(inviterString);
|
||||||
}
|
}
|
||||||
else if ("reason".equals(elementName)) {
|
else if ("reason".equals(elementName)) {
|
||||||
invitation.reason = parser.nextText();
|
invitation.reason = parser.nextText();
|
||||||
}
|
}
|
||||||
else if ("room".equals(elementName)) {
|
else if ("room".equals(elementName)) {
|
||||||
invitation.room = parser.nextText();
|
String roomString = parser.nextText();
|
||||||
|
invitation.room = JidCreate.entityBareFrom(roomString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
|
else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
|
||||||
|
|
Loading…
Reference in a new issue