浏览代码

no message

kuaifan 5 年之前
父节点
当前提交
29202e3bee

+ 3 - 1
resources/assets/js/main/App.vue

@@ -184,7 +184,9 @@
                         }
                         switch (msgDetail.messageType) {
                             case 'open':
-                                window.localStorage.setItem("__::WookTeam:config", $A.jsonStringify(msgDetail.config));
+                                window.localStorage.setItem("__::WookTeam:config", $A.jsonStringify(Object.assign(msgDetail.config, {
+                                    nickname: $A.getNickName(false)
+                                })));
                                 break;
                             case 'close':
                                 window.localStorage.setItem("__::WookTeam:config", $A.jsonStringify({}));

+ 4 - 3
resources/assets/js/main/main.js

@@ -145,14 +145,15 @@ import '../../sass/main.scss';
 
         /**
          * 获取会员昵称
-         * @returns string
+         * @param nullName
+         * @returns {string|*}
          */
-        getNickName() {
+        getNickName(nullName = true) {
             if ($A.getToken() === false) {
                 return "";
             }
             let userInfo = $A.getUserInfo();
-            return $A.ishave(userInfo.nickname) ? userInfo.nickname : $A.getUserName();
+            return $A.ishave(userInfo.nickname) ? userInfo.nickname : (nullName ? $A.getUserName() : '');
         },
 
         /**

+ 44 - 35
resources/notify/chrome/js/notify.js

@@ -47,6 +47,7 @@ const getBadgeNum = function () {
                 username: config.username,
                 token: config.token,
                 url: config.url,
+                key: key,
                 channel: 'chromeExtend'
             }).setOnMsgListener('notify', ['open', 'unread', 'user'], function (msgDetail) {
                 let body = msgDetail.body;
@@ -102,45 +103,53 @@ getBadgeNum();
  */
 chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
     var configLists;
-    if (request.act === "config") {
-        if (sender.tab) {
-            var hostname = $A.getHost(sender.tab.url);
-            if (hostname) {
-                configLists = $A.jsonParse($A.getStorage("configLists"), {});
-                if (typeof configLists[hostname] !== "object") {
-                    configLists[hostname] = {};
+    switch (request.act) {
+        case "config":
+            if (sender.tab) {
+                var hostname = $A.getHost(sender.tab.url);
+                if (hostname) {
+                    configLists = $A.jsonParse($A.getStorage("configLists"), {});
+                    if (typeof configLists[hostname] !== "object" || configLists[hostname] === null) {
+                        configLists[hostname] = {};
+                    }
+                    configLists[hostname] = Object.assign(configLists[hostname], request.config, {
+                        hostname: hostname,
+                    });
+                    $A.setStorage("configLists", $A.jsonStringify(configLists));
+                    sendResponse(configLists);
                 }
-                configLists[hostname] = Object.assign(request.config, {
-                    hostname: hostname,
-                });
+            }
+            break;
+
+        case "getInstances":
+            sendResponse(instances);
+            break;
+
+        case "clickInstances":
+            if (typeof instances[request.index] === "object") {
+                instances[request.index].ws.sendTo('unread', function (res) {
+                    if (res.status === 1) {
+                        instances[request.index].unread = $A.runNum(res.message);
+                        updateBadgeNum();
+                    }
+                    sendResponse(res);
+                })
+            }
+            break;
+
+        case "delInstances":
+            configLists = $A.jsonParse($A.getStorage("configLists"), {});
+            if (typeof configLists[request.index] === "object") {
+                delete configLists[request.index];
                 $A.setStorage("configLists", $A.jsonStringify(configLists));
-                sendResponse(configLists);
             }
-        }
-    } else if (request.act === "getInstances") {
-        sendResponse(instances);
-    } else if (request.act === "clickInstances") {
-        if (typeof instances[request.index] === "object") {
-            instances[request.index].ws.sendTo('unread', function (res) {
-                if (res.status === 1) {
-                    instances[request.index].unread = $A.runNum(res.message);
-                    updateBadgeNum();
+            if (typeof instances[request.index] === "object") {
+                if (typeof instances[request.index].ws !== "undefined") {
+                    instances[request.index].ws.config(null).close();
                 }
-                sendResponse(res);
-            })
-        }
-    } else if (request.act === "delInstances") {
-        configLists = $A.jsonParse($A.getStorage("configLists"), {});
-        if (typeof configLists[request.index] === "object") {
-            delete configLists[request.index];
-            $A.setStorage("configLists", $A.jsonStringify(configLists));
-        }
-        if (typeof instances[request.index] === "object") {
-            if (typeof  instances[request.index].ws !== "undefined") {
-                 instances[request.index].ws.config(null).close();
+                delete instances[request.index];
             }
-            delete instances[request.index];
-        }
-        updateBadgeNum();
+            updateBadgeNum();
+            break;
     }
 });

+ 12 - 3
resources/notify/chrome/js/popup.js

@@ -33,12 +33,21 @@ function showLists(lists) {
         if (!lists.hasOwnProperty(index)) {
             continue;
         }
-        if (typeof tempLists[index] == "object" && tempLists[index].disabled === true) {
+        if (tempLists[index] === null || typeof tempLists[index] !== "object") {
             continue;
         }
-        const item = lists[index];
+        if (tempLists[index].disabled === true) {
+            continue;
+        }
+        const item = Object.assign(lists[index], {
+            nickname: tempLists[index].nickname
+        });
         html+= '<li class="message_box' + (j == length ? ' last' : '') + '" data-index="' + index + '" data-token="' + item.token + '">';
-        html+= '<div class="message_username">' + item.username + '</div>';
+        if (item.nickname) {
+            html+= `<div class="message_username">${item.nickname} (${item.username})</div>`;
+        } else {
+            html+= '<div class="message_username">' + item.username + '</div>';
+        }
         html+= '<div class="message_host">' + index + '</div>';
         html+= '<div class="message_unread' + (item.unread == 0 ? ' zero' : '') + '">未读: ' + item.unread + '</div>';
         html+= '<div class="message_delete">删除</div>';

+ 10 - 0
resources/notify/chrome/js/wtws.js

@@ -106,6 +106,7 @@ const WTWS = function (config) {
             config = {};
         }
         config.username = config.username || '';
+        config.key = config.key || '';
         config.url = config.url || '';
         config.token = config.token || '';
         config.channel = config.channel || '';
@@ -134,6 +135,15 @@ const WTWS = function (config) {
             return this;
         }
 
+        var configLists = $A.jsonParse($A.getStorage("configLists"), {});
+        var keyConfig = configLists[this.__config.key];
+        if (keyConfig !== null && typeof keyConfig == "object") {
+            if (keyConfig['disabled'] === true) {
+                this.__log("[WS] " + this.__config.key + " is disabled");
+                return this;
+            }
+        }
+
         var thas = this;
 
         // 初始化客户端套接字并建立连接

+ 1 - 1
resources/notify/chrome/manifest.json

@@ -1,6 +1,6 @@
 {
     "manifest_version": 2,
-    "version": "1.2",
+    "version": "1.3",
     "name": "TEAM提醒",
     "description": "TEAM消息提醒",
     "icons": {

+ 3 - 3
resources/notify/chrome/popup.html

@@ -28,12 +28,12 @@
             font-size: 14px;
         }
 
-        .message_lists {
+        ul.message_lists {
             max-height: 500px;
             overflow: auto;
         }
 
-        .message_box {
+        ul.message_lists li {
             margin: 6px 16px;
             padding: 6px 0;
             color: #555555;
@@ -42,7 +42,7 @@
             position: relative;
         }
 
-        .message_box.last {
+        ul.message_lists li:last-child {
             border-bottom: 0;
         }