|
@@ -214,6 +214,14 @@ if (Meteor.isClient) {
|
|
|
});
|
|
|
|
|
|
Template.room.events({
|
|
|
+ "click #like": function(e) {
|
|
|
+ console.log("Liked");
|
|
|
+ Meteor.call("likeSong", Session.get("currentSong").mid);
|
|
|
+ },
|
|
|
+ "click #dislike": function(e) {
|
|
|
+ console.log("Disliked");
|
|
|
+ Meteor.call("dislikeSong", Session.get("currentSong").mid);
|
|
|
+ },
|
|
|
"click #report-prev": function(e) {
|
|
|
if (Session.get("previousSong") !== undefined) {
|
|
|
Session.set("reportPrevious", true);
|
|
@@ -246,30 +254,6 @@ if (Meteor.isClient) {
|
|
|
});
|
|
|
$("#close-modal-a").click();
|
|
|
},
|
|
|
- "click #smile-modal": function(e){
|
|
|
- e.preventDefault();
|
|
|
- if (Session.get("smileClicked")) {
|
|
|
- $("#smile-modal").removeClass("active");
|
|
|
- Session.set("smileClicked", false);
|
|
|
- } else {
|
|
|
- $("#meh-modal").removeClass("active");
|
|
|
- Session.set("mehClicked", false);
|
|
|
- $("#smile-modal").addClass("active");
|
|
|
- Session.set("smileClicked", true);
|
|
|
- }
|
|
|
- },
|
|
|
- "click #meh-modal": function(e){
|
|
|
- e.preventDefault();
|
|
|
- if (Session.get("mehClicked")) {
|
|
|
- $("#meh-modal").removeClass("active");
|
|
|
- Session.set("mehClicked", false);
|
|
|
- } else {
|
|
|
- $("#smile-modal").removeClass("active");
|
|
|
- Session.set("smileClicked", false);
|
|
|
- $("#meh-modal").addClass("active");
|
|
|
- Session.set("mehClicked", true);
|
|
|
- }
|
|
|
- },
|
|
|
"click #toggle-video": function(e){
|
|
|
e.preventDefault();
|
|
|
if (Session.get("mediaHidden")) {
|
|
@@ -1313,7 +1297,7 @@ if (Meteor.isServer) {
|
|
|
username = user.username;
|
|
|
}
|
|
|
}
|
|
|
- user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default"};
|
|
|
+ user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default", liked: [], disliked: []};
|
|
|
return user;
|
|
|
});
|
|
|
|
|
@@ -1371,6 +1355,48 @@ if (Meteor.isServer) {
|
|
|
}
|
|
|
|
|
|
Meteor.methods({
|
|
|
+ likeSong: function(mid) {
|
|
|
+ console.log("Liked! ", mid);
|
|
|
+ if (Meteor.userId()) {
|
|
|
+ var user = Meteor.user();
|
|
|
+ if (user.profile.liked.indexOf(mid) === -1) {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.liked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": 1}})
|
|
|
+ } else {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}})
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user.profile.disliked.indexOf(mid) !== -1) {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}})
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dislikeSong: function(mid) {
|
|
|
+ console.log("Disliked! ", mid);
|
|
|
+ if (Meteor.userId()) {
|
|
|
+ var user = Meteor.user();
|
|
|
+ if (user.profile.disliked.indexOf(mid) === -1) {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.disliked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": 1}});
|
|
|
+ } else {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}});
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user.profile.liked.indexOf(mid) !== -1) {
|
|
|
+ Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
|
|
|
+ Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}});
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
|
+ }
|
|
|
+ },
|
|
|
submitReport: function(report, id) {
|
|
|
var obj = report;
|
|
|
obj.id = id;
|
|
@@ -1522,6 +1548,9 @@ if (Meteor.isServer) {
|
|
|
Playlists.insert({type: type, songs: []});
|
|
|
}
|
|
|
if (songData !== undefined && Object.keys(songData).length === 7 && songData.type !== undefined && songData.mid !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.duration !== undefined && songData.img !== undefined) {
|
|
|
+ songData.likes = 0;
|
|
|
+ songData.dislikes = 0
|
|
|
+
|
|
|
Playlists.update({type: type}, {
|
|
|
$push: {
|
|
|
songs: {
|
|
@@ -1531,7 +1560,9 @@ if (Meteor.isServer) {
|
|
|
artist: songData.artist,
|
|
|
duration: songData.duration,
|
|
|
img: songData.img,
|
|
|
- type: songData.type
|
|
|
+ type: songData.type,
|
|
|
+ likes: songData.likes,
|
|
|
+ dislikes: songData.dislikes
|
|
|
}
|
|
|
}
|
|
|
});
|