Skip to content

Commit

Permalink
Added Patreon notification badge for new patreon posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed Feb 21, 2019
1 parent 2253672 commit 3fbb006
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 17 deletions.
26 changes: 26 additions & 0 deletions app/Model/Meta/PatreonPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PatreonPosts = new Mongo.Collection("patreonPosts");

Schemas.PatreonPosts = new SimpleSchema({
link: {
type: String,
},
dateAdded: {
type: Date,
autoValue(){
return new Date();
},
},
});

PatreonPosts.attachSchema(Schemas.PatreonPosts);

PatreonPosts.allow({
insert: function(userId, doc) {
var user = Meteor.users.findOne(userId);
if (user) return _.contains(user.roles, "admin");
},
remove: function(userId, doc) {
var user = Meteor.users.findOne(userId);
if (user) return _.contains(user.roles, "admin");
},
});
12 changes: 12 additions & 0 deletions app/Model/Users/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ Schemas.User = new SimpleSchema({
index: 1,
optional: true,
},
lastPatreonPostClicked: {
type: String,
optional: true,
},
});

Meteor.users.attachSchema(Schemas.User);
Expand Down Expand Up @@ -107,3 +111,11 @@ if (Meteor.isServer) Meteor.methods({
Meteor.users.update(this.userId, {$set: {apiKey}});
},
});

Meteor.methods({
clickPatreonPost(link) {
Meteor.users.update(this.userId, {$set: {
lastPatreonPostClicked: link
}});
},
});
11 changes: 9 additions & 2 deletions app/client/views/layout/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@
<iron-icon icon="bug-report" item-icon></iron-icon>
Send Feedback
</paper-icon-item>
<a class="patreon" href="https://www.patreon.com/dicecloud" target="_blank" tabindex="-1">
<a class="patreon" href="{{patreonLink}}" target="_blank" tabindex="-1">
<paper-icon-item>
<iron-icon icon="dicecloud:patreon" item-icon></iron-icon>
<iron-icon id="patreon-link-icon" icon="dicecloud:patreon" item-icon></iron-icon>
{{#if showPatreonBadge}}
<paper-badge
icon="av:new-releases"
for="patreon-link-icon"
label="New post">
</paper-badge>
{{/if}}
Patreon
</paper-icon-item>
</a>
Expand Down
13 changes: 13 additions & 0 deletions app/client/views/layout/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Template.appDrawer.helpers({
var user = Meteor.user();
return user.profile && user.profile.username || user.username || "My Account";
},
showPatreonBadge: function(){
let post = PatreonPosts.findOne({}, {sort: {date: -1}});
let user = Meteor.user();
if (!post || !user) return false;
return post.link !== user.lastPatreonPostClicked;
},
patreonLink: function(){
let post = PatreonPosts.findOne({}, {sort: {date: -1}});
return (post && post.link) || 'https://www.patreon.com/dicecloud';
},
});

let drawerLayout;
Expand Down Expand Up @@ -37,6 +47,9 @@ Template.appDrawer.events({
closeDrawer(instance);
},
"click .patreon": function(event, instance){
let post = PatreonPosts.findOne({}, {sort: {date: -1}});
let link = (post && post.link) || 'https://www.patreon.com/dicecloud';
Meteor.call('clickPatreonPost', link);
ga("send", "event", "externalLink", "patreon");
},
"click .github": function(event, instance){
Expand Down
9 changes: 5 additions & 4 deletions app/config.vulcanize
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"polyfill": "/components/webcomponentsjs/webcomponents.min.js",
"useShadowDom": true,
"imports": [
"/components/app-layout/app-layout.html",
"/components/app-layout/app-layout.html",
"/components/app-layout/app-layout.html",
"/components/app-layout/app-layout.html",
"/components/app-layout/app-scroll-effects/effects/waterfall.html",
"/components/app-layout/app-scroll-effects/effects/parallax-background.html",
"/components/app-layout/app-scroll-effects/effects/resize-title.html",

"/components/iron-collapse/iron-collapse.html",
"/components/iron-collapse/iron-collapse.html",
"/components/iron-icon/iron-icon.html",
"/components/iron-icons/av-icons.html",
"/components/iron-icons/editor-icons.html",
Expand All @@ -21,7 +21,8 @@

"/components/neon-animation/neon-animation.html",

"/components/paper-button/paper-button.html",
"/components/paper-button/paper-button.html",
"/components/paper-badge/paper-badge.html",
"/components/paper-swatch-picker/paper-swatch-picker.html",
"/components/paper-dialog/paper-dialog.html",
"/components/paper-dropdown-menu/paper-dropdown-menu.html",
Expand Down
6 changes: 3 additions & 3 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"bower": "^1.7.9",
"core-js": "^2.5.7",
"fibers": "^2.0.2",
"file-saver": "^2.0.0",
"file-saver": "^2.0.1",
"meteor-node-stubs": "^0.3.3",
"qrcode": "^1.3.0",
"source-map-support": "^0.5.9",
Expand Down
18 changes: 11 additions & 7 deletions app/server/publications/user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Meteor.publish("user", function(){
return Meteor.users.find(this.userId, {fields: {
roles: 1,
username: 1,
profile: 1,
apiKey: 1,
librarySubscriptions: 1,
}});
return [
Meteor.users.find(this.userId, {fields: {
roles: 1,
username: 1,
profile: 1,
apiKey: 1,
librarySubscriptions: 1,
lastPatreonPostClicked: 1,
}}),
PatreonPosts.find({},{sort: {dateAdded: -1}, limit: 1})
];
});

0 comments on commit 3fbb006

Please sign in to comment.