24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

mod_irc must send presence unavailable to the departing occupant (EJAB-1417)

This commit is contained in:
Badlop 2011-03-01 22:32:50 +01:00
parent 339fa6e41b
commit 1548a18b5e

View File

@ -219,6 +219,7 @@ handle_info({route_chan, Channel, Resource,
NewStateData = NewStateData =
case xml:get_attr_s("type", Attrs) of case xml:get_attr_s("type", Attrs) of
"unavailable" -> "unavailable" ->
send_stanza_unavailable(Channel, StateData),
S1 = ?SEND(io_lib:format("PART #~s\r\n", [Channel])), S1 = ?SEND(io_lib:format("PART #~s\r\n", [Channel])),
S1#state{channels = S1#state{channels =
dict:erase(Channel, S1#state.channels)}; dict:erase(Channel, S1#state.channels)};
@ -656,13 +657,9 @@ terminate(_Reason, _StateName, FullStateData) ->
bounce_messages("Server Connect Failed"), bounce_messages("Server Connect Failed"),
lists:foreach( lists:foreach(
fun(Chan) -> fun(Chan) ->
ejabberd_router:route( Stanza = {xmlelement, "presence", [{"type", "error"}],
jlib:make_jid( [Error]},
lists:concat([Chan, "%", StateData#state.server]), send_stanza(Chan, StateData, Stanza)
StateData#state.host, StateData#state.nick),
StateData#state.user,
{xmlelement, "presence", [{"type", "error"}],
[Error]})
end, dict:fetch_keys(StateData#state.channels)), end, dict:fetch_keys(StateData#state.channels)),
case StateData#state.socket of case StateData#state.socket of
undefined -> undefined ->
@ -672,6 +669,30 @@ terminate(_Reason, _StateName, FullStateData) ->
end, end,
ok. 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 %%% Internal functions
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------