Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/client/app.css
Wesley McCann 9 lat temu
rodzic
commit
a7eee3bdb9

+ 1 - 0
app/.meteor/packages

@@ -30,3 +30,4 @@ http
 zimme:iron-router-active
 momentjs:moment
 copleykj:livestamp
+emojione:emojione

+ 1 - 0
app/.meteor/versions

@@ -30,6 +30,7 @@ ecmascript@0.1.6
 ecmascript-runtime@0.2.6
 ejson@1.0.7
 email@1.0.8
+emojione:emojione@1.5.2
 es5-shim@4.1.14
 facebook@1.2.2
 fastclick@1.0.7

+ 8 - 0
app/client/app.css

@@ -1318,3 +1318,11 @@ nav form input[type="image"]{
     height: 28px;
     font-size: 28px !important;
 }
+<<<<<<< HEAD
+=======
+
+.settings-label {
+    color: #50a3a2;
+    line-height: 18px;
+}
+>>>>>>> origin/master

+ 38 - 3
app/client/client.js

@@ -49,6 +49,12 @@ function getSpotifyInfo(title, cb, artist) {
     });
 }
 
+Template.settings.events({
+    "click #save-settings": function() {
+        Meteor.call("updateSettings", $("#showRating").is(":checked"));
+    }
+});
+
 Template.profile.helpers({
     "username": function() {
         return Session.get("username");
@@ -83,7 +89,7 @@ Template.profile.onCreated(function() {
     var parts = Router.current().url.split('/');
     var username = parts.pop();
     Session.set("loaded", false);
-    Meteor.subscribe("userProfiles", function() {
+    Meteor.subscribe("userProfiles", username.toLowerCase(), function() {
         if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() === 0) {
             window.location = "/";
         } else {
@@ -99,10 +105,39 @@ Template.profile.onCreated(function() {
 
 Template.settings.helpers({
     username: function() {
-        return Meteor.user().profile.username;
+        if (Meteor.user() !== undefined) {
+            return Meteor.user().profile.username;
+        } else {
+            return "";
+        }
     }
 });
 
+Template.settings.onCreated(function() {
+    $(document).ready(function() {
+        var user = Meteor.user();
+        function initSettings() {
+            if (user !== undefined) {
+                if (user.profile.settings && user.profile.settings.showRating === true) {
+                    function setChecked() {
+                        $("#showRating").prop("checked", true);
+                        if (!$("#showRating").prop("checked")) {
+                            Meteor.setTimeout(function() {
+                                setChecked();
+                            }, 100);
+                        }
+                    }
+                    setChecked();
+                }
+            } else {
+                Meteor.setTimeout(function() {
+                    initSettings();
+                }, 500);
+            }
+        }
+        initSettings();
+    });
+});
 
 curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
 
@@ -327,7 +362,7 @@ Template.room.events({
     "keyup #chat-input": function(e) {
         if (e.type == "keyup" && e.which == 13) {
             e.preventDefault();
-            sendMessage();
+            sendMessage()
         }
     },
     "click #like": function(e) {

+ 3 - 1
app/client/templates/room.html

@@ -113,7 +113,9 @@
                         <div class="tab-pane" id="chat">
                             <ul id="chat-ul">
                                 {{#each chat}}
-                                    <li class="chat-message"><small class="rank-{{this.rawrank}}">{{this.rank}}</small> <a style="text-decoration: none" href="/u/{{this.username}}" target="_blank"><b class="bold">{{this.username}}</b></a> <span data-livestamp="{{time}}" title="{{time}}" style="float: right;"></span> <br/>{{this.message}}</li>
+                                    {{#emojione}}
+                                        <li class="chat-message"><small class="rank-{{this.rawrank}}">{{this.rank}}</small> <a style="text-decoration: none" href="/u/{{this.username}}" target="_blank"><b class="bold">{{this.username}}</b></a> <span data-livestamp="{{time}}" title="{{time}}" style="float: right;"></span> <br/>{{this.message}}</li>
+                                    {{/emojione}}
                                     <hr>
                                 {{/each}}
                             </ul>

+ 8 - 1
app/client/templates/settings.html

@@ -6,7 +6,14 @@
             <div class="panel panel-primary">
                 <div class="panel-heading">Basic Info</div>
                 <div class="panel-body">
-                    <h3 class="text text-warning text-center">Unfortunately, there is currently nothing for you to edit.</h3>
+                    <!--h3 class="text text-warning text-center">Unfortunately, there is currently nothing for you to edit.</h3-->
+                    <div class="checkbox">
+                        <input class="checkbox-box" type="checkbox" id="showRating">
+                        <label for="showRating" class="settings-label">
+                            Show your likes/dislikes on your public profile
+                        </label>
+                    </div>
+                    <button class="btn btn-warning btn-block" id="save-settings">Save</button>
                 </div>
             </div>
         </div>

+ 26 - 3
app/server/server.js

@@ -8,6 +8,7 @@ Meteor.startup(function() {
             createRoom(stations[i].display, stations[i].tag);
         }
     }
+    emojione.ascii = true;
 });
 
 Alerts.update({active: true}, {$set: {active: false}}, { multi: true });
@@ -361,7 +362,7 @@ Accounts.onCreateUser(function(options, user) {
             username = user.username;
         }
     }
-    user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default", liked: [], disliked: []};
+    user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default", liked: [], disliked: [], settings: {showRating: false}};
     return user;
 });
 
@@ -413,8 +414,15 @@ Meteor.publish("chat", function() {
     return Chat.find({});
 });
 
-Meteor.publish("userProfiles", function() {
-    return Meteor.users.find({}, {fields: {profile: 1, createdAt: 1}});
+Meteor.publish("userProfiles", function(username) {
+    var settings = Meteor.users.findOne({"profile.usernameL": username}, {fields: {"profile.settings": 1}});
+    if (settings !== undefined && settings.profile.settings) {
+        settings = settings.profile.settings;
+        if (settings.showRating === true) {
+            return Meteor.users.find({"profile.usernameL": username}, {fields: {"profile.username": 1, "profile.usernameL": 1, "profile.rank": 1, createdAt: 1, "profile.liked": 1, "profile.disliked": 1, "profile.settings": 1}});
+        }
+    }
+    return Meteor.users.find({"profile.usernameL": username}, {fields: {"profile.username": 1, "profile.usernameL": 1, "profile.rank": 1, createdAt: 1, "profile.settings": 1}});
 });
 
 Meteor.publish("isAdmin", function() {
@@ -431,6 +439,21 @@ function isAdmin() {
 }
 
 Meteor.methods({
+    updateSettings: function(showRating) {
+        if (Meteor.userId()) {
+            var user = Meteor.user();
+            if (showRating !== true && showRating !== false) {
+                showRating = false;
+            }
+            if (user.profile.settings) {
+                Meteor.users.update({"profile.username": user.profile.username}, {$set: {"profile.settings.showRating": showRating}});
+            } else {
+                Meteor.users.update({"profile.username": user.profile.username}, {$set: {"profile.settings": {showRating: showRating}}});
+            }
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     resetRating: function() {
         if (isAdmin()) {
             stations.forEach(function (station) {