From 93fa9276b507b3a4d2923cf1a27cd2c7acfc6f04 Mon Sep 17 00:00:00 2001 From: Mohamed Amine Krout Date: Thu, 29 Aug 2024 14:35:16 +0100 Subject: [PATCH] fix: chat : no chat notifications if user is idle for few days - EXO-69418 (#766) Before this fix, no chat notifications if user is idle for few days. This is due to the clean notification job that removes all chat notifications not seen for 24 for our This commit add a new chat property (chat.notifications.days.toLive) to define the number of days to live for notifications and set a default value of 30 days. --- .../org/exoplatform/chat/utils/PropertyManager.java | 2 ++ .../mongodb/NotificationMongoDataStorage.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/exoplatform/chat/utils/PropertyManager.java b/common/src/main/java/org/exoplatform/chat/utils/PropertyManager.java index 4f04ff8bed..c2d965238c 100644 --- a/common/src/main/java/org/exoplatform/chat/utils/PropertyManager.java +++ b/common/src/main/java/org/exoplatform/chat/utils/PropertyManager.java @@ -110,6 +110,8 @@ public class PropertyManager { public static final String PROPERTY_REQUEST_TIMEOUT = "request.timeout"; + public static final String PROPERTY_NOTIFICATION_DAYS_TO_LIVE = "chat.notifications.days.toLive"; + public static String getProperty(String key) { String value = (String)properties().get(key); diff --git a/server-embedded/src/main/java/org/exoplatform/chat/services/mongodb/NotificationMongoDataStorage.java b/server-embedded/src/main/java/org/exoplatform/chat/services/mongodb/NotificationMongoDataStorage.java index 323aa52a30..dbe4786c4c 100644 --- a/server-embedded/src/main/java/org/exoplatform/chat/services/mongodb/NotificationMongoDataStorage.java +++ b/server-embedded/src/main/java/org/exoplatform/chat/services/mongodb/NotificationMongoDataStorage.java @@ -33,6 +33,7 @@ import org.exoplatform.chat.services.ChatService; import org.exoplatform.chat.services.NotificationDataStorage; import org.exoplatform.chat.services.UserService; +import org.exoplatform.chat.utils.PropertyManager; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.json.JSONException; @@ -68,7 +69,16 @@ private MongoDatabase db() public static void cleanupNotifications() { MongoCollection coll = ConnectionManager.getInstance().getDB().getCollection(M_NOTIFICATIONS); - Bson query = Filters.lt(TIMESTAMP, System.currentTimeMillis() - 24*60*60*1000); + long daysToLive = 30; + String daysToLiveProp = PropertyManager.getProperty(PropertyManager.PROPERTY_NOTIFICATION_DAYS_TO_LIVE); + if (!StringUtils.isBlank(daysToLiveProp)) { + try { + daysToLive = Long.parseLong(daysToLiveProp); + } catch (NumberFormatException e) { + LOG.warn("value set as chat notifications days to live is not a number, the default value will be used"); + } + } + Bson query = Filters.lt(TIMESTAMP, System.currentTimeMillis() - 24*60*60*1000*daysToLive); coll.deleteMany(query); }