Show nick also in oneself list of subscriptions (#3206)

This commit is contained in:
Badlop 2020-04-03 12:34:57 +02:00
parent 8d969a4a9f
commit 66c2f45bff
5 changed files with 16 additions and 16 deletions

View File

@ -1134,7 +1134,7 @@ select_with_mucsub_fallback(LServer, JidRequestor, JidArchive, Query, RSM, Flags
_ -> _ ->
[] []
end, end,
SubRoomJids = [Jid || {Jid, _} <- SubRooms], SubRoomJids = [Jid || {Jid, _, _} <- SubRooms],
{E2, A2, C2} = {E2, A2, C2} =
lists:foldl( lists:foldl(
fun(MucJid, {E0, A0, C0}) -> fun(MucJid, {E0, A0, C0}) ->

View File

@ -221,7 +221,7 @@ select_with_mucsub(LServer, JidRequestor, #jid{luser = LUser} = JidArchive,
_ -> _ ->
[] []
end, end,
[jid:encode(Jid) || {Jid, _} <- SubRooms] [jid:encode(Jid) || {Jid, _, _} <- SubRooms]
end, end,
{Query, CountQuery} = make_sql_query(LUser, LServer, MAMQuery, RSM, Extra), {Query, CountQuery} = make_sql_query(LUser, LServer, MAMQuery, RSM, Extra),
do_select_query(LServer, JidRequestor, JidArchive, RSM, chat, Query, CountQuery, Flags). do_select_query(LServer, JidRequestor, JidArchive, RSM, chat, Query, CountQuery, Flags).

View File

@ -107,7 +107,7 @@
-callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer(). -callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer().
-callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}]. -callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}].
-callback get_subscribed_rooms(binary(), binary(), jid()) -> -callback get_subscribed_rooms(binary(), binary(), jid()) ->
{ok, [{jid(), [binary()]}]} | {error, db_failure}. {ok, [{jid(), binary(), [binary()]}]} | {error, db_failure}.
-optional_callbacks([get_subscribed_rooms/3]). -optional_callbacks([get_subscribed_rooms/3]).
@ -701,8 +701,8 @@ process_mucsub(#iq{type = get, from = From, to = To, lang = Lang,
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
case get_subscribed_rooms(ServerHost, Host, From) of case get_subscribed_rooms(ServerHost, Host, From) of
{ok, Subs} -> {ok, Subs} ->
List = [#muc_subscription{jid = JID, events = Nodes} List = [#muc_subscription{jid = JID, nick = Nick, events = Nodes}
|| {JID, Nodes} <- Subs], || {JID, Nick, Nodes} <- Subs],
xmpp:make_iq_result(IQ, #muc_subscriptions{list = List}); xmpp:make_iq_result(IQ, #muc_subscriptions{list = List});
{error, _} -> {error, _} ->
Txt = ?T("Database failure"), Txt = ?T("Database failure"),
@ -946,13 +946,13 @@ get_room_disco_item({Name, Host, Pid}, {Filter, JID, Lang}) ->
Err Err
end. end.
-spec get_subscribed_rooms(binary(), jid()) -> {ok, [{jid(), [binary()]}]} | {error, any()}. -spec get_subscribed_rooms(binary(), jid()) -> {ok, [{jid(), binary(), [binary()]}]} | {error, any()}.
get_subscribed_rooms(Host, User) -> get_subscribed_rooms(Host, User) ->
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
get_subscribed_rooms(ServerHost, Host, User). get_subscribed_rooms(ServerHost, Host, User).
-spec get_subscribed_rooms(binary(), binary(), jid()) -> -spec get_subscribed_rooms(binary(), binary(), jid()) ->
{ok, [{jid(), [binary()]}]} | {error, any()}. {ok, [{jid(), binary(), [binary()]}]} | {error, any()}.
get_subscribed_rooms(ServerHost, Host, From) -> get_subscribed_rooms(ServerHost, Host, From) ->
LServer = jid:nameprep(ServerHost), LServer = jid:nameprep(ServerHost),
Mod = gen_mod:db_mod(LServer, ?MODULE), Mod = gen_mod:db_mod(LServer, ?MODULE),
@ -964,15 +964,15 @@ get_subscribed_rooms(ServerHost, Host, From) ->
fun({Name, _, Pid}) when Pid == self() -> fun({Name, _, Pid}) when Pid == self() ->
USR = jid:split(BareFrom), USR = jid:split(BareFrom),
case erlang:get(muc_subscribers) of case erlang:get(muc_subscribers) of
#{USR := #subscriber{nodes = Nodes}} -> #{USR := #subscriber{nodes = Nodes, nick = Nick}} ->
[{jid:make(Name, Host), Nodes}]; [{jid:make(Name, Host), Nick, Nodes}];
_ -> _ ->
[] []
end; end;
({Name, _, Pid}) -> ({Name, _, Pid}) ->
case mod_muc_room:is_subscribed(Pid, BareFrom) of case mod_muc_room:is_subscribed(Pid, BareFrom) of
{true, Nodes} -> {true, Nick, Nodes} ->
[{jid:make(Name, Host), Nodes}]; [{jid:make(Name, Host), Nick, Nodes}];
false -> [] false -> []
end; end;
(_) -> (_) ->

View File

@ -223,7 +223,7 @@ unsubscribe(Pid, JID) ->
{error, ?T("Conference room does not exist")} {error, ?T("Conference room does not exist")}
end. end.
-spec is_subscribed(pid(), jid()) -> {true, [binary()]} | false. -spec is_subscribed(pid(), jid()) -> {true, binary(), [binary()]} | false.
is_subscribed(Pid, JID) -> is_subscribed(Pid, JID) ->
try p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, JID}) try p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, JID})
catch _:{_, {p1_fsm, _, _}} -> false catch _:{_, {p1_fsm, _, _}} -> false
@ -759,7 +759,7 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName,
end; end;
handle_sync_event({is_subscribed, From}, _From, StateName, StateData) -> handle_sync_event({is_subscribed, From}, _From, StateName, StateData) ->
IsSubs = try maps:get(jid:split(From), StateData#state.subscribers) of IsSubs = try maps:get(jid:split(From), StateData#state.subscribers) of
#subscriber{nodes = Nodes} -> {true, Nodes} #subscriber{nick = Nick, nodes = Nodes} -> {true, Nick, Nodes}
catch _:{badkey, _} -> false catch _:{badkey, _} -> false
end, end,
{reply, IsSubs, StateName, StateData}; {reply, IsSubs, StateName, StateData};

View File

@ -410,11 +410,11 @@ get_subscribed_rooms(LServer, Host, Jid) ->
JidS = jid:encode(Jid), JidS = jid:encode(Jid),
case ejabberd_sql:sql_query( case ejabberd_sql:sql_query(
LServer, LServer,
?SQL("select @(room)s, @(nodes)s from muc_room_subscribers " ?SQL("select @(room)s, @(nick)s, @(nodes)s from muc_room_subscribers "
"where jid=%(JidS)s and host=%(Host)s")) of "where jid=%(JidS)s and host=%(Host)s")) of
{selected, Subs} -> {selected, Subs} ->
{ok, [{jid:make(Room, Host), ejabberd_sql:decode_term(Nodes)} {ok, [{jid:make(Room, Host), Nick, ejabberd_sql:decode_term(Nodes)}
|| {Room, Nodes} <- Subs]}; || {Room, Nick, Nodes} <- Subs]};
_Error -> _Error ->
{error, db_failure} {error, db_failure}
end. end.