use of org.jivesoftware.openfire.muc.CannotBeInvitedException in project Openfire by igniterealtime.
the class LocalMUCRoom method sendInvitation.
@Override
public void sendInvitation(JID to, String reason, MUCRole senderRole, List<Element> extensions) throws ForbiddenException, CannotBeInvitedException {
if (!isMembersOnly() || canOccupantsInvite() || MUCRole.Affiliation.admin == senderRole.getAffiliation() || MUCRole.Affiliation.owner == senderRole.getAffiliation()) {
// If the room is not members-only OR if the room is members-only and anyone can send
// invitations or the sender is an admin or an owner, then send the invitation
Message message = new Message();
message.setFrom(role.getRoleAddress());
message.setTo(to);
if (((MultiUserChatServiceImpl) mucService).getMUCDelegate() != null) {
switch(((MultiUserChatServiceImpl) mucService).getMUCDelegate().sendingInvitation(this, to, senderRole.getUserAddress(), reason)) {
case HANDLED_BY_DELEGATE:
//if the delegate is taking care of it, there's nothing for us to do
return;
case HANDLED_BY_OPENFIRE:
//continue as normal if we're asked to handle it
break;
case REJECTED:
//we can't invite that person
throw new CannotBeInvitedException();
}
}
// Add a list of extensions sent with the original message invitation (if any)
if (extensions != null) {
for (Element element : extensions) {
element.setParent(null);
message.getElement().add(element);
}
}
Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
// ChatUser will be null if the room itself (ie. via admin console) made the request
if (senderRole.getUserAddress() != null) {
frag.addElement("invite").addAttribute("from", senderRole.getUserAddress().toBareJID());
}
if (reason != null && reason.length() > 0) {
Element invite = frag.element("invite");
if (invite == null) {
invite = frag.addElement("invite");
}
invite.addElement("reason").setText(reason);
}
if (isPasswordProtected()) {
frag.addElement("password").setText(getPassword());
}
// Include the jabber:x:conference information for backward compatibility
frag = message.addChildElement("x", "jabber:x:conference");
frag.addAttribute("jid", role.getRoleAddress().toBareJID());
// Send the message with the invitation
router.route(message);
} else {
throw new ForbiddenException();
}
}
Aggregations