How to manage PubSub notifications send while offline in XMPP? - xmpp

How to get offline message in PubSub? Using the Smack library. after searching I found an answer which looks like this:
// Create a pubsub manager using an existing XMPPConnection
PubSubManager mgr = PubSubManager.getInstanceFor(con);
// Get the node
LeafNode node = mgr.getNode("testNode");
List<? extends Item> items = node.getItems(100);
But node.getItems(100) returns last 100 messages, which can be online and offline too.
1) how to keep track of online and offline message in pubsub using smack?
2) is it possible to get unread message count in pubsub using smack? if yes then how to achieve it?
3) how to know that who(publisher) send this message in a node?
I just went through the documentation of Smack and PubSub from here
and here but didn't find the solutions related to my queries. So can anyone help me to solve this?

1) how to keep track of online and offline message in pubsub using
smack?
I would suggest using the PubSub item ID.
2) is it possible to get unread message count in pubsub using smack?
if yes then how to achieve it?
PubSub nodes don't have a per subscribed unread message count.
If you want to catch-up on all new items since you received the last item from a PubSub node, you'd usually remember the last item's ID and use that to query for all newer items on the PubSub node. Unfortunately there is (currently) no way to query a PubSub node for newer items after a certain ID.
But if you are subscribed to a node, then the service will notify you about new items even if you are offline. And if your server stores those offline messages for you, then you will receive them eventually.
3) how to know that who(publisher) send this message in a node?
Unfortunately there is no reliable way to the the JID of the entity which published an item. This too, could probably be fixed with an extension XEP.

Related

MAM XEP-0313 - Query conversation list for a particular user

I am developing a mobile messaging app (ios) and I support the logout feature. I want to keep the latest conversation list when the users logs in back again. Because the local storage of the app gets cleaned once logout.
I am using MAM XEP-0313 sucessfully but I have not found an IQ to query the conversation list of a particular user.
For example:
chat
user_a -> user_b
user_c
user_d
user_f
user_a has had conversations with 4 users and he wants to logout of the app, when he comes back in he needs to get those last 4 conversation threads on his list.
What I do when a user messages another user is that I add them to my roster and have the logic of automatic subscription. So I was thinking to use the roster history logic to query this collection but I was also expecting the MAM module to have a more direct way..
I am using MongooseIM server
I understand your problem, the solution you have is probably the best one you can have with standard XEPs and their implementations.
The conversation list is actually sth missing in MAM spec or in general in XMPP. There are some works to define an extension to get you all the conversations where you have some unread messages (so called "unread sync"). Will this be enough for you or you would rather want to get some kind of "inbox". By "inbox" I mean a list of all recent conversations with unread messages count where there are some unread messages.

XEP-0060 pubsub auto subscribe node to other users Smack

I am implementing pubsub model to achieve group chat. All things are working well. I am able to create node, other users subscribe the node, publish item by owner or subscriber and item is getting to all subscriber.
Now i have requirement, the owner(User creating node) should be able to subscribe node to roster users and subscribed user start getting item publish.
Is there any way to achieve this?
My node creation code is below:
ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
form.setPublishModel(PublishModel.open);
setSubscribers(form);
LeafNode node = (LeafNode) manager.createNode(nodeName, form);
As document says it is possible to autosubscribe to a node, based on access model which may be roster/presence/open access model.

XMPP: count of unread messages

I'm trying to implement chat for my webapp with following features:
When user logs in he should see a number of unread messages (which is both offline messages and "unseen", I will explain "unseen" in next step).
When user is anywhere in the app but on chat window he should be notified that he has a new message. Message should be marked "unseen" and must be added to the count of unread messages.
The first point is quite easily achieved using XEP-0013: Flexible Offline Message Retrieval. So I can retrieve offline messages and when I'm sure user has seen them - I remove them from unread list. But the problem is: how do I achieve same thing for "unseen" messages?
In short what I need is: any message should be marked as offline, unless user sees it and it's removed from the list by explicit request.
Can I achieve that with XMPP and how do I do that?
Thanks in advance.
What you are trying to do is to basically store a counter of unseen stuff in your account. I think you do not need flexible offline retrieval as when you connect the messages would simply become unseen. You thus only have to deal with one case: Unseen.
I will reply from the perspective of ejabberd, that I know better as one of the developer: I would use private storage to store your current state of unseen count and conversation.

OpenFire - Permanent Group Chat using PubSub

First from this question :
Asmack/openfire How do I keep a user permanently in groupchat room
I read that I cannot use MUC to keep the user persistent in the group, they'll automatically leave the group and can rejoin after they come online again, that concept is like IRC like what've been asked in here -> http://community.igniterealtime.org/thread/48020.
Then from the stackoverflow question I read about using pubsub, then I've done some research about pubsub and what I've got is pubsub can persist the user to be in the group even the user is offline but the message flow is more like one directional from the publisher to the subscriber (read-only).
So if I want to create a group chat application can I use pubsub and set all the member to become both publisher and subscriber? or is there any alternative solution?or my understanding of the pubsub and MUC is incorrect?
my goal is to create some group chat like in the whatsapp or blackberry messenger group.
Thanks.
You can make users permanent in Group chat in MUC by changing the following code of openfire.
File : src/java/org/jivesoftware/openfire/muc/spi/LocalMUCUser.java
change line 547-550:
// TODO Consider that different nodes can be creating and processing this presence at the same time (when
remote node went down)
removeRole(group);
role.getChatRoom().leaveRoom(role);
TO:
// TODO Consider that different nodes can be creating and processing this presence at the same time (when
remote node went down)
// TODO Dont remove user from group when they go offline.
//removeRole(group);
//role.getChatRoom().leaveRoom(role);

On presence receiving published item twice ejabberd

I am developing a xmpp client and currently working on "pubsub".
I created a node in pubsub and subscribed two users to it.
But when a subscriber login(show presence) i get the last published item twice.
I am using ejabberd server.
Can anyone help??
Thank you.
Same here,
There seems to be two different queues. With notification_type=normal, messages are stored offline. When receiver becomes online, it receives the message twice:
from offline spool, without headline attribute
from pubsub send loop (as node is still configured with send_last_published_item = on_sub_and_presence)
As stated here when configuring pubsub node with notification_type=normal, it's best to disable send_last_published_item or set it to on_sub only in order to avoid receiving the message twice.