Skip to content

Commit 13fd366

Browse files
committed
OF-2918: Expose numeric MUC room ID in events
A MUC room of the same name (JID) can be created, destroyed and recreated again. The two rooms should be seen as two different rooms. When using the JID of the rooms, there's no way to distinghuish between them. For that, Openfire's numeric ID can be used. In this commit, the numeric ID is added to selected MUC events.
1 parent b9f01e3 commit 13fd366

6 files changed

Lines changed: 34 additions & 28 deletions

File tree

xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCEventDispatcher.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2005-2008 Jive Software, 2017-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -102,32 +102,32 @@ public static void privateMessageRecieved(JID toJID, JID fromJID, Message messag
102102
}
103103
}
104104

105-
public static void roomCreated(JID roomJID) {
105+
public static void roomCreated(long roomID, JID roomJID) {
106106
for (MUCEventListener listener : listeners) {
107107
try {
108-
listener.roomCreated(roomJID);
108+
listener.roomCreated(roomID, roomJID);
109109
} catch (Exception e) {
110-
Log.warn("An exception occurred while dispatching a 'roomCreated' event!", e);
110+
Log.warn("An exception occurred while dispatching a 'roomCreated' event for room {} ({})!", roomJID, roomID, e);
111111
}
112112
}
113113
}
114114

115-
public static void roomDestroyed(JID roomJID) {
115+
public static void roomDestroyed(long roomID, JID roomJID) {
116116
for (MUCEventListener listener : listeners) {
117117
try {
118-
listener.roomDestroyed(roomJID);
118+
listener.roomDestroyed(roomID, roomJID);
119119
} catch (Exception e) {
120-
Log.warn("An exception occurred while dispatching a 'roomDestroyed' event!", e);
120+
Log.warn("An exception occurred while dispatching a 'roomDestroyed' event for room {} ({})!", roomJID, roomID, e);
121121
}
122122
}
123123
}
124124

125-
public static void roomClearChatHistory(JID roomJID) {
125+
public static void roomClearChatHistory(long roomID, JID roomJID) {
126126
for (MUCEventListener listener : listeners) {
127127
try {
128-
listener.roomClearChatHistory(roomJID);
128+
listener.roomClearChatHistory(roomID, roomJID);
129129
} catch (Exception e) {
130-
Log.warn("An exception occurred while dispatching a 'roomClearChatHistory' event for room {}!", roomJID, e);
130+
Log.warn("An exception occurred while dispatching a 'roomClearChatHistory' event for room {} ({})!", roomJID, roomID, e);
131131
}
132132
}
133133
}

xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCEventListener.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2005-2008 Jive Software, 2017-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
import org.xmpp.packet.JID;
2020
import org.xmpp.packet.Message;
2121

22+
import javax.annotation.Nonnull;
23+
2224
/**
2325
* Interface to listen for MUC events. Use the {@link MUCEventDispatcher#addListener(MUCEventListener)}
2426
* method to register for events.
@@ -32,21 +34,21 @@ public interface MUCEventListener {
3234
*
3335
* @param roomJID JID of the room that was created.
3436
*/
35-
void roomCreated(JID roomJID);
37+
void roomCreated(final long roomID, final @Nonnull JID roomJID);
3638

3739
/**
3840
* Event triggered when a room was destroyed.
3941
*
4042
* @param roomJID JID of the room that was destroyed.
4143
*/
42-
void roomDestroyed(JID roomJID);
44+
void roomDestroyed(final long roomID, final @Nonnull JID roomJID);
4345

4446
/**
4547
* Event triggered when a clear chat history command was issued.
4648
*
4749
* @param roomJID JID of the room to clear chat history.
4850
*/
49-
void roomClearChatHistory(JID roomJID);
51+
void roomClearChatHistory(final long roomID, final @Nonnull JID roomJID);
5052

5153
/**
5254
* Event triggered when a new occupant joins a room.

xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoom.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2004-2008 Jive Software, 2016-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2004-2008 Jive Software, 2016-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1364,7 +1364,7 @@ public CompletableFuture<Void> clearChatHistory() {
13641364
// Remove the history of the room from memory (preventing it to pop up in a new room by the same name).
13651365
roomHistory.purge();
13661366
// Fire event to clear chat room history
1367-
MUCEventDispatcher.roomClearChatHistory(getJID());
1367+
MUCEventDispatcher.roomClearChatHistory(getID(), getJID());
13681368
});
13691369
}
13701370

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

14551455
/**

xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/LocalMUCRoomManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2016-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2016-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -402,7 +402,8 @@ public void entryRemoved(@Nonnull String key, @Nullable MUCRoom oldValue, @Nonnu
402402
localRooms.remove(key);
403403
final MultiUserChatService service = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName);
404404
if (service != null) {
405-
service.getOccupantManager().roomDestroyed(new JID(key, service.getServiceDomain(), null));
405+
final long roomID = -1; // Unused by OccupantManager.
406+
service.getOccupantManager().roomDestroyed(roomID, new JID(key, service.getServiceDomain(), null));
406407
}
407408
}
408409

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

xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/MultiUserChatServiceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2004-2008 Jive Software, 2016-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2004-2008 Jive Software, 2016-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1963,7 +1963,7 @@ public MUCRoom getChatRoom(@Nonnull final String roomName, @Nonnull final JID us
19631963
}
19641964
if (created) {
19651965
// Fire event that a new room has been created
1966-
MUCEventDispatcher.roomCreated(room.getSelfRepresentation().getOccupantJID());
1966+
MUCEventDispatcher.roomCreated(room.getID(), room.getSelfRepresentation().getOccupantJID());
19671967
}
19681968
if (loaded || created) {
19691969
// Initiate FMUC, when enabled.
@@ -3325,6 +3325,7 @@ public void leftCluster(byte[] nodeID)
33253325
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);
33263326
final Set<OccupantManager.Occupant> occupants = occupantManager.occupantsForRoomByNode(lostRoomName, XMPPServer.getInstance().getNodeID(), true);
33273327
final JID roomJID = new JID(lostRoomName, fullServiceName, null);
3328+
final long roomID = -1; // As this value is currently not used by OccupantManager, we can avoid the complexity in having it looked up.
33283329
for (final OccupantManager.Occupant occupant : occupants) {
33293330
try {
33303331
// Send a presence stanza of type "unavailable" to the occupant
@@ -3349,7 +3350,7 @@ public void leftCluster(byte[] nodeID)
33493350
}
33503351
}
33513352
// Clean up the locally maintained bookkeeping.
3352-
occupantManager.roomDestroyed(roomJID);
3353+
occupantManager.roomDestroyed(roomID, roomJID);
33533354
removeChatRoom(lostRoomName);
33543355
} catch (Exception e) {
33553356
Log.warn("Unable to inform occupants on local cluster node that they are being removed from room '{}' because of a (cluster) error.", lostRoomName, e);

xmppserver/src/main/java/org/jivesoftware/openfire/muc/spi/OccupantManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2024 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2021-2025 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -937,12 +937,13 @@ public Map<Occupant, NodeID> getNodeByLocalOccupant()
937937
}
938938

939939
@Override
940-
public void roomCreated(JID roomJID) {
940+
public void roomCreated(final long roomID, @Nonnull final JID roomJID) {
941941
// Not used.
942942
}
943943

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

963964
@Override
964-
public void roomClearChatHistory(JID roomJID) {
965+
public void roomClearChatHistory(final long roomID, final @Nonnull JID roomJID) {
965966
// Not used.
966967
}
967968

0 commit comments

Comments
 (0)