Browse Source

[add] NEW! text before unread
[add] [add] [add] catch https error

B Thibault 8 years ago
parent
commit
7551343458
2 changed files with 22 additions and 15 deletions
  1. 1 0
      srv/public/style.css
  2. 21 15
      srv/src/slack.js

+ 1 - 0
srv/public/style.css

@@ -40,6 +40,7 @@ body { display: flex; margin: 0; padding: 0; font-family: Lato, sans-serif; }
 .slackmsg-item { display: flex; position: relative; padding: 10px; }
 .slackmsg-item:hover { background: #F9F9F9; }
 .slackmsg-item.slackmsg-first-unread { border-top: 1px solid red; }
+.slackmsg-item.slackmsg-first-unread::before { display: inline-block; position: absolute; right: 0; top: -1em; content: "New"; color: red; background: white; padding: 0 5px 0 3px; font-style: italic; }
 .slackmsg-content { display: inline-block; }
 .slackmsg-author { display: inline-block; }
 .slackmsg-author-img { max-height: 36px; max-width: 36px; margin-right: 10px; border-radius: 3px; }

+ 21 - 15
srv/src/slack.js

@@ -70,22 +70,28 @@ Slack.prototype.onRequest = function(knownVersion, cb) {
 };
 
 function httpsRequest(url, cb) {
-    https.get(url, (res) => {
-        if (res.statusCode !== 200) {
-            cb(res.statusCode, null);
-            return;
-        }
-        var body = null;
-        res.on('data', (chunk) => {
-            body = body ? Buffer.concat([body, chunk], body.length +chunk.length) : Buffer.from(chunk);
-        });
-        res.on('end', () => {
-            try {
-                body = JSON.parse(body.toString("utf8"));
-            } catch (e) {}
-            cb && cb(res.statusCode, body);
+    try {
+        https.get(url, (res) => {
+            if (res.statusCode !== 200) {
+                cb(res.statusCode, null);
+                return;
+            }
+            var body = null;
+            res.on('data', (chunk) => {
+                body = body ? Buffer.concat([body, chunk], body.length +chunk.length) : Buffer.from(chunk);
+            });
+            res.on('end', () => {
+                try {
+                    body = JSON.parse(body.toString("utf8"));
+                } catch (e) {}
+                cb && cb(res.statusCode, body);
+            });
         });
-    });
+    }
+    catch (e) {
+        console.error("Error in https request: ", e);
+        cb && cb(0, null);
+    }
 }
 
 Slack.prototype.connect = function(knownVersion) {