/** * Adds a bookmark. * * @param bookmark The bookmark. * @return The async result. */ public final AsyncResult<Void> addBookmark(Bookmark bookmark) { return privateDataManager.getData(BookmarkStorage.class).thenCompose(bookmarkStorage -> { Collection<Bookmark> bookmarks = new ArrayDeque<>(bookmarkStorage.getBookmarks()); bookmarks.remove(bookmark); bookmarks.add(bookmark); return privateDataManager.storeData(new BookmarkStorage(bookmarks)); }); }
return getAvailableStreamHosts().thenCompose(streamHosts -> { final Jid requester = xmppSession.getConnectedResource();
/** * Removes a web page bookmark. * * @param webPage The web page. * @return The async result. */ public final AsyncResult<Void> removeWebPageBookmark(URL webPage) { return privateDataManager.getData(BookmarkStorage.class).thenCompose(bookmarkStorage -> { Collection<Bookmark> bookmarks = new ArrayDeque<>(bookmarkStorage.getBookmarks()); bookmarks.remove(new WebPageBookmark("", webPage)); return privateDataManager.storeData(new BookmarkStorage(bookmarks)); }); }
/** * Removes a chat room bookmark. * * @param chatRoom The chat room. * @return The async result. */ public final AsyncResult<Void> removeChatRoomBookmark(Jid chatRoom) { return privateDataManager.getData(BookmarkStorage.class).thenCompose(bookmarkStorage -> { Collection<Bookmark> bookmarks = new ArrayDeque<>(bookmarkStorage.getBookmarks()); bookmarks.remove(new ChatRoomBookmark("", chatRoom)); return privateDataManager.storeData(new BookmarkStorage(bookmarks)); }); }
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); }); }
/** * Discovers the SOCKS5 proxies. * * @return The async result with the proxies. * @see <a href="https://xmpp.org/extensions/xep-0065.html#disco">4. Discovering Proxies</a> */ public AsyncResult<List<StreamHost>> discoverProxies() { // First discover the items which identify the proxy host. return serviceDiscoveryManager.discoverServices(Identity.proxyByteStreams()).thenCompose(items -> { // For each proxy service, send a disco request to it (to discover stream hosts) Collection<CompletionStage<List<StreamHost>>> stages = items.stream() .map(service -> xmppSession.query(IQ.get(service.getJid(), new Socks5ByteStream())).thenApply(result -> { Socks5ByteStream socks5ByteStream = result.getExtension(Socks5ByteStream.class); if (socks5ByteStream != null) { return socks5ByteStream.getStreamHosts(); } return Collections.<StreamHost>emptyList(); })) .collect(Collectors.toList()); // Combine all discovery of all stream hosts into one future. return CompletionStages.allOf(stages); }); }
/** * Publishes an avatar to your VCard. * * @param imageData The avatar image data, which must be in PNG format. {@code null} resets the avatar. * @return The async result. * @see <a href="https://xmpp.org/extensions/xep-0153.html#publish">3.1 User Publishes Avatar</a> */ public final AsyncResult<Void> publishAvatar(byte[] imageData) { String hash = imageData != null ? XmppUtils.hash(imageData) : null; AvatarMetadata.Info info = imageData != null ? new AvatarMetadata.Info(imageData.length, hash, hash) : null; // Try publishing to vCard first. If this fails, don't immediately throw an exception, but try PEP first. return publishToVCard(imageData, null, hash) .whenComplete((result, e) -> { if (e != null) { logger.warning("Failed to publish avatar to vCard."); } }) .thenCompose((aVoid) -> publishToPersonalEventingService(imageData, hash, info)) .thenRun(() -> { }); }
DataForm dataForm = new DataForm(DataForm.Type.FORM, Collections.singleton(field)); return xmppSession.query(IQ.set(receiver, new StreamInitiation(Objects.requireNonNull(sessionId), SIFileTransferOffer.NAMESPACE, mimeType, profile, new FeatureNegotiation(dataForm))), timeout).thenCompose(result -> {
return this.entityCapabilitiesManager.isSupported(StreamInitiation.NAMESPACE, recipient).thenCompose(isSISupported -> { if (!isSISupported) { throw new CompletionException(new XmppException("Feature not supported")); return this.entityCapabilitiesManager.isSupported(SIFileTransferOffer.NAMESPACE, recipient).thenCompose(isSIFileTransferSupported -> { if (!isSIFileTransferSupported) { throw new CompletionException(new XmppException("Feature not supported"));
rosterDelimiterQuery = new AsyncResult<>(CompletableFuture.completedFuture(null)); return rosterDelimiterQuery.thenCompose(result -> {