diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2016-08-09 13:36:43 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2016-08-09 13:36:43 +0300 |
commit | 1fc58ace2f139ea01c13bac0a8f30735d9f8af29 (patch) | |
tree | 86e7339e0227eaeb02b7e5a6ff2dacaf019e8448 /src/mod_muc_admin.erl | |
parent | Update to released version (diff) |
Add commands for MUC subscriptions management
Diffstat (limited to 'src/mod_muc_admin.erl')
-rw-r--r-- | src/mod_muc_admin.erl | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 0b5e79f6..a07ac0bc 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -20,6 +20,7 @@ change_room_option/4, get_room_options/2, set_room_affiliation/4, get_room_affiliations/2, web_menu_main/2, web_page_main/2, web_menu_host/3, + subscribe_room/4, unsubscribe_room/2, web_page_host/3, mod_opt_type/1, get_commands_spec/0]). -include("ejabberd.hrl"). @@ -151,7 +152,17 @@ get_commands_spec() -> {value, string} ]}} }}}, - + #ejabberd_commands{name = subscribe_room, tags = [muc_room], + desc = "Subscribe to a MUC conference", + module = ?MODULE, function = subscribe_room, + args = [{user, binary}, {nick, binary}, {room, binary}, + {nodes, binary}], + result = {list, {node, string}}}, + #ejabberd_commands{name = unsubscribe_room, tags = [muc_room], + desc = "Unsubscribe from a MUC conference", + module = ?MODULE, function = unsubscribe_room, + args = [{user, binary}, {room, binary}], + result = {res, rescode}}, #ejabberd_commands{name = set_room_affiliation, tags = [muc_room], desc = "Change an affiliation in a MUC room", module = ?MODULE, function = set_room_affiliation, @@ -884,6 +895,64 @@ set_room_affiliation(Name, Service, JID, AffiliationString) -> error end. +%%% +%%% MUC Subscription +%%% + +subscribe_room(_User, Nick, _Room, _Nodes) when Nick == <<"">> -> + throw({error, "Nickname must be set"}); +subscribe_room(User, Nick, Room, Nodes) -> + NodeList = re:split(Nodes, "\\h*,\\h*"), + case jid:from_string(Room) of + #jid{luser = Name, lserver = Host} when Name /= <<"">> -> + case jid:from_string(User) of + error -> + throw({error, "Malformed user JID"}); + JID -> + UserJID = jid:replace_resource(JID, Nick), + case get_room_pid(Name, Host) of + Pid when is_pid(Pid) -> + case gen_fsm:sync_send_all_state_event( + Pid, + {muc_subscribe, UserJID, Nick, NodeList}) of + {ok, SubscribedNodes} -> + SubscribedNodes; + {error, Reason} -> + throw({error, binary_to_list(Reason)}) + end; + _ -> + throw({error, "The room does not exist"}) + end + end; + _ -> + throw({error, "Malformed room JID"}) + end. + +unsubscribe_room(User, Room) -> + case jid:from_string(Room) of + #jid{luser = Name, lserver = Host} when Name /= <<"">> -> + case jid:from_string(User) of + error -> + throw({error, "Malformed user JID"}); + UserJID -> + case get_room_pid(Name, Host) of + Pid when is_pid(Pid) -> + case gen_fsm:sync_send_all_state_event( + Pid, + {muc_unsubscribe, UserJID}) of + ok -> + ok; + {error, Reason} -> + throw({error, binary_to_list(Reason)}) + end; + _ -> + throw({error, "The room does not exist"}) + end + end; + _ -> + throw({error, "Malformed room JID"}) + end. + make_opts(StateData) -> Config = StateData#state.config, [ |