From 6c5850752ef019a38665d1c812ae9e33850c529d Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Wed, 21 Aug 2019 23:30:26 +0200 Subject: [PATCH 1/7] Update package.js --- package.js | 131 +++++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/package.js b/package.js index 040d95e..fe743da 100644 --- a/package.js +++ b/package.js @@ -1,89 +1,104 @@ Package.describe({ - name: 'arkham:comments-ui', - summary: 'Simple templates for disqus-like comment functionality', - version: '1.4.3', - git: 'https://github.com/komentify/meteor-comments-ui.git' + name: "arkham:comments-ui", + summary: "Simple templates for disqus-like comment functionality", + version: "1.4.3", + git: "https://github.com/komentify/meteor-comments-ui.git" }); Npm.depends({ - linkifyjs: '2.0.2', + "simpl-schema": "1.5.5", + "linkifyjs": "2.0.2", }); Package.onUse(function(api) { // Meteor Version - api.versionsFrom('METEOR@1.4.1.2'); + api.versionsFrom("METEOR@1.4.1.2"); // Meteor Core Dependencies - api.use(['accounts-password@1.0.1'], { weak: true }); + api.use(["accounts-password@1.0.1"], { weak: true }); api.use([ - 'accounts-base', - 'ecmascript', - 'underscore', - 'mongo-livedata', - 'templating', - 'jquery', - 'check', - 'less@2.5.0_2', - 'tracker', - 'check', - 'random', - 'markdown', - 'reactive-dict', + "accounts-base", + "ecmascript", + "underscore", + "mongo-livedata", + "templating", + "jquery", + "check", + "less@2.5.0_2", + "tracker", + "check", + "random", + "markdown", + "reactive-dict" ]); // Atmosphere Package Dependencies api.use([ - 'aldeed:collection2@2.5.0', 'aldeed:simple-schema@1.3.3', 'dburles:collection-helpers@1.0.3', - 'momentjs:moment@2.10.6', 'reywood:publish-composite@1.4.2', - 'aldeed:template-extension@4.0.0', 'barbatus:stars-rating@1.0.7' + "aldeed:collection2@3.0.0", + "dburles:collection-helpers", + "reywood:publish-composite", + "aldeed:template-extension@4.0.0", + "barbatus:stars-rating@1.0.7" ]); // Package specific globals and files api.addFiles([ - 'lib/collections/anonymous-user.js', - 'lib/collections/comments.js', - 'lib/collections/methods/anonymous-user.js', - 'lib/collections/methods/comments.js', + "lib/collections/anonymous-user.js", + "lib/collections/comments.js", + "lib/collections/methods/anonymous-user.js", + "lib/collections/methods/comments.js" ]); api.addFiles([ - 'lib/services/media-analyzers/image.js', - 'lib/services/media-analyzers/youtube.js', - 'lib/services/user.js', - 'lib/services/time-tick.js', - 'lib/services/media.js', - 'lib/components/commentsBox/commentsBox.html', - 'lib/components/commentsBox/commentsBox.less', - 'lib/components/commentsSingleComment/commentsSingleComment.html', - 'lib/components/commentsTextarea/commentsTextarea.html', - 'lib/components/commentsSubheader/commentsSubheader.html', - 'lib/components/commentsList/commentsList.html', - 'lib/api.js', + "lib/services/media-analyzers/image.js", + "lib/services/media-analyzers/youtube.js", + "lib/services/user.js", + "lib/services/time-tick.js", + "lib/services/media.js", + "lib/components/commentsBox/commentsBox.html", + "lib/components/commentsBox/commentsBox.less", + "lib/components/commentsSingleComment/commentsSingleComment.html", + "lib/components/commentsTextarea/commentsTextarea.html", + "lib/components/commentsSubheader/commentsSubheader.html", + "lib/components/commentsList/commentsList.html", + "lib/api.js" ]); - api.addFiles([ - 'lib/components/helpers.js', - 'lib/components/commentsBox/commentsBox.js', - 'lib/components/commentsSingleComment/commentsSingleComment.js', - 'lib/components/commentsTextarea/commentsTextarea.js', - 'lib/components/commentsSubheader/commentsSubheader.js', - 'lib/components/commentsList/commentsList.js', - ], 'client'); + api.addFiles( + [ + "lib/components/helpers.js", + "lib/components/commentsBox/commentsBox.js", + "lib/components/commentsSingleComment/commentsSingleComment.js", + "lib/components/commentsTextarea/commentsTextarea.js", + "lib/components/commentsSubheader/commentsSubheader.js", + "lib/components/commentsList/commentsList.js" + ], + "client" + ); - api.addFiles([ - 'lib/server/publish.js', - 'lib/services/hashing.js', - 'lib/comment-status-api.js', - 'lib/server/api.js', - ], 'server'); + api.addFiles( + [ + "lib/server/publish.js", + "lib/services/hashing.js", + "lib/comment-status-api.js", + "lib/server/api.js" + ], + "server" + ); - api.export('Comments'); + api.export("Comments"); }); Package.onTest(function(api) { - api.use(['tinytest', 'accounts-password', 'ecmascript', 'audit-argument-checks', 'check']); - api.use('arkham:comments-ui'); + api.use([ + "tinytest", + "accounts-password", + "ecmascript", + "audit-argument-checks", + "check" + ]); + api.use("arkham:comments-ui"); - api.addFiles(['tests/api-tests.js', 'tests/reply-service-tests.js']); - api.addFiles('tests/ui-tests.js', 'client'); + api.addFiles(["tests/api-tests.js", "tests/reply-service-tests.js"]); + api.addFiles("tests/ui-tests.js", "client"); }); From 5ccd7fe79e4e80d270032e226fe266bbecd41269 Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Wed, 21 Aug 2019 23:31:41 +0200 Subject: [PATCH 2/7] Update anonymous.js --- lib/collections/anonymous-user.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/collections/anonymous-user.js b/lib/collections/anonymous-user.js index b506c2e..302ef45 100644 --- a/lib/collections/anonymous-user.js +++ b/lib/collections/anonymous-user.js @@ -1,3 +1,7 @@ +import SimpleSchema from 'simpl-schema'; +import { AutoForm } from 'meteor/aldeed:autoform'; +SimpleSchema.extendOptions(['autoform']); + AnonymousUserCollection = new Mongo.Collection('commentsui-anonymoususer') AnonymousUserCollection.allow({ From 1bd9dbfd7ddb02053fd6db334104ead4ce675eba Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Wed, 21 Aug 2019 23:32:48 +0200 Subject: [PATCH 3/7] Update comments.js --- lib/collections/comments.js | 248 ++++++++++++++++++++---------------- 1 file changed, 141 insertions(+), 107 deletions(-) diff --git a/lib/collections/comments.js b/lib/collections/comments.js index c255310..cbd9b6b 100644 --- a/lib/collections/comments.js +++ b/lib/collections/comments.js @@ -1,15 +1,19 @@ -import { Mongo } from 'meteor/mongo' +import { Mongo } from "meteor/mongo"; -import linkifyStr from 'linkifyjs/string' -import timeTickService from '../services/time-tick' -import userService from '../services/user' -import comment from '../services/comment' -import { addCollectionMethods } from './CommentCollectionMethods' -import { addReplyMethods } from './ReplyCollectionMethods' +import SimpleSchema from "simpl-schema"; -export const CommentsCollection = new Mongo.Collection('comments') +SimpleSchema.extendOptions(["autoform"]); -CommentsCollection.schemas = {} +import linkifyStr from "linkifyjs/string"; +import timeTickService from "../services/time-tick"; +import userService from "../services/user"; +import comment from "../services/comment"; +import { addCollectionMethods } from "./CommentCollectionMethods"; +import { addReplyMethods } from "./ReplyCollectionMethods"; + +export const CommentsCollection = new Mongo.Collection("comments"); + +CommentsCollection.schemas = {}; CommentsCollection.schemas.StarRatingSchema = new SimpleSchema({ userId: { @@ -18,17 +22,7 @@ CommentsCollection.schemas.StarRatingSchema = new SimpleSchema({ rating: { type: Number } -}) - -const likeableConfig = { - type: [String], - autoValue: function() { - if (this.isInsert) { - return [] - } - }, - optional: true -} +}); /** * Return a comment schema enhanced with the given schema config. @@ -45,11 +39,14 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { isAnonymous: { type: Boolean }, - 'media.type': { + media: { + type: Object + }, + "media.type": { type: String, optional: true }, - 'media.content': { + "media.content": { type: String, optional: true }, @@ -60,29 +57,56 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { }, status: { type: String, - autoValue: function () { + autoValue: function() { if (this.isInsert) { - return Comments.config().defaultCommentStatus + return Comments.config().defaultCommentStatus; } }, - optional: true, + optional: true }, + replies: { - type: [Object], - autoValue: function () { + type: Array + }, + "replies.$": { + type: Object, + autoValue: function() { + if (this.isInsert) { + return []; + } + }, + optional: true + }, + likes: { + type: Array + }, + "likes.$": { + type: String, + autoValue: function() { if (this.isInsert) { - return [] + return []; + } + }, + optional: true + }, + dislikes: { type: Array }, + "dislikes.$": { + type: String, + autoValue: function() { + if (this.isInsert) { + return []; } }, optional: true }, - likes: { ...likeableConfig }, - dislikes: { ...likeableConfig }, starRatings: { - type: [CommentsCollection.schemas.StarRatingSchema], + type: Array + }, + "starRatings.$": { + type: CommentsCollection.schemas.StarRatingSchema, autoValue: function() { if (this.isInsert) { - return [] + return []; } }, optional: true @@ -90,10 +114,9 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { // general rating number that is used for sorting ratingScore: { type: Number, - decimal: true, autoValue: function() { if (this.isInsert) { - return 0 + return 0; } } }, @@ -101,11 +124,11 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { type: Date, autoValue: function() { if (this.isInsert) { - return new Date + return new Date(); } else if (this.isUpsert) { - return { $setOnInsert: new Date } + return { $setOnInsert: new Date() }; } else { - this.unset() + this.unset(); } } }, @@ -113,14 +136,13 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { type: Date, autoValue: function() { if (this.isUpdate) { - return new Date() + return new Date(); } }, - denyInsert: true, optional: true }, ...additionalSchemaConfig - } + }; } /** @@ -133,11 +155,11 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { */ function enhanceReplies(scope, position) { if (!position) { - position = [] + position = []; } - return _.map(scope.replies, function (reply, index) { - position.push(index) + return _.map(scope.replies, function(reply, index) { + position.push(index); reply = Object.assign(reply, { position: position.slice(0), @@ -148,7 +170,7 @@ function enhanceReplies(scope, position) { createdAgo: scope.createdAgo.bind(reply), getStarRating: scope.getStarRating.bind(reply), enhancedContent: scope.enhancedContent.bind(reply) - }) + }); if (reply.replies) { // recursive! @@ -157,69 +179,75 @@ function enhanceReplies(scope, position) { null, _.extend(_.clone(scope), { replies: reply.replies }), position - )() + )(); } - position.pop() + position.pop(); - return reply - }) + return reply; + }); } -CommentsCollection.schemas.ReplySchema = new SimpleSchema(getCommonCommentSchema({ - replyId: { - type: String - } -})) +CommentsCollection.schemas.ReplySchema = new SimpleSchema( + getCommonCommentSchema({ + replyId: { + type: String + } + }) +); -CommentsCollection.schemas.CommentSchema = new SimpleSchema(getCommonCommentSchema({ - referenceId: { - type: String - } -})) +CommentsCollection.schemas.CommentSchema = new SimpleSchema( + getCommonCommentSchema({ + referenceId: { + type: String + } + }) +); -CommentsCollection.attachSchema(CommentsCollection.schemas.CommentSchema) +CommentsCollection.attachSchema(CommentsCollection.schemas.CommentSchema); // Is handled with Meteor.methods CommentsCollection.allow({ insert: () => false, update: () => false, remove: () => false -}) +}); -const calculateAverageRating = (ratings) => _.reduce( - ratings, - (averageRating, rating) => (averageRating + rating.rating / ratings.length), - 0 -) +const calculateAverageRating = ratings => + _.reduce( + ratings, + (averageRating, rating) => averageRating + rating.rating / ratings.length, + 0 + ); -CommentsCollection._calculateAverageRating = calculateAverageRating +CommentsCollection._calculateAverageRating = calculateAverageRating; -const getCount = (scope, field) => scope[field] && scope[field].length ? scope[field].length : 0 +const getCount = (scope, field) => + scope[field] && scope[field].length ? scope[field].length : 0; -addCollectionMethods(CommentsCollection) -addReplyMethods(CommentsCollection) +addCollectionMethods(CommentsCollection); +addReplyMethods(CommentsCollection); CommentsCollection.helpers({ - likesCount: function () { - return getCount(this, 'likes'); + likesCount: function() { + return getCount(this, "likes"); }, - dislikesCount: function () { - return getCount(this, 'dislikes'); + dislikesCount: function() { + return getCount(this, "dislikes"); }, - user: function () { - return userService.getUserById(this.userId) + user: function() { + return userService.getUserById(this.userId); }, - createdAgo: function () { - return timeTickService.fromNowReactive(moment(this.createdAt)) + createdAgo: function() { + return timeTickService.fromNowReactive(moment(this.createdAt)); }, - filteredReplies: function () { + filteredReplies: function() { return comment.filterOutNotApprovedReplies( this.replies, - userService.getUserId(), - ) + userService.getUserId() + ); }, - enhancedReplies: function (position) { + enhancedReplies: function(position) { const { _id, user, @@ -228,50 +256,56 @@ CommentsCollection.helpers({ createdAgo, getStarRating, enhancedContent, - referenceId, - } = this + referenceId + } = this; - const userId = userService.getUserId() - let replies = this.replies + const userId = userService.getUserId(); + let replies = this.replies; if (!Comments.config().canSeePendingComments(referenceId, userId)) { - replies = this.filteredReplies() + replies = this.filteredReplies(); } - return enhanceReplies({ - _id, - user, - likesCount, - dislikesCount, - createdAgo, - getStarRating, - enhancedContent, - replies, - }, position) + return enhanceReplies( + { + _id, + user, + likesCount, + dislikesCount, + createdAgo, + getStarRating, + enhancedContent, + replies + }, + position + ); }, - enhancedContent: function () { - return linkifyStr((this.content || '')) + enhancedContent: function() { + return linkifyStr(this.content || ""); }, - getStarRating: function () { + getStarRating: function() { if (_.isArray(this.starRatings)) { - const ownRating = _.find(this.starRatings, rating => rating.userId === Meteor.userId()) + const ownRating = _.find( + this.starRatings, + rating => rating.userId === Meteor.userId() + ); if (ownRating) { return { - type: 'user', + type: "user", rating: ownRating.rating - } + }; } return { - type: 'average', + type: "average", rating: calculateAverageRating(this.starRatings) - } + }; } return { - type: 'average', + type: "average", rating: 0 - } + }; } -}) +}); From 502ef80c2fbe1828fad92630b96668bf54db0b3e Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Wed, 21 Aug 2019 23:33:52 +0200 Subject: [PATCH 4/7] Update time-tick.js --- lib/services/time-tick.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/services/time-tick.js b/lib/services/time-tick.js index a0eb66f..7af83a7 100644 --- a/lib/services/time-tick.js +++ b/lib/services/time-tick.js @@ -1,3 +1,5 @@ +import moment from 'moment'; + const timeTickService = (() => { const timeTick = new Tracker.Dependency() From 1321897b60cfc8657f37156da3745ccdcc4a40ba Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Thu, 22 Aug 2019 03:29:58 +0200 Subject: [PATCH 5/7] Convert likes and dislikes into optional fields --- lib/collections/comments.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/collections/comments.js b/lib/collections/comments.js index cbd9b6b..4362a1d 100644 --- a/lib/collections/comments.js +++ b/lib/collections/comments.js @@ -78,7 +78,8 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { optional: true }, likes: { - type: Array + type: Array, + optional: true }, "likes.$": { type: String, @@ -86,18 +87,19 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { if (this.isInsert) { return []; } - }, - optional: true + } }, - dislikes: { type: Array }, + dislikes: { + type: Array, + optional: true + }, "dislikes.$": { type: String, autoValue: function() { if (this.isInsert) { return []; } - }, - optional: true + } }, starRatings: { type: Array From 2923ec6a7312fa494a0420818b305056f84e123f Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Thu, 22 Aug 2019 03:33:50 +0200 Subject: [PATCH 6/7] Make starRatings optional --- lib/collections/comments.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/collections/comments.js b/lib/collections/comments.js index 4362a1d..4d9d57c 100644 --- a/lib/collections/comments.js +++ b/lib/collections/comments.js @@ -102,7 +102,8 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { } }, starRatings: { - type: Array + type: Array, + optional: true }, "starRatings.$": { type: CommentsCollection.schemas.StarRatingSchema, @@ -110,8 +111,7 @@ function getCommonCommentSchema(additionalSchemaConfig = {}) { if (this.isInsert) { return []; } - }, - optional: true + } }, // general rating number that is used for sorting ratingScore: { From fc4c8783ac31a0e8cd6a141820cbaabcec17b1b4 Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Thu, 22 Aug 2019 03:37:01 +0200 Subject: [PATCH 7/7] Add moment import --- lib/collections/comments.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/collections/comments.js b/lib/collections/comments.js index 4d9d57c..cac841a 100644 --- a/lib/collections/comments.js +++ b/lib/collections/comments.js @@ -4,6 +4,7 @@ import SimpleSchema from "simpl-schema"; SimpleSchema.extendOptions(["autoform"]); +import moment from 'moment'; import linkifyStr from "linkifyjs/string"; import timeTickService from "../services/time-tick"; import userService from "../services/user";