Browse Source

advanced peers information

psy 1 year ago
parent
commit
aaa4267204
5 changed files with 103 additions and 15 deletions
  1. 1 1
      package-lock.json
  2. 1 1
      package.json
  3. 3 2
      src/assets/style.css
  4. 14 4
      src/views/i18n.js
  5. 84 7
      src/views/index.js

+ 1 - 1
package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "@krakenslab/oasis",
-  "version": "0.1.4",
+  "version": "0.1.5",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@krakenslab/oasis",
-  "version": "0.1.4",
+  "version": "0.1.5",
   "description": "SNH-Oasis Project Network GUI",
   "repository": {
     "type": "git",

+ 3 - 2
src/assets/style.css

@@ -330,7 +330,7 @@ section audio {
 
 nav {
   margin: var(--size-0) 0;
-  margin-left: 20px;
+  margin-left: 40px;
 }
 
 nav > ul > li > a {
@@ -363,7 +363,7 @@ section {
   margin: var(--size-0) 0;
   word-wrap: break-word;
   background: var(--bg);
-  width: 100%;
+  width: 105%;
   box-sizing: border-box;
 }
 
@@ -479,6 +479,7 @@ nav > ul {
   flex-wrap: wrap;
   justify-content: space-between;
   margin: 0;
+  margin-right: 30px;
   padding: 0;
 }
 

+ 14 - 4
src/views/i18n.js

@@ -151,9 +151,14 @@ const i18n = {
     setLanguage: "Set language",
     status: "Status",
     peerConnections: "Peers",
-    connectionsIntro:
-      "Your device is syncing data with these other devices:",
+    online: "Online",
+    supported: "Supported",
+    recommended: "Recommended", 
+    blocked: "Blocked",
     noConnections: "No peers connected.",
+    noSupportedConnections: "No peers supported.",
+    noBlockedConnections: "No peers blocked.",
+    noRecommendedConnections: "No peers recommended.",
     connectionActionIntro:
       "",
     startNetworking: "Start networking",
@@ -339,9 +344,14 @@ const i18n = {
     setLanguage: "Seleccionar idioma",
     status: "Estado",
     peerConnections: "Enlaces",
-    connectionsIntro:
-      "Tu dispositivo está sincronizando datos con los siguientes dispositivos:",
+    online: "Online",
+    supported: "Soportados",
+    recommended: "Recomendados",
+    blocked: "Bloqueados",
     noConnections: "Sin enlaces conectados.",
+    noSupportedConnections: "Sin enlaces soportados.",
+    noBlockedConnections: "Sin enlaces bloqueados.",
+    noRecommendedConnections: "Sin enlaces recomendados.",
     connectionActionIntro:
       "",
     startNetworking: "Iniciar red",

+ 84 - 7
src/views/index.js

@@ -4,6 +4,9 @@ const path = require("path");
 const envPaths = require("env-paths");
 const fs = require("fs");
 
+const homedir = require('os').homedir();
+const supportingPath = path.join(homedir, ".ssb/flume/contacts2.json");
+
 const debug = require("debug")("oasis");
 const highlightJs = require("highlight.js");
 
@@ -48,6 +51,8 @@ const {
   ul,
 } = require("hyperaxe");
 
+const { about, blob, vote } = require("../models")({});
+
 const lodash = require("lodash");
 const markdown = require("./markdown");
 
@@ -929,19 +934,15 @@ const generatePreview = ({ previewData, contentWarning, action }) => {
               matches.map((m) => {
                 let relationship = { emoji: "", desc: "" };
                 if (m.rel.followsMe && m.rel.following) {
-                  // mutuals get the handshake emoji
                   relationship.emoji = "☍";
                   relationship.desc = i18n.relationshipMutuals;
                 } else if (m.rel.following) {
-                  // if we're following that's an eyes emoji
                   relationship.emoji = "☌";
                   relationship.desc = i18n.relationshipFollowing;
                 } else if (m.rel.followsMe) {
-                  // follower has waving-hand emoji
                   relationship.emoji = "⚼";
                   relationship.desc = i18n.relationshipTheyFollow;
                 } else {
-                  // no relationship has question mark emoji
                   relationship.emoji = "❓";
                   relationship.desc = i18n.relationshipNotFollowing;
                 }
@@ -1011,7 +1012,8 @@ exports.previewView = ({ previewData, contentWarning }) => {
   return exports.publishView(preview, previewData.text, contentWarning);
 };
 
-exports.peersView =  ({ peers }) => {
+exports.peersView = async ({ peers }) => {
+
  const startButton = form(
     { action: "/settings/conn/start", method: "post" },
     button({ type: "submit" }, i18n.startNetworking)
@@ -1050,20 +1052,95 @@ exports.peersView =  ({ peers }) => {
       );
    });
 
+  const supportedList = (supporting)
+    var supporting = JSON.parse(fs.readFileSync(supportingPath, "utf8")).value;
+    var arr = [];
+    var keys = Object.keys(supporting);
+      var data = Object.entries(supporting[keys[0]]);
+       Object.entries(data).forEach(([key, value]) => {
+         if (value[1]===1){
+          var supported = (value[0])
+           if (!arr.includes(supported)) {
+              arr.push(
+               li(
+                 a(
+                  { href: `/author/${encodeURIComponent(supported)}` }, 
+                  supported
+                 )
+               )
+              );
+           }
+         }
+      });
+  var supports = arr;
+
+  const blockedList = (supporting)
+    var supporting = JSON.parse(fs.readFileSync(supportingPath, "utf8")).value;
+    var arr = [];
+    var keys = Object.keys(supporting);
+      var data = Object.entries(supporting[keys[0]]);
+       Object.entries(data).forEach(([key, value]) => {
+         if (value[1]===-1){
+          var blocked = (value[0])
+           if (!arr.includes(blocked)) {
+              arr.push(
+               li(
+                 a(
+                  { href: `/author/${encodeURIComponent(blocked)}` }, 
+                  blocked
+                 )
+               )
+              );
+           }
+         }
+      });
+  var blocks = arr;
+
+  const recommendedList = (supporting)
+    var supporting = JSON.parse(fs.readFileSync(supportingPath, "utf8")).value;
+    var arr = [];
+    var keys = Object.keys(supporting);
+      var data = Object.entries(supporting[keys[0]]);
+       Object.entries(data).forEach(([key, value]) => {
+         if (value[1]===-2){
+          var recommended = (value[0])
+           if (!arr.includes(recommended)) {
+              arr.push(
+               li(
+                 a(
+                  { href: `/author/${encodeURIComponent(recommended)}` }, 
+                  recommended
+                 )
+               )
+              );
+           }
+         }
+      });
+ var recommends = arr;
+
  return template(
   i18n.peers,
     section(
       { class: "message" },
       h1(i18n.peerConnections),
       connButtons,
-      p(i18n.connectionsIntro),
+      h1(i18n.online, " (", peerList.length, ")"),
       peerList.length > 0 ? ul(peerList) : i18n.noConnections,
       p(i18n.connectionActionIntro),
+      h1(i18n.supported, " (", supports.length, ")"),
+      supports.length > 0 ? ul(supports): i18n.noSupportedConnections,
+      p(i18n.connectionActionIntro),
+      h1(i18n.recommended, " (", recommends.length, ")"),
+      recommends.length > 0 ? ul(recommends): i18n.noRecommendedConnections,
+      p(i18n.connectionActionIntro),
+      h1(i18n.blocked, " (", blocks.length, ")"),
+      blocks.length > 0 ? ul(blocks): i18n.noBlockedConnections,
+      p(i18n.connectionActionIntro),
       )
     );
 };
 
-exports.invitesView =  ({ invites }) => {
+exports.invitesView = ({ invites }) => {
  return template(
   i18n.invites,
     section(