Skip to content

Commit

Permalink
Store the subject author JID, and run muc_filter_message when sending…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
badlop committed Aug 16, 2023
1 parent 2bd61ab commit ffa07c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/mod_muc_room.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 4 additions & 2 deletions src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 15 additions & 5 deletions src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 = [],
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ffa07c6

Please sign in to comment.