mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-02 21:17:12 +02:00
Restore multiple invitations support (#1468)
This commit is contained in:
parent
3d9997288d
commit
4cf83ca3a7
|
@ -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,29 +860,23 @@ 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
|
Config = StateData#state.config,
|
||||||
{error, Error} ->
|
case Config#config.members_only of
|
||||||
ejabberd_router:route_error(StateData#state.jid, From, Pkt, Error),
|
true ->
|
||||||
StateData;
|
case get_affiliation(IJID, StateData) of
|
||||||
IJID ->
|
none ->
|
||||||
Config = StateData#state.config,
|
NSD = set_affiliation(IJID, member, StateData),
|
||||||
case Config#config.members_only of
|
send_affiliation(IJID, member, StateData),
|
||||||
true ->
|
store_room(NSD),
|
||||||
case get_affiliation(IJID, StateData) of
|
NSD;
|
||||||
none ->
|
_ ->
|
||||||
NSD = set_affiliation(IJID, member, StateData),
|
|
||||||
send_affiliation(IJID, member, StateData),
|
|
||||||
store_room(NSD),
|
|
||||||
NSD;
|
|
||||||
_ ->
|
|
||||||
StateData
|
|
||||||
end;
|
|
||||||
false ->
|
|
||||||
StateData
|
StateData
|
||||||
end
|
end;
|
||||||
|
false ->
|
||||||
|
StateData
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec process_voice_request(jid(), message(), state()) -> state().
|
-spec process_voice_request(jid(), message(), state()) -> state().
|
||||||
|
@ -3897,60 +3895,70 @@ 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 ->
|
|
||||||
#muc_invite{to = JID, reason = Reason} = Invitation,
|
|
||||||
Invite = Invitation#muc_invite{to = undefined, from = From},
|
|
||||||
Password = case (StateData#state.config)#config.password_protected of
|
|
||||||
true ->
|
|
||||||
(StateData#state.config)#config.password;
|
|
||||||
false ->
|
|
||||||
undefined
|
|
||||||
end,
|
|
||||||
XUser = #muc_user{password = Password, invites = [Invite]},
|
|
||||||
XConference = #x_conference{jid = jid:make(StateData#state.room,
|
|
||||||
StateData#state.host),
|
|
||||||
reason = Reason},
|
|
||||||
Body = iolist_to_binary(
|
|
||||||
[io_lib:format(
|
|
||||||
translate:translate(
|
|
||||||
Lang,
|
|
||||||
<<"~s invites you to the room ~s">>),
|
|
||||||
[jid:to_string(From),
|
|
||||||
jid:to_string({StateData#state.room,
|
|
||||||
StateData#state.host,
|
|
||||||
<<"">>})]),
|
|
||||||
case (StateData#state.config)#config.password_protected of
|
|
||||||
true ->
|
|
||||||
<<", ",
|
|
||||||
(translate:translate(
|
|
||||||
Lang, <<"the password is">>))/binary,
|
|
||||||
" '",
|
|
||||||
((StateData#state.config)#config.password)/binary,
|
|
||||||
"'">>;
|
|
||||||
_ -> <<"">>
|
|
||||||
end,
|
|
||||||
case Reason of
|
|
||||||
<<"">> -> <<"">>;
|
|
||||||
_ -> <<" (", Reason/binary, ") ">>
|
|
||||||
end]),
|
|
||||||
Msg = #message{type = normal,
|
|
||||||
body = xmpp:mk_text(Body),
|
|
||||||
sub_els = [XUser, XConference]},
|
|
||||||
ejabberd_router:route(StateData#state.jid, JID, Msg),
|
|
||||||
JID
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec route_invitation(jid(), muc_invite(), binary(), state()) -> jid().
|
||||||
|
route_invitation(From, Invitation, Lang, StateData) ->
|
||||||
|
#muc_invite{to = JID, reason = Reason} = Invitation,
|
||||||
|
Invite = Invitation#muc_invite{to = undefined, from = From},
|
||||||
|
Password = case (StateData#state.config)#config.password_protected of
|
||||||
|
true ->
|
||||||
|
(StateData#state.config)#config.password;
|
||||||
|
false ->
|
||||||
|
undefined
|
||||||
|
end,
|
||||||
|
XUser = #muc_user{password = Password, invites = [Invite]},
|
||||||
|
XConference = #x_conference{jid = jid:make(StateData#state.room,
|
||||||
|
StateData#state.host),
|
||||||
|
reason = Reason},
|
||||||
|
Body = iolist_to_binary(
|
||||||
|
[io_lib:format(
|
||||||
|
translate:translate(
|
||||||
|
Lang,
|
||||||
|
<<"~s invites you to the room ~s">>),
|
||||||
|
[jid:to_string(From),
|
||||||
|
jid:to_string({StateData#state.room, StateData#state.host, <<"">>})]),
|
||||||
|
case (StateData#state.config)#config.password_protected of
|
||||||
|
true ->
|
||||||
|
<<", ",
|
||||||
|
(translate:translate(
|
||||||
|
Lang, <<"the password is">>))/binary,
|
||||||
|
" '",
|
||||||
|
((StateData#state.config)#config.password)/binary,
|
||||||
|
"'">>;
|
||||||
|
_ -> <<"">>
|
||||||
|
end,
|
||||||
|
case Reason of
|
||||||
|
<<"">> -> <<"">>;
|
||||||
|
_ -> <<" (", Reason/binary, ") ">>
|
||||||
|
end]),
|
||||||
|
Msg = #message{type = normal,
|
||||||
|
body = xmpp:mk_text(Body),
|
||||||
|
sub_els = [XUser, XConference]},
|
||||||
|
ejabberd_router:route(StateData#state.jid, JID, Msg),
|
||||||
|
JID.
|
||||||
|
|
||||||
%% 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.
|
||||||
%% Otherwise, an error message is sent to the sender.
|
%% Otherwise, an error message is sent to the sender.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user