2017-01-10 10:09:24 +01:00
|
|
|
import SimpleSchema from 'simpl-schema';
|
2016-11-08 16:33:25 +09:00
|
|
|
import Users from "meteor/nova:users";
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-06-23 12:17:39 +09:00
|
|
|
import Comments from "meteor/nova:comments";
|
2016-03-21 10:27:43 +09:00
|
|
|
|
2016-12-12 16:48:49 +09:00
|
|
|
/**
|
|
|
|
* @summary Vote schema
|
|
|
|
* @type {SimpleSchema}
|
|
|
|
*/
|
|
|
|
const voteSchema = new SimpleSchema({
|
|
|
|
itemId: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
power: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
votedAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-08 16:33:25 +09:00
|
|
|
Users.addField([
|
|
|
|
/**
|
|
|
|
An array containing comments upvotes
|
|
|
|
*/
|
|
|
|
{
|
2016-11-10 14:22:47 +01:00
|
|
|
fieldName: '__upvotedComments',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-11-08 16:33:25 +09:00
|
|
|
publish: false,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-10 14:22:47 +01:00
|
|
|
resolveAs: '__upvotedComments: [Vote]',
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing posts upvotes
|
|
|
|
*/
|
|
|
|
{
|
2016-11-10 14:22:47 +01:00
|
|
|
fieldName: '__upvotedPosts',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-11-08 16:33:25 +09:00
|
|
|
publish: false,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-10 14:22:47 +01:00
|
|
|
resolveAs: '__upvotedPosts: [Vote]',
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing comment downvotes
|
|
|
|
*/
|
|
|
|
{
|
2016-11-10 14:22:47 +01:00
|
|
|
fieldName: '__downvotedComments',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-11-08 16:33:25 +09:00
|
|
|
publish: false,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-10 14:22:47 +01:00
|
|
|
resolveAs: '__downvotedComments: [Vote]',
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing posts downvotes
|
|
|
|
*/
|
|
|
|
{
|
2016-11-10 14:22:47 +01:00
|
|
|
fieldName: '__downvotedPosts',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-11-08 16:33:25 +09:00
|
|
|
publish: false,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-10 14:22:47 +01:00
|
|
|
resolveAs: '__downvotedPosts: [Vote]',
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]);
|
2016-02-17 12:54:18 +09:00
|
|
|
|
|
|
|
Posts.addField([
|
2016-02-17 11:28:00 +09:00
|
|
|
/**
|
|
|
|
How many upvotes the post has received
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "upvotes",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
2016-04-05 16:27:48 +09:00
|
|
|
optional: true,
|
2016-04-14 09:54:41 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 11:28:00 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing the `_id`s of the post's upvoters
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "upvoters",
|
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-04-05 16:27:48 +09:00
|
|
|
optional: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
publish: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-08 14:56:39 +09:00
|
|
|
resolveAs: 'upvoters: [User]',
|
2016-02-17 11:28:00 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
How many downvotes the post has received
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "downvotes",
|
|
|
|
fieldSchema: {
|
2016-04-05 16:27:48 +09:00
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-04-14 09:54:41 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 11:28:00 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing the `_id`s of the post's downvoters
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "downvoters",
|
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-04-05 16:27:48 +09:00
|
|
|
optional: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
publish: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-08 14:56:39 +09:00
|
|
|
resolveAs: 'downvoters: [User]',
|
2016-02-17 11:28:00 +09:00
|
|
|
}
|
|
|
|
},
|
2016-02-17 12:54:18 +09:00
|
|
|
/**
|
|
|
|
The post's base score (not factoring in the post's age)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "baseScore",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
The post's current score (factoring in age)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "score",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Comments.addField([
|
|
|
|
/**
|
|
|
|
The number of upvotes the comment has received
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "upvotes",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing the `_id`s of upvoters
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "upvoters",
|
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-02-17 12:54:18 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-08 14:56:39 +09:00
|
|
|
resolveAs: 'upvoters: [User]',
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
The number of downvotes the comment has received
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "downvotes",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
An array containing the `_id`s of downvoters
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "downvoters",
|
|
|
|
fieldSchema: {
|
2017-01-10 10:09:24 +01:00
|
|
|
type: Array,
|
2017-01-10 11:17:16 +01:00
|
|
|
blackbox: true,
|
2016-02-17 12:54:18 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-08 14:56:39 +09:00
|
|
|
resolveAs: 'downvoters: [User]',
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
The comment's base score (not factoring in the comment's age)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "baseScore",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
The comment's current score (factoring in age)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
fieldName: "score",
|
|
|
|
fieldSchema: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-10-31 18:21:28 +01:00
|
|
|
defaultValue: 0,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-02-17 12:54:18 +09:00
|
|
|
}
|
|
|
|
},
|
2016-02-17 11:28:00 +09:00
|
|
|
]);
|