diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/cardComments.js | 6 | ||||
-rw-r--r-- | models/cards.js | 24 | ||||
-rw-r--r-- | models/users.js | 78 |
3 files changed, 91 insertions, 17 deletions
diff --git a/models/cardComments.js b/models/cardComments.js index ce6edf3c..070c148e 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -57,6 +57,12 @@ CardComments.helpers({ CardComments.hookOptions.after.update = { fetchPrevious: false }; if (Meteor.isServer) { + // Comments are often fetched within a card, so we create an index to make these + // queries more efficient. + Meteor.startup(() => { + CardComments._collection._ensureIndex({ cardId: 1, createdAt: -1 }); + }); + CardComments.after.insert((userId, doc) => { Activities.insert({ userId, diff --git a/models/cards.js b/models/cards.js index 84fbb6c2..9e7d58c8 100644 --- a/models/cards.js +++ b/models/cards.js @@ -56,6 +56,14 @@ Cards.attachSchema(new SimpleSchema({ type: [String], optional: true, }, + startAt: { + type: Date, + optional: true, + }, + dueAt: { + type: Date, + optional: true, + }, // XXX Should probably be called `authorId`. Is it even needed since we have // the `members` field? userId: { @@ -207,6 +215,22 @@ Cards.mutations({ unsetCover() { return { $unset: { coverId: '' }}; }, + + setStart(startAt) { + return { $set: { startAt }}; + }, + + unsetStart() { + return { $unset: { startAt: '' }}; + }, + + setDue(dueAt) { + return { $set: { dueAt }}; + }, + + unsetDue() { + return { $unset: { dueAt: '' }}; + }, }); if (Meteor.isServer) { diff --git a/models/users.js b/models/users.js index 790ee0a1..58513231 100644 --- a/models/users.js +++ b/models/users.js @@ -1,3 +1,7 @@ +// Sandstorm context is detected using the METEOR_SETTINGS environment variable +// in the package definition. +const isSandstorm = Meteor.settings && Meteor.settings.public && + Meteor.settings.public.sandstorm; Users = Meteor.users; Users.attachSchema(new SimpleSchema({ @@ -55,6 +59,10 @@ Users.attachSchema(new SimpleSchema({ type: String, optional: true, }, + 'profile.hiddenSystemMessages': { + type: Boolean, + optional: true, + }, 'profile.initials': { type: String, optional: true, @@ -71,6 +79,10 @@ Users.attachSchema(new SimpleSchema({ type: [String], optional: true, }, + 'profile.showCardsCountAt': { + type: Number, + optional: true, + }, 'profile.starredBoards': { type: [String], optional: true, @@ -147,6 +159,11 @@ Users.helpers({ return _.contains(notifications, activityId); }, + hasHiddenSystemMessages() { + const profile = this.profile || {}; + return profile.hiddenSystemMessages || false; + }, + getEmailBuffer() { const {emailBuffer = []} = this.profile; return emailBuffer; @@ -167,6 +184,11 @@ Users.helpers({ } }, + getLimitToShowCardsCount() { + const profile = this.profile || {}; + return profile.showCardsCountAt; + }, + getName() { const profile = this.profile || {}; return profile.fullname || this.username; @@ -227,6 +249,14 @@ Users.mutations({ this.addTag(tag); }, + toggleSystem(value = false) { + return { + $set: { + 'profile.hiddenSystemMessages': !value, + }, + }; + }, + addNotification(activityId) { return { $addToSet: { @@ -262,6 +292,10 @@ Users.mutations({ setAvatarUrl(avatarUrl) { return { $set: { 'profile.avatarUrl': avatarUrl }}; }, + + setShowCardsCountAt(limit) { + return { $set: { 'profile.showCardsCountAt': limit } }; + }, }); Meteor.methods({ @@ -274,6 +308,14 @@ Meteor.methods({ Users.update(this.userId, {$set: { username }}); } }, + toggleSystemMessages() { + const user = Meteor.user(); + user.toggleSystem(user.hasHiddenSystemMessages()); + }, + changeLimitToShowCardsCount(limit) { + check(limit, Number); + Meteor.user().setShowCardsCountAt(limit); + }, }); if (Meteor.isServer) { @@ -394,24 +436,26 @@ if (Meteor.isServer) { return fakeUserId.get() || getUserId(); }; - Users.after.insert((userId, doc) => { - const fakeUser = { - extendAutoValueContext: { - userId: doc._id, - }, - }; - - fakeUserId.withValue(doc._id, () => { - // Insert the Welcome Board - Boards.insert({ - title: TAPi18n.__('welcome-board'), - permission: 'private', - }, fakeUser, (err, boardId) => { - - ['welcome-list1', 'welcome-list2'].forEach((title) => { - Lists.insert({ title: TAPi18n.__(title), boardId }, fakeUser); + if (!isSandstorm) { + Users.after.insert((userId, doc) => { + const fakeUser = { + extendAutoValueContext: { + userId: doc._id, + }, + }; + + fakeUserId.withValue(doc._id, () => { + // Insert the Welcome Board + Boards.insert({ + title: TAPi18n.__('welcome-board'), + permission: 'private', + }, fakeUser, (err, boardId) => { + + ['welcome-list1', 'welcome-list2'].forEach((title) => { + Lists.insert({ title: TAPi18n.__(title), boardId }, fakeUser); + }); }); }); }); - }); + } } |