From 283b707e600ff305c3726edb986a5bc493f91441 Mon Sep 17 00:00:00 2001 From: Audrey Baxter Date: Sun, 19 Apr 2020 23:13:52 -0400 Subject: [PATCH 1/3] simple RSS syndication --- .meteor/packages | 1 + .meteor/versions | 1 + collections/posts.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index fc10111..55920a8 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -25,3 +25,4 @@ npm-container nemo64:bootstrap atoy40:accounts-cas +raix:rssfeed diff --git a/.meteor/versions b/.meteor/versions index e4d4fd8..428b0a9 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -56,6 +56,7 @@ npm-container@1.0.0 observe-sequence@1.0.6 ordered-dict@1.0.3 percolatestudio:synced-cron@1.0.0 +raix:rssfeed@0.0.5 random@1.0.3 reactive-dict@1.1.0 reactive-var@1.0.5 diff --git a/collections/posts.js b/collections/posts.js index d1a9eb3..fbaa527 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -49,6 +49,40 @@ var validatePost = function validatePost (postAttributes) { throw new Meteor.Error(422, 'Description must not exceed 4000 characters. Currently: ' + descriptionLength ); }; +var updateRSS = function updateRSS() { + if (Meteor.isServer) { + RssFeed.publish('petitions', function(query) { + var self = this; // need to store a reference to this so we can add items in the forEach loop later + + self.setValue('title', self.cdata('RPI Petitions')); + self.setValue('description', self.cdata('Create and sign petitions. Receive official responses from the Student Senate.')); + self.setValue('link', 'https://petitions.union.rpi.edu'); + self.setValue('lastBuildDate', new Date()); + self.setValue('pubDate', new Date()); + self.setValue('ttl', 60); + + Posts.find(query ? query : {}, {sort: {submitted: -1}, limit: 20}).forEach(function(post) { + var info = undefined; + if (post.response) { + info = "Received a Response"; + } else if (post.votes >= post.minimumVotes) { + info = "Reached Vote Threshold"; + } + + date = new Date(); + date.setTime(post.submitted); + + self.addItem({ + title: (info === undefined) ? post.title : (post.title + " (" + post.info + ")"), + description: post.description, + link: "https://petitions.union.rpi.edu/petitions/" + post._id, + pubDate: date + }); + }); + }); + } +} + Meteor.methods({ post: function(postAttributes) { @@ -70,6 +104,7 @@ Meteor.methods({ var postId = Posts.insert(post); Singleton.update({}, {$inc: {postsCount: 1}}); + updateRSS(); return postId; }, @@ -104,6 +139,7 @@ Meteor.methods({ "\n\nThanks, \nRPI Web Technologies Group" }); } + updateRSS(); } }, @@ -124,6 +160,7 @@ Meteor.methods({ $pull: {upvoters: user._id}, $inc: {votes: -1} }); + updateRSS(); } }, @@ -203,6 +240,8 @@ Meteor.methods({ "\n\nThanks, \nRIT Student Government" }); } + + updateRSS(); }, delete: function (postId) { @@ -215,6 +254,6 @@ Meteor.methods({ Posts.remove(postId); Singleton.update({}, {$inc: {postsCount: -1}}); - + updateRSS(); } -}); \ No newline at end of file +}); From c3480536881a4dffa253ae5cc820b684c6dfd267 Mon Sep 17 00:00:00 2001 From: Audrey Baxter Date: Sun, 19 Apr 2020 23:31:04 -0400 Subject: [PATCH 2/3] (re)create RSS feed on startup --- collections/posts.js | 20 +++++++++----------- server/startup.js | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/collections/posts.js b/collections/posts.js index fbaa527..4d936f8 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -49,8 +49,8 @@ var validatePost = function validatePost (postAttributes) { throw new Meteor.Error(422, 'Description must not exceed 4000 characters. Currently: ' + descriptionLength ); }; -var updateRSS = function updateRSS() { - if (Meteor.isServer) { +Meteor.methods({ + updateRSS: function() { RssFeed.publish('petitions', function(query) { var self = this; // need to store a reference to this so we can add items in the forEach loop later @@ -80,10 +80,8 @@ var updateRSS = function updateRSS() { }); }); }); - } -} + }, -Meteor.methods({ post: function(postAttributes) { validatePost(postAttributes); @@ -104,7 +102,7 @@ Meteor.methods({ var postId = Posts.insert(post); Singleton.update({}, {$inc: {postsCount: 1}}); - updateRSS(); + Metor.call('updateRSS'); return postId; }, @@ -139,7 +137,7 @@ Meteor.methods({ "\n\nThanks, \nRPI Web Technologies Group" }); } - updateRSS(); + Meteor.call('updateRSS'); } }, @@ -160,7 +158,7 @@ Meteor.methods({ $pull: {upvoters: user._id}, $inc: {votes: -1} }); - updateRSS(); + Meteor.call('updateRSS'); } }, @@ -241,9 +239,9 @@ Meteor.methods({ }); } - updateRSS(); + Meteor.call('updateRSS'); }, - + delete: function (postId) { var user = Meteor.user(); @@ -254,6 +252,6 @@ Meteor.methods({ Posts.remove(postId); Singleton.update({}, {$inc: {postsCount: -1}}); - updateRSS(); + Meteor.call('updateRSS'); } }); diff --git a/server/startup.js b/server/startup.js index ecc8659..3b59935 100644 --- a/server/startup.js +++ b/server/startup.js @@ -1,4 +1,5 @@ Meteor.startup(function () { Singleton.update({}, {$set: { version: "v1.2.2.3" }}); + Meteor.call('updateRSS'); process.env.MAIL_URL = Meteor.settings.MAIL_URL; }); From e40f3f5f0099ccf4e1bf2fe6575a2cff2909c29e Mon Sep 17 00:00:00 2001 From: Audrey Baxter Date: Sun, 19 Apr 2020 23:35:08 -0400 Subject: [PATCH 3/3] recieve -> receive --- client/views/posts/post_page.js | 2 +- collections/posts.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/views/posts/post_page.js b/client/views/posts/post_page.js index 37cb476..add88a5 100644 --- a/client/views/posts/post_page.js +++ b/client/views/posts/post_page.js @@ -58,7 +58,7 @@ Template.postPage.helpers({ } else if (post.status == "responded") { return { title: "Responded", - description: "This petition has recieved an official response." + description: "This petition has received an official response." }; } else { if (post.votes >= post.minimumVotes) { diff --git a/collections/posts.js b/collections/posts.js index 4d936f8..c7e78e6 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -233,7 +233,7 @@ Meteor.methods({ from: "sgnoreply@rit.edu", subject: "PawPrints - A petition you signed has received a response", text: "Hello, \n\n" + - "Petition \"" + post.title + "\" by " + oldPost.author + " has recieved a response: \n\n" + + "Petition \"" + post.title + "\" by " + oldPost.author + " has received a response: \n\n" + Meteor.settings.public.root_url + "/petitions/" + oldPost._id + "\n\nThanks, \nRIT Student Government" });