1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Call XMPPConnection.sendIqRequestAndWaitForResponse(IQ) where possible

Refactored using

find . -type f -name "*.java" |\
	 xargs sed -i -E |\
		's/\.createStanzaCollectorAndSend\((\w+)\)\.nextResultOrThrow\(\);/.sendIqRequestAndWaitForResponse(\1);/'

and some manual refactoring.
This commit is contained in:
Florian Schmaus 2021-05-11 22:03:24 +02:00
parent c9ea1c11b6
commit aab48570c9
53 changed files with 206 additions and 188 deletions

View file

@ -43,7 +43,7 @@ public class Agent {
public static Collection<String> getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
AgentWorkgroups request = new AgentWorkgroups(agentJID);
request.setTo(serviceJID);
AgentWorkgroups response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
AgentWorkgroups response = connection.sendIqRequestAndWaitForResponse(request);
return response.getWorkgroups();
}
@ -78,7 +78,7 @@ public class Agent {
agentInfo.setType(IQ.Type.get);
agentInfo.setTo(workgroupJID);
agentInfo.setFrom(getUser());
AgentInfo response = connection.createStanzaCollectorAndSend(agentInfo).nextResultOrThrow();
AgentInfo response = connection.sendIqRequestAndWaitForResponse(agentInfo);
return response.getName();
}
@ -100,6 +100,6 @@ public class Agent {
agentInfo.setTo(workgroupJID);
agentInfo.setFrom(getUser());
agentInfo.setName(newName);
connection.createStanzaCollectorAndSend(agentInfo).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(agentInfo);
}
}

View file

