From 756cd06625c818e7987c70ed725372529041a83f Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 30 Jul 2008 18:24:08 +0000 Subject: [PATCH] * src/mod_muc/mod_muc_room.erl: Support Reasons for all affiliation and role changes (EJAB-306) SVN Revision: 1498 --- ChangeLog | 3 +++ src/mod_muc/mod_muc_room.erl | 37 ++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6946fc8a..fafc949cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2008-07-30 Badlop + * src/mod_muc/mod_muc_room.erl: Support Reasons for all + affiliation and role changes (EJAB-306) + * src/gen_mod.erl: When ejabberd is kindly stopped, don't forget modules configuration (EJAB-706) * src/ejabberd_app.erl: Likewise diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index a912aa9c7..9324e777a 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -1701,6 +1701,9 @@ extract_history([_ | Els], Type) -> send_update_presence(JID, StateData) -> + send_update_presence(JID, "", StateData). + +send_update_presence(JID, Reason, StateData) -> LJID = jlib:jid_tolower(JID), LJIDs = case LJID of {U, S, ""} -> @@ -1722,10 +1725,13 @@ send_update_presence(JID, StateData) -> end end, lists:foreach(fun(J) -> - send_new_presence(J, StateData) + send_new_presence(J, Reason, StateData) end, LJIDs). send_new_presence(NJID, StateData) -> + send_new_presence(NJID, "", StateData). + +send_new_presence(NJID, Reason, StateData) -> {ok, #user{jid = RealJID, nick = Nick, role = Role, @@ -1747,6 +1753,13 @@ send_new_presence(NJID, StateData) -> [{"affiliation", SAffiliation}, {"role", SRole}] end, + ItemEls = case Reason of + "" -> + []; + _ -> + [{xmlelement, "reason", [], + [{xmlcdata, Reason}]}] + end, Status = case StateData#state.just_created of true -> [{xmlelement, "status", [{"code", "201"}], []}]; @@ -1756,7 +1769,7 @@ send_new_presence(NJID, StateData) -> Packet = append_subtags( Presence, [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}], - [{xmlelement, "item", ItemAttrs, []} | Status]}]), + [{xmlelement, "item", ItemAttrs, ItemEls} | Status]}]), ejabberd_router:route( jlib:jid_replace_resource(StateData#state.jid, Nick), Info#user.jid, @@ -2124,21 +2137,21 @@ process_admin_items_set(UJID, Items, Lang, StateData) -> set_affiliation_and_reason( JID, outcast, Reason, set_role(JID, none, SD)); - {JID, affiliation, A, _Reason} when + {JID, affiliation, A, Reason} when (A == admin) or (A == owner) -> - SD1 = set_affiliation(JID, A, SD), + SD1 = set_affiliation_and_reason(JID, A, Reason, SD), SD2 = set_role(JID, moderator, SD1), - send_update_presence(JID, SD2), + send_update_presence(JID, Reason, SD2), SD2; - {JID, affiliation, member, _Reason} -> - SD1 = set_affiliation( - JID, member, SD), + {JID, affiliation, member, Reason} -> + SD1 = set_affiliation_and_reason( + JID, member, Reason, SD), SD2 = set_role(JID, participant, SD1), - send_update_presence(JID, SD2), + send_update_presence(JID, Reason, SD2), SD2; - {JID, role, R, _Reason} -> - SD1 = set_role(JID, R, SD), - catch send_new_presence(JID, SD1), + {JID, role, Role, Reason} -> + SD1 = set_role(JID, Role, SD), + catch send_new_presence(JID, Reason, SD1), SD1; {JID, affiliation, A, _Reason} -> SD1 = set_affiliation(JID, A, SD),