add send_message_normal command

This commit is contained in:
HAMANO Tsukasa 2015-02-11 01:09:03 +09:00 committed by Badlop
parent ca25d44c8b
commit 9a64bfe605
1 changed files with 22 additions and 0 deletions

View File

@ -29,6 +29,8 @@
-behaviour(gen_mod).
-include("logger.hrl").
-export([start/2, stop/1,
%% Node
compile/1,
@ -84,6 +86,7 @@
srg_user_del/4,
%% Stanza
send_message_headline/4,
send_message_normal/4,
send_message_chat/3,
send_stanza_c2s/4,
privacy_set/3,
@ -518,6 +521,12 @@ commands() ->
args = [{from, binary}, {to, binary},
{subject, binary}, {body, binary}],
result = {res, rescode}},
#ejabberd_commands{name = send_message_normal, tags = [stanza],
desc = "Send a normal message to a local or remote bare of full JID",
module = ?MODULE, function = send_message_normal,
args = [{from, binary}, {to, binary},
{subject, binary}, {body, binary}],
result = {res, rescode}},
#ejabberd_commands{name = send_stanza_c2s, tags = [stanza],
desc = "Send a stanza as if sent from a c2s session",
module = ?MODULE, function = send_stanza_c2s,
@ -1348,6 +1357,12 @@ send_message_headline(From, To, Subject, Body) ->
Packet = build_packet(message_headline, [Subject, Body]),
send_packet_all_resources(From, To, Packet).
%% @doc Send a normal message to a Jabber account.
%% @spec (From::binary(), To::binary(), Subject::binary(), Body::binary()) -> ok
send_message_normal(From, To, Subject, Body) ->
Packet = build_packet(message_normal, [Subject, Body]),
send_packet_all_resources(From, To, Packet).
%% @doc Send a packet to a Jabber account.
%% If a resource was specified in the JID,
%% the packet is sent only to that specific resource.
@ -1397,6 +1412,13 @@ build_packet(message_headline, [Subject, Body]) ->
[{xmlel, <<"subject">>, [], [{xmlcdata, Subject}]},
{xmlel, <<"body">>, [], [{xmlcdata, Body}]}
]
};
build_packet(message_normal, [Subject, Body]) ->
{xmlel, <<"message">>,
[{<<"type">>, <<"normal">>}, {<<"id">>, randoms:get_string()}],
[{xmlel, <<"subject">>, [], [{xmlcdata, Subject}]},
{xmlel, <<"body">>, [], [{xmlcdata, Body}]}
]
}.
send_stanza_c2s(Username, Host, Resource, Stanza) ->