Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OF-2918: Expose numeric MUC room ID in events #2639

Merged
merged 1 commit into from
Jan 6, 2025
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Jive Software, 2017-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,32 +102,32 @@ public static void privateMessageRecieved(JID toJID, JID fromJID, Message messag
}
}

public static void roomCreated(JID roomJID) {
public static void roomCreated(long roomID, JID roomJID) {
for (MUCEventListener listener : listeners) {
try {
listener.roomCreated(roomJID);
listener.roomCreated(roomID, roomJID);
} catch (Exception e) {
Log.warn("An exception occurred while dispatching a 'roomCreated' event!", e);
Log.warn("An exception occurred while dispatching a 'roomCreated' event for room {} ({})!", roomJID, roomID, e);
}
}
}

public static void roomDestroyed(JID roomJID) {
public static void roomDestroyed(long roomID, JID roomJID) {
for (MUCEventListener listener : listeners) {
try {
listener.roomDestroyed(roomJID);
listener.roomDestroyed(roomID, roomJID);
} catch (Exception e) {
Log.warn("An exception occurred while dispatching a 'roomDestroyed' event!", e);
Log.warn("An exception occurred while dispatching a 'roomDestroyed' event for room {} ({})!", roomJID, roomID, e);
}
}
}

public static void roomClearChatHistory(JID roomJID) {
public static void roomClearChatHistory(long roomID, JID roomJID) {
for (MUCEventListener listener : listeners) {
try {
listener.roomClearChatHistory(roomJID);
listener.roomClearChatHistory(roomID, roomJID);
} catch (Exception e) {
Log.warn("An exception occurred while dispatching a 'roomClearChatHistory' event for room {}!", roomJID, e);
Log.warn("An exception occurred while dispatching a 'roomClearChatHistory' event for room {} ({})!", roomJID, roomID, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2008 Jive Software, 2017-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,8 @@
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;

import javax.annotation.Nonnull;

/**
* Interface to listen for MUC events. Use the {@link MUCEventDispatcher#addListener(MUCEventListener)}
* method to register for events.
Expand All @@ -32,21 +34,21 @@ public interface MUCEventListener {
*
* @param roomJID JID of the room that was created.
*/
void roomCreated(JID roomJID);
void roomCreated(final long roomID, final @Nonnull JID roomJID);

/**
* Event triggered when a room was destroyed.
*
* @param roomJID JID of the room that was destroyed.
*/
void roomDestroyed(JID roomJID);
void roomDestroyed(final long roomID, final @Nonnull JID roomJID);

/**
* Event triggered when a clear chat history command was issued.
*
* @param roomJID JID of the room to clear chat history.
*/
void roomClearChatHistory(JID roomJID);
void roomClearChatHistory(final long roomID, final @Nonnull JID roomJID);

/**
* Event triggered when a new occupant joins a room.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software, 2016-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2016-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public CompletableFuture<Void> clearChatHistory() {
// Remove the history of the room from memory (preventing it to pop up in a new room by the same name).
roomHistory.purge();
// Fire event to clear chat room history
MUCEventDispatcher.roomClearChatHistory(getJID());
MUCEventDispatcher.roomClearChatHistory(getID(), getJID());
});
}

Expand Down Expand Up @@ -1446,10 +1446,10 @@ public void destroyRoom(JID alternateJID, String password, String reason) {
roomHistory.purge();
// If we are not preserving room history on deletion, fire event to clear chat room history
if(!preserveHistOnRoomDeletion) {
MUCEventDispatcher.roomClearChatHistory(getJID());
MUCEventDispatcher.roomClearChatHistory(getID(), getJID());
}
// Fire event that the room has been destroyed
MUCEventDispatcher.roomDestroyed(getJID());
MUCEventDispatcher.roomDestroyed(getID(), getJID());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2016-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -402,7 +402,8 @@ public void entryRemoved(@Nonnull String key, @Nullable MUCRoom oldValue, @Nonnu
localRooms.remove(key);
final MultiUserChatService service = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName);
if (service != null) {
service.getOccupantManager().roomDestroyed(new JID(key, service.getServiceDomain(), null));
final long roomID = -1; // Unused by OccupantManager.
service.getOccupantManager().roomDestroyed(roomID, new JID(key, service.getServiceDomain(), null));
}
}

Expand All @@ -415,7 +416,8 @@ public void entryEvicted(@Nonnull String key, @Nullable MUCRoom oldValue, @Nonnu
localRooms.remove(key);
final MultiUserChatService service = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName);
if (service != null) {
service.getOccupantManager().roomDestroyed(new JID(key, service.getServiceDomain(), null));
final long roomID = -1; // Unused by OccupantManager.
service.getOccupantManager().roomDestroyed(roomID, new JID(key, service.getServiceDomain(), null));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software, 2016-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2016-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1963,7 +1963,7 @@ public MUCRoom getChatRoom(@Nonnull final String roomName, @Nonnull final JID us
}
if (created) {
// Fire event that a new room has been created
MUCEventDispatcher.roomCreated(room.getSelfRepresentation().getOccupantJID());
MUCEventDispatcher.roomCreated(room.getID(), room.getSelfRepresentation().getOccupantJID());
}
if (loaded || created) {
// Initiate FMUC, when enabled.
Expand Down Expand Up @@ -3325,6 +3325,7 @@ public void leftCluster(byte[] nodeID)
Log.info("Room '{}' was lost from the data structure that's shared in the cluster (the cache). This room is now considered 'gone' for this cluster node. Occupants will be informed.", lostRoomName);
final Set<OccupantManager.Occupant> occupants = occupantManager.occupantsForRoomByNode(lostRoomName, XMPPServer.getInstance().getNodeID(), true);
final JID roomJID = new JID(lostRoomName, fullServiceName, null);
final long roomID = -1; // As this value is currently not used by OccupantManager, we can avoid the complexity in having it looked up.
for (final OccupantManager.Occupant occupant : occupants) {
try {
// Send a presence stanza of type "unavailable" to the occupant
Expand All @@ -3349,7 +3350,7 @@ public void leftCluster(byte[] nodeID)
}
}
// Clean up the locally maintained bookkeeping.
occupantManager.roomDestroyed(roomJID);
occupantManager.roomDestroyed(roomID, roomJID);
removeChatRoom(lostRoomName);
} catch (Exception e) {
Log.warn("Unable to inform occupants on local cluster node that they are being removed from room '{}' because of a (cluster) error.", lostRoomName, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2021-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -937,12 +937,13 @@ public Map<Occupant, NodeID> getNodeByLocalOccupant()
}

@Override
public void roomCreated(JID roomJID) {
public void roomCreated(final long roomID, @Nonnull final JID roomJID) {
// Not used.
}

@Override
public void roomDestroyed(@Nonnull final JID roomJID)
// Beware that the invocation does not properly initialize the first argument! Do not use it without fixing that!
public void roomDestroyed(final long unused, @Nonnull final JID roomJID)
{
// When a room is destroyed, remove all registered occupants for that room.
mutex.writeLock().lock();
Expand All @@ -961,7 +962,7 @@ public void roomDestroyed(@Nonnull final JID roomJID)
}

@Override
public void roomClearChatHistory(JID roomJID) {
public void roomClearChatHistory(final long roomID, final @Nonnull JID roomJID) {
// Not used.
}

Expand Down
Loading