@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content); }
void processMetadataEvent(JID jid, ItemsExtension itemsExt) { List<? extends ExtensionElement> items = itemsExt.getItems(); if (items.isEmpty()) { LOGGER.warning("no items in items event"); return; } // there should be only one item ExtensionElement 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()); } } }
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(); } }); } } }); }
@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); }