MUC/Sub - User subscription lost when session is reconnected
What version of ejabberd are you using?
ejabberd-master / trunk.
What operating system (version) are you using?
Ubuntu 16.04
How did you install ejabberd (source, package, distribution)?
Source
What did not work as expected? Are there error messages in the log? What was the unexpected behavior? What was the expected result?
Thanks for the earlier response to the issue #1230 . Further testing out MUC/Sub, I find that when the client reconnects the ejabberd session, the earlier room subscriptions that he / she had subscribed to are now lost.
Therefore, when the user creates a room, the following subscription IQ is received (post sending the subscription stanza). This is in line per the documentation expectation.
<iq xmlns="jabber:client" from="conference.myurl.com" to="[email protected]/42270795038596795122166" id="asksub" type="result">
<subscriptions xmlns="urn:xmpp:mucsub:0">
<subscription jid="[email protected]">
</subscription>
</subscriptions>
</iq>
When however, I relogin and the subscription list is asked for, the IQ result is per the below - you can see that the room the user joined earlier is now missing.
<iq xmlns="jabber:client" from="conference.myurl.com" to="[email protected]/39833017248756024842168" id="asksub" type="result">
<subscriptions xmlns="urn:xmpp:mucsub:0"></subscriptions>
</iq>
The room is persistent and the allow_subscriptions flag is also set to true. Is there something obvious I am missing here please?
Thanks.
Believe there is an issue with the function get_subscribed_rooms in mod_muc.erl. Please confirm.
same issue here
There is a bug, that the Allow Subscription room option is not stored in the database, so when the server restarts and the room is started, that option is reset to false. I couldn't reproduce your problem, but maybe this bug is related. Try this patch, and tell me if it fixes it.
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -4432,6 +4432,7 @@ make_opts(StateData) ->
?MAKE_CONFIG_OPT(password), ?MAKE_CONFIG_OPT(anonymous),
?MAKE_CONFIG_OPT(logging), ?MAKE_CONFIG_OPT(max_users),
?MAKE_CONFIG_OPT(allow_voice_requests),
+ ?MAKE_CONFIG_OPT(allow_subscription),
?MAKE_CONFIG_OPT(mam),
?MAKE_CONFIG_OPT(voice_request_min_interval),
?MAKE_CONFIG_OPT(vcard),
Otherwise, please describe the minimal steps to reproduce the problem: how to configure mod_muc in the config file; how to create the room, how to configure it, stanza to subscribe...
By the way, I found a bug: when requesting the list of subscribed rooms, the server only returns the persistent rooms, does not check if I'm subscribed to temporary rooms. I guess you don't see that problem as you only use persistent ones.
For the problem that only persistent rooms are checked when user asks list of subscribed rooms, I propose this patch:
diff --git a/src/mod_muc.erl b/src/mod_muc.erl
index 4eb129a..ad2be4c 100644
--- a/src/mod_muc.erl
+++ b/src/mod_muc.erl
@@ -718,13 +718,12 @@ get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})->
index = NewIndex}}
end.
-get_subscribed_rooms(ServerHost, Host, From) ->
- Rooms = get_rooms(ServerHost, Host),
+get_subscribed_rooms(_ServerHost, Host1, From) ->
+ Rooms = get_vh_rooms(Host1),
BareFrom = jid:remove_resource(From),
lists:flatmap(
- fun(#muc_room{name_host = {Name, _}, opts = Opts}) ->
- Subscribers = proplists:get_value(subscribers, Opts, []),
- case lists:keymember(BareFrom, 1, Subscribers) of
+ fun(#muc_online_room{name_host = {Name, Host}, pid = Pid}) ->
+ case gen_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
true -> [jid:make(Name, Host, <<>>)];
false -> []
end;
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index 5aceb94..fc2aeeb 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -800,6 +800,9 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName, StateData) ->
{error, Err} ->
{reply, {error, get_error_text(Err)}, StateName, StateData}
end;
+handle_sync_event({is_subscribed, From}, _From, StateName, StateData) ->
+ IsSubs = ?DICT:is_key(jid:split(From), StateData#state.subscribers),
+ {reply, IsSubs, StateName, StateData};
handle_sync_event(_Event, _From, StateName,
StateData) ->
Reply = ok, {reply, Reply, StateName, StateData}.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.