Skip to content

Commit 1982a50

Browse files
authored
Merge pull request #55 from esl/message-body
Make message body configurable
2 parents accac00 + c762f20 commit 1982a50

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/helpers/amoc_xmpp.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#{name => legacy_tls, description => "use legacy tls connection",
1616
default_value => false, verification => ?V(boolean)},
1717
#{name => connection_attempts, default_value => 1, verification => ?V(positive_integer),
18-
description => "number of attempts to establish xmpp connection before exiting"}]).
18+
description => "number of attempts to establish xmpp connection before exiting"},
19+
#{name => message_body, default_value => <<"hello">>, verification => ?V(binary),
20+
description => "body of the message to send"}]).
1921

2022
%% @doc Connects and authenticates a user with the given id and additional properties.
2123
%% If the passed proplist is empty, a default user spec created by

src/helpers/amoc_xmpp_muc.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ received_handler_spec() ->
8080

8181
-spec ttd(exml:element(), escalus_connection:metadata()) -> non_neg_integer().
8282
ttd(Stanza, #{recv_timestamp := ReceivedTS}) ->
83-
SentBin = exml_query:path(Stanza, [{element, <<"body">>}, cdata]),
83+
SentBin = exml_query:path(Stanza, [{element, <<"timestamp">>}, cdata]),
8484
ReceivedTS - binary_to_integer(SentBin).
8585

8686
-spec is_muc_notification(exml:element()) -> boolean().
@@ -106,7 +106,9 @@ is_muc_message(_) -> false.
106106
-spec send_message_to_room(escalus:client(), binary()) -> ok.
107107
send_message_to_room(Client, RoomJid) ->
108108
Timestamp = integer_to_binary(os:system_time(microsecond)),
109-
escalus:send(Client, escalus_stanza:groupchat_to(RoomJid, Timestamp)).
109+
Message = #xmlel{children = Children} = escalus_stanza:groupchat_to(RoomJid, cfg(message_body)),
110+
TimestampElement = #xmlel{name = <<"timestamp">>, children = [#xmlcdata{content = Timestamp}]},
111+
escalus:send(Client, Message#xmlel{children = [TimestampElement | Children]}).
110112

111113
%%% MUC Light: Room creation
112114

src/scenarios/dynamic_domains_pm.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ do(MyId, Client) ->
6262

6363
-spec send_stanza(escalus:client(), chat, #state{}) -> #state{}.
6464
send_stanza(Client, chat, State = #state{neighbours = [RecipientId | Rest]}) ->
65-
Msg = escalus_stanza:chat_to_with_id_and_timestamp(make_jid(RecipientId), <<"hello">>),
65+
Msg = escalus_stanza:chat_to_with_id_and_timestamp(make_jid(RecipientId), cfg(message_body)),
6666
escalus_connection:send(Client, Msg),
6767
State#state{neighbours = Rest ++ [RecipientId]}.
6868

0 commit comments

Comments
 (0)