git ssb

2+

ev / mvd



Commit d3fa74279a5889e43979815541017b56d50f9c23

add support for private messages

Ev Bogue committed on 6/11/2018, 9:29:34 PM
Parent: b934c63c9cd0fa08b3e84acd8cf5c8bae64e994c

Files changed

tools.jschanged
tools.jsView
@@ -2,16 +2,82 @@
22 var human = require('human-time')
33 var avatar = require('./avatar')
44 var ref = require('ssb-ref')
55
6 +var ssbKeys = require('ssb-keys')
7 +
68 var pull = require('pull-stream')
79
810 var sbot = require('./scuttlebot')
911
1012 var config = require('./config')()
1113
1214 var id = require('./keys').id
1315
16 +module.exports.box = function (content) {
17 + return ssbKeys.box(content, content.recps.map(function (e) {
18 + return ref.isFeed(e) ? e : e.link
19 + }))
20 +}
21 +
22 +module.exports.publish = function (content, cb) {
23 + if(content.recps)
24 + content = exports.box(content)
25 + sbot.publish(content, function (err, msg) {
26 + if(err) throw err
27 + console.log('Published!', msg)
28 + if(cb) cb(err, msg)
29 + })
30 +}
31 +
32 +module.exports.done = function (src) {
33 + var content = {
34 + type: 'done',
35 + vote: {'link': src}
36 + }
37 +
38 + var done = h('button.btn.right', 'Done ', h('img.emoji', {src: config.emojiUrl + 'v.png'}), {
39 + onclick: function () {
40 + content.done = true
41 + content.mentions = [id]
42 + content.recps = [id]
43 + exports.publish(content, function (err, published) {
44 + if (err) throw err
45 + })
46 + }
47 + })
48 +
49 + return done
50 +
51 +}
52 +
53 +module.exports.mute = function (src) {
54 + if (!localStorage[src])
55 + var cache = {mute: false}
56 + else
57 + var cache = JSON.parse(localStorage[src])
58 +
59 + if (cache.mute == true) {
60 + var mute = h('button.btn', 'Unmute', {
61 + onclick: function () {
62 + cache.mute = false
63 + localStorage[src] = JSON.stringify(cache)
64 + location.reload()
65 + }
66 + })
67 + return mute
68 + } else {
69 + var mute = h('button.btn', 'Mute', {
70 + onclick: function () {
71 + cache.mute = true
72 + localStorage[src] = JSON.stringify(cache)
73 + location.reload()
74 + }
75 + })
76 + return mute
77 + }
78 +}
79 +
1480 module.exports.star = function (msg) {
1581 var votebutton = h('span.star:' + msg.key.substring(0,44))
1682
1783 var vote = {
@@ -48,13 +114,15 @@
48114 pull.drain(function (link) {
49115 if (link.key) {
50116 sbot.get(link.key, function (err, data) {
51117 if (err) throw err
52- if (data.author == id) {
53- if (data.content.vote.value == 1)
54- votebutton.replaceChild(unstar, star)
55- if (data.content.vote.value == -1)
56- votebutton.replaceChild(star, unstar)
118 + if (data.content.vote) {
119 + if (data.author == id) {
120 + if (data.content.vote.value == 1)
121 + votebutton.replaceChild(unstar, star)
122 + if (data.content.vote.value == -1)
123 + votebutton.replaceChild(star, unstar)
124 + }
57125 }
58126 })
59127 }
60128 })
@@ -71,20 +139,24 @@
71139 pull.drain(function (link) {
72140 if (link.key) {
73141 sbot.get(link.key, function (err, data) {
74142 if (err) throw err
75- if (data.content.vote.value == 1) {
76- if (localStorage[data.author + 'name'])
77- name = localStorage[data.author + 'name']
78- else
79- name = data.author
80- votes.appendChild(h('a#vote:' + data.author.substring(0, 44), {href:'#' + data.author, title: name}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
143 + if (data.content.vote) {
144 + if (data.content.vote.value == 1) {
145 + if (localStorage[data.author + 'name'])
146 + name = localStorage[data.author + 'name']
147 + else
148 + name = data.author
149 + votes.appendChild(h('a#vote:' + data.author.substring(0, 44), {href:'#' + data.author, title: name}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
150 + }
151 + else if (data.content.vote.value == -1) {
152 + var lookFor = 'vote:' + data.author.substring(0, 44)
153 + document.getElementById(lookFor, function (err, gotit) {
154 + if (err) throw err
155 + gotit.parentNode.removeChild(remove)
156 + })
157 + }
81158 }
82- else if (data.content.vote.value == -1) {
83- var lookFor = 'vote:' + data.author.substring(0, 44)
84- var remove = document.getElementById(lookFor)
85- remove.parentNode.removeChild(remove)
86- }
87159 })
88160 }
89161 })
90162 )
@@ -116,18 +188,25 @@
116188 }
117189
118190
119191 module.exports.header = function (msg) {
120- return h('div.header',
121- h('span.avatar',
192 + var header = h('div.header')
193 +
194 + header.appendChild(h('span.avatar',
122195 h('a', {href: '#' + msg.value.author},
123196 h('span.avatar--small', avatar.image(msg.value.author)),
124197 avatar.name(msg.value.author)
125198 )
126- ),
127- exports.timestamp(msg),
128- votes(msg)
199 + )
129200 )
201 +
202 + header.appendChild(exports.timestamp(msg))
203 + header.appendChild(votes(msg))
204 +
205 + if (msg.value.private)
206 + header.appendChild(h('span.right', ' ', h('img.emoji', {src: config.emojiUrl + 'lock.png'})))
207 +
208 + return header
130209 }
131210
132211 var ref = require('ssb-ref')
133212

Built with git-ssb-web