1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Make PubSubManager.deleteNode(String) "node did not exists" aware

This commit is contained in:
Florian Schmaus 2018-08-15 17:48:54 +02:00
parent 3e65cb31c3
commit a1d4a91fa0
2 changed files with 22 additions and 24 deletions

View file

@ -471,10 +471,21 @@ public final class PubSubManager extends Manager {
* @throws NoResponseException * @throws NoResponseException
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
* @return <code>true</code> if this node existed and was deleted and <code>false</code> if this node did not exist.
*/ */
public void deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { public boolean deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace()); boolean res = true;
try {
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace());
} catch (XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
res = false;
} else {
throw e;
}
}
nodeMap.remove(nodeId); nodeMap.remove(nodeId);
return res;
} }
/** /**

View file

@ -224,20 +224,13 @@ public class OpenPgpPubSubUtil {
* @throws SmackException.NotConnectedException if we are not connected. * @throws SmackException.NotConnectedException if we are not connected.
* @throws InterruptedException if the thread is interrupted. * @throws InterruptedException if the thread is interrupted.
* @throws SmackException.NoResponseException if the server doesn't respond. * @throws SmackException.NoResponseException if the server doesn't respond.
* @return <code>true</code> if the node existed and was deleted, <code>false</code> if the node did not exist.
*/ */
public static void deletePubkeysListNode(XMPPConnection connection) public static boolean deletePubkeysListNode(XMPPConnection connection)
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
SmackException.NoResponseException { SmackException.NoResponseException {
PubSubManager pm = PubSubManager.getInstance(connection, connection.getUser().asBareJid()); PubSubManager pm = PubSubManager.getInstance(connection, connection.getUser().asBareJid());
try { return pm.deleteNode(PEP_NODE_PUBLIC_KEYS);
pm.deleteNode(PEP_NODE_PUBLIC_KEYS);
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
LOGGER.log(Level.FINE, "Node does not exist. No need to delete it.");
} else {
throw e;
}
}
} }
/** /**
@ -250,20 +243,13 @@ public class OpenPgpPubSubUtil {
* @throws SmackException.NotConnectedException if we are not connected. * @throws SmackException.NotConnectedException if we are not connected.
* @throws InterruptedException if the thread gets interrupted. * @throws InterruptedException if the thread gets interrupted.
* @throws SmackException.NoResponseException if the server doesn't respond. * @throws SmackException.NoResponseException if the server doesn't respond.
* @return <code>true</code> if the node existed and was deleted, <code>false</code> if the node did not exist.
*/ */
public static void deletePublicKeyNode(XMPPConnection connection, OpenPgpV4Fingerprint fingerprint) public static boolean deletePublicKeyNode(XMPPConnection connection, OpenPgpV4Fingerprint fingerprint)
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
SmackException.NoResponseException { SmackException.NoResponseException {
PubSubManager pm = PubSubManager.getInstance(connection, connection.getUser().asBareJid()); PubSubManager pm = PubSubManager.getInstance(connection, connection.getUser().asBareJid());
try { return pm.deleteNode(PEP_NODE_PUBLIC_KEY(fingerprint));
pm.deleteNode(PEP_NODE_PUBLIC_KEY(fingerprint));
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
LOGGER.log(Level.FINE, "Node does not exist. No need to delete it.");
} else {
throw e;
}
}
} }
@ -404,12 +390,13 @@ public class OpenPgpPubSubUtil {
* @throws SmackException.NotConnectedException if we are not connected * @throws SmackException.NotConnectedException if we are not connected
* @throws InterruptedException if the thread gets interrupted * @throws InterruptedException if the thread gets interrupted
* @throws SmackException.NoResponseException if the server sends no response * @throws SmackException.NoResponseException if the server sends no response
* @return <code>true</code> if the node existed and was deleted, <code>false</code> if the node did not exist.
*/ */
public static void deleteSecretKeyNode(XMPPConnection connection) public static boolean deleteSecretKeyNode(XMPPConnection connection)
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
SmackException.NoResponseException { SmackException.NoResponseException {
PubSubManager pm = PubSubManager.getInstance(connection); PubSubManager pm = PubSubManager.getInstance(connection);
pm.deleteNode(PEP_NODE_SECRET_KEY); return pm.deleteNode(PEP_NODE_SECRET_KEY);
} }
/** /**