from scenarios import *
import scenarios.simple_channel_join
scenario = (
# Join the channel with user 1
scenarios.simple_channel_join.scenario,
# Make it persistent for user 1
send_stanza(""),
expect_stanza("/iq[@type='result']/muc_owner:query/dataform:x/dataform:field[@var='persistent'][@type='boolean']/dataform:value[text()='false']"),
send_stanza("true"),
expect_stanza("/iq[@type='result']"),
# Check that the value is now effectively true
send_stanza(""),
expect_stanza("/iq[@type='result']/muc_owner:query/dataform:x/dataform:field[@var='persistent'][@type='boolean']/dataform:value[text()='true']"),
# A second user joins the same channel
send_stanza(""),
sequences.connection("irc.localhost", '{jid_two}/{resource_one}'),
expect_unordered(
["/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']"],
[
"/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']",
"/presence/muc_user:x/muc_user:status[@code='110']"
],
["/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']"],
),
expect_stanza("/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
# First user leaves the room (but biboumi will stay in the channel)
send_stanza(""),
# Only user 1 receives the unavailable presence
expect_stanza("/presence[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']",
"/presence/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']"),
# Second user sends a channel message
send_stanza("coucou"),
# Message should only be received by user 2, since user 1 has no resource in the room
expect_stanza("/message[@type='groupchat'][@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']"),
# Second user leaves the channel
send_stanza(""),
expect_stanza("/presence[@type='unavailable'][@from='#foo%{irc_server_one}/{nick_two}']"),
)