浏览代码

Made people their windows automatically refresh when they are banned/unbanned.

KrisVos130 9 年之前
父节点
当前提交
31b1e3a35f
共有 3 个文件被更改,包括 30 次插入9 次删除
  1. 29 3
      app/client/client.js
  2. 0 1
      app/client/routes.js
  3. 1 5
      app/server/server.js

+ 29 - 3
app/client/client.js

@@ -22,6 +22,34 @@ Deps.autorun(function() {
     Meteor.subscribe("userData", Meteor.userId());
 });
 
+var ban_interval = Meteor.setInterval(function() {
+    var userId = Meteor.userId();
+    if (userId !== undefined) {
+        var userData = Meteor.user();
+        if (localStorage.getItem("banned") === "true") {
+            if (userData !== undefined && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
+                var ban = userData.punishments.ban;
+                if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
+                    Meteor.call("isBanned", function(err, res) {
+                        if (res === false) {
+                            localStorage.setItem("banned", false);
+                            Meteor._reload.reload();
+                        }
+                    });
+                }
+            } else {
+                localStorage.setItem("banned", false);
+                Meteor._reload.reload();
+            }
+        } else {
+            if (userData.punishments !== undefined && userData.punishments.ban !== undefined) {
+                localStorage.setItem("banned", true);
+                Meteor._reload.reload();
+            }
+        }
+    }
+}, 1000);
+
 var minterval;
 var hpSound = undefined;
 var songsArr = [];
@@ -721,9 +749,7 @@ Template.banned.onCreated(function() {
     rTimeInterval = Meteor.setInterval(function() {
         Session.set("time", new Date().getTime());
     }, 10000);
-    Meteor.subscribe("ownBan", Meteor.userId(), function() {
-        Session.set("ban", Meteor.user().punishments.ban);
-    });
+    Session.set("ban", Meteor.user().punishments.ban);
 });
 
 Template.registerHelper("rtime", function(date) {

+ 0 - 1
app/client/routes.js

@@ -9,7 +9,6 @@ Router.onBeforeAction(function() {
         Meteor.call("isBanned", function(err, res) {
             if (res) {
                 self.render('banned');
-                pause();
             } else {
                 next();
             }

+ 1 - 5
app/server/server.js

@@ -380,7 +380,7 @@ Meteor.publish("alerts", function() {
 
 Meteor.publish("userData", function(userId) {
     if (userId !== undefined) {
-        return Meteor.users.find(userId, {fields: {"services.github.username": 1}})
+        return Meteor.users.find(userId, {fields: {"services.github.username": 1, "punishments": 1}})
     } else {
         return undefined;
     }
@@ -410,10 +410,6 @@ Meteor.publish("chat", function() {
     return Chat.find({});
 });
 
-Meteor.publish("ownBan", function(userId) {
-    return Meteor.users.find(userId, {"punishments.ban": 1, "profile": 1});
-});
-
 Meteor.publish("userProfiles", function(username) {
     var settings = Meteor.users.findOne({"profile.usernameL": username}, {fields: {"profile.settings": 1}});
     if (settings !== undefined && settings.profile.settings) {