mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-28 17:38:54 +01:00
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:
parent
2bd61abd71
commit
ffa07c649b
@ -125,7 +125,7 @@
|
|||||||
roles = #{} :: roles(),
|
roles = #{} :: roles(),
|
||||||
history = #lqueue{} :: lqueue(),
|
history = #lqueue{} :: lqueue(),
|
||||||
subject = [] :: [text()],
|
subject = [] :: [text()],
|
||||||
subject_author = <<"">> :: binary(),
|
subject_author = {<<"">>, #jid{}} :: {binary(), jid()},
|
||||||
hats_users = #{} :: map(), % FIXME on OTP 21+: #{ljid() => #{binary() => binary()}},
|
hats_users = #{} :: map(), % FIXME on OTP 21+: #{ljid() => #{binary() => binary()}},
|
||||||
just_created = erlang:system_time(microsecond) :: true | integer(),
|
just_created = erlang:system_time(microsecond) :: true | integer(),
|
||||||
activity = treap:empty() :: treap:treap(),
|
activity = treap:empty() :: treap:treap(),
|
||||||
|
@ -1191,8 +1191,10 @@ opts_to_binary(Opts) ->
|
|||||||
{password, iolist_to_binary(Pass)};
|
{password, iolist_to_binary(Pass)};
|
||||||
({subject, [C|_] = Subj}) when is_integer(C), C >= 0, C =< 255 ->
|
({subject, [C|_] = Subj}) when is_integer(C), C >= 0, C =< 255 ->
|
||||||
{subject, iolist_to_binary(Subj)};
|
{subject, iolist_to_binary(Subj)};
|
||||||
({subject_author, Author}) ->
|
({subject_author, {AuthorNick, AuthorJID}}) ->
|
||||||
{subject_author, iolist_to_binary(Author)};
|
{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
|
({allow_private_messages, Value}) -> % ejabberd 23.04 or older
|
||||||
Value2 = case Value of
|
Value2 = case Value of
|
||||||
true -> anyone;
|
true -> anyone;
|
||||||
|
@ -1053,7 +1053,7 @@ process_groupchat_message(#message{from = From, lang = Lang} = Packet, StateData
|
|||||||
true ->
|
true ->
|
||||||
NSD =
|
NSD =
|
||||||
StateData#state{subject = Subject,
|
StateData#state{subject = Subject,
|
||||||
subject_author = FromNick},
|
subject_author = {FromNick, From}},
|
||||||
store_room(NSD),
|
store_room(NSD),
|
||||||
{NSD, true};
|
{NSD, true};
|
||||||
_ -> {StateData, false}
|
_ -> {StateData, false}
|
||||||
@ -3000,14 +3000,24 @@ send_history(JID, History, StateData) ->
|
|||||||
end, History).
|
end, History).
|
||||||
|
|
||||||
-spec send_subject(jid(), state()) -> ok.
|
-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
|
Subject = case StateData#state.subject of
|
||||||
[] -> [#text{}];
|
[] -> [#text{}];
|
||||||
[_|_] = S -> S
|
[_|_] = S -> S
|
||||||
end,
|
end,
|
||||||
Packet = #message{from = jid:replace_resource(StateData#state.jid, Nick),
|
Packet = #message{from = AuthorJID,
|
||||||
to = JID, type = groupchat, subject = Subject},
|
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()].
|
-spec check_subject(message()) -> [text()].
|
||||||
check_subject(#message{subject = [_|_] = Subj, body = [],
|
check_subject(#message{subject = [_|_] = Subj, body = [],
|
||||||
@ -4294,7 +4304,7 @@ expand_opts(CompactOpts) ->
|
|||||||
{Pos+1, [{Field, Val}|Opts]}
|
{Pos+1, [{Field, Val}|Opts]}
|
||||||
end
|
end
|
||||||
end, {2, []}, Fields),
|
end, {2, []}, Fields),
|
||||||
SubjectAuthor = proplists:get_value(subject_author, CompactOpts, <<"">>),
|
SubjectAuthor = proplists:get_value(subject_author, CompactOpts, {<<"">>, #jid{}}),
|
||||||
Subject = proplists:get_value(subject, CompactOpts, <<"">>),
|
Subject = proplists:get_value(subject, CompactOpts, <<"">>),
|
||||||
Subscribers = proplists:get_value(subscribers, CompactOpts, []),
|
Subscribers = proplists:get_value(subscribers, CompactOpts, []),
|
||||||
HibernationTime = proplists:get_value(hibernation_time, CompactOpts, 0),
|
HibernationTime = proplists:get_value(hibernation_time, CompactOpts, 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user