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); }