@ -596,7 +596,7 @@ public class AgentSession {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
OccupantsInfo response = (OccupantsInfo) connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
OccupantsInfo response = (OccupantsInfo) connection.sendIqRequestAndWaitForResponse(request);
return response;
}
@ -868,7 +868,7 @@ public class AgentSession {
notes.setTo(workgroupJID);
notes.setSessionID(sessionID);
notes.setNotes(note);
connection.createStanzaCollectorAndSend(notes).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(notes);
}
/**
@ -887,7 +887,7 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setSessionID(sessionID);
ChatNotes response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
ChatNotes response = connection.sendIqRequestAndWaitForResponse(request);
return response;
}
@ -901,8 +901,9 @@ public class AgentSession {
* @throws XMPPException if an error occurs while retrieving the AgentChatHistory.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NoResponseException if there was no response from the remote entity.
*/
public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException {
public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException, NoResponseException {
AgentChatHistory request;
if (startDate != null) {
request = new AgentChatHistory(jid, maxSessions, startDate);
@ -914,8 +915,8 @@ public class AgentSession {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
AgentChatHistory response = connection.createStanzaCollectorAndSend(
request).nextResult();
AgentChatHistory response = connection.sendIqRequestAndWaitForResponse(
request);
return response;
}
@ -934,7 +935,7 @@ public class AgentSession {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
SearchSettings response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
SearchSettings response = connection.sendIqRequestAndWaitForResponse(request);
return response;
}
@ -954,7 +955,7 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setPersonal(!global);
Macros response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
Macros response = connection.sendIqRequestAndWaitForResponse(request);
return response.getRootGroup();
}
@ -974,7 +975,7 @@ public class AgentSession {
request.setPersonal(true);
request.setPersonalMacroGroup(group);
connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(request);
}
/**
@ -985,14 +986,15 @@ public class AgentSession {
* @throws XMPPException if an error occurs while getting information from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NoResponseException if there was no response from the remote entity.
*/
public Map<String, List<String>> getChatMetadata(String sessionID) throws XMPPException, NotConnectedException, InterruptedException {
public Map<String, List<String>> getChatMetadata(String sessionID) throws XMPPException, NotConnectedException, InterruptedException, NoResponseException {
ChatMetadata request = new ChatMetadata();
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
request.setSessionID(sessionID);
ChatMetadata response = connection.createStanzaCollectorAndSend(request).nextResult();
ChatMetadata response = connection.sendIqRequestAndWaitForResponse(request);
return response.getMetadata();
}
@ -1033,7 +1035,7 @@ public class AgentSession {
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iq);
}
/**
@ -1070,7 +1072,7 @@ public class AgentSession {
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iq);
}
/**
@ -1089,8 +1091,8 @@ public class AgentSession {
setting.setType(IQ.Type.get);
setting.setTo(workgroupJID);
GenericSettings response = connection.createStanzaCollectorAndSend(
setting).nextResultOrThrow();
GenericSettings response = connection.sendIqRequestAndWaitForResponse(
setting);
return response;
}
@ -1099,7 +1101,7 @@ public class AgentSession {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
MonitorPacket response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
MonitorPacket response = connection.sendIqRequestAndWaitForResponse(request);
return response.isMonitor();
}
@ -1109,6 +1111,6 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setSessionID(sessionID);
connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(request);
}
}

View file

@ -56,7 +56,7 @@ public class TranscriptManager {
public Transcript getTranscript(EntityBareJid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Transcript request = new Transcript(sessionID);
request.setTo(workgroupJID);
Transcript response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
Transcript response = connection.sendIqRequestAndWaitForResponse(request);
return response;
}
@ -75,7 +75,7 @@ public class TranscriptManager {
public Transcripts getTranscripts(EntityBareJid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Transcripts request = new Transcripts(userID);
request.setTo(workgroupJID);
Transcripts response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
Transcripts response = connection.sendIqRequestAndWaitForResponse(request);
return response;
}
}

View file

@ -61,8 +61,8 @@ public class TranscriptSearchManager {
search.setType(IQ.Type.get);
search.setTo(serviceJID);
TranscriptSearch response = connection.createStanzaCollectorAndSend(
search).nextResultOrThrow();
TranscriptSearch response = connection.sendIqRequestAndWaitForResponse(
search);
return Form.from(response);
}
@ -85,8 +85,8 @@ public class TranscriptSearchManager {
search.setTo(serviceJID);
search.addExtension(completedForm.getDataFormToSubmit());
TranscriptSearch response = connection.createStanzaCollectorAndSend(
search).nextResultOrThrow();
TranscriptSearch response = connection.sendIqRequestAndWaitForResponse(
search);
return ReportedData.getReportedDataFrom(response);
}
}

View file

@ -355,7 +355,7 @@ public class Workgroup {
JoinQueuePacket joinPacket = new JoinQueuePacket(workgroupJID, answerForm, userID);
connection.createStanzaCollectorAndSend(joinPacket).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(joinPacket);
// Notify listeners that we've joined the queue.
fireQueueJoinedEvent();
}
@ -436,7 +436,7 @@ public class Workgroup {
}
DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID);
connection.createStanzaCollectorAndSend(departPacket).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(departPacket);
// Notify listeners that we're no longer in the queue.
fireQueueDepartedEvent();
@ -657,7 +657,7 @@ public class Workgroup {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
ChatSettings response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
ChatSettings response = connection.sendIqRequestAndWaitForResponse(request);
return response;
}
@ -697,7 +697,7 @@ public class Workgroup {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
return connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(request);
}
/**
@ -714,7 +714,7 @@ public class Workgroup {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
return connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(request);
}
/**
@ -731,7 +731,7 @@ public class Workgroup {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
return connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(request);
}
/**
@ -750,8 +750,8 @@ public class Workgroup {
request.setType(IQ.Type.get);
request.setTo(workgroupJID);
return connection.createStanzaCollectorAndSend(
request).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(
request);
}
@ -771,8 +771,8 @@ public class Workgroup {
workgroupForm.setType(IQ.Type.get);
workgroupForm.setTo(workgroupJID);
WorkgroupForm response = connection.createStanzaCollectorAndSend(
workgroupForm).nextResultOrThrow();
WorkgroupForm response = connection.sendIqRequestAndWaitForResponse(
workgroupForm);
return Form.from(response);
}
}