]> granicus.if.org Git - ejabberd/commitdiff
Resend presences and history if presence possesses <x/> MUC element
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 9 Oct 2017 14:59:22 +0000 (17:59 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 9 Oct 2017 14:59:22 +0000 (17:59 +0300)
Behave according to the new rule from XEP-0045, section 7.2.2:

> When a MUC service receives an <x/> tagged join stanza from an
> already-joined client (as identified by the client's full JID),
> the service should assume that the client lost its synchronization,
> and therefore it SHOULD send exactly the same stanzas to the client
> as if it actually just joined the MUC.

src/mod_muc_room.erl

index 8521238e8a3a2f27dd932683ab64e8217c89e0fd..e06c206835b8a7800bfb8a8d64d43cfcfec0aa34 100644 (file)
@@ -1014,7 +1014,13 @@ do_process_presence(Nick, #presence{from = From, type = available, lang = Lang}
                               From, Packet, StateData),
                    NewState = add_user_presence(From, Stanza,
                                                 StateData),
-                   send_new_presence(From, NewState, StateData),
+                   case xmpp:has_subtag(Packet, #muc{}) of
+                       true ->
+                           send_initial_presences_and_messages(
+                             From, Nick, Packet, NewState, StateData);
+                       false ->
+                           send_new_presence(From, NewState, StateData)
+                   end,
                    NewState
            end
     end;
@@ -1869,11 +1875,8 @@ add_new_user(From, Nick, Packet, StateData) ->
                                           From, Packet,
                                           add_online_user(From, Nick, Role,
                                                           StateData)),
-                             send_existing_presences(From, NewState),
-                             send_initial_presence(From, NewState, StateData),
-                             History = get_history(Nick, Packet, NewState),
-                             send_history(From, History, NewState),
-                             send_subject(From, StateData),
+                             send_initial_presences_and_messages(
+                               From, Nick, Packet, NewState, StateData),
                              NewState;
                         true ->
                              set_subscriber(From, Nick, Nodes, StateData)
@@ -2068,6 +2071,15 @@ presence_broadcast_allowed(JID, StateData) ->
     Role = get_role(JID, StateData),
     lists:member(Role, (StateData#state.config)#config.presence_broadcast).
 
+-spec send_initial_presences_and_messages(
+       jid(), binary(), presence(), state(), state()) -> ok.
+send_initial_presences_and_messages(From, Nick, Presence, NewState, OldState) ->
+    send_existing_presences(From, NewState),
+    send_initial_presence(From, NewState, OldState),
+    History = get_history(Nick, Presence, NewState),
+    send_history(From, History, NewState),
+    send_subject(From, OldState).
+
 -spec send_initial_presence(jid(), state(), state()) -> ok.
 send_initial_presence(NJID, StateData, OldStateData) ->
     send_new_presence1(NJID, <<"">>, true, StateData, OldStateData).