]> granicus.if.org Git - ejabberd/commitdiff
mod_irc must send presence unavailable to the departing occupant (EJAB-1417)
authorBadlop <badlop@process-one.net>
Tue, 1 Mar 2011 21:32:50 +0000 (22:32 +0100)
committerBadlop <badlop@process-one.net>
Tue, 1 Mar 2011 21:33:11 +0000 (22:33 +0100)
src/mod_irc/mod_irc_connection.erl

index 55432dd1ca92ba8d767299fab093fdb5a3ca1576..c342f2877d4541e1518ceb090058d5d0624bb79f 100644 (file)
@@ -219,6 +219,7 @@ handle_info({route_chan, Channel, Resource,
     NewStateData =
        case xml:get_attr_s("type", Attrs) of
            "unavailable" ->
+               send_stanza_unavailable(Channel, StateData),
                S1 = ?SEND(io_lib:format("PART #~s\r\n", [Channel])),
                S1#state{channels =
                         dict:erase(Channel, S1#state.channels)};
@@ -656,13 +657,9 @@ terminate(_Reason, _StateName, FullStateData) ->
     bounce_messages("Server Connect Failed"),
     lists:foreach(
       fun(Chan) ->
-             ejabberd_router:route(
-               jlib:make_jid(
-                 lists:concat([Chan, "%", StateData#state.server]),
-                 StateData#state.host, StateData#state.nick),
-               StateData#state.user,
-               {xmlelement, "presence", [{"type", "error"}],
-                [Error]})
+             Stanza = {xmlelement, "presence", [{"type", "error"}],
+                [Error]},
+             send_stanza(Chan, StateData, Stanza)
       end, dict:fetch_keys(StateData#state.channels)),
     case StateData#state.socket of
        undefined ->
@@ -672,6 +669,30 @@ terminate(_Reason, _StateName, FullStateData) ->
     end,
     ok.
 
+send_stanza(Chan, StateData, Stanza) ->
+    ejabberd_router:route(
+      jlib:make_jid(
+       lists:concat([Chan, "%", StateData#state.server]),
+       StateData#state.host, StateData#state.nick),
+      StateData#state.user,
+      Stanza).
+
+send_stanza_unavailable(Chan, StateData) ->
+    Affiliation = "member", % this is a simplification
+    Role = "none",
+    Stanza =
+       {xmlelement, "presence", [{"type", "unavailable"}],
+        [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}],
+          [{xmlelement, "item",
+            [{"affiliation", Affiliation},
+             {"role", Role}],
+            []},
+           {xmlelement, "status",
+            [{"code", "110"}],
+            []}
+          ]}]},
+    send_stanza(Chan, StateData, Stanza).
+
 %%%----------------------------------------------------------------------
 %%% Internal functions
 %%%----------------------------------------------------------------------