Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ <h1>
REST API Plugin Changelog
</h1>

<p><b>1.9.1</b> (tbd)</p>
<ul>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/148'>#148</a>] - Example of MUC invite contains escaped characters</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/146'>#146</a>] - Chatroom 'affiliation' URL template clash</li>
</ul>

<p><b>1.9.0</b> August 4, 2022</p>
<ul>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/141'>#141</a>] - Remove boilerplate code for managing MUC room affiliations</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,18 @@ public MUCRoomMessageEntities getRoomHistory(String roomName, String serviceName
* the service name
* @param roomName
* the room name
* @param mucInvitationEntity
* @param mucInvitationsEntity
* the invitation entity containing invitation reason and jids to invite
* @throws ServiceException
* the service exception
*/
public void inviteUsersAndOrGroups(String serviceName, String roomName, MUCInvitationEntity mucInvitationEntity)
public void inviteUsersAndOrGroups(String serviceName, String roomName, MUCInvitationsEntity mucInvitationsEntity)
throws ServiceException {
MUCRoom room = getRoom(serviceName, roomName);

// First determine where to send all the invitations
Set<JID> targetJIDs = new HashSet<>();
for (String jidString : mucInvitationEntity.getJidsToInvite()) {
for (String jidString : mucInvitationsEntity.getJidsToInvite()) {
JID jid = UserUtils.checkAndGetJID(jidString);
// Is it a group? Then unpack and send to every single group member.
Group g = UserUtils.getGroupIfIsGroup(jid);
Expand All @@ -575,7 +575,7 @@ public void inviteUsersAndOrGroups(String serviceName, String roomName, MUCInvit
// And now send
for (JID jid : targetJIDs) {
try {
room.sendInvitation(jid, mucInvitationEntity.getReason(), room.getRole(), null);
room.sendInvitation(jid, mucInvitationsEntity.getReason(), room.getRole(), null);
} catch (ForbiddenException | CannotBeInvitedException e) {
throw new ServiceException("Could not invite user", jid.toString(), ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@

package org.jivesoftware.openfire.plugin.rest.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "mucInvitation")
public class MUCInvitationEntity {

String reason;

private List<String> jidsToInvite;

public MUCInvitationEntity() {
}

Expand All @@ -44,19 +38,4 @@ public String getReason() {
public void setReason(String reason) {
this.reason = reason;
}

@XmlElementWrapper(name = "jidsToInvite")
@XmlElement(name = "jid")
@JsonProperty(value = "jidsToInvite")
@Schema(description = "The JIDs and/or names of the users and groups to invite into the room", example = "<jidsToInvite><jid>jane@example.org</jid></jidsToInvite>")
public List<String> getJidsToInvite() {
if (jidsToInvite == null) {
jidsToInvite = new ArrayList<>();
}
return jidsToInvite;
}

public void setJidsToInvite(List<String> jidsToInvite) {
this.jidsToInvite = jidsToInvite;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jivesoftware.openfire.plugin.rest.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "mucInvitations")
public class MUCInvitationsEntity extends MUCInvitationEntity
{
public MUCInvitationsEntity() {
super();
}

private List<String> jidsToInvite;

@XmlElementWrapper(name = "jidsToInvite")
@XmlElement(name = "jid")
@JsonProperty(value = "jidsToInvite")
@Schema(description = "The JIDs and/or names of the users and groups to invite into the room")
public List<String> getJidsToInvite() {
if (jidsToInvite == null) {
jidsToInvite = new ArrayList<>();
}
return jidsToInvite;
}

public void setJidsToInvite(List<String> jidsToInvite) {
this.jidsToInvite = jidsToInvite;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.List;
import java.util.stream.Collectors;

@Path("restapi/v1/chatrooms/{roomName}/{affiliation}")
@Path("restapi/v1/chatrooms/{roomName}/{affiliation: (admins|members|outcasts|owners)}")
@Tag(name = "Chat room", description = "Managing Multi-User chat rooms.")
public class MUCRoomAffiliationsService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,12 @@ public Response inviteUserOrGroupToMUCRoom(
@RequestBody(description = "The invitation message to send and whom to send it to.", required = true) MUCInvitationEntity mucInvitationEntity)
throws ServiceException
{
if (!mucInvitationEntity.getJidsToInvite().contains(jid)) {
mucInvitationEntity.getJidsToInvite().add(jid);
final MUCInvitationsEntity multiple = new MUCInvitationsEntity();
multiple.setReason(mucInvitationEntity.getReason());
if (!multiple.getJidsToInvite().contains(jid)) {
multiple.getJidsToInvite().add(jid);
}
MUCRoomController.getInstance().inviteUsersAndOrGroups(serviceName, roomName, mucInvitationEntity);
MUCRoomController.getInstance().inviteUsersAndOrGroups(serviceName, roomName, multiple);
return Response.status(Status.OK).build();
}

Expand All @@ -262,10 +264,10 @@ public Response inviteUserOrGroupToMUCRoom(
public Response inviteUsersAndOrGroupsToMUCRoom(
@Parameter(description = "The name of the chat room in which to invite a user or group", example = "lobby", required = true) @PathParam("roomName") String roomName,
@Parameter(description = "The name of the chat room's MUC service.", example = "conference", required = false) @DefaultValue("conference") @QueryParam("servicename") String serviceName,
@RequestBody(description = "The invitation message to send and whom to send it to.", required = true) MUCInvitationEntity mucInvitationEntity)
@RequestBody(description = "The invitation message to send and whom to send it to.", required = true) MUCInvitationsEntity mucInvitationsEntity)
throws ServiceException
{
MUCRoomController.getInstance().inviteUsersAndOrGroups(serviceName, roomName, mucInvitationEntity);
MUCRoomController.getInstance().inviteUsersAndOrGroups(serviceName, roomName, mucInvitationsEntity);
return Response.status(Status.OK).build();
}

Expand Down