0
votes

I am developing, chat application for android using ejabberd as XMPP server. I want to send GCM push notification, when user is offline. For that I am creating new module in ejabberd, registerd offline_message_hook, but this function gets called only when somebody starts typing and finishes typing. Below are the only packets passed to this hook. Although, user receive message when he/she comes online.

Packet: {xmlelement,
      "message",
      [{"type",
       "chat"},
      {"id",
       "purple7d4d0773"},
      {"to",
       "xxx@rakshith"}],
      [{xmlelement,
       "paused",
       [{"xmlns",
         "http://jabber.org/protocol/chatstates"}],
       []}]}
Packet: {xmlelement,
      "message",
      [{"type",
       "chat"},
      {"id",
       "purple7d4d0773"},
      {"to",
       "xxx@rakshith"}],
      [{xmlelement,
       "composing",
       [{"xmlns",
         "http://jabber.org/protocol/chatstates"}],
       []}]}
1
Hi can you share your gcm module ?Tolgay Toklar
Hi @TolgayToklar, I don't have the actual implementation with me at the moment. However you can implement GCM push using offline hook in ejabberd. Hope that helps!raxith
Where do you store android device token ?Tolgay Toklar
@TolgayToklar using ejabberd archive module one can archive all the messages, you may need to extend the module or you can write your own. In any case the archive module gives more insight into how to work with database.raxith

1 Answers

5
votes

Two things about hooks in ejabberd: 1) The callbacks are called always in order, the order is defined by the priority you specify when registering it. 2) If a callback return 'stop' it prevents the event to be propagated to the rest of the listeners on the chain.

What is happening is that the ejabberd offline module is listening in the offline_message_hook, the same than your code. It handles the message, and returns 'stop', so your code isn't executed.

(your code do receive the message for the chatstates notifications because those are ignored by the offline module, and so it don't stop the chain in those cases).

You probably wants your code to be run before the offline storage module. Just remember to not return 'stop' so the offline module has the oportunity to store the message.