[ejabberd] How to get timestamp in the message packet from server

Badlop badlop at gmail.com
Mon Mar 6 17:33:53 MSK 2017


Hi,

just as a very quick example, with this change in ejabberd 17.03-beta:
diff --git a/src/mod_client_state.erl b/src/mod_client_state.erl
index bbce725..231c950 100644
--- a/src/mod_client_state.erl
+++ b/src/mod_client_state.erl
@@ -294,11 +294,15 @@ filter_other({Stanza, #{jid := JID} = C2SState}
= Acc) when ?is_stanza(Stanza) -
     ?DEBUG("Won't add stanza for ~s to CSI queue", [jid:encode(JID)]),
     From = xmpp:get_from(Stanza),
     C2SState1 = dequeue_sender(From, C2SState),
-    {Stanza, C2SState1}
+    {add_delay_info2(Stanza, From, undefined), C2SState1}
     end;
 filter_other(Acc) ->
     Acc.

+add_delay_info2(Packet, From, TS) ->
+    NewTS = p1_time_compat:timestamp(),
+    xmpp_util:add_delay_info(Packet, From, NewTS, <<"Jacob test">>).
+
 -spec add_stream_feature([xmpp_element()], binary()) -> [xmpp_element()].
 add_stream_feature(Features, Host) ->
     case gen_mod:is_loaded(Host, ?MODULE) of

Then enable that module like the example configuration in
https://docs.ejabberd.im/admin/configuration/#modclientstate

With this, messages sent by clients connected to ejabberd will be
received like this:
<message to='user2 at localhost/tka1' from='user1 at localhost/tka1' type='chat'>
  <delay from='user1 at localhost/tka1'
      stamp='2017-03-06T14:29:30.097315Z'
      xmlns='urn:xmpp:delay'>Jacob test</delay>
  <body>aaaaa</body>
</message>

---
Badlop
ProcessOne



On 5 March 2017 at 12:43, jacob jabber <ejabberd.jacob at gmail.com> wrote:
> Hi. how can I modify ejabberd source code, to add a timestamp(when receive
> ejabberd) to each message it routes?
> thanks alot
>
> Best Regards
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd
>


More information about the ejabberd mailing list