Store the subject author JID, and run muc_filter_message when sending subject (#3397)

When changing the room subject, store the original author JID,
so later it can be provided in the hook and mod_room_occupantid
can use it to calculate and provide the occupant id

This is noticeable when a new occupant joins an existing room,
and receives the room subject.
This commit is contained in:
Badlop 2023-08-15 12:44:41 +02:00
parent 2bd61abd71
commit ffa07c649b
3 changed files with 20 additions and 8 deletions

View File

@ -125,7 +125,7 @@
roles = #{} :: roles(),
history = #lqueue{} :: lqueue(),
subject = [] :: [text()],
subject_author = <<"">> :: binary(),
subject_author = {<<"">>, #jid{}} :: {binary(), jid()},
hats_users = #{} :: map(), % FIXME on OTP 21+: #{ljid() => #{binary() => binary()}},
just_created = erlang:system_time(microsecond) :: true | integer(),
activity = treap:empty() :: treap:treap(),

View File

@ -1191,8 +1191,10 @@ opts_to_binary(Opts) ->
{password, iolist_to_binary(Pass)};
({subject, [C|_] = Subj}) when is_integer(C), C >= 0, C =< 255 ->
{subject, iolist_to_binary(Subj)};
({subject_author, Author}) ->
{subject_author, iolist_to_binary(Author)};
({subject_author, {AuthorNick, AuthorJID}}) ->
{subject_author, {iolist_to_binary(AuthorNick), AuthorJID}};
({subject_author, AuthorNick}) -> % ejabberd 23.04 or older
{subject_author, {iolist_to_binary(AuthorNick), #jid{}}};
({allow_private_messages, Value}) -> % ejabberd 23.04 or older
Value2 = case Value of
true -> anyone;

View File

@ -1053,7 +1053,7 @@ process_groupchat_message(#message{from = From, lang = Lang} = Packet, StateData
true ->
NSD =
StateData#state{subject = Subject,
subject_author = FromNick},
subject_author = {FromNick, From}},
store_room(NSD),
{NSD, true};
_ -> {StateData, false}
@ -3000,14 +3000,24 @@ send_history(JID, History, StateData) ->
end, History).
-spec send_subject(jid(), state()) -> ok.
send_subject(JID, #state{subject_author = Nick} = StateData) ->
send_subject(JID, #state{subject_author = {Nick, AuthorJID}} = StateData) ->
Subject = case StateData#state.subject of
[] -> [#text{}];
[_|_] = S -> S
end,
Packet = #message{from = jid:replace_resource(StateData#state.jid, Nick),
Packet = #message{from = AuthorJID,
to = JID, type = groupchat, subject = Subject},
ejabberd_router:route(Packet).
case ejabberd_hooks:run_fold(muc_filter_message,
StateData#state.server_host,
Packet,
[StateData, Nick]) of
drop ->
ok;
NewPacket1 ->
FromRoomNick = jid:replace_resource(StateData#state.jid, Nick),
NewPacket2 = xmpp:set_from(NewPacket1, FromRoomNick),
ejabberd_router:route(NewPacket2)
end.
-spec check_subject(message()) -> [text()].
check_subject(#message{subject = [_|_] = Subj, body = [],
@ -4294,7 +4304,7 @@ expand_opts(CompactOpts) ->
{Pos+1, [{Field, Val}|Opts]}
end
end, {2, []}, Fields),
SubjectAuthor = proplists:get_value(subject_author, CompactOpts, <<"">>),
SubjectAuthor = proplists:get_value(subject_author, CompactOpts, {<<"">>, #jid{}}),
Subject = proplists:get_value(subject, CompactOpts, <<"">>),
Subscribers = proplists:get_value(subscribers, CompactOpts, []),
HibernationTime = proplists:get_value(hibernation_time, CompactOpts, 0),