mirror of
https://github.com/processone/ejabberd
synced 2025-10-05 19:42:11 +02:00
Support multiple room invitations (#1285)
This commit is contained in:
parent
fe1bf27ef3
commit
d0761039ff
1 changed files with 40 additions and 23 deletions
|
@ -253,20 +253,13 @@ normal_state({route, From, <<"">>,
|
||||||
Err = jlib:make_error_reply(Packet, Error),
|
Err = jlib:make_error_reply(Packet, Error),
|
||||||
ejabberd_router:route(StateData#state.jid, From, Err),
|
ejabberd_router:route(StateData#state.jid, From, Err),
|
||||||
{next_state, normal_state, StateData};
|
{next_state, normal_state, StateData};
|
||||||
IJID ->
|
IJIDs ->
|
||||||
Config = StateData#state.config,
|
Config = StateData#state.config,
|
||||||
case Config#config.members_only of
|
case Config#config.members_only of
|
||||||
true ->
|
true ->
|
||||||
case get_affiliation(IJID, StateData) of
|
NSD = process_invitees(IJIDs, StateData),
|
||||||
none ->
|
store_room(NSD),
|
||||||
NSD = set_affiliation(IJID, member,
|
{next_state, normal_state, NSD};
|
||||||
StateData),
|
|
||||||
send_affiliation(IJID, member,
|
|
||||||
StateData),
|
|
||||||
store_room(NSD),
|
|
||||||
{next_state, normal_state, NSD};
|
|
||||||
_ -> {next_state, normal_state, StateData}
|
|
||||||
end;
|
|
||||||
false -> {next_state, normal_state, StateData}
|
false -> {next_state, normal_state, StateData}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
@ -4914,18 +4907,35 @@ is_invitation(Els) ->
|
||||||
end,
|
end,
|
||||||
false, Els).
|
false, Els).
|
||||||
|
|
||||||
|
process_invitees(Invetees, StateDataIni) ->
|
||||||
|
lists:foldl(
|
||||||
|
fun(IJID, StateData) ->
|
||||||
|
case get_affiliation(IJID, StateData) of
|
||||||
|
none ->
|
||||||
|
NSD = set_affiliation(IJID, member,
|
||||||
|
StateData),
|
||||||
|
send_affiliation(IJID, member,
|
||||||
|
StateData),
|
||||||
|
NSD;
|
||||||
|
_ -> StateData
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
StateDataIni,
|
||||||
|
Invetees).
|
||||||
|
|
||||||
check_invitation(From, Packet, Lang, StateData) ->
|
check_invitation(From, Packet, Lang, StateData) ->
|
||||||
FAffiliation = get_affiliation(From, StateData),
|
FAffiliation = get_affiliation(From, StateData),
|
||||||
CanInvite =
|
CanInvite =
|
||||||
(StateData#state.config)#config.allow_user_invites
|
(StateData#state.config)#config.allow_user_invites
|
||||||
orelse
|
orelse
|
||||||
FAffiliation == admin orelse FAffiliation == owner,
|
FAffiliation == admin orelse FAffiliation == owner,
|
||||||
InviteEl = case fxml:get_subtag_with_xmlns(Packet, <<"x">>, ?NS_MUC_USER) of
|
|
||||||
|
InviteEls = case fxml:get_subtag_with_xmlns(Packet, <<"x">>, ?NS_MUC_USER) of
|
||||||
false ->
|
false ->
|
||||||
Txt1 = <<"No 'x' element found">>,
|
Txt1 = <<"No 'x' element found">>,
|
||||||
throw({error, ?ERRT_BAD_REQUEST(Lang, Txt1)});
|
throw({error, ?ERRT_BAD_REQUEST(Lang, Txt1)});
|
||||||
XEl ->
|
XEl ->
|
||||||
case fxml:get_subtag(XEl, <<"invite">>) of
|
case fxml:get_subtags(XEl, <<"invite">>) of
|
||||||
false ->
|
false ->
|
||||||
Txt2 = <<"No 'invite' element found">>,
|
Txt2 = <<"No 'invite' element found">>,
|
||||||
throw({error, ?ERRT_BAD_REQUEST(Lang, Txt2)});
|
throw({error, ?ERRT_BAD_REQUEST(Lang, Txt2)});
|
||||||
|
@ -4933,20 +4943,17 @@ check_invitation(From, Packet, Lang, StateData) ->
|
||||||
InviteEl1
|
InviteEl1
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
JID = case
|
|
||||||
jid:from_string(fxml:get_tag_attr_s(<<"to">>,
|
|
||||||
InviteEl))
|
|
||||||
of
|
|
||||||
error ->
|
|
||||||
Txt = <<"Incorrect value of 'to' attribute">>,
|
|
||||||
throw({error, ?ERRT_JID_MALFORMED(Lang, Txt)});
|
|
||||||
JID1 -> JID1
|
|
||||||
end,
|
|
||||||
case CanInvite of
|
case CanInvite of
|
||||||
false ->
|
false ->
|
||||||
Txt3 = <<"Invitations are not allowed in this conference">>,
|
Txt3 = <<"Invitations are not allowed in this conference">>,
|
||||||
throw({error, ?ERRT_NOT_ALLOWED(Lang, Txt3)});
|
throw({error, ?ERRT_NOT_ALLOWED(Lang, Txt3)});
|
||||||
true ->
|
true ->
|
||||||
|
process_invitations(From, InviteEls, Lang, StateData)
|
||||||
|
end.
|
||||||
|
|
||||||
|
process_invitations(From, InviteEls, Lang, StateData) ->
|
||||||
|
lists:map(
|
||||||
|
fun(InviteEl) ->
|
||||||
Reason = fxml:get_path_s(InviteEl,
|
Reason = fxml:get_path_s(InviteEl,
|
||||||
[{elem, <<"reason">>}, cdata]),
|
[{elem, <<"reason">>}, cdata]),
|
||||||
ContinueEl = case fxml:get_path_s(InviteEl,
|
ContinueEl = case fxml:get_path_s(InviteEl,
|
||||||
|
@ -5015,9 +5022,19 @@ check_invitation(From, Packet, Lang, StateData) ->
|
||||||
<<"">>})}],
|
<<"">>})}],
|
||||||
children = [{xmlcdata, Reason}]},
|
children = [{xmlcdata, Reason}]},
|
||||||
Body]},
|
Body]},
|
||||||
|
JID = case
|
||||||
|
jid:from_string(fxml:get_tag_attr_s(<<"to">>,
|
||||||
|
InviteEl))
|
||||||
|
of
|
||||||
|
error ->
|
||||||
|
Txt = <<"Incorrect value of 'to' attribute">>,
|
||||||
|
throw({error, ?ERRT_JID_MALFORMED(Lang, Txt)});
|
||||||
|
JID1 -> JID1
|
||||||
|
end,
|
||||||
ejabberd_router:route(StateData#state.jid, JID, Msg),
|
ejabberd_router:route(StateData#state.jid, JID, Msg),
|
||||||
JID
|
JID
|
||||||
end.
|
end,
|
||||||
|
InviteEls).
|
||||||
|
|
||||||
%% 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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue