1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +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

@ -339,7 +339,7 @@ public final class CarbonManager extends Manager {
IQ setIQ = carbonsEnabledIQ(new_state);
connection().createStanzaCollectorAndSend(setIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(setIQ);
enabled_state = new_state;
}

View file

@ -418,7 +418,7 @@ public final class HttpFileUploadManager extends Manager {
throw new AssertionError();
}
return connection.createStanzaCollectorAndSend(slotRequest).nextResultOrThrow();
return connection.sendIqRequestAndWaitForResponse(slotRequest);
}
public void setTlsContext(SSLContext tlsContext) {

View file

@ -128,7 +128,7 @@ public final class IoTControlManager extends IoTManager {
public IoTSetResponse setUsingIq(FullJid jid, Collection<? extends SetData> data) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
IoTSetRequest request = new IoTSetRequest(data);
request.setTo(jid);
IoTSetResponse response = connection().createStanzaCollectorAndSend(request).nextResultOrThrow();
IoTSetResponse response = connection().sendIqRequestAndWaitForResponse(request);
return response;
}

View file

@ -191,7 +191,7 @@ public final class IoTDataManager extends IoTManager {
StanzaCollector dataCollector = connection.createStanzaCollector(dataCollectorConfiguration);
try {
connection.createStanzaCollectorAndSend(iotDataRequest).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iotDataRequest);
// Wait until a message with an IoTFieldsExtension and the done flag comes in.
doneCollector.nextResult();
}

View file

@ -246,7 +246,7 @@ public final class IoTDiscoveryManager extends Manager {
final XMPPConnection connection = connection();
IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened());
iotRegister.setTo(registry);
IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow();
IQ result = connection.sendIqRequestAndWaitForResponse(iotRegister);
if (result instanceof IoTClaimed) {
IoTClaimed iotClaimedResult = (IoTClaimed) result;
throw new IoTClaimedException(iotClaimedResult);
@ -293,7 +293,7 @@ public final class IoTDiscoveryManager extends Manager {
IoTMine iotMine = new IoTMine(metaTags, publicThing);
iotMine.setTo(registry);
IoTClaimed iotClaimed = connection().createStanzaCollectorAndSend(iotMine).nextResultOrThrow();
IoTClaimed iotClaimed = connection().sendIqRequestAndWaitForResponse(iotMine);
// The 'jid' attribute of the <claimed/> response now represents the XMPP address of the thing we just successfully claimed.
Jid thing = iotClaimed.getJid();
@ -322,7 +322,7 @@ public final class IoTDiscoveryManager extends Manager {
IoTRemove iotRemove = new IoTRemove(thing, nodeInfo);
iotRemove.setTo(registry);
connection().createStanzaCollectorAndSend(iotRemove).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(iotRemove);
// We no not update the ThingState here, as this is done in the <removed/> IQ handler above.;
}
@ -346,7 +346,7 @@ public final class IoTDiscoveryManager extends Manager {
IoTUnregister iotUnregister = new IoTUnregister(nodeInfo);
iotUnregister.setTo(registry);
connection().createStanzaCollectorAndSend(iotUnregister).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(iotUnregister);
ThingState state = getStateFor(nodeInfo);
state.setUnregistered();
@ -375,7 +375,7 @@ public final class IoTDiscoveryManager extends Manager {
IoTDisown iotDisown = new IoTDisown(thing, nodeInfo);
iotDisown.setTo(registry);
connection().createStanzaCollectorAndSend(iotDisown).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(iotDisown);
}
// Registry utility methods

View file

@ -344,7 +344,7 @@ public final class IoTProvisioningManager extends Manager {
IoTIsFriend iotIsFriend = new IoTIsFriend(friendInQuestion);
iotIsFriend.setTo(provisioningServer);
IoTIsFriendResponse response = connection().createStanzaCollectorAndSend(iotIsFriend).nextResultOrThrow();
IoTIsFriendResponse response = connection().sendIqRequestAndWaitForResponse(iotIsFriend);
assert response.getJid().equals(friendInQuestion);
boolean isFriend = response.getIsFriendResult();
if (!isFriend) {

View file

@ -533,7 +533,7 @@ public final class MamManager extends Manager {
MamQueryIQ mamQueryIq = new MamQueryIQ(queryId, node, null);
mamQueryIq.setTo(archiveAddress);
MamQueryIQ mamResponseQueryIq = connection().createStanzaCollectorAndSend(mamQueryIq).nextResultOrThrow();
MamQueryIQ mamResponseQueryIq = connection().sendIqRequestAndWaitForResponse(mamQueryIq);
return mamResponseQueryIq.getDataForm().getFields();
}
@ -864,7 +864,7 @@ public final class MamManager extends Manager {
NotConnectedException, InterruptedException, NotLoggedInException {
final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow();
MamPrefsIQ mamPrefsResultIQ = connection.sendIqRequestAndWaitForResponse(mamPrefsIQ);
return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ));
}

View file

@ -301,7 +301,7 @@ public class MultiUserChatLight {
messageCollector = connection.createStanzaCollector(fromRoomGroupChatFilter);
try {
connection.createStanzaCollectorAndSend(createMUCLightIQ).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(createMUCLightIQ);
} catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
removeConnectionCallbacks();
throw e;
@ -332,7 +332,7 @@ public class MultiUserChatLight {
affiliations.put(connection.getUser(), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
IQ responseIq = connection.createStanzaCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
IQ responseIq = connection.sendIqRequestAndWaitForResponse(changeAffiliationsIQ);
boolean roomLeft = responseIq.getType().equals(IQ.Type.result);
if (roomLeft) {
@ -354,7 +354,7 @@ public class MultiUserChatLight {
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetInfoIQ mucLightGetInfoIQ = new MUCLightGetInfoIQ(room, version);
IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetInfoIQ).nextResultOrThrow();
IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetInfoIQ);
MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) responseIq;
return new MUCLightRoomInfo(mucLightInfoResponseIQ.getVersion(), room,
@ -388,7 +388,7 @@ public class MultiUserChatLight {
public MUCLightRoomConfiguration getConfiguration(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(room, version);
IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetConfigsIQ).nextResultOrThrow();
IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetConfigsIQ);
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) responseIq;
return mucLightConfigurationIQ.getConfiguration();
}
@ -421,7 +421,7 @@ public class MultiUserChatLight {
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(room, version);
IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetAffiliationsIQ).nextResultOrThrow();
IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetAffiliationsIQ);
MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) responseIq;
return mucLightAffiliationsIQ.getAffiliations();
@ -453,7 +453,7 @@ public class MultiUserChatLight {
public void changeAffiliations(HashMap<Jid, MUCLightAffiliation> affiliations)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
connection.createStanzaCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(changeAffiliationsIQ);
}
/**
@ -466,7 +466,7 @@ public class MultiUserChatLight {
*/
public void destroy() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(room);
IQ responseIq = connection.createStanzaCollectorAndSend(mucLightDestroyIQ).nextResultOrThrow();
IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightDestroyIQ);
boolean roomDestroyed = responseIq.getType().equals(IQ.Type.result);
if (roomDestroyed) {
@ -486,7 +486,7 @@ public class MultiUserChatLight {
public void changeSubject(String subject)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, null, subject, null);
connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ);
}
/**
@ -501,7 +501,7 @@ public class MultiUserChatLight {
public void changeRoomName(String roomName)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, null);
connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ);
}
/**
@ -531,7 +531,7 @@ public class MultiUserChatLight {
public void setRoomConfigs(String roomName, HashMap<String, String> customConfigs)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, customConfigs);
connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ);
}
}

View file

@ -279,7 +279,7 @@ public final class MultiUserChatLightManager extends Manager {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(IQ.Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ);
}
/**
@ -323,7 +323,7 @@ public final class MultiUserChatLightManager extends Manager {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(IQ.Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ);
}
/**
@ -367,7 +367,7 @@ public final class MultiUserChatLightManager extends Manager {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(IQ.Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ);
}
/**
@ -411,7 +411,7 @@ public final class MultiUserChatLightManager extends Manager {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(IQ.Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ);
}
}

View file

@ -164,7 +164,7 @@ public final class PushNotificationsManager extends Manager {
private boolean changePushNotificationsStatus(IQ iq)
throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
final XMPPConnection connection = connection();
IQ responseIQ = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
IQ responseIQ = connection.sendIqRequestAndWaitForResponse(iq);
return responseIQ.getType() != IQ.Type.error;
}