getConnectedUsers()
- {
- return this.users.values().stream().filter(user -> user.getSession() != null && user.isConnected()).toList();
- }
-
/**
* @return the channel messages
*/
diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/ChannelStore.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/ChannelStore.java
index 4c5ba0027f..66e0c2d5f2 100644
--- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/ChannelStore.java
+++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/ChannelStore.java
@@ -54,9 +54,22 @@ public class ChannelStore
*/
public Channel create()
{
- Channel channel = new Channel(this.idGenerator.generateChannelId());
+ return create(this.idGenerator.generateChannelId());
+ }
+
+ /**
+ * Creates a new channel with a passed key.
+ *
+ * @param channelKey the identifier of the new channel
+ * @return the new channel
+ * @since 17.10.0RC1
+ */
+ public Channel create(String channelKey)
+ {
+ Channel channel = new Channel(channelKey);
askBotsToJoin(channel);
this.channelByKey.put(channel.getKey(), channel);
+
return channel;
}
@@ -85,6 +98,25 @@ public Channel get(String key)
return this.channelByKey.get(key);
}
+ /**
+ * Access an existing channel by its key.
+ *
+ * @param key the channel key
+ * @param create if true, create the channel when it does not exist
+ * @return the corresponding channel
+ * @since 17.10.0RC1
+ */
+ public Channel get(String key, boolean create)
+ {
+ Channel channel = get(key);
+
+ if (channel == null) {
+ channel = create(key);
+ }
+
+ return channel;
+ }
+
/**
* Remove a channel from memory.
*
@@ -106,8 +138,7 @@ public void prune()
try {
long currentTime = System.currentTimeMillis();
for (Channel channel : this.channelByKey.values()) {
- if (channel.getConnectedUsers().isEmpty()
- && (currentTime - channel.getCreationDate()) > (1000 * 60 * 60 * 2)) {
+ if (channel.getUsers().isEmpty() && (currentTime - channel.getCreationDate()) > (1000 * 60 * 60 * 2)) {
remove(channel);
}
}
diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/DefaultLocalUserFactory.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/DefaultLocalUserFactory.java
new file mode 100644
index 0000000000..5af5ed4c92
--- /dev/null
+++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/DefaultLocalUserFactory.java
@@ -0,0 +1,49 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.netflux.internal;
+
+import jakarta.inject.Singleton;
+import jakarta.websocket.Session;
+
+import org.xwiki.component.annotation.Component;
+
+/**
+ * Default implementation of {@link LocalUserFactory}.
+ *
+ * Use the session id as user id.
+ *
+ * @version $Id$
+ * @since 17.10.0RC1
+ */
+@Component
+@Singleton
+public class DefaultLocalUserFactory implements LocalUserFactory
+{
+ @Override
+ public LocalUser createLocalUser(Session session)
+ {
+ return new LocalUser(session, getId(session));
+ }
+
+ protected String getId(Session session)
+ {
+ return session.getId();
+ }
+}
diff --git a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/HistoryKeeper.java b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/HistoryKeeper.java
index 7d2ee6b319..350bdc398f 100644
--- a/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/HistoryKeeper.java
+++ b/xwiki-commons-core/xwiki-commons-netflux/src/main/java/org/xwiki/netflux/internal/HistoryKeeper.java
@@ -30,6 +30,8 @@
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
+import org.xwiki.netflux.internal.event.NetfluxMessageUserEvent;
+import org.xwiki.observation.ObservationManager;
/**
* Holds the key of the history keeper fake user that is added to all Netflux channels.
@@ -51,6 +53,9 @@ public class HistoryKeeper extends AbstractBot
@Inject
private MessageBuilder messageBuilder;
+ @Inject
+ private ObservationManager observation;
+
@Override
public String getId()
{
@@ -60,7 +65,7 @@ public String getId()
}
@Override
- public void onUserMessage(User sender, List