mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
Rewrite muc_register_nick and muc_unregister_nick to be DB independent (#1954)
Notice: The arguments expected have changed, instead of muc_register_nick Tim tim@example.org muc.example.org muc_unregister_nick Tim it expects now: muc_register_nick Tim tim@example.org example.org muc_unregister_nick tim@example.org example.org
This commit is contained in:
parent
7f3fceb432
commit
1d396b4716
@ -61,6 +61,7 @@
|
|||||||
count_online_rooms/1,
|
count_online_rooms/1,
|
||||||
register_online_user/4,
|
register_online_user/4,
|
||||||
unregister_online_user/4,
|
unregister_online_user/4,
|
||||||
|
iq_set_register_info/5,
|
||||||
count_online_rooms_by_user/3,
|
count_online_rooms_by_user/3,
|
||||||
get_online_rooms_by_user/3,
|
get_online_rooms_by_user/3,
|
||||||
can_use_nick/4]).
|
can_use_nick/4]).
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2, stop/1, reload/3, depends/2, muc_online_rooms/1,
|
-export([start/2, stop/1, reload/3, depends/2, muc_online_rooms/1,
|
||||||
muc_register_nick/3, muc_unregister_nick/1,
|
muc_register_nick/3, muc_unregister_nick/2,
|
||||||
create_room_with_opts/4, create_room/3, destroy_room/2,
|
create_room_with_opts/4, create_room/3, destroy_room/2,
|
||||||
create_rooms_file/1, destroy_rooms_file/1,
|
create_rooms_file/1, destroy_rooms_file/1,
|
||||||
rooms_unused_list/2, rooms_unused_destroy/2,
|
rooms_unused_list/2, rooms_unused_destroy/2,
|
||||||
@ -91,16 +91,18 @@ get_commands_spec() ->
|
|||||||
args = [{host, binary}],
|
args = [{host, binary}],
|
||||||
result = {rooms, {list, {room, string}}}},
|
result = {rooms, {list, {room, string}}}},
|
||||||
#ejabberd_commands{name = muc_register_nick, tags = [muc],
|
#ejabberd_commands{name = muc_register_nick, tags = [muc],
|
||||||
desc = "Register a nick in the MUC service",
|
desc = "Register a nick to a User JID in the MUC service of a server",
|
||||||
module = ?MODULE, function = muc_register_nick,
|
module = ?MODULE, function = muc_register_nick,
|
||||||
args_desc = ["Nick", "User JID", "MUC service"],
|
args_desc = ["Nick", "User JID", "Server Host"],
|
||||||
args_example = [<<"Tim">>, <<"tim@example.org">>, <<"muc.example.org">>],
|
args_example = [<<"Tim">>, <<"tim@example.org">>, <<"example.org">>],
|
||||||
args = [{nick, binary}, {jid, binary}, {domain, binary}],
|
args = [{nick, binary}, {jid, binary}, {serverhost, binary}],
|
||||||
result = {res, rescode}},
|
result = {res, rescode}},
|
||||||
#ejabberd_commands{name = muc_unregister_nick, tags = [muc],
|
#ejabberd_commands{name = muc_unregister_nick, tags = [muc],
|
||||||
desc = "Unregister the nick in the MUC service",
|
desc = "Unregister the nick registered by that account in the MUC service",
|
||||||
module = ?MODULE, function = muc_unregister_nick,
|
module = ?MODULE, function = muc_unregister_nick,
|
||||||
args = [{nick, binary}],
|
args_desc = ["User JID", "MUC service"],
|
||||||
|
args_example = [<<"tim@example.org">>, <<"example.org">>],
|
||||||
|
args = [{jid, binary}, {serverhost, binary}],
|
||||||
result = {res, rescode}},
|
result = {res, rescode}},
|
||||||
|
|
||||||
#ejabberd_commands{name = create_room, tags = [muc_room],
|
#ejabberd_commands{name = create_room, tags = [muc_room],
|
||||||
@ -305,31 +307,14 @@ muc_online_rooms(ServerHost) ->
|
|||||||
|| {Name, _, _} <- mod_muc:get_online_rooms(Host)]
|
|| {Name, _, _} <- mod_muc:get_online_rooms(Host)]
|
||||||
end, Hosts).
|
end, Hosts).
|
||||||
|
|
||||||
muc_register_nick(Nick, JIDBinary, Domain) ->
|
muc_register_nick(Nick, FromBinary, ServerHost) ->
|
||||||
try jid:decode(JIDBinary) of
|
Host = find_host(ServerHost),
|
||||||
JID ->
|
From = jid:decode(FromBinary),
|
||||||
F = fun (MHost, MNick) ->
|
Lang = <<"en">>,
|
||||||
mnesia:write(#muc_registered{us_host=MHost, nick=MNick})
|
mod_muc:iq_set_register_info(ServerHost, Host, From, Nick, Lang).
|
||||||
end,
|
|
||||||
case mnesia:transaction(F, [{{JID#jid.luser, JID#jid.lserver},
|
|
||||||
Domain}, Nick]) of
|
|
||||||
{atomic, ok} -> ok;
|
|
||||||
{aborted, _Error} -> error
|
|
||||||
end
|
|
||||||
catch _:{bad_jid, _} -> throw({error, "Malformed JID"})
|
|
||||||
end.
|
|
||||||
|
|
||||||
muc_unregister_nick(Nick) ->
|
muc_unregister_nick(FromBinary, ServerHost) ->
|
||||||
F2 = fun(N) ->
|
muc_register_nick(<<"">>, FromBinary, ServerHost).
|
||||||
[{_,Key,_}|_] = mnesia:index_read(muc_registered, N, 3),
|
|
||||||
mnesia:delete({muc_registered, Key})
|
|
||||||
end,
|
|
||||||
case mnesia:transaction(F2, [Nick], 1) of
|
|
||||||
{atomic, ok} ->
|
|
||||||
ok;
|
|
||||||
{aborted, _Error} ->
|
|
||||||
error
|
|
||||||
end.
|
|
||||||
|
|
||||||
get_user_rooms(LUser, LServer) ->
|
get_user_rooms(LUser, LServer) ->
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
|
Loading…
Reference in New Issue
Block a user