diff --git a/client/methods/hideOldSubscriptions.js b/client/methods/hideOldSubscriptions.js new file mode 100644 index 000000000000..5106058b5597 --- /dev/null +++ b/client/methods/hideOldSubscriptions.js @@ -0,0 +1,33 @@ +const DURATION_WEEK = 1000 * 60 * 60 * 24 * 7; +Meteor.methods({ + hideOldSubscriptions(userId = Meteor.userId(), idleDuration = DURATION_WEEK) { + if (!Meteor.userId()) { + return 0; + } + + if (!Match.test(idleDuration, Number)) { + throw new Meteor.Error('error-invalid-room', 'Invalid room', { + method: 'hideOldSubscriptions', + }); + } + + const thresholdDate = new Date(new Date() - idleDuration); + + const query = { + 'u._id': userId, + alert: false, // ignore unred rooms + f: { $ne: true }, // ignore favored rooms + ls: { $lt: thresholdDate }, + }; + + return ChatSubscription.update( + query, + { + $set: { + alert: false, + open: false, + }, + }, + { multi: true }); + }, +}); diff --git a/packages/rocketchat-i18n/i18n/de-IN.i18n.json b/packages/rocketchat-i18n/i18n/de-IN.i18n.json index 3b8653a2d5e3..7ead6c48aa06 100644 --- a/packages/rocketchat-i18n/i18n/de-IN.i18n.json +++ b/packages/rocketchat-i18n/i18n/de-IN.i18n.json @@ -943,6 +943,7 @@ "Duplicate_channel_name": "Ein Kanal mit dem Namen '%s' existiert bereits", "Duplicate_private_group_name": "Eine private Gruppe mit dem Namen '%s' existiert bereits.", "Duration": "Dauer", + "Duration_nothing_happened_in_days": "Dauer in Tagen", "Edit_Custom_Field": "Benutzerdefinierte Felder bearbeiten", "Edit_Department": "Abteilung bearbeiten", "Edit_previous_message": "`%s` - Bearbeite vorherige Nachricht", @@ -1264,6 +1265,7 @@ "Hide_flextab": "Rechte Seitenleiste über Klick verstecken", "Hide_Group_Warning": "Bist Du sicher, dass Du den privaten Kanal \"%s\" verstecken möchtest?", "Hide_Livechat_Warning": "Bist Du Dir sicher, dass Du den Livechat mit \"%s\" ausblenden möchtest?", + "Hide_old_subscriptions": "Inaktive Räume verstecken", "Hide_Private_Warning": "Bist Du Dir sicher, dass Du das Gespräch mit \"%s\" verstecken möchtest?", "Hide_roles": "Rollen ausblenden", "Hide_Room_Warning": "Bist Du Dir sicher, dass Du den Raum \"%s\" verstecken möchtest?", @@ -2789,6 +2791,7 @@ "yesterday": "gestern", "you_are_in_preview_mode_of": "Du befindest Dich im Vorschaumodus des Kanals #__room_name__", "You_are_logged_in_as": "Du bist angemeldet als", + "You_are_hiding_unread_idle_rooms": "Du versteckst alle Räume, in denen schon länger nichts mehr passiert ist.", "You_are_not_authorized_to_view_this_page": "Du darfst diese Seite nicht sehen.", "You_can_change_a_different_avatar_too": "Du kannst für Nachrichten aus dieser Integration ein anderes Profilbild verwenden.", "You_can_search_using_RegExp_eg": "Du kannst einen regulären Ausdruck zum Suchen verwenden. z.B.", diff --git a/packages/rocketchat-i18n/i18n/de.i18n.json b/packages/rocketchat-i18n/i18n/de.i18n.json index d10b329791c4..7c602513af35 100644 --- a/packages/rocketchat-i18n/i18n/de.i18n.json +++ b/packages/rocketchat-i18n/i18n/de.i18n.json @@ -969,6 +969,7 @@ "Duplicate_channel_name": "Ein Kanal mit dem Namen '%s' existiert bereits", "Duplicate_private_group_name": "Eine private Gruppe mit dem Namen '%s' existiert bereits.", "Duration": "Dauer", + "Duration_nothing_happened_in_days": "Dauer in Tagen", "Edit_Custom_Field": "Benutzerdefinierte Felder bearbeiten", "Edit_Department": "Abteilung bearbeiten", "Edit_previous_message": "`%s` - Bearbeite vorherige Nachricht", @@ -1294,6 +1295,7 @@ "Hide_flextab": "Rechte Seitenleiste über Klick verstecken", "Hide_Group_Warning": "Sind Sie sicher, dass Sie die Gruppe \"%s\" ausblenden wollen?", "Hide_Livechat_Warning": "Sind Sie sich sicher, dass Sie den Livechat mit \"%s\" ausblenden wollen?", + "Hide_old_subscriptions": "Inaktive Räume verstecken", "Hide_Private_Warning": "Sind Sie sicher, dass Sie das Gespräch mit \"%s\" ausblenden wollen?", "Hide_roles": "Rollen ausblenden", "Hide_Room_Warning": "Sind Sie sicher, dass Sie den Raum \"%s\" verstecken wollen?", @@ -2877,6 +2879,7 @@ "yesterday": "gestern", "you_are_in_preview_mode_of": "Sie befinden sich im Vorschaumodus des Kanals #__room_name__", "You_are_logged_in_as": "Sie sind angemeldet als", + "You_are_hiding_unread_idle_rooms": "Sie verstecken alle Räume, in denen schon länger nichts mehr passiert ist.", "You_are_not_authorized_to_view_this_page": "Sie sind nicht berechtigt, diese Seite zu sehen", "You_can_change_a_different_avatar_too": "Sie können für Post dieser Integration ein anderes Profilbild verwenden", "You_can_search_using_RegExp_eg": "Sie können einen regulären Ausdruck zum Suchen verwenden. z.B. /^text$/i", diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index a2758d3d90e1..b64ef627f09b 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -987,6 +987,7 @@ "Duplicate_channel_name": "A Channel with name '%s' exists", "Duplicate_private_group_name": "A Private Group with name '%s' exists", "Duration": "Duration", + "Duration_nothing_happened_in_days": "Duration in days", "E2E_Enable_alert": "This feature is currently in beta! Please report bugs to github.com/RocketChat/Rocket.Chat/issues and be aware of:
- Encrypted messages of encrypted rooms will not be found by search operations.
- The mobile apps may not support the encypted messages (they are implementing it).
- Bots may not be able to see encrypted messages until they implement support for it.
- Uploads will not be encrypted in this version.", "E2E_Enable_description": "Enable option to create encrypted groups and be able to change groups and direct messages to be encrypted", "E2E_Encryption_Password_Explanation": "You can now create encrypted private groups and direct messages. You may also change existing private groups or DMs to encrypted.

This is end to end encryption so the key to encode/decode your messages will not be saved on the server. For that reason you need to store your password somewhere safe. You will be required to enter it on other devices you wish to use e2e encryption on.", @@ -1331,6 +1332,7 @@ "Hide_flextab": "Hide Right Sidebar with Click", "Hide_Group_Warning": "Are you sure you want to hide the group \"%s\"?", "Hide_Livechat_Warning": "Are you sure you want to hide the livechat with \"%s\"?", + "Hide_old_subscriptions": "Hide inactive rooms", "Hide_Private_Warning": "Are you sure you want to hide the discussion with \"%s\"?", "Hide_roles": "Hide Roles", "Hide_room": "Hide Room", @@ -2944,6 +2946,7 @@ "You": "You", "you_are_in_preview_mode_of": "You are in preview mode of channel #__room_name__", "You_are_logged_in_as": "You are logged in as", + "You_are_hiding_unread_idle_rooms": "You are hiding all rooms where nothing happened for a longer time.", "You_are_not_authorized_to_view_this_page": "You are not authorized to view this page.", "You_can_change_a_different_avatar_too": "You can override the avatar used to post from this integration.", "You_can_search_using_RegExp_eg": "You can search using RegExp. e.g. /^text$/i", diff --git a/packages/rocketchat-lib/client/lib/ChannelActions.js b/packages/rocketchat-lib/client/lib/ChannelActions.js index 9dbcc0fde93f..e6ce489feb86 100644 --- a/packages/rocketchat-lib/client/lib/ChannelActions.js +++ b/packages/rocketchat-lib/client/lib/ChannelActions.js @@ -101,3 +101,27 @@ export function erase(rid) { }); }); } + +export function hideOldSubscriptions() { + const DURATION_DAY = 1000 * 60 * 60 * 24; + + modal.open({ + title: t('Are_you_sure'), + text: t('You_are_hiding_unread_idle_rooms'), + type: 'input', + inputType: 'number', + inputPlaceholder: t('Duration_nothing_happened_in_days'), + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes_hide_it'), + cancelButtonText: t('Cancel'), + closeOnConfirm: true, + html: false, + }, async function(inputValue) { + const days = parseInt(inputValue); + if (!days) { + return false; + } + await call('hideOldSubscriptions', Meteor.userId(), DURATION_DAY * days); + }); +} diff --git a/packages/rocketchat-lib/client/lib/index.js b/packages/rocketchat-lib/client/lib/index.js index 4684347c02a1..c7ae608a874c 100644 --- a/packages/rocketchat-lib/client/lib/index.js +++ b/packages/rocketchat-lib/client/lib/index.js @@ -9,7 +9,7 @@ import { RocketChatTabBar } from './RocketChatTabBar'; import { RocketChatAnnouncement } from './RocketChatAnnouncement'; import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext } from '../../lib/RoomTypeConfig'; -import { hide, leave, erase } from './ChannelActions'; +import { hide, hideOldSubscriptions, leave, erase } from './ChannelActions'; import { call } from './callMethod'; import { LoginPresence } from './LoginPresence'; import * as DateFormat from './formatDate'; @@ -18,6 +18,7 @@ export { call, erase, hide, + hideOldSubscriptions, leave, RocketChatTabBar, RoomSettingsEnum, diff --git a/packages/rocketchat-lib/server/models/Subscriptions.js b/packages/rocketchat-lib/server/models/Subscriptions.js index 802f8d95da63..5883473693c8 100644 --- a/packages/rocketchat-lib/server/models/Subscriptions.js +++ b/packages/rocketchat-lib/server/models/Subscriptions.js @@ -848,6 +848,27 @@ class ModelSubscriptions extends RocketChat.models._Base { return result; } + + hideOldByUserId(userId, thresholdDate) { + const query = { + 'u._id': userId, + alert: false, // ignore unred rooms + f: { $ne: true }, // ignore favored rooms + ls: { $lt: thresholdDate }, + }; + + const result = this.update( + query, + { + $set: { + alert: false, + open: false, + }, + }, + { multi: true }); + + return result; + } } RocketChat.models.Subscriptions = new ModelSubscriptions('subscription', true); diff --git a/packages/rocketchat-ui-sidenav/client/sortlist.html b/packages/rocketchat-ui-sidenav/client/sortlist.html index 44984c5e69cc..a06bbdbb218c 100644 --- a/packages/rocketchat-ui-sidenav/client/sortlist.html +++ b/packages/rocketchat-ui-sidenav/client/sortlist.html @@ -32,15 +32,15 @@ {{#if favorite}} -
  • - -
  • +
  • + +
  • {{/if}}
  • + + diff --git a/packages/rocketchat-ui-sidenav/client/sortlist.js b/packages/rocketchat-ui-sidenav/client/sortlist.js index bb09017fe282..45aae8366058 100644 --- a/packages/rocketchat-ui-sidenav/client/sortlist.js +++ b/packages/rocketchat-ui-sidenav/client/sortlist.js @@ -1,5 +1,7 @@ /* globals popover */ +import { hideOldSubscriptions } from 'meteor/rocketchat:lib'; + const checked = function(prop, field) { const user = Meteor.userId(); if (prop === 'sidebarShowFavorites') { @@ -40,4 +42,8 @@ Template.sortlist.events({ }); popover.close(); }, + 'click .js-hide-old-subscriptions'(/* event, instance*/) { + hideOldSubscriptions(); + popover.close(); + }, }); diff --git a/server/methods/hideOldSubscriptions.js b/server/methods/hideOldSubscriptions.js new file mode 100644 index 000000000000..4f2e5b076941 --- /dev/null +++ b/server/methods/hideOldSubscriptions.js @@ -0,0 +1,20 @@ +const DURATION_WEEK = 1000 * 60 * 60 * 24 * 7; +Meteor.methods({ + hideOldSubscriptions(userId = Meteor.userId(), idleDuration = DURATION_WEEK) { + if (!Meteor.userId()) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { + method: 'hideOldSubscriptions', + }); + } + + if (!Match.test(idleDuration, Number)) { + throw new Meteor.Error('error-invalid-room', 'Invalid room', { + method: 'hideOldSubscriptions', + }); + } + + const thresholdDate = new Date(new Date() - idleDuration); + + return RocketChat.models.Subscriptions.hideOldByUserId(userId, thresholdDate); + }, +});