mod_push: Omit summary for outgoing messages
Don't include a urn:xmpp:push:summary form in push notifications that are triggered by outgoing messages. App servers might use the form fields to generate user-visible notifications directly (as opposed to just waking the client app). This is usually not desired for outgoing messages.
This commit is contained in:
parent
645f11d79d
commit
85f09b365f
|
@ -44,7 +44,7 @@
|
||||||
-export([get_commands_spec/0, delete_old_sessions/1]).
|
-export([get_commands_spec/0, delete_old_sessions/1]).
|
||||||
|
|
||||||
%% API (used by mod_push_keepalive).
|
%% API (used by mod_push_keepalive).
|
||||||
-export([notify/2, notify/4, notify/6, is_message_with_body/1]).
|
-export([notify/3, notify/5, notify/7, is_incoming_chat_msg/1]).
|
||||||
|
|
||||||
%% For IQ callbacks
|
%% For IQ callbacks
|
||||||
-export([delete_session/3]).
|
-export([delete_session/3]).
|
||||||
|
@ -60,6 +60,7 @@
|
||||||
-type timestamp() :: erlang:timestamp().
|
-type timestamp() :: erlang:timestamp().
|
||||||
-type push_session() :: {timestamp(), ljid(), binary(), xdata()}.
|
-type push_session() :: {timestamp(), ljid(), binary(), xdata()}.
|
||||||
-type err_reason() :: notfound | db_failure.
|
-type err_reason() :: notfound | db_failure.
|
||||||
|
-type direction() :: send | recv | undefined.
|
||||||
|
|
||||||
-callback init(binary(), gen_mod:opts())
|
-callback init(binary(), gen_mod:opts())
|
||||||
-> any().
|
-> any().
|
||||||
|
@ -346,20 +347,20 @@ c2s_stanza(State, #stream_error{}, _SendResult) ->
|
||||||
c2s_stanza(#{push_enabled := true, mgmt_state := pending} = State,
|
c2s_stanza(#{push_enabled := true, mgmt_state := pending} = State,
|
||||||
Pkt, _SendResult) ->
|
Pkt, _SendResult) ->
|
||||||
?DEBUG("Notifying client of stanza", []),
|
?DEBUG("Notifying client of stanza", []),
|
||||||
notify(State, xmpp_util:unwrap_carbon(Pkt)),
|
notify(State, unwrap_carbon(Pkt), get_direction(Pkt)),
|
||||||
State;
|
State;
|
||||||
c2s_stanza(State, _Pkt, _SendResult) ->
|
c2s_stanza(State, _Pkt, _SendResult) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
-spec mam_message(message() | drop, binary(), binary(), jid(),
|
-spec mam_message(message() | drop, binary(), binary(), jid(),
|
||||||
chat | groupchat, recv | send) -> message().
|
chat | groupchat, recv | send) -> message().
|
||||||
mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, _Dir) ->
|
mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, Dir) ->
|
||||||
case lookup_sessions(LUser, LServer) of
|
case lookup_sessions(LUser, LServer) of
|
||||||
{ok, [_|_] = Clients} ->
|
{ok, [_|_] = Clients} ->
|
||||||
case drop_online_sessions(LUser, LServer, Clients) of
|
case drop_online_sessions(LUser, LServer, Clients) of
|
||||||
[_|_] = Clients1 ->
|
[_|_] = Clients1 ->
|
||||||
?DEBUG("Notifying ~s@~s of MAM message", [LUser, LServer]),
|
?DEBUG("Notifying ~s@~s of MAM message", [LUser, LServer]),
|
||||||
notify(LUser, LServer, Clients1, Pkt);
|
notify(LUser, LServer, Clients1, Pkt, Dir);
|
||||||
[] ->
|
[] ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
|
@ -377,7 +378,7 @@ offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) ->
|
||||||
case lookup_sessions(LUser, LServer) of
|
case lookup_sessions(LUser, LServer) of
|
||||||
{ok, [_|_] = Clients} ->
|
{ok, [_|_] = Clients} ->
|
||||||
?DEBUG("Notifying ~s@~s of offline message", [LUser, LServer]),
|
?DEBUG("Notifying ~s@~s of offline message", [LUser, LServer]),
|
||||||
notify(LUser, LServer, Clients, Pkt);
|
notify(LUser, LServer, Clients, Pkt, recv);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
|
@ -388,8 +389,12 @@ c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) ->
|
||||||
case p1_queue:len(Queue) of
|
case p1_queue:len(Queue) of
|
||||||
Len when Len > 0 ->
|
Len when Len > 0 ->
|
||||||
?DEBUG("Notifying client of unacknowledged stanza(s)", []),
|
?DEBUG("Notifying client of unacknowledged stanza(s)", []),
|
||||||
Pkt = mod_stream_mgmt:queue_find(fun is_message_with_body/1, Queue),
|
{Pkt, Dir} = case mod_stream_mgmt:queue_find(
|
||||||
notify(State, xmpp_util:unwrap_carbon(Pkt)),
|
fun is_incoming_chat_msg/1, Queue) of
|
||||||
|
none -> {none, undefined};
|
||||||
|
Pkt0 -> {unwrap_carbon(Pkt0), get_direction(Pkt0)}
|
||||||
|
end,
|
||||||
|
notify(State, Pkt, Dir),
|
||||||
State;
|
State;
|
||||||
0 ->
|
0 ->
|
||||||
State
|
State
|
||||||
|
@ -421,18 +426,20 @@ remove_user(LUser, LServer) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Generate push notifications.
|
%% Generate push notifications.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec notify(c2s_state(), xmpp_element() | xmlel() | none) -> ok.
|
-spec notify(c2s_state(), xmpp_element() | xmlel() | none, direction()) -> ok.
|
||||||
notify(#{jid := #jid{luser = LUser, lserver = LServer}, sid := {TS, _}}, Pkt) ->
|
notify(#{jid := #jid{luser = LUser, lserver = LServer},
|
||||||
|
sid := {TS, _}},
|
||||||
|
Pkt, Dir) ->
|
||||||
case lookup_session(LUser, LServer, TS) of
|
case lookup_session(LUser, LServer, TS) of
|
||||||
{ok, Client} ->
|
{ok, Client} ->
|
||||||
notify(LUser, LServer, [Client], Pkt);
|
notify(LUser, LServer, [Client], Pkt, Dir);
|
||||||
_Err ->
|
_Err ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec notify(binary(), binary(), [push_session()],
|
-spec notify(binary(), binary(), [push_session()],
|
||||||
xmpp_element() | xmlel() | none) -> ok.
|
xmpp_element() | xmlel() | none, direction()) -> ok.
|
||||||
notify(LUser, LServer, Clients, Pkt) ->
|
notify(LUser, LServer, Clients, Pkt, Dir) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({TS, PushLJID, Node, XData}) ->
|
fun({TS, PushLJID, Node, XData}) ->
|
||||||
HandleResponse = fun(#iq{type = result}) ->
|
HandleResponse = fun(#iq{type = result}) ->
|
||||||
|
@ -443,15 +450,15 @@ notify(LUser, LServer, Clients, Pkt) ->
|
||||||
(timeout) ->
|
(timeout) ->
|
||||||
ok % Hmm.
|
ok % Hmm.
|
||||||
end,
|
end,
|
||||||
notify(LServer, PushLJID, Node, XData, Pkt, HandleResponse)
|
notify(LServer, PushLJID, Node, XData, Pkt, Dir, HandleResponse)
|
||||||
end, Clients).
|
end, Clients).
|
||||||
|
|
||||||
-spec notify(binary(), ljid(), binary(), xdata(),
|
-spec notify(binary(), ljid(), binary(), xdata(),
|
||||||
xmpp_element() | xmlel() | none,
|
xmpp_element() | xmlel() | none, direction(),
|
||||||
fun((iq() | timeout) -> any())) -> ok.
|
fun((iq() | timeout) -> any())) -> ok.
|
||||||
notify(LServer, PushLJID, Node, XData, Pkt, HandleResponse) ->
|
notify(LServer, PushLJID, Node, XData, Pkt, Dir, HandleResponse) ->
|
||||||
From = jid:make(LServer),
|
From = jid:make(LServer),
|
||||||
Summary = make_summary(LServer, Pkt),
|
Summary = make_summary(LServer, Pkt, Dir),
|
||||||
Item = #ps_item{sub_els = [#push_notification{xdata = Summary}]},
|
Item = #ps_item{sub_els = [#push_notification{xdata = Summary}]},
|
||||||
PubSub = #pubsub{publish = #ps_publish{node = Node, items = [Item]},
|
PubSub = #pubsub{publish = #ps_publish{node = Node, items = [Item]},
|
||||||
publish_options = XData},
|
publish_options = XData},
|
||||||
|
@ -465,11 +472,13 @@ notify(LServer, PushLJID, Node, XData, Pkt, HandleResponse) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Miscellaneous.
|
%% Miscellaneous.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec is_message_with_body(stanza()) -> boolean().
|
-spec is_incoming_chat_msg(stanza()) -> boolean().
|
||||||
is_message_with_body(#message{} = Msg) ->
|
is_incoming_chat_msg(#message{} = Msg) ->
|
||||||
Msg1 = xmpp_util:unwrap_carbon(Msg),
|
case get_direction(Msg) of
|
||||||
get_body_text(Msg1) /= none;
|
recv -> get_body_text(unwrap_carbon(Msg)) /= none;
|
||||||
is_message_with_body(_Stanza) ->
|
send -> false
|
||||||
|
end;
|
||||||
|
is_incoming_chat_msg(_Stanza) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -593,9 +602,9 @@ drop_online_sessions(LUser, LServer, Clients) ->
|
||||||
[Client || {TS, _, _, _} = Client <- Clients,
|
[Client || {TS, _, _, _} = Client <- Clients,
|
||||||
lists:keyfind(TS, 1, SessIDs) == false].
|
lists:keyfind(TS, 1, SessIDs) == false].
|
||||||
|
|
||||||
-spec make_summary(binary(), xmpp_element() | xmlel() | none)
|
-spec make_summary(binary(), xmpp_element() | xmlel() | none, direction())
|
||||||
-> xdata() | undefined.
|
-> xdata() | undefined.
|
||||||
make_summary(Host, #message{from = From} = Pkt) ->
|
make_summary(Host, #message{from = From} = Pkt, recv) ->
|
||||||
case {gen_mod:get_module_opt(Host, ?MODULE, include_sender),
|
case {gen_mod:get_module_opt(Host, ?MODULE, include_sender),
|
||||||
gen_mod:get_module_opt(Host, ?MODULE, include_body)} of
|
gen_mod:get_module_opt(Host, ?MODULE, include_body)} of
|
||||||
{false, false} ->
|
{false, false} ->
|
||||||
|
@ -622,7 +631,23 @@ make_summary(Host, #message{from = From} = Pkt) ->
|
||||||
#xdata{type = submit, fields = push_summary:encode(Fields2)}
|
#xdata{type = submit, fields = push_summary:encode(Fields2)}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
make_summary(_Host, _Pkt) ->
|
make_summary(_Host, _Pkt, _Dir) ->
|
||||||
|
undefined.
|
||||||
|
|
||||||
|
-spec unwrap_carbon(stanza()) -> stanza().
|
||||||
|
unwrap_carbon(#message{meta = #{carbon_copy := true}} = Msg) ->
|
||||||
|
xmpp_util:unwrap_carbon(Msg);
|
||||||
|
unwrap_carbon(Stanza) ->
|
||||||
|
Stanza.
|
||||||
|
|
||||||
|
-spec get_direction(stanza()) -> direction().
|
||||||
|
get_direction(#message{meta = #{carbon_copy := true},
|
||||||
|
from = #jid{luser = U, lserver = S},
|
||||||
|
to = #jid{luser = U, lserver = S}}) ->
|
||||||
|
send;
|
||||||
|
get_direction(#message{}) ->
|
||||||
|
recv;
|
||||||
|
get_direction(_Stanza) ->
|
||||||
undefined.
|
undefined.
|
||||||
|
|
||||||
-spec get_body_text(message()) -> binary() | none.
|
-spec get_body_text(message()) -> binary() | none.
|
||||||
|
|
|
@ -131,7 +131,7 @@ unregister_hooks(Host) ->
|
||||||
-spec c2s_stanza(c2s_state(), xmpp_element() | xmlel(), term()) -> c2s_state().
|
-spec c2s_stanza(c2s_state(), xmpp_element() | xmlel(), term()) -> c2s_state().
|
||||||
c2s_stanza(#{push_enabled := true, mgmt_state := pending} = State,
|
c2s_stanza(#{push_enabled := true, mgmt_state := pending} = State,
|
||||||
Pkt, _SendResult) ->
|
Pkt, _SendResult) ->
|
||||||
case mod_push:is_message_with_body(Pkt) of
|
case mod_push:is_incoming_chat_msg(Pkt) of
|
||||||
true ->
|
true ->
|
||||||
maybe_restore_resume_timeout(State);
|
maybe_restore_resume_timeout(State);
|
||||||
false ->
|
false ->
|
||||||
|
@ -142,7 +142,7 @@ c2s_stanza(State, _Pkt, _SendResult) ->
|
||||||
|
|
||||||
-spec c2s_session_pending(c2s_state()) -> c2s_state().
|
-spec c2s_session_pending(c2s_state()) -> c2s_state().
|
||||||
c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) ->
|
c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) ->
|
||||||
case mod_stream_mgmt:queue_find(fun mod_push:is_message_with_body/1,
|
case mod_stream_mgmt:queue_find(fun mod_push:is_incoming_chat_msg/1,
|
||||||
Queue) of
|
Queue) of
|
||||||
none ->
|
none ->
|
||||||
State1 = maybe_adjust_resume_timeout(State),
|
State1 = maybe_adjust_resume_timeout(State),
|
||||||
|
@ -190,7 +190,7 @@ c2s_handle_cast(State, _Msg) ->
|
||||||
c2s_handle_info(#{push_enabled := true, mgmt_state := pending,
|
c2s_handle_info(#{push_enabled := true, mgmt_state := pending,
|
||||||
jid := JID} = State, {timeout, _, push_keepalive}) ->
|
jid := JID} = State, {timeout, _, push_keepalive}) ->
|
||||||
?INFO_MSG("Waking ~s before session times out", [jid:encode(JID)]),
|
?INFO_MSG("Waking ~s before session times out", [jid:encode(JID)]),
|
||||||
mod_push:notify(State, none),
|
mod_push:notify(State, none, undefined),
|
||||||
{stop, State};
|
{stop, State};
|
||||||
c2s_handle_info(State, _) ->
|
c2s_handle_info(State, _) ->
|
||||||
State.
|
State.
|
||||||
|
@ -235,7 +235,8 @@ wake_all(LServer) ->
|
||||||
IgnoreResponse = fun(_) -> ok end,
|
IgnoreResponse = fun(_) -> ok end,
|
||||||
lists:foreach(fun({_, PushLJID, Node, XData}) ->
|
lists:foreach(fun({_, PushLJID, Node, XData}) ->
|
||||||
mod_push:notify(LServer, PushLJID, Node,
|
mod_push:notify(LServer, PushLJID, Node,
|
||||||
XData, none, IgnoreResponse)
|
XData, none, undefined,
|
||||||
|
IgnoreResponse)
|
||||||
end, Sessions);
|
end, Sessions);
|
||||||
error ->
|
error ->
|
||||||
error
|
error
|
||||||
|
|
Loading…
Reference in New Issue