]> granicus.if.org Git - ejabberd/commitdiff
Produce mod_last entry on account creation (processone/ejabberd-contrib#62)
authorBadlop <badlop@process-one.net>
Wed, 8 Jun 2016 11:02:02 +0000 (13:02 +0200)
committerBadlop <badlop@process-one.net>
Wed, 8 Jun 2016 11:02:20 +0000 (13:02 +0200)
src/mod_last.erl

index c39681f69385bdeca15123de66e1a9d9922e96e6..92694cf13554c0d05444b12e042e7c4958c246db 100644 (file)
@@ -37,7 +37,7 @@
         process_sm_iq/3, on_presence_update/4, import/1,
         import/3, store_last_info/4, get_last_info/2,
         remove_user/2, transform_options/1, mod_opt_type/1,
-        opt_type/1]).
+        opt_type/1, register_user/2]).
 
 -include("ejabberd.hrl").
 -include("logger.hrl").
@@ -64,12 +64,16 @@ start(Host, Opts) ->
                                  ?NS_LAST, ?MODULE, process_local_iq, IQDisc),
     gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
                                  ?NS_LAST, ?MODULE, process_sm_iq, IQDisc),
+    ejabberd_hooks:add(register_user, Host, ?MODULE,
+                      register_user, 50),
     ejabberd_hooks:add(remove_user, Host, ?MODULE,
                       remove_user, 50),
     ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE,
                       on_presence_update, 50).
 
 stop(Host) ->
+    ejabberd_hooks:delete(register_user, Host, ?MODULE,
+                         register_user, 50),
     ejabberd_hooks:delete(remove_user, Host, ?MODULE,
                          remove_user, 50),
     ejabberd_hooks:delete(unset_presence_hook, Host,
@@ -198,6 +202,13 @@ get_last_iq(#iq{lang = Lang} = IQ, SubEl, LUser, LServer) ->
                            children = []}]}
     end.
 
+register_user(User, Server) ->
+    on_presence_update(
+       User,
+       Server,
+       <<"RegisterResource">>,
+       <<"Registered but didn't login">>).
+
 on_presence_update(User, Server, _Resource, Status) ->
     TimeStamp = p1_time_compat:system_time(seconds),
     store_last_info(User, Server, TimeStamp, Status).