From c762f20816f810cb3ee77583ad26bc27f2b78d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Oct 2025 14:39:59 +0200 Subject: [PATCH] Make message body configurable In case of MUC, the body was a timestamp. As attributes are stripped in MUC, a new element was used for the timestamp. --- src/helpers/amoc_xmpp.erl | 4 +++- src/helpers/amoc_xmpp_muc.erl | 6 ++++-- src/scenarios/dynamic_domains_pm.erl | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helpers/amoc_xmpp.erl b/src/helpers/amoc_xmpp.erl index b3ef2b0..0c2ea30 100644 --- a/src/helpers/amoc_xmpp.erl +++ b/src/helpers/amoc_xmpp.erl @@ -15,7 +15,9 @@ #{name => legacy_tls, description => "use legacy tls connection", default_value => false, verification => ?V(boolean)}, #{name => connection_attempts, default_value => 1, verification => ?V(positive_integer), - description => "number of attempts to establish xmpp connection before exiting"}]). + description => "number of attempts to establish xmpp connection before exiting"}, + #{name => message_body, default_value => <<"hello">>, verification => ?V(binary), + description => "body of the message to send"}]). %% @doc Connects and authenticates a user with the given id and additional properties. %% If the passed proplist is empty, a default user spec created by diff --git a/src/helpers/amoc_xmpp_muc.erl b/src/helpers/amoc_xmpp_muc.erl index c2c3549..4799a23 100644 --- a/src/helpers/amoc_xmpp_muc.erl +++ b/src/helpers/amoc_xmpp_muc.erl @@ -80,7 +80,7 @@ received_handler_spec() -> -spec ttd(exml:element(), escalus_connection:metadata()) -> non_neg_integer(). ttd(Stanza, #{recv_timestamp := ReceivedTS}) -> - SentBin = exml_query:path(Stanza, [{element, <<"body">>}, cdata]), + SentBin = exml_query:path(Stanza, [{element, <<"timestamp">>}, cdata]), ReceivedTS - binary_to_integer(SentBin). -spec is_muc_notification(exml:element()) -> boolean(). @@ -106,7 +106,9 @@ is_muc_message(_) -> false. -spec send_message_to_room(escalus:client(), binary()) -> ok. send_message_to_room(Client, RoomJid) -> Timestamp = integer_to_binary(os:system_time(microsecond)), - escalus:send(Client, escalus_stanza:groupchat_to(RoomJid, Timestamp)). + Message = #xmlel{children = Children} = escalus_stanza:groupchat_to(RoomJid, cfg(message_body)), + TimestampElement = #xmlel{name = <<"timestamp">>, children = [#xmlcdata{content = Timestamp}]}, + escalus:send(Client, Message#xmlel{children = [TimestampElement | Children]}). %%% MUC Light: Room creation diff --git a/src/scenarios/dynamic_domains_pm.erl b/src/scenarios/dynamic_domains_pm.erl index 1b0ad13..574ff06 100644 --- a/src/scenarios/dynamic_domains_pm.erl +++ b/src/scenarios/dynamic_domains_pm.erl @@ -62,7 +62,7 @@ do(MyId, Client) -> -spec send_stanza(escalus:client(), chat, #state{}) -> #state{}. send_stanza(Client, chat, State = #state{neighbours = [RecipientId | Rest]}) -> - Msg = escalus_stanza:chat_to_with_id_and_timestamp(make_jid(RecipientId), <<"hello">>), + Msg = escalus_stanza:chat_to_with_id_and_timestamp(make_jid(RecipientId), cfg(message_body)), escalus_connection:send(Client, Msg), State#state{neighbours = Rest ++ [RecipientId]}.