#906 headline messages not delivered on resource-bind
Reporter
rafaeli
Owner
Zash
Created
Updated
Stars
★ (1)
Tags
Priority-Medium
Type-Defect
Status-Invalid
rafaeli
on
What steps will reproduce the problem?
1. Create and enable a module with this contents (mod_xxx.lua):
local stanzaM = require 'util.stanza'
module:hook('resource-bind', function ()
local s = stanzaM.stanza('message', {type = 'headline', to = 'admin@localhost'}):body('a head')
module:send(s)
local s = stanzaM.stanza('message', {type = 'chat', to = 'admin@localhost'}):body('a chat')
module:send(s)
end)
2. Log in as admin@localhost
3. Observe only the second message received (chat)
What is the expected output? What do you see instead?
According to the XML console, the client never receives the headline message which is the normal case for offline messages. But the client is not offline.
If this behavior cannot be fixed for some reason, then I believe Prosody must introduce an event fired after presence and all other preparatory work finished, suitable for sending any kind of online messages.
What version of the product are you using? On what operating system?
Prosody 0.9.12 / Gajim / Ubuntu
Note: the event documentation says that:
After authentication a client binds a resource, which is a unique identifier for that connection. This is the best way to know when a user has logged in or out (but they won't have sent presence or anything else yet).
Several plugins are using this event to send messages to the user (e.g. mod_motd_sequential).
As I would expect, at this point user is already considered online. However, messages sent at this point seem to be routed as if he was offline.
rafaeli
on
Now that I check mod_motd.lua it uses presence/bare for this purpose. It's a workaround at best because there's a clear distinction between having a handler triggered when a user logs in and a handler triggered any time a user changes his presence, including the first presence he sends when he logs in.
Yeah, the user is still considered offline on resource-bind, so sending messages to their bare JID will go into offline message store. Except headline messages don't, so they are discarded. Also, the resource-bind fires before the response has been sent to the client, so routing stanzas might break some clients.
presence/initial is indeed the correct approach. In earlier versions, one can hook presence/bare and check if the session has a presence field yet, which it won't if it is the initial presence.
Since it looks like you figured out, I'll close this.
What steps will reproduce the problem? 1. Create and enable a module with this contents (mod_xxx.lua): local stanzaM = require 'util.stanza' module:hook('resource-bind', function () local s = stanzaM.stanza('message', {type = 'headline', to = 'admin@localhost'}):body('a head') module:send(s) local s = stanzaM.stanza('message', {type = 'chat', to = 'admin@localhost'}):body('a chat') module:send(s) end) 2. Log in as admin@localhost 3. Observe only the second message received (chat) What is the expected output? What do you see instead? According to the XML console, the client never receives the headline message which is the normal case for offline messages. But the client is not offline. If this behavior cannot be fixed for some reason, then I believe Prosody must introduce an event fired after presence and all other preparatory work finished, suitable for sending any kind of online messages. What version of the product are you using? On what operating system? Prosody 0.9.12 / Gajim / Ubuntu Note: the event documentation says that: After authentication a client binds a resource, which is a unique identifier for that connection. This is the best way to know when a user has logged in or out (but they won't have sent presence or anything else yet). Several plugins are using this event to send messages to the user (e.g. mod_motd_sequential). As I would expect, at this point user is already considered online. However, messages sent at this point seem to be routed as if he was offline.
Now that I check mod_motd.lua it uses presence/bare for this purpose. It's a workaround at best because there's a clear distinction between having a handler triggered when a user logs in and a handler triggered any time a user changes his presence, including the first presence he sends when he logs in.
Found presence/initial (0.10+), I believe that's the event I need. Problem solved. https://prosody.im/doc/developers/events#initial_presence
Yeah, the user is still considered offline on resource-bind, so sending messages to their bare JID will go into offline message store. Except headline messages don't, so they are discarded. Also, the resource-bind fires before the response has been sent to the client, so routing stanzas might break some clients. presence/initial is indeed the correct approach. In earlier versions, one can hook presence/bare and check if the session has a presence field yet, which it won't if it is the initial presence. Since it looks like you figured out, I'll close this.
Changes