org.jivesoftware.smackx.pubsub.ItemsExtension Java Examples

The following examples show how to use org.jivesoftware.smackx.pubsub.ItemsExtension. 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: AvatarSendReceiver.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
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 #2
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 4 votes vote down vote up
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 #3
Source File: ItemsProvider.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
    return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
}