Skip to content

Commit

Permalink
fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
deleolajide committed Oct 14, 2021
1 parent 61b07fb commit 845f226
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
version=$(echo ${{ github.ref }} | cut -d '/' -f3 | cut -c 2-)
echo "::set-output name=version::$version"
echo "version is '$version'"
rel_id=$(curl -sL https://api.github.com/repos/${{github.repository}}/releases?access_token=${{ secrets.GITHUB_TOKEN }} | jq -r --arg TAG "$tag" '.[] | select(.tag_name==$TAG) | .id')
rel_id=$(curl -sL https://api.github.com/repos/${{github.repository}}/releases | jq -r --arg TAG "$tag" '.[] | select(.tag_name==$TAG) | .id')
echo ::set-output name=rel_id::$rel_id
echo "rel_id is '$rel_id'"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.6.0</version>
<version>4.6.1</version>
</parent>

<groupId>org.igniterealtime.openfire</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws

// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
room.setRolesToBroadcastPresence(MUCRoomUtils.convertStringsToRoles(mucRoomEntity.getBroadcastPresenceRoles()));
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
room.setRolesToBroadcastPresence(new ArrayList<>());
}
// Set all roles
setRoles(room, mucRoomEntity);
Expand Down Expand Up @@ -481,8 +481,7 @@ public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room, boolean expand) {
mucRoomEntity.setAdminGroups(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
mucRoomEntity.setMemberGroups(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
mucRoomEntity.setOutcastGroups(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));

mucRoomEntity.setBroadcastPresenceRoles(room.getRolesToBroadcastPresence());
mucRoomEntity.setBroadcastPresenceRoles(MUCRoomUtils.convertRolesToStringList(room.getRolesToBroadcastPresence()));

mucRoomEntity.setCreationDate(room.getCreationDate());
mucRoomEntity.setModificationDate(room.getModificationDate());
Expand Down
161 changes: 113 additions & 48 deletions src/java/org/jivesoftware/openfire/plugin/rest/utils/MUCRoomUtils.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,133 @@
package org.jivesoftware.openfire.plugin.rest.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;

/**
* The Class MUCRoomUtils.
*/
public class MUCRoomUtils {

/**
* Instantiates a new MUC room utils.
*/
private MUCRoomUtils() {
throw new AssertionError();
}
/**
* Instantiates a new MUC room utils.
*/
private MUCRoomUtils() {
throw new AssertionError();
}

/**
* Convert jids to string list.
* In case the jid is not bare (=it is a group jid) exclude it
*
* @param jids
* the jids
* @return the array list< string>
*/
public static List<String> convertJIDsToStringList(Collection<JID> jids) {
List<String> result = new ArrayList<String>();
/**
* Convert jids to string list.
* In case the jid is not bare (=it is a group jid) exclude it
*
* @param jids
* the jids
* @return the array list< string>
*/
public static List<String> convertJIDsToStringList(Collection<JID> jids) {
List<String> result = new ArrayList<String>();

for (JID jid : jids) {
if (jid.getResource() == null) result.add(jid.toBareJID());
}
return result;
}
for (JID jid : jids) {
if (jid.getResource() == null) result.add(jid.toBareJID());
}
return result;
}

/**
* Convert groups to string list
* @param groups
* the groups
* @return the array list of the group names
*/
public static List<String> convertGroupsToStringList(Collection<Group> groups) {
List<String> result = new ArrayList<String>();
for (Group group : groups) {
result.add(group.getName());
}
return result;
}
/**
* Convert groups to string list
* @param groups
* the groups
* @return the array list of the group names
*/
public static List<String> convertGroupsToStringList(Collection<Group> groups) {
List<String> result = new ArrayList<String>();
for (Group group : groups) {
result.add(group.getName());
}
return result;
}

/**
* Convert strings to jids.
*
* @param jids
* the jids
* @return the list<jid>
*/
public static List<JID> convertStringsToJIDs(List<String> jids) {
List<JID> result = new ArrayList<JID>();
/**
* Convert strings to jids.
*
* @param jids
* the jids
* @return the list<jid>
*/
public static List<JID> convertStringsToJIDs(List<String> jids) {
List<JID> result = new ArrayList<JID>();

for (String jidString : jids) {
result.add(new JID(jidString));
}
return result;
}
for (String jidString : jids) {
result.add(new JID(jidString));
}
return result;
}

/**
* Convert MUCRole.role instances to string list.
*
* @param roles
* the roles
* @return the array list<string>
*/
public static List<String> convertRolesToStringList(Collection<MUCRole.Role> roles) {
return roles.stream()
.map(MUCRole.Role::toString)
.collect(Collectors.toList());
}

/**
* Convert string instances to a MUCRole.role list.
*
* @param roles
* the roles
* @return the array list<MUCRole.role>
*/
public static List<MUCRole.Role> convertStringsToRoles(Collection<String> roles) {
return roles.stream()
.map(MUCRole.Role::valueOf)
.collect(Collectors.toList());
}

/**
* Wrapper around MUCRoom::send
*
* Attempts to call the legacy implementation of MUCRoom::send, if an Openfire version < 4.6 is used.
*/
public static void send(MUCRoom room, Packet packet, MUCRole role)
throws InvocationTargetException, IllegalAccessException {
Method legacySend = legacySendMethod();

if (legacySend != null) {
legacySend.invoke(room, packet); // Openfire < 4.6
} else {
room.send(packet, role); // Openfire >= 4.6
}
}

/**
* Attempts to find the legacy MUCRoom::send method signature
* depending on the used Openfire version via reflection.
*
* Openfire versions < 4.6 offer the MUCRoom::send function with one parameters,
* while later versions expect two.
*
* @return the legacy MUCRoom::send method, if present, else null
*/
private static Method legacySendMethod() {
try {
return MUCRoom.class.getMethod("send", Packet.class);
} catch (NoSuchMethodException e) {
return null;
}
}
}

0 comments on commit 845f226

Please sign in to comment.