mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Merge pull request #914 from weiss/mam-expose-jid
Expose occupant JID in MUC MAM messages whenever possible
This commit is contained in:
commit
2bfb619d19
@ -919,12 +919,12 @@ select_and_send(LServer, From, To, Start, End, With, RSM, IQ, MsgType, DBType) -
|
|||||||
select_and_start(LServer, From, To, Start, End, With, RSM, MsgType, DBType) ->
|
select_and_start(LServer, From, To, Start, End, With, RSM, MsgType, DBType) ->
|
||||||
case MsgType of
|
case MsgType of
|
||||||
chat ->
|
chat ->
|
||||||
select(LServer, From, Start, End, With, RSM, MsgType, DBType);
|
select(LServer, From, From, Start, End, With, RSM, MsgType, DBType);
|
||||||
{groupchat, _Role, _MUCState} ->
|
{groupchat, _Role, _MUCState} ->
|
||||||
select(LServer, To, Start, End, With, RSM, MsgType, DBType)
|
select(LServer, From, To, Start, End, With, RSM, MsgType, DBType)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
select(_LServer, JidRequestor, Start, End, _With, RSM,
|
select(_LServer, JidRequestor, JidArchive, Start, End, _With, RSM,
|
||||||
{groupchat, _Role, #state{config = #config{mam = false},
|
{groupchat, _Role, #state{config = #config{mam = false},
|
||||||
history = History}} = MsgType,
|
history = History}} = MsgType,
|
||||||
_DBType) ->
|
_DBType) ->
|
||||||
@ -944,8 +944,8 @@ select(_LServer, JidRequestor, Start, End, _With, RSM,
|
|||||||
peer = undefined,
|
peer = undefined,
|
||||||
nick = Nick,
|
nick = Nick,
|
||||||
packet = Pkt},
|
packet = Pkt},
|
||||||
MsgType,
|
MsgType, JidRequestor, JidArchive)}],
|
||||||
JidRequestor)}], I+1};
|
I+1};
|
||||||
false ->
|
false ->
|
||||||
{[], I+1}
|
{[], I+1}
|
||||||
end
|
end
|
||||||
@ -961,7 +961,8 @@ select(_LServer, JidRequestor, Start, End, _With, RSM,
|
|||||||
_ ->
|
_ ->
|
||||||
{Msgs, true, L}
|
{Msgs, true, L}
|
||||||
end;
|
end;
|
||||||
select(_LServer, #jid{luser = LUser, lserver = LServer} = JidRequestor,
|
select(_LServer, JidRequestor,
|
||||||
|
#jid{luser = LUser, lserver = LServer} = JidArchive,
|
||||||
Start, End, With, RSM, MsgType, mnesia) ->
|
Start, End, With, RSM, MsgType, mnesia) ->
|
||||||
MS = make_matchspec(LUser, LServer, Start, End, With),
|
MS = make_matchspec(LUser, LServer, Start, End, With),
|
||||||
Msgs = mnesia:dirty_select(archive_msg, MS),
|
Msgs = mnesia:dirty_select(archive_msg, MS),
|
||||||
@ -972,13 +973,13 @@ select(_LServer, #jid{luser = LUser, lserver = LServer} = JidRequestor,
|
|||||||
fun(Msg) ->
|
fun(Msg) ->
|
||||||
{Msg#archive_msg.id,
|
{Msg#archive_msg.id,
|
||||||
jlib:binary_to_integer(Msg#archive_msg.id),
|
jlib:binary_to_integer(Msg#archive_msg.id),
|
||||||
msg_to_el(Msg, MsgType, JidRequestor)}
|
msg_to_el(Msg, MsgType, JidRequestor, JidArchive)}
|
||||||
end, FilteredMsgs), IsComplete, Count};
|
end, FilteredMsgs), IsComplete, Count};
|
||||||
select(LServer, #jid{luser = LUser} = JidRequestor,
|
select(LServer, JidRequestor, #jid{luser = LUser} = JidArchive,
|
||||||
Start, End, With, RSM, MsgType, {odbc, Host}) ->
|
Start, End, With, RSM, MsgType, {odbc, Host}) ->
|
||||||
User = case MsgType of
|
User = case MsgType of
|
||||||
chat -> LUser;
|
chat -> LUser;
|
||||||
{groupchat, _Role, _MUCState} -> jid:to_string(JidRequestor)
|
{groupchat, _Role, _MUCState} -> jid:to_string(JidArchive)
|
||||||
end,
|
end,
|
||||||
{Query, CountQuery} = make_sql_query(User, LServer,
|
{Query, CountQuery} = make_sql_query(User, LServer,
|
||||||
Start, End, With, RSM),
|
Start, End, With, RSM),
|
||||||
@ -1022,8 +1023,7 @@ select(LServer, #jid{luser = LUser} = JidRequestor,
|
|||||||
type = T,
|
type = T,
|
||||||
nick = Nick,
|
nick = Nick,
|
||||||
peer = PeerJid},
|
peer = PeerJid},
|
||||||
MsgType,
|
MsgType, JidRequestor, JidArchive)}]
|
||||||
JidRequestor)}]
|
|
||||||
catch _:Err ->
|
catch _:Err ->
|
||||||
?ERROR_MSG("failed to parse data from SQL: ~p. "
|
?ERROR_MSG("failed to parse data from SQL: ~p. "
|
||||||
"The data was: "
|
"The data was: "
|
||||||
@ -1038,31 +1038,44 @@ select(LServer, #jid{luser = LUser} = JidRequestor,
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
msg_to_el(#archive_msg{timestamp = TS, packet = Pkt1, nick = Nick, peer = Peer},
|
msg_to_el(#archive_msg{timestamp = TS, packet = Pkt1, nick = Nick, peer = Peer},
|
||||||
MsgType, #jid{lserver = LServer} = JidRequestor) ->
|
MsgType, JidRequestor, #jid{lserver = LServer} = JidArchive) ->
|
||||||
Pkt2 = maybe_update_from_to(Pkt1, JidRequestor, Peer, MsgType, Nick),
|
Pkt2 = maybe_update_from_to(Pkt1, JidRequestor, JidArchive, Peer, MsgType,
|
||||||
|
Nick),
|
||||||
Pkt3 = #xmlel{name = <<"forwarded">>,
|
Pkt3 = #xmlel{name = <<"forwarded">>,
|
||||||
attrs = [{<<"xmlns">>, ?NS_FORWARD}],
|
attrs = [{<<"xmlns">>, ?NS_FORWARD}],
|
||||||
children = [fxml:replace_tag_attr(
|
children = [fxml:replace_tag_attr(
|
||||||
<<"xmlns">>, <<"jabber:client">>, Pkt2)]},
|
<<"xmlns">>, <<"jabber:client">>, Pkt2)]},
|
||||||
jlib:add_delay_info(Pkt3, LServer, TS).
|
jlib:add_delay_info(Pkt3, LServer, TS).
|
||||||
|
|
||||||
maybe_update_from_to(#xmlel{children = Els} = Pkt, JidRequestor,
|
maybe_update_from_to(#xmlel{children = Els} = Pkt, JidRequestor, JidArchive,
|
||||||
Peer, {groupchat, Role, _MUCState}, Nick) ->
|
Peer, {groupchat, Role,
|
||||||
Items = case Role of
|
#state{config = #config{anonymous = Anon}}},
|
||||||
moderator when Peer /= undefined ->
|
Nick) ->
|
||||||
|
ExposeJID = case {Peer, JidRequestor} of
|
||||||
|
{undefined, _JidRequestor} ->
|
||||||
|
false;
|
||||||
|
{{U, S, _R}, #jid{luser = U, lserver = S}} ->
|
||||||
|
true;
|
||||||
|
{_Peer, _JidRequestor} when not Anon; Role == moderator ->
|
||||||
|
true;
|
||||||
|
{_Peer, _JidRequestor} ->
|
||||||
|
false
|
||||||
|
end,
|
||||||
|
Items = case ExposeJID of
|
||||||
|
true ->
|
||||||
[#xmlel{name = <<"x">>,
|
[#xmlel{name = <<"x">>,
|
||||||
attrs = [{<<"xmlns">>, ?NS_MUC_USER}],
|
attrs = [{<<"xmlns">>, ?NS_MUC_USER}],
|
||||||
children =
|
children =
|
||||||
[#xmlel{name = <<"item">>,
|
[#xmlel{name = <<"item">>,
|
||||||
attrs = [{<<"jid">>,
|
attrs = [{<<"jid">>,
|
||||||
jid:to_string(Peer)}]}]}];
|
jid:to_string(Peer)}]}]}];
|
||||||
_ ->
|
false ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
Pkt1 = Pkt#xmlel{children = Items ++ Els},
|
Pkt1 = Pkt#xmlel{children = Items ++ Els},
|
||||||
Pkt2 = jlib:replace_from(jid:replace_resource(JidRequestor, Nick), Pkt1),
|
Pkt2 = jlib:replace_from(jid:replace_resource(JidArchive, Nick), Pkt1),
|
||||||
jlib:remove_attr(<<"to">>, Pkt2);
|
jlib:remove_attr(<<"to">>, Pkt2);
|
||||||
maybe_update_from_to(Pkt, _JidRequestor, _Peer, chat, _Nick) ->
|
maybe_update_from_to(Pkt, _JidRequestor, _JidArchive, _Peer, chat, _Nick) ->
|
||||||
Pkt.
|
Pkt.
|
||||||
|
|
||||||
is_bare_copy(#jid{luser = U, lserver = S, lresource = R}, To) ->
|
is_bare_copy(#jid{luser = U, lserver = S, lresource = R}, To) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user