relita

an encrypted, decentralized, peer-to-peer social network
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/relita

commit d817ae2e2c99455d60a3bb400226e9cfb93e3363
parent 53697ff268cf57d311961d3837fe915bd9a48b5a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun,  9 Apr 2017 20:39:57 +0200

Add(Relita): Now can add / read global feed

Diffstat:
Mcss/main.css | 4++++
Mindex.html | 5+++++
Mjs/renderer.js | 29+++++++++++++++++++++++++++--
Mmain.js | 45++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/css/main.css b/css/main.css @@ -49,3 +49,7 @@ html, body { margin-bottom: 30px; color: #F2F2F2; } + +.add_post { + display: none; +} diff --git a/index.html b/index.html @@ -13,6 +13,11 @@ <li><i class='fa fa-spinner fa-pulse fa-fw'></i></li> </ul> </div> + <div class='add_post'> + <input type='text' placeholder="Say Hi !"/> + <button class='submit_post'>Send !</button> + <div> + <div class='posts_list'></div> </body> <script>window.$ = window.jQuery = require('./js/jquery.min.js');</script> diff --git a/js/renderer.js b/js/renderer.js @@ -2,9 +2,34 @@ $(function() { const {ipcRenderer} = require('electron') ipcRenderer.on('connect_client', (event, arg) => { - console.log(arg) - $(".title .status").html("Connection established.") + $(".title .status").html("Connection established. ("+ arg +")") + $(".title i").fadeOut(600, function() { + $(".title").fadeOut(500, function() { + $(".add_post").fadeIn(100); + ipcRenderer.send('get_feed', null); + }); + }) + }) + + ipcRenderer.on('add_post', (event, arg) => { + ipcRenderer.send('get_feed', null); + }) + + ipcRenderer.on('get_feed', (event, arg) => { + $(".posts_list").html("") + for (i = 0; i < arg.length; i++) + { + $(".posts_list").append("<strong>"+ arg[i].value.author + "</strong>: "+ arg[i].value.content.text + "<br />") + } }) ipcRenderer.send('connect_client', null); + + $(".add_post button").click(function() { + val = $(".add_post input").val() + if (val === "") + return ; + ipcRenderer.send('add_post', val); + $(".add_post input").val("") + }) }) diff --git a/main.js b/main.js @@ -19,11 +19,15 @@ const sbot = require('scuttlebot') .use(require('scuttlebot/plugins/block')) .use(require('scuttlebot/plugins/local')) .use(require('scuttlebot/plugins/logging')) +const ssb_client = require('ssb-client') +const pull = require('pull-stream') const default_port = 6666; const default_name = "Relita" let mainWindow +let sbot_client +let user_id function launch_sbot_server() { config.keys = keys @@ -72,5 +76,44 @@ app.on('activate', function () { ipcMain.on('connect_client', (event, arg) => { console.log("Attempting to connect client...") - event.sender.send('connect_client', 'OK') + ssb_client({port: default_port}, function(err, sbot) { + if (err) + event.sender.send('connect_client', 'KO') + else + { + sbot_client = sbot + sbot.whoami(function(err, info) { + user_id = info.id; + }) + event.sender.send('connect_client', 'OK') + } + + }) +}) + +ipcMain.on('get_feed', (event, arg) => { + console.log("Getting feed...") + pull( + sbot_client.createUserStream({id: user_id}), + pull.collect(function (err, msgs) { + if (err) + throw err; + event.sender.send('get_feed', msgs); + }) + ) +}) + +ipcMain.on('add_post', (event, arg) => { + console.log("Adding new post, content is: "+ arg) + sbot_client.publish({ + type: 'post', + text: arg, + }, + function (err, msg) { + if (err) + event.sender.send('add_post', 'KO') + else + event.sender.send('add_post', 'OK') + } + ) })