24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-12 21:52:07 +02:00

Restore multiple invitations support (#1468)

This commit is contained in:
Evgeniy Khramtsov 2017-01-19 17:26:08 +03:00
parent 3d9997288d
commit 4cf83ca3a7

View File

@ -825,14 +825,15 @@ process_normal_message(From, #message{lang = Lang} = Pkt, StateData) ->
Action = lists:foldl( Action = lists:foldl(
fun(_, {error, _} = Err) -> fun(_, {error, _} = Err) ->
Err; Err;
(#muc_user{invites = [#muc_invite{to = undefined}]}, _) -> (_, {ok, _} = Result) ->
Txt = <<"No 'to' attribute found">>, Result;
{error, xmpp:err_bad_request(Txt, Lang)}; (#muc_user{invites = [_|_] = Invites}, _) ->
(#muc_user{invites = [I]}, _) -> case check_invitation(From, Invites, Lang, StateData) of
{ok, I}; ok ->
(#muc_user{invites = [_|_]}, _) -> {ok, Invites};
Txt = <<"Multiple invitations are not allowed">>, {error, _} = Err ->
{error, xmpp:err_resource_constraint(Txt, Lang)}; Err
end;
(#xdata{type = submit, fields = Fs}, _) -> (#xdata{type = submit, fields = Fs}, _) ->
try {ok, muc_request:decode(Fs)} try {ok, muc_request:decode(Fs)}
catch _:{muc_request, Why} -> catch _:{muc_request, Why} ->
@ -843,8 +844,11 @@ process_normal_message(From, #message{lang = Lang} = Pkt, StateData) ->
Acc Acc
end, ok, xmpp:get_els(Pkt)), end, ok, xmpp:get_els(Pkt)),
case Action of case Action of
{ok, #muc_invite{} = Invitation} -> {ok, [#muc_invite{}|_] = Invitations} ->
process_invitation(From, Pkt, Invitation, StateData); lists:foldl(
fun(Invitation, AccState) ->
process_invitation(From, Invitation, Lang, AccState)
end, StateData, Invitations);
{ok, [{role, participant}]} -> {ok, [{role, participant}]} ->
process_voice_request(From, Pkt, StateData); process_voice_request(From, Pkt, StateData);
{ok, VoiceApproval} -> {ok, VoiceApproval} ->
@ -856,14 +860,9 @@ process_normal_message(From, #message{lang = Lang} = Pkt, StateData) ->
StateData StateData
end. end.
-spec process_invitation(jid(), message(), muc_invite(), state()) -> state(). -spec process_invitation(jid(), muc_invite(), binary(), state()) -> state().
process_invitation(From, Pkt, Invitation, StateData) -> process_invitation(From, Invitation, Lang, StateData) ->
Lang = xmpp:get_lang(Pkt), IJID = route_invitation(From, Invitation, Lang, StateData),
case check_invitation(From, Invitation, Lang, StateData) of
{error, Error} ->
ejabberd_router:route_error(StateData#state.jid, From, Pkt, Error),
StateData;
IJID ->
Config = StateData#state.config, Config = StateData#state.config,
case Config#config.members_only of case Config#config.members_only of
true -> true ->
@ -878,7 +877,6 @@ process_invitation(From, Pkt, Invitation, StateData) ->
end; end;
false -> false ->
StateData StateData
end
end. end.
-spec process_voice_request(jid(), message(), state()) -> state(). -spec process_voice_request(jid(), message(), state()) -> state().
@ -3897,18 +3895,31 @@ send_voice_request(From, Lang, StateData) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Invitation support % Invitation support
-spec check_invitation(jid(), [muc_invite()], binary(), state()) ->
-spec check_invitation(jid(), muc_invite(), binary(), state()) -> {error, stanza_error()} | jid(). ok | {error, stanza_error()}.
check_invitation(From, Invitation, Lang, StateData) -> check_invitation(From, Invitations, Lang, StateData) ->
FAffiliation = get_affiliation(From, StateData), FAffiliation = get_affiliation(From, StateData),
CanInvite = (StateData#state.config)#config.allow_user_invites CanInvite = (StateData#state.config)#config.allow_user_invites orelse
orelse
FAffiliation == admin orelse FAffiliation == owner, FAffiliation == admin orelse FAffiliation == owner,
case CanInvite of case CanInvite of
true ->
case lists:all(
fun(#muc_invite{to = #jid{}}) -> true;
(_) -> false
end, Invitations) of
true ->
ok;
false ->
Txt = <<"No 'to' attribute found in the invitation">>,
{error, xmpp:err_bad_request(Txt, Lang)}
end;
false -> false ->
Txt = <<"Invitations are not allowed in this conference">>, Txt = <<"Invitations are not allowed in this conference">>,
{error, xmpp:err_not_allowed(Txt, Lang)}; {error, xmpp:err_not_allowed(Txt, Lang)}
true -> end.
-spec route_invitation(jid(), muc_invite(), binary(), state()) -> jid().
route_invitation(From, Invitation, Lang, StateData) ->
#muc_invite{to = JID, reason = Reason} = Invitation, #muc_invite{to = JID, reason = Reason} = Invitation,
Invite = Invitation#muc_invite{to = undefined, from = From}, Invite = Invitation#muc_invite{to = undefined, from = From},
Password = case (StateData#state.config)#config.password_protected of Password = case (StateData#state.config)#config.password_protected of
@ -3927,9 +3938,7 @@ check_invitation(From, Invitation, Lang, StateData) ->
Lang, Lang,
<<"~s invites you to the room ~s">>), <<"~s invites you to the room ~s">>),
[jid:to_string(From), [jid:to_string(From),
jid:to_string({StateData#state.room, jid:to_string({StateData#state.room, StateData#state.host, <<"">>})]),
StateData#state.host,
<<"">>})]),
case (StateData#state.config)#config.password_protected of case (StateData#state.config)#config.password_protected of
true -> true ->
<<", ", <<", ",
@ -3948,8 +3957,7 @@ check_invitation(From, Invitation, Lang, StateData) ->
body = xmpp:mk_text(Body), body = xmpp:mk_text(Body),
sub_els = [XUser, XConference]}, sub_els = [XUser, XConference]},
ejabberd_router:route(StateData#state.jid, JID, Msg), ejabberd_router:route(StateData#state.jid, JID, Msg),
JID JID.
end.
%% Handle a message sent to the room by a non-participant. %% Handle a message sent to the room by a non-participant.
%% If it is a decline, send to the inviter. %% If it is a decline, send to the inviter.