-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split mod_push_plugin into two modules
- Loading branch information
Showing
3 changed files
with
61 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author Rafal Slota | ||
%%% @copyright (C) 2017 Erlang Solutions Ltd. | ||
%%% This software is released under the Apache License, Version 2.0 | ||
%%% cited in 'LICENSE.txt'. | ||
%%% @end | ||
%%%------------------------------------------------------------------- | ||
%%% @doc | ||
%%% Default plugin module for mod_push. This module allows for some dynamic customizations. | ||
%%% @end | ||
%%%------------------------------------------------------------------- | ||
-module(mod_push_plugin_default). | ||
-behavior(mod_push_plugin). | ||
-author('rafal.slota@erlang-solutions.com'). | ||
|
||
-include_lib("ejabberd/include/jlib.hrl"). | ||
-include_lib("ejabberd/include/ejabberd.hrl"). | ||
|
||
%% Callback API | ||
-export([should_publish/3, sender_id/2]). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Callbacks | ||
%%-------------------------------------------------------------------- | ||
|
||
%% Callback 'should_publish' | ||
-spec should_publish(From :: ejabberd:jid(), To :: ejabberd:jid(), Packet :: jlib:xmlel()) -> | ||
boolean(). | ||
should_publish(_From, To = #jid{luser = LUser, lserver = LServer}, _Packet) -> | ||
try ejabberd_users:does_user_exist(LUser, LServer) of | ||
false -> | ||
false; | ||
true -> | ||
is_offline(To) | ||
catch | ||
_:_ -> | ||
is_offline(To) | ||
end. | ||
|
||
is_offline(#jid{luser = LUser, lserver = LServer}) -> | ||
case catch lists:max(ejabberd_sm:get_user_present_pids(LUser, LServer)) of | ||
{Priority, _} when is_integer(Priority), Priority >= 0 -> | ||
false; | ||
_ -> | ||
true | ||
end. | ||
|
||
%% Callback 'sender_id' | ||
-spec sender_id(From :: ejabberd:jid(), Packet :: jlib:xmlel()) -> SenderId :: binary(). | ||
sender_id(From, Packet) -> | ||
case exml_query:attr(Packet, <<"type">>) of | ||
<<"chat">> -> | ||
jid:to_binary(jid:to_bare(jid:to_lower(From))); | ||
<<"groupchat">> -> | ||
jid:to_binary(jid:to_lower(From)) | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters