mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-14 22:00:16 +02:00
Improve add_message_type/2 function
Let add_message_type/2 accept the type as an atom, and let the function handle the 'normal' message type. This doesn't change the behavior, but avoids some code duplication.
This commit is contained in:
parent
cc958f7787
commit
e5428c5500
|
@ -4485,10 +4485,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy
|
||||||
NotificationType = get_option(NodeOptions, notification_type, headline),
|
NotificationType = get_option(NodeOptions, notification_type, headline),
|
||||||
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
||||||
From = service_jid(Host),
|
From = service_jid(Host),
|
||||||
Stanza = case NotificationType of
|
Stanza = add_message_type(BaseStanza, NotificationType),
|
||||||
normal -> BaseStanza;
|
|
||||||
MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
|
|
||||||
end,
|
|
||||||
%% Handles explicit subscriptions
|
%% Handles explicit subscriptions
|
||||||
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
||||||
lists:foreach(fun ({LJID, NodeName, SubIDs}) ->
|
lists:foreach(fun ({LJID, NodeName, SubIDs}) ->
|
||||||
|
@ -4520,10 +4517,8 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, NodeId, Type, Nod
|
||||||
SenderResource = user_resource(LUser, LServer, LResource),
|
SenderResource = user_resource(LUser, LServer, LResource),
|
||||||
case ejabberd_sm:get_session_pid(LUser, LServer, SenderResource) of
|
case ejabberd_sm:get_session_pid(LUser, LServer, SenderResource) of
|
||||||
C2SPid when is_pid(C2SPid) ->
|
C2SPid when is_pid(C2SPid) ->
|
||||||
Stanza = case get_option(NodeOptions, notification_type, headline) of
|
NotificationType = get_option(NodeOptions, notification_type, headline),
|
||||||
normal -> BaseStanza;
|
Stanza = add_message_type(BaseStanza, NotificationType),
|
||||||
MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
|
|
||||||
end,
|
|
||||||
%% set the from address on the notification to the bare JID of the account owner
|
%% set the from address on the notification to the bare JID of the account owner
|
||||||
%% Also, add "replyto" if entity has presence subscription to the account owner
|
%% Also, add "replyto" if entity has presence subscription to the account owner
|
||||||
%% See XEP-0163 1.1 section 4.3.1
|
%% See XEP-0163 1.1 section 4.3.1
|
||||||
|
@ -5301,10 +5296,19 @@ itemsEls(Items) ->
|
||||||
#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload}
|
#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload}
|
||||||
end, Items).
|
end, Items).
|
||||||
|
|
||||||
|
-spec(add_message_type/2 ::
|
||||||
|
(
|
||||||
|
Message :: xmlel(),
|
||||||
|
Type :: atom())
|
||||||
|
-> xmlel()
|
||||||
|
).
|
||||||
|
|
||||||
|
add_message_type(Message, normal) -> Message;
|
||||||
add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els},
|
add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els},
|
||||||
Type) ->
|
Type) ->
|
||||||
#xmlel{name = <<"message">>,
|
#xmlel{name = <<"message">>,
|
||||||
attrs = [{<<"type">>, Type} | Attrs], children = Els};
|
attrs = [{<<"type">>, jlib:atom_to_binary(Type)} | Attrs],
|
||||||
|
children = Els};
|
||||||
add_message_type(XmlEl, _Type) -> XmlEl.
|
add_message_type(XmlEl, _Type) -> XmlEl.
|
||||||
|
|
||||||
%% Place of <headers/> changed at the bottom of the stanza
|
%% Place of <headers/> changed at the bottom of the stanza
|
||||||
|
|
|
@ -4091,10 +4091,7 @@ broadcast_stanza(Host, _Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTy
|
||||||
NotificationType = get_option(NodeOptions, notification_type, headline),
|
NotificationType = get_option(NodeOptions, notification_type, headline),
|
||||||
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
||||||
From = service_jid(Host),
|
From = service_jid(Host),
|
||||||
Stanza = case NotificationType of
|
Stanza = add_message_type(BaseStanza, NotificationType),
|
||||||
normal -> BaseStanza;
|
|
||||||
MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
|
|
||||||
end,
|
|
||||||
%% Handles explicit subscriptions
|
%% Handles explicit subscriptions
|
||||||
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
SubIDsByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
||||||
lists:foreach(fun ({LJID, NodeName, SubIDs}) ->
|
lists:foreach(fun ({LJID, NodeName, SubIDs}) ->
|
||||||
|
@ -4126,10 +4123,8 @@ broadcast_stanza({LUser, LServer, LResource}, Publisher, Node, NodeId, Type, Nod
|
||||||
SenderResource = user_resource(LUser, LServer, LResource),
|
SenderResource = user_resource(LUser, LServer, LResource),
|
||||||
case ejabberd_sm:get_session_pid(LUser, LServer, SenderResource) of
|
case ejabberd_sm:get_session_pid(LUser, LServer, SenderResource) of
|
||||||
C2SPid when is_pid(C2SPid) ->
|
C2SPid when is_pid(C2SPid) ->
|
||||||
Stanza = case get_option(NodeOptions, notification_type, headline) of
|
NotificationType = get_option(NodeOptions, notification_type, headline),
|
||||||
normal -> BaseStanza;
|
Stanza = add_message_type(BaseStanza, NotificationType),
|
||||||
MsgType -> add_message_type(BaseStanza, iolist_to_binary(atom_to_list(MsgType)))
|
|
||||||
end,
|
|
||||||
%% set the from address on the notification to the bare JID of the account owner
|
%% set the from address on the notification to the bare JID of the account owner
|
||||||
%% Also, add "replyto" if entity has presence subscription to the account owner
|
%% Also, add "replyto" if entity has presence subscription to the account owner
|
||||||
%% See XEP-0163 1.1 section 4.3.1
|
%% See XEP-0163 1.1 section 4.3.1
|
||||||
|
@ -4966,10 +4961,19 @@ itemsEls(Items) ->
|
||||||
#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload}
|
#xmlel{name = <<"item">>, attrs = itemAttr(ItemId), children = Payload}
|
||||||
end, Items).
|
end, Items).
|
||||||
|
|
||||||
|
-spec(add_message_type/2 ::
|
||||||
|
(
|
||||||
|
Message :: xmlel(),
|
||||||
|
Type :: atom())
|
||||||
|
-> xmlel()
|
||||||
|
).
|
||||||
|
|
||||||
|
add_message_type(Message, normal) -> Message;
|
||||||
add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els},
|
add_message_type(#xmlel{name = <<"message">>, attrs = Attrs, children = Els},
|
||||||
Type) ->
|
Type) ->
|
||||||
#xmlel{name = <<"message">>,
|
#xmlel{name = <<"message">>,
|
||||||
attrs = [{<<"type">>, Type} | Attrs], children = Els};
|
attrs = [{<<"type">>, jlib:atom_to_binary(Type)} | Attrs],
|
||||||
|
children = Els};
|
||||||
add_message_type(XmlEl, _Type) -> XmlEl.
|
add_message_type(XmlEl, _Type) -> XmlEl.
|
||||||
|
|
||||||
%% Place of <headers/> changed at the bottom of the stanza
|
%% Place of <headers/> changed at the bottom of the stanza
|
||||||
|
|
Loading…
Reference in New Issue
Block a user