0
votes

I am using using MongooseIM with XEP-0022 < message > events like < offline >, < delivered >, < displayed >, < composing > for confirming message delivery etc. I am satisfied with the working of < offline > and < composing > but have some difficulty with the other two.

If both the users (chatting) are online than everything works great. But If consider the below use case:

  1. Suppose 2nd user is offline and 1st user is online and send < message > with all 4 events and then go offline.
  2. Then 2nd user come online (remember, 1st user is offline now) and that user received the < message > and in return he sends the < delivery > and < displayed > event and now 2nd user go into offline stage.
  3. After sometime when 1st user again come online then he doesn't received any of < delivery > and < displayed > events.

In short, both needs to be online at the same time to make it work. so, my concern is:

  1. How can I ensure that the message is delivered and displayed to the 2nd user without the headache of making both online at the same time.
  2. Am I missing something or it can be solved with some config changes?
  3. Should I need to use FCM here?
1
What do you mean by FCM?erszcz
OK, I'm assuming that you mean Firebase Cloud Messaging.erszcz
Yes, Firebase Cloud MessaginShubham1164
The last solution that I have found is that I will use normal < message > and the < body > element and a special element to tell the difference between normal message stanza and my ping message stanza so that mod_offline helps in saving it for offline if the user is offline.Shubham1164
I will put the check to ignore the message ping stanza for chat message in logic. This will work 100%. Its kind of hacky but I don't any other way round. What u say?Shubham1164

1 Answers

2
votes

First of all, XEP-0022 is obsoleted. It's best to follow the XSF advice - it's the foundation which standardizes XMPP - and use more modern XEPs addressing the issue. That being said, I would use XEP-0085: Chat State Notifications for <composing/> like notifications and XEP-0333: Chat Markers for <received/> or <displayed/> receipts.

How can I ensure that the message is delivered and displayed to the 2nd user without the headache of making both online at the same time.

You should use XEP-313: Message Archive Management implemented by MongooseIM's (or ejabberd's) mod_mam. It keeps chat history in a database of the server, allowing you to fetch past conversations at any time, without the chat partners being online anymore.

By default, mod_mam does not store messages which do not carry text (have no or empty <body/> subelement to be precise), but it's configurable and in order to store XEP-333 chat markers, you would have to reconfigure it. It probably doesn't make sense to store XEP-85 notifications, since they only make sense when both users are online.

Once you're able to fetch chat markers, the client app would have to query the message archive, process the results and find any chat markers which correspond to messages from users who are now offline. Please bear in mind that while a regular marker sent from an online user would look like this (example 4 from XEP-333):

<message from='[email protected]/throne'
         id='message-2'
         to='[email protected]/westminster'>
  <thread>sleeping</thread>
  <received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>
</message>

A chat marker returned from the archive for user [email protected] would look like this - it would be wrapped in an "envelope" marking that it's an archive query result:

<message id='aeb213'
    from='[email protected]'
    to='[email protected]/westminster'>
    <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
        <forwarded xmlns='urn:xmpp:forward:0'>
            <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
            <message from='[email protected]/throne'
                id='message-2'
                to='[email protected]/westminster'>
                <thread>sleeping</thread>
                <received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>
            </message>
        </forwarded>
    </result>
</message>

This way [email protected] knows that [email protected] has received <message id='message-1'/>, even if [email protected] is currently offline.