/** * Checks whether the entity supports the given feature. If the features are already known and cached * * @param feature The feature. * @param jid The JID, which should usually be a full JID. * @return The async result with true, if this entity supports the feature. */ public final AsyncResult<Boolean> isSupported(String feature, Jid jid) { return discoverCapabilities(jid) .handle((infoNode, e) -> { if (e == null) { return infoNode.getFeatures().contains(feature); } else { if (e.getCause() instanceof StanzaErrorException) { return false; } throw (CompletionException) e; } }); }
private AsyncResult<List<Item>> discoverServices(Predicate<InfoNode> predicate) { // First discover the items of the server. // Then, for each item, discover the features of the item, but ignore any exceptions. return discoverItems(xmppSession.getDomain()).thenCompose(itemDiscovery -> { Collection<CompletionStage<List<Item>>> stages = itemDiscovery.getItems().stream() .map(item -> discoverInformation(item.getJid()).thenApply(infoDiscovery -> { if (predicate.test(infoDiscovery)) { return Collections.singletonList(item); } return Collections.<Item>emptyList(); }).handle((items, throwable) -> { // If one disco#info fails, don't let the whole discoverServices() method fail. // Instead of failing, return an empty list, other services can hopefully be discovered successfully. if (throwable != null) { return Collections.<Item>emptyList(); } else { return items; } })) .collect(Collectors.toList()); return CompletionStages.allOf(stages); }); }
return xmppSession.query(request).handle((iq, e) -> { if (e != null) { Throwable cause = e instanceof CompletionException ? e.getCause() : e;
vCard = vCardManager.getVCard(contact); return vCard.handle((result, exc) -> {
/** * Offers a file to another user in form of an URL. The file can be downloaded by the recipient via an HTTP GET request. * If this method returns without exception you can assume, that the file has been successfully downloaded by the recipient. * * @param uri The URI of the file. * @param description The description of the file. * @param recipient The recipient's JID (must be a full JID). * @param timeout The timeout (indicates how long to wait until the file offer has either been accepted or rejected). * @return The async result. * @see <a href="https://xmpp.org/extensions/xep-0066.html">XEP-0066: Out of Band Data</a> */ public final AsyncResult<IQ> offerFile(URI uri, String description, Jid recipient, Duration timeout) { return xmppSession.query(IQ.set(recipient, new OobIQ(uri, description)), timeout).handle((iq, e) -> { if (e != null) { if (e instanceof CompletionException) { if (e.getCause() instanceof StanzaErrorException && ((StanzaErrorException) e.getCause()).getCondition() == Condition.NOT_ACCEPTABLE) { throw new CompletionException(new FileTransferRejectedException()); } else { throw (CompletionException) e; } } else { throw new CompletionException(e); } } return null; }); }
/** * Exits the room with a custom message. * * @param message The exit message. * @return The async result. * @see <a href="https://xmpp.org/extensions/xep-0045.html#exit">7.14 Exiting a Room</a> */ public final AsyncResult<Void> exit(String message) { if (!hasEntered()) { return new AsyncResult<>(CompletableFuture.completedFuture(null)); } // Store the current nick, to determine self-presence (because nick gets null before determining self-presence). final String usedNick = getNick(); return xmppSession.sendAndAwaitPresence(new Presence(roomJid.withResource(usedNick), Presence.Type.UNAVAILABLE, message), presence -> { Jid room = presence.getFrom().asBareJid(); return !presence.isAvailable() && room.equals(roomJid) && isSelfPresence(presence, usedNick); }).handle((result, throwable) -> { userHasExited(); return null; }); }
return this.streamInitiationManager.initiateStream(recipient, fileTransfer, mType, timeout, sessionId).handle((byteStreamSession, e) -> { if (e != null) { if (e instanceof CompletionException) {