mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Improve send_message command
This commit is contained in:
parent
71c44bff8b
commit
6e68ca2211
@ -1480,20 +1480,26 @@ srg_user_del(User, Host, Group, GroupHost) ->
|
|||||||
%% @doc Send a message to a Jabber account.
|
%% @doc Send a message to a Jabber account.
|
||||||
%% @spec (Type::binary(), From::binary(), To::binary(), Subject::binary(), Body::binary()) -> ok
|
%% @spec (Type::binary(), From::binary(), To::binary(), Subject::binary(), Body::binary()) -> ok
|
||||||
send_message(Type, From, To, Subject, Body) ->
|
send_message(Type, From, To, Subject, Body) ->
|
||||||
FromJID = jid:decode(From),
|
CodecOpts = ejabberd_config:codec_options(),
|
||||||
ToJID = jid:decode(To),
|
try xmpp:decode(
|
||||||
Packet = build_packet(Type, Subject, Body, FromJID, ToJID),
|
#xmlel{name = <<"message">>,
|
||||||
State1 = #{jid => FromJID},
|
attrs = [{<<"to">>, To},
|
||||||
ejabberd_hooks:run_fold(user_send_packet, FromJID#jid.lserver, {Packet, State1}, []),
|
{<<"from">>, From},
|
||||||
ejabberd_router:route(xmpp:set_from_to(Packet, FromJID, ToJID)).
|
{<<"type">>, Type},
|
||||||
|
{<<"id">>, p1_rand:get_string()}],
|
||||||
build_packet(Type, Subject, Body, FromJID, ToJID) ->
|
children =
|
||||||
#message{type = misc:binary_to_atom(Type),
|
[#xmlel{name = <<"subject">>,
|
||||||
body = xmpp:mk_text(Body),
|
children = [{xmlcdata, Subject}]},
|
||||||
from = FromJID,
|
#xmlel{name = <<"body">>,
|
||||||
to = ToJID,
|
children = [{xmlcdata, Body}]}]},
|
||||||
id = p1_rand:get_string(),
|
?NS_CLIENT, CodecOpts) of
|
||||||
subject = xmpp:mk_text(Subject)}.
|
#message{from = JID} = Msg ->
|
||||||
|
State = #{jid => JID},
|
||||||
|
ejabberd_hooks:run_fold(user_send_packet, JID#jid.lserver, {Msg, State}, []),
|
||||||
|
ejabberd_router:route(Msg)
|
||||||
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
{error, xmpp:format_error(Why)}
|
||||||
|
end.
|
||||||
|
|
||||||
send_stanza(FromString, ToString, Stanza) ->
|
send_stanza(FromString, ToString, Stanza) ->
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user