0

Is it possible to get the timestamp of the message inside muc_filter_message hook ? I need to notify the muc messages, the notification payload must include the timestamp of the messages.

muc_filter_message(#message{from = From, body = Body} = Pkt,
           #state{config = Config, jid = RoomJID} = MUCState,
           FromNick) ->

    ?INFO_MSG("~p.", [From#jid.lserver]),

    PostUrl = gen_mod:get_module_opt(From#jid.lserver, ?MODULE, post_url, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),

Is there a field that I can extract from Pkt which indicates the timestamp ?

In the client side, I got this frame where archived -> id is matching with the timestamp stored in the archive table of the ejabberd database

enter image description here

Md. Arafat Al Mahmud
  • 3,124
  • 5
  • 35
  • 66

2 Answers2

0

What timestamp? A groupchat message, as described in https://xmpp.org/extensions/xep-0045.html does not contain any element or attribute about the timestamp. So, Pkt does not contain any time information.

Badlop
  • 3,840
  • 1
  • 8
  • 9
0

XMPP messages (including MUC) are not timestamped when they are delivered in real time. All timestamps you see in the client application and in logs are simply taken from the local clock when a message is received - this is why the chat log and your local application tend to show different timestamps.

In your use case, I think this means you should just generate your timestamp from the current time on the server.

Christoph Burschka
  • 4,467
  • 3
  • 16
  • 31
  • please see the edited question. In the screenshot attached, the archived.id is the actual timestamp that is stored in the database used by the chat server. when this timestamp is generated ? – Md. Arafat Al Mahmud Feb 01 '19 at 16:43
  • The archived element is generated in mod_mam, later after muc_filter_message is called, so attributed in the hook you mention do not contain the archive element. On the other hand, the store_mam_message hook contains the Pkt after including stanza_id, maybe you can use that somehow. – Badlop Feb 04 '19 at 13:15
  • @Badlop is store_mam_message hook called before the message is delivered to the recipient ? – Md. Arafat Al Mahmud Feb 04 '19 at 17:04