Skip to content

Commit

Permalink
[NEW] Hide inactive rooms (RocketChat#528)
Browse files Browse the repository at this point in the history
* port 5cee4db from PR towards Rocket.Chat

* Added commas which are required now
  • Loading branch information
mrsimpson authored and jschirrmacher committed Jan 9, 2019
1 parent dbd1d9c commit d942675
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 10 deletions.
33 changes: 33 additions & 0 deletions client/methods/hideOldSubscriptions.js
Original file line number Diff line number Diff line change
@@ -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 });
},
});
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/de-IN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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?",
Expand Down Expand Up @@ -2789,6 +2791,7 @@
"yesterday": "gestern",
"you_are_in_preview_mode_of": "Du befindest Dich im Vorschaumodus des Kanals #<strong>__room_name__</strong>",
"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.",
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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?",
Expand Down Expand Up @@ -2877,6 +2879,7 @@
"yesterday": "gestern",
"you_are_in_preview_mode_of": "Sie befinden sich im Vorschaumodus des Kanals #<strong>__room_name__</strong>",
"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. <code class='code-colors inline'>/^text$/i</code>",
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br/>- Encrypted messages of encrypted rooms will not be found by search operations.<br/>- The mobile apps may not support the encypted messages (they are implementing it).<br/>- Bots may not be able to see encrypted messages until they implement support for it.<br/>- 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.<br/><br/>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.",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2944,6 +2946,7 @@
"You": "You",
"you_are_in_preview_mode_of": "You are in preview mode of channel #<strong>__room_name__</strong>",
"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. <code class='code-colors inline'>/^text$/i</code>",
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-lib/client/lib/ChannelActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,6 +18,7 @@ export {
call,
erase,
hide,
hideOldSubscriptions,
leave,
RocketChatTabBar,
RoomSettingsEnum,
Expand Down
21 changes: 21 additions & 0 deletions packages/rocketchat-lib/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
29 changes: 20 additions & 9 deletions packages/rocketchat-ui-sidenav/client/sortlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
</label>
</li>
{{#if favorite}}
<li class="rc-popover__item {{bold 'sidebarShowFavorites'}}">
<label class="rc-popover__label">
<input type="checkbox" name="sidebarShowFavorites" class="hidden" checked="{{checked 'sidebarShowFavorites'}}"/>
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='star' }}
</span>
<span class="rc-popover__item-text">{{_"Group_favorites"}}</span>
</label>
</li>
<li class="rc-popover__item {{bold 'sidebarShowFavorites'}}">
<label class="rc-popover__label">
<input type="checkbox" name="sidebarShowFavorites" class="hidden" checked="{{checked 'sidebarShowFavorites'}}"/>
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='star' }}
</span>
<span class="rc-popover__item-text">{{_"Group_favorites"}}</span>
</label>
</li>
{{/if}}
<li class="rc-popover__item {{bold 'sidebarShowUnread'}}">
<label class="rc-popover__label">
Expand All @@ -52,5 +52,16 @@
</label>
</li>
</ul>
<span class="rc-popover__divider"></span>
<ul class="rc-popover__list">
<li class="rc-popover__item js-hide-old-subscriptions">
<label class="rc-popover__label">
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='eye-off' }}
</span>
<span class="rc-popover__item-text">{{_ "Hide_old_subscriptions"}}</span>
</label>
</li>
</ul>
</div>
</template>
6 changes: 6 additions & 0 deletions packages/rocketchat-ui-sidenav/client/sortlist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* globals popover */

import { hideOldSubscriptions } from 'meteor/rocketchat:lib';

const checked = function(prop, field) {
const user = Meteor.userId();
if (prop === 'sidebarShowFavorites') {
Expand Down Expand Up @@ -40,4 +42,8 @@ Template.sortlist.events({
});
popover.close();
},
'click .js-hide-old-subscriptions'(/* event, instance*/) {
hideOldSubscriptions();
popover.close();
},
});
20 changes: 20 additions & 0 deletions server/methods/hideOldSubscriptions.js
Original file line number Diff line number Diff line change
@@ -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);
},
});

0 comments on commit d942675

Please sign in to comment.