org.jivesoftware.smackx.pubsub.PayloadItem Java Examples
The following examples show how to use
org.jivesoftware.smackx.pubsub.PayloadItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OmemoService.java From Smack with Apache License 2.0 | 6 votes |
/** * Retrieve a users OMEMO bundle. * * @param connection authenticated XMPP connection. * @param contactsDevice device of which we want to retrieve the bundle. * @return OmemoBundle of the device or null, if it doesn't exist. * * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException.NoResponseException if there was no response from the remote entity. * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. * @throws PubSubException.NotAPubSubNodeException if a involved node is not a PubSub node. */ private static OmemoBundleElement fetchBundle(XMPPConnection connection, OmemoDevice contactsDevice) throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, PubSubException.NotAPubSubNodeException { PubSubManager pm = PubSubManager.getInstanceFor(connection, contactsDevice.getJid()); LeafNode node = pm.getLeafNode(contactsDevice.getBundleNodeName()); if (node == null) { return null; } List<PayloadItem<OmemoBundleElement>> bundleItems = node.getItems(); if (bundleItems.isEmpty()) { return null; } return bundleItems.get(bundleItems.size() - 1).getPayload(); }
Example #2
Source File: OmemoService.java From Smack with Apache License 2.0 | 6 votes |
/** * Retrieve the OMEMO device list of a contact. * * @param connection authenticated XMPP connection. * @param contact BareJid of the contact of which we want to retrieve the device list from. * @return device list * * @throws InterruptedException if the calling thread was interrupted. * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. * @throws SmackException.NoResponseException if there was no response from the remote entity. * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws PubSubException.NotAPubSubNodeException if a involved node is not a PubSub node. */ private static OmemoDeviceListElement fetchDeviceList(XMPPConnection connection, BareJid contact) throws InterruptedException, PubSubException.NotALeafNodeException, SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException { PubSubManager pm = PubSubManager.getInstanceFor(connection, contact); String nodeName = OmemoConstants.PEP_NODE_DEVICE_LIST; LeafNode node = pm.getLeafNode(nodeName); if (node == null) { return null; } List<PayloadItem<OmemoDeviceListElement>> items = node.getItems(); if (items.isEmpty()) { return null; } return items.get(items.size() - 1).getPayload(); }
Example #3
Source File: AvatarSendReceiver.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
void processMetadataEvent(JID jid, ItemsExtension itemsExt) { List<? extends NamedElement> items = itemsExt.getItems(); if (items.isEmpty()) { LOGGER.warning("no items in items event"); return; } // there should be only one item NamedElement e = items.get(0); if (!(e instanceof PayloadItem)) { LOGGER.warning("element not a payloaditem"); return; } PayloadItem item = (PayloadItem) e; ExtensionElement metadataExt = item.getPayload(); if (!(metadataExt instanceof AvatarMetadataExtension)) { LOGGER.warning("payload not avatar metadata"); return; } AvatarMetadataExtension metadata = (AvatarMetadataExtension) metadataExt; List<AvatarMetadataExtension.Info> infos = metadata.getInfos(); if (infos.isEmpty()) { // this means the contact disabled avatar publishing mHandler.onNotify(jid, ""); return; } // assuming infos are always in the same order for (AvatarMetadataExtension.Info info : infos) { if (AvatarHandler.SUPPORTED_TYPES.contains(info.getType())) { mHandler.onNotify(jid, info.getId()); break; } else { LOGGER.info("image type not supported: "+info.getType()); } } }
Example #4
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 5 votes |
/** * Publish the users OpenPGP public key to the public key node if necessary. * Also announce the key to other users by updating the metadata node. * * @see <a href="https://xmpp.org/extensions/xep-0373.html#annoucning-pubkey">XEP-0373 §4.1</a> * * @param pepManager The PEP manager. * @param pubkeyElement {@link PubkeyElement} containing the public key * @param fingerprint fingerprint of the public key * * @throws InterruptedException if the thread gets interrupted. * @throws PubSubException.NotALeafNodeException if either the metadata node or the public key node is not a * {@link LeafNode}. * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error. * @throws SmackException.NotConnectedException if we are not connected. * @throws SmackException.NoResponseException if the server doesn't respond. */ public static void publishPublicKey(PepManager pepManager, PubkeyElement pubkeyElement, OpenPgpV4Fingerprint fingerprint) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { String keyNodeName = PEP_NODE_PUBLIC_KEY(fingerprint); PubSubManager pm = pepManager.getPepPubSubManager(); // Check if key available at data node // If not, publish key to data node LeafNode keyNode = pm.getOrCreateLeafNode(keyNodeName); changeAccessModelIfNecessary(keyNode, AccessModel.open); List<Item> items = keyNode.getItems(1); if (items.isEmpty()) { LOGGER.log(Level.FINE, "Node " + keyNodeName + " is empty. Publish."); keyNode.publish(new PayloadItem<>(pubkeyElement)); } else { LOGGER.log(Level.FINE, "Node " + keyNodeName + " already contains key. Skip."); } // Fetch IDs from metadata node LeafNode metadataNode = pm.getOrCreateLeafNode(PEP_NODE_PUBLIC_KEYS); changeAccessModelIfNecessary(metadataNode, AccessModel.open); List<PayloadItem<PublicKeysListElement>> metadataItems = metadataNode.getItems(1); PublicKeysListElement.Builder builder = PublicKeysListElement.builder(); if (!metadataItems.isEmpty() && metadataItems.get(0).getPayload() != null) { // Add old entries back to list. PublicKeysListElement publishedList = metadataItems.get(0).getPayload(); for (PublicKeysListElement.PubkeyMetadataElement meta : publishedList.getMetadata().values()) { builder.addMetadata(meta); } } builder.addMetadata(new PublicKeysListElement.PubkeyMetadataElement(fingerprint, new Date())); // Publish IDs to metadata node metadataNode.publish(new PayloadItem<>(builder.build())); }
Example #5
Source File: ItemProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public Item parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { String id = parser.getAttributeValue(null, "id"); String node = parser.getAttributeValue(null, "node"); String xmlns = parser.getNamespace(); ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns); XmlPullParser.Event tag = parser.next(); if (tag == XmlPullParser.Event.END_ELEMENT) { return new Item(itemNamespace, id, node); } else { String payloadElemName = parser.getName(); String payloadNS = parser.getNamespace(); final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS); if (extensionProvider == null) { // TODO: Should we use StandardExtensionElement in this case? And probably remove SimplePayload all together. CharSequence payloadText = PacketParserUtils.parseElement(parser, true); return new PayloadItem<>(itemNamespace, id, node, new SimplePayload(payloadText.toString())); } else { return new PayloadItem<>(itemNamespace, id, node, extensionProvider.parse(parser)); } } }
Example #6
Source File: XMPPSession.java From mangosta-android with Apache License 2.0 | 4 votes |
private void receiveBlogPosts() { PEPManager pepManager = PEPManager.getInstanceFor(mXMPPConnection); pepManager.addPEPListener(new PEPListener() { @Override public void eventReceived(EntityBareJid entityBareJid, EventElement eventElement, Message message) { if (EventElementType.items == eventElement.getEventType()) { ItemsExtension itemsExtension = (ItemsExtension) eventElement.getExtensions().get(0); PayloadItem payloadItem = (PayloadItem) itemsExtension.getItems().get(0); PostEntryExtension postEntryExtension = (PostEntryExtension) payloadItem.getPayload(); String id = postEntryExtension.getId(); String jid = entityBareJid.toString(); String title = postEntryExtension.getTitle(); Date published = postEntryExtension.getPublished(); Date updated = postEntryExtension.getUpdated(); BlogPost blogPost = new BlogPost(id, jid, null, title, published, updated); RealmManager.getInstance().saveBlogPost(blogPost); String commentsNode = PublishCommentExtension.NODE + "/" + id; ServiceDiscoveryManager.getInstanceFor(mXMPPConnection).addFeature(commentsNode + "+notify"); notifyNewBlogPost(); } } private void notifyNewBlogPost() { MangostaApplication mangostaApplication = MangostaApplication.getInstance(); if (mangostaApplication.isClosed()) { BlogPostNotifications.newBlogPostNotification(); } else { mangostaApplication.getCurrentActivity().runOnUiThread(new Runnable() { @Override public void run() { new Event(Event.Type.BLOG_POST_CREATED).post(); } }); } } }); }
Example #7
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 4 votes |
/** * Fetch the OpenPGP public key of a {@code contact}, identified by its OpenPGP {@code v4_fingerprint}. * * @see <a href="https://xmpp.org/extensions/xep-0373.html#discover-pubkey">XEP-0373 §4.3</a> * * @param connection XMPP connection * @param contact {@link BareJid} of the contact we want to fetch a key from. * @param v4_fingerprint upper case, hex encoded v4 fingerprint of the contacts key. * @return {@link PubkeyElement} containing the requested public key. * * @throws InterruptedException if the thread gets interrupted.A * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error. * @throws PubSubException.NotAPubSubNodeException in case the targeted entity is not a PubSub node. * @throws PubSubException.NotALeafNodeException in case the fetched node is not a {@link LeafNode}. * @throws SmackException.NotConnectedException in case we are not connected. * @throws SmackException.NoResponseException if the server doesn't respond. */ public static PubkeyElement fetchPubkey(XMPPConnection connection, BareJid contact, OpenPgpV4Fingerprint v4_fingerprint) throws InterruptedException, XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException, PubSubException.NotALeafNodeException, SmackException.NotConnectedException, SmackException.NoResponseException { PubSubManager pm = PubSubManager.getInstanceFor(connection, contact); String nodeName = PEP_NODE_PUBLIC_KEY(v4_fingerprint); LeafNode node = getLeafNode(pm, nodeName); List<PayloadItem<PubkeyElement>> list = node.getItems(1); if (list.isEmpty()) { return null; } return list.get(0).getPayload(); }
Example #8
Source File: MoodManager.java From Smack with Apache License 2.0 | 4 votes |
private void publishMood(MoodElement moodElement) throws SmackException.NotLoggedInException, InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { pepManager.publish(MOOD_NODE, new PayloadItem<>(moodElement)); }
Example #9
Source File: UserTuneManager.java From Smack with Apache License 2.0 | 4 votes |
public void publishUserTune(UserTuneElement userTuneElement) throws NotLoggedInException, NotALeafNodeException, NoResponseException, NotConnectedException, XMPPErrorException, InterruptedException { // TODO: To prevent a large number of updates when a user is skipping through tracks, an implementation SHOULD wait several seconds before publishing new tune information. pepManager.publish(USERTUNE_NODE, new PayloadItem<>(userTuneElement)); }
Example #10
Source File: OmemoService.java From Smack with Apache License 2.0 | 3 votes |
/** * Publish the given OMEMO bundle to the server using PubSub. * * @param connection our connection. * @param userDevice our device * @param bundle the bundle we want to publish * * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException.NoResponseException if there was no response from the remote entity. * @throws NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. */ static void publishBundle(XMPPConnection connection, OmemoDevice userDevice, OmemoBundleElement bundle) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, NotALeafNodeException { PepManager pm = PepManager.getInstanceFor(connection); pm.publish(userDevice.getBundleNodeName(), new PayloadItem<>(bundle)); }
Example #11
Source File: OmemoService.java From Smack with Apache License 2.0 | 3 votes |
/** * Publish the given device list to the server. * * @param connection authenticated XMPP connection. * @param deviceList users deviceList. * * @throws InterruptedException if the calling thread was interrupted. * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws SmackException.NoResponseException if there was no response from the remote entity. * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. */ static void publishDeviceList(XMPPConnection connection, OmemoDeviceListElement deviceList) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, NotALeafNodeException { PepManager pm = PepManager.getInstanceFor(connection); pm.publish(OmemoConstants.PEP_NODE_DEVICE_LIST, new PayloadItem<>(deviceList)); }
Example #12
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 3 votes |
/** * Consult the public key metadata node of {@code contact} to fetch the list of their published OpenPGP public keys. * * @see <a href="https://xmpp.org/extensions/xep-0373.html#discover-pubkey-list"> * XEP-0373 §4.3: Discovering Public Keys of a User</a> * * @param connection XMPP connection * @param contact {@link BareJid} of the user we want to fetch the list from. * @return content of {@code contact}'s metadata node. * * @throws InterruptedException if the thread gets interrupted. * @throws XMPPException.XMPPErrorException in case of an XMPP protocol exception. * @throws SmackException.NoResponseException in case the server doesn't respond * @throws PubSubException.NotALeafNodeException in case the queried node is not a {@link LeafNode} * @throws SmackException.NotConnectedException in case we are not connected * @throws PubSubException.NotAPubSubNodeException in case the queried entity is not a PubSub node */ public static PublicKeysListElement fetchPubkeysList(XMPPConnection connection, BareJid contact) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, PubSubException.NotALeafNodeException, SmackException.NotConnectedException, PubSubException.NotAPubSubNodeException { PubSubManager pm = PubSubManager.getInstanceFor(connection, contact); LeafNode node = getLeafNode(pm, PEP_NODE_PUBLIC_KEYS); List<PayloadItem<PublicKeysListElement>> list = node.getItems(1); if (list.isEmpty()) { return null; } return list.get(0).getPayload(); }
Example #13
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 3 votes |
/** * Publishes a {@link SecretkeyElement} to the secret key node. * The node will be configured to use the whitelist access model to prevent access from subscribers. * * @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep"> * XEP-0373 §5. Synchronizing the Secret Key with a Private PEP Node</a> * * @param connection {@link XMPPConnection} of the user * @param element a {@link SecretkeyElement} containing the encrypted secret key of the user * * @throws InterruptedException if the thread gets interrupted. * @throws PubSubException.NotALeafNodeException if something is wrong with the PubSub node * @throws XMPPException.XMPPErrorException in case of an protocol related error * @throws SmackException.NotConnectedException if we are not connected * @throws SmackException.NoResponseException /watch?v=0peBq89ZTrc * @throws SmackException.FeatureNotSupportedException if the Server doesn't support the whitelist access model */ public static void depositSecretKey(XMPPConnection connection, SecretkeyElement element) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, SmackException.FeatureNotSupportedException { if (!OpenPgpManager.serverSupportsSecretKeyBackups(connection)) { throw new SmackException.FeatureNotSupportedException("http://jabber.org/protocol/pubsub#access-whitelist"); } PubSubManager pm = PepManager.getInstanceFor(connection).getPepPubSubManager(); LeafNode secretKeyNode = pm.getOrCreateLeafNode(PEP_NODE_SECRET_KEY); OpenPgpPubSubUtil.changeAccessModelIfNecessary(secretKeyNode, AccessModel.whitelist); secretKeyNode.publish(new PayloadItem<>(element)); }
Example #14
Source File: OpenPgpPubSubUtil.java From Smack with Apache License 2.0 | 3 votes |
/** * Fetch the latest {@link SecretkeyElement} from the private backup node. * * @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep"> * XEP-0373 §5. Synchronizing the Secret Key with a Private PEP Node</a> * * @param pepManager the PEP manager. * @return the secret key node or null, if it doesn't exist. * * @throws InterruptedException if the thread gets interrupted * @throws PubSubException.NotALeafNodeException if there is an issue with the PubSub node * @throws XMPPException.XMPPErrorException if there is an XMPP protocol related issue * @throws SmackException.NotConnectedException if we are not connected * @throws SmackException.NoResponseException /watch?v=7U0FzQzJzyI */ public static SecretkeyElement fetchSecretKey(PepManager pepManager) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { PubSubManager pm = pepManager.getPepPubSubManager(); LeafNode secretKeyNode = pm.getOrCreateLeafNode(PEP_NODE_SECRET_KEY); List<PayloadItem<SecretkeyElement>> list = secretKeyNode.getItems(1); if (list.size() == 0) { LOGGER.log(Level.INFO, "No secret key published!"); return null; } SecretkeyElement secretkeyElement = list.get(0).getPayload(); return secretkeyElement; }
Example #15
Source File: GeoLocationManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Publish the user's geographic location through the Personal Eventing Protocol (PEP). * * @param geoLocation the geographic location to publish. * @throws InterruptedException if the calling thread was interrupted. * @throws NotConnectedException if the XMPP connection is not connected. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. */ public void publishGeoLocation(GeoLocation geoLocation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException { pepManager.publish(GEOLOCATION_NODE, new PayloadItem<GeoLocation>(geoLocation)); }
Example #16
Source File: GeoLocationManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Send empty geolocation through the PubSub node. * * @throws InterruptedException if the calling thread was interrupted. * @throws NotConnectedException if the XMPP connection is not connected. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node. */ public void stopPublishingGeolocation() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException { pepManager.publish(GEOLOCATION_NODE, new PayloadItem<GeoLocation>(GeoLocation.EMPTY_GEO_LOCATION)); }