diff options
Diffstat (limited to 'src/mod_push.erl')
-rw-r--r-- | src/mod_push.erl | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/src/mod_push.erl b/src/mod_push.erl index 409ded8cd..f8783b314 100644 --- a/src/mod_push.erl +++ b/src/mod_push.erl @@ -5,7 +5,7 @@ %%% Created : 15 Jul 2017 by Holger Weiss <holger@zedat.fu-berlin.de> %%% %%% -%%% ejabberd, Copyright (C) 2017-2019 ProcessOne +%%% ejabberd, Copyright (C) 2017-2020 ProcessOne %%% %%% This program is free software; you can redistribute it and/or %%% modify it under the terms of the GNU General Public License as @@ -31,7 +31,7 @@ %% gen_mod callbacks. -export([start/2, stop/1, reload/3, mod_opt_type/1, mod_options/1, depends/2]). - +-export([mod_doc/0]). %% ejabberd_hooks callbacks. -export([disco_sm_features/5, c2s_session_pending/1, c2s_copy_session/2, c2s_handle_cast/2, c2s_stanza/3, mam_message/7, offline_message/1, @@ -153,6 +153,60 @@ mod_options(Host) -> {cache_missed, ejabberd_option:cache_missed(Host)}, {cache_life_time, ejabberd_option:cache_life_time(Host)}]. +mod_doc() -> + #{desc => + ?T("This module implements the XMPP server's part of " + "the push notification solution specified in " + "https://xmpp.org/extensions/xep-0357.html" + "[XEP-0357: Push Notifications]. It does not generate, " + "for example, APNS or FCM notifications directly. " + "Instead, it's designed to work with so-called " + "\"app servers\" operated by third-party vendors of " + "mobile apps. Those app servers will usually trigger " + "notification delivery to the user's mobile device using " + "platform-dependant backend services such as FCM or APNS."), + opts => + [{include_sender, + #{value => "true | false", + desc => + ?T("If this option is set to 'true', the sender's JID " + "is included with push notifications generated for " + "incoming messages with a body. " + "The default value is 'false'.")}}, + {include_body, + #{value => "true | false | Text", + desc => + ?T("If this option is set to 'true', the message text " + "is included with push notifications generated for " + "incoming messages with a body. The option can instead " + "be set to a static 'Text', in which case the specified " + "text will be included in place of the actual message " + "body. This can be useful to signal the app server " + "whether the notification was triggered by a message " + "with body (as opposed to other types of traffic) " + "without leaking actual message contents. " + "The default value is \"New message\".")}}, + {db_type, + #{value => "mnesia | sql", + desc => + ?T("Same as top-level 'default_db' option, but applied to this module only.")}}, + {use_cache, + #{value => "true | false", + desc => + ?T("Same as top-level 'use_cache' option, but applied to this module only.")}}, + {cache_size, + #{value => "pos_integer() | infinity", + desc => + ?T("Same as top-level 'cache_size' option, but applied to this module only.")}}, + {cache_missed, + #{value => "true | false", + desc => + ?T("Same as top-level 'cache_missed' option, but applied to this module only.")}}, + {cache_life_time, + #{value => "timeout()", + desc => + ?T("Same as top-level 'cache_life_time' option, but applied to this module only.")}}]}. + %%-------------------------------------------------------------------- %% ejabberd command callback. %%-------------------------------------------------------------------- @@ -209,8 +263,8 @@ register_hooks(Host) -> c2s_stanza, 50), ejabberd_hooks:add(store_mam_message, Host, ?MODULE, mam_message, 50), - ejabberd_hooks:add(store_offline_message, Host, ?MODULE, - offline_message, 50), + ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, + offline_message, 55), ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50). @@ -228,8 +282,8 @@ unregister_hooks(Host) -> c2s_stanza, 50), ejabberd_hooks:delete(store_mam_message, Host, ?MODULE, mam_message, 50), - ejabberd_hooks:delete(store_offline_message, Host, ?MODULE, - offline_message, 50), + ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE, + offline_message, 55), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50). @@ -373,10 +427,12 @@ mam_message(#message{} = Pkt, LUser, LServer, _Peer, _Nick, chat, Dir) -> mam_message(Pkt, _LUser, _LServer, _Peer, _Nick, _Type, _Dir) -> Pkt. --spec offline_message(message()) -> message(). -offline_message(#message{meta = #{mam_archived := true}} = Pkt) -> - Pkt; % Push notification was triggered via MAM. -offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) -> +-spec offline_message({any(), message()}) -> {any(), message()}. +offline_message({offlined, #message{meta = #{mam_archived := true}}} = Acc) -> + Acc; % Push notification was triggered via MAM. +offline_message({offlined, + #message{to = #jid{luser = LUser, + lserver = LServer}} = Pkt} = Acc) -> case lookup_sessions(LUser, LServer) of {ok, [_|_] = Clients} -> ?DEBUG("Notifying ~ts@~ts of offline message", [LUser, LServer]), @@ -384,7 +440,9 @@ offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) -> _ -> ok end, - Pkt. + Acc; +offline_message(Acc) -> + Acc. -spec c2s_session_pending(c2s_state()) -> c2s_state(). c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) -> |