Selaa lähdekoodia

Merge pull request #19 from mario-orlicky/hide-system-messages

New change settings option and possibility to hide system messagaes
Lauri Ojansivu 8 vuotta sitten
vanhempi
sitoutus
1ad4107201

+ 3 - 1
client/components/activities/activities.js

@@ -12,10 +12,12 @@ BlazeComponent.extendComponent({
       const capitalizedMode = Utils.capitalize(mode);
       const id = Session.get(`current${capitalizedMode}`);
       const limit = this.page.get() * activitiesPerPage;
+      const user = Meteor.user();
+      const hideSystem = user ? user.hasHiddenSystemMessages() : false;
       if (id === null)
         return;
 
-      this.subscribe('activities', mode, id, limit, () => {
+      this.subscribe('activities', mode, id, limit, hideSystem, () => {
         this.loadNextPageLocked = false;
 
         // If the sibear peak hasn't increased, that mean that there are no more

+ 13 - 4
client/components/users/userHeader.jade

@@ -12,10 +12,11 @@ template(name="memberMenuPopup")
   ul.pop-over-list
     with currentUser
       li: a.js-edit-profile {{_ 'edit-profile'}}
-    li: a.js-change-avatar {{_ 'edit-avatar'}}
-    li: a.js-change-password {{_ 'changePasswordPopup-title'}}
-    li: a.js-change-language {{_ 'changeLanguagePopup-title'}}
-    li: a.js-edit-notification {{_ 'editNotificationPopup-title'}}
+      li: a.js-change-settings {{_ 'change-settings'}}
+      li: a.js-change-avatar {{_ 'edit-avatar'}}
+      li: a.js-change-password {{_ 'changePasswordPopup-title'}}
+      li: a.js-change-language {{_ 'changeLanguagePopup-title'}}
+      li: a.js-edit-notification {{_ 'editNotificationPopup-title'}}
   hr
   ul.pop-over-list
     li: a.js-logout {{_ 'log-out'}}
@@ -63,3 +64,11 @@ template(name="changeLanguagePopup")
           = name
           if isCurrentLanguage
             i.fa.fa-check
+
+template(name="changeSettingsPopup")
+  ul.pop-over-list
+    li
+      a.js-toggle-system-messages
+        | {{_ 'hide-system-messages'}}
+        if hiddenSystemMessages
+          i.fa.fa-check

+ 13 - 0
client/components/users/userHeader.js

@@ -5,6 +5,7 @@ Template.headerUserBar.events({
 
 Template.memberMenuPopup.events({
   'click .js-edit-profile': Popup.open('editProfile'),
+  'click .js-change-settings': Popup.open('changeSettings'),
   'click .js-change-avatar': Popup.open('changeAvatar'),
   'click .js-change-password': Popup.open('changePassword'),
   'click .js-change-language': Popup.open('changeLanguage'),
@@ -89,3 +90,15 @@ Template.changeLanguagePopup.events({
     evt.preventDefault();
   },
 });
+
+Template.changeSettingsPopup.helpers({
+  hiddenSystemMessages() {
+    return Meteor.user().hasHiddenSystemMessages();
+  },
+});
+
+Template.changeSettingsPopup.events({
+  'click .js-toggle-system-messages'() {
+    Meteor.call('toggleSystemMessages');
+  },
+});

+ 3 - 0
i18n/en.i18n.json

@@ -104,10 +104,12 @@
     "change-avatar": "Change Avatar",
     "change-password": "Change Password",
     "change-permissions": "Change permissions",
+    "change-settings": "Change Settings",
     "changeAvatarPopup-title": "Change Avatar",
     "changeLanguagePopup-title": "Change Language",
     "changePasswordPopup-title": "Change Password",
     "changePermissionsPopup-title": "Change Permissions",
+    "changeSettingsPopup-title": "Change Settings",
     "click-to-star": "Click to star this board.",
     "click-to-unstar": "Click to unstar this board.",
     "clipboard" : "Clipboard or drag & drop",
@@ -181,6 +183,7 @@
     "filter-to-selection": "Filter to selection",
     "fullname": "Full Name",
     "header-logo-title": "Go back to your boards page.",
+    "hide-system-messages": "Hide system messages",
     "home": "Home",
     "import": "Import",
     "import-board": "import from Trello",

+ 21 - 0
models/users.js

@@ -59,6 +59,10 @@ Users.attachSchema(new SimpleSchema({
     type: String,
     optional: true,
   },
+  'profile.hiddenSystemMessages': {
+    type: Boolean,
+    optional: true,
+  },
   'profile.initials': {
     type: String,
     optional: true,
@@ -151,6 +155,11 @@ Users.helpers({
     return _.contains(notifications, activityId);
   },
 
+  hasHiddenSystemMessages() {
+    const profile = this.profile || {};
+    return profile.hiddenSystemMessages || false;
+  },
+
   getEmailBuffer() {
     const {emailBuffer = []} = this.profile;
     return emailBuffer;
@@ -231,6 +240,14 @@ Users.mutations({
       this.addTag(tag);
   },
 
+  toggleSystem(value = false) {
+    return {
+      $set: {
+        'profile.hiddenSystemMessages': !value,
+      },
+    };
+  },
+
   addNotification(activityId) {
     return {
       $addToSet: {
@@ -278,6 +295,10 @@ Meteor.methods({
       Users.update(this.userId, {$set: { username }});
     }
   },
+  toggleSystemMessages() {
+    const user = Meteor.user();
+    user.toggleSystem(user.hasHiddenSystemMessages());
+  },
 });
 
 if (Meteor.isServer) {

+ 4 - 4
server/publications/activities.js

@@ -3,16 +3,16 @@
 // 2. The card activity tab
 // We use this publication to paginate for these two publications.
 
-Meteor.publish('activities', (kind, id, limit) => {
+Meteor.publish('activities', (kind, id, limit, hideSystem) => {
   check(kind, Match.Where((x) => {
     return ['board', 'card'].indexOf(x) !== -1;
   }));
   check(id, String);
   check(limit, Number);
+  check(hideSystem, Boolean);
 
-  return Activities.find({
-    [`${kind}Id`]: id,
-  }, {
+  const selector = (hideSystem) ? {$and: [{activityType: 'addComment'}, {[`${kind}Id`]: id}]} : {[`${kind}Id`]: id};
+  return Activities.find(selector, {
     limit,
     sort: {createdAt: -1},
   });