Commit d3fa74279a5889e43979815541017b56d50f9c23
add support for private messages
Ev Bogue committed on 6/11/2018, 9:29:34 PMParent: b934c63c9cd0fa08b3e84acd8cf5c8bae64e994c
Files changed
tools.js | changed |
tools.js | ||
---|---|---|
@@ -2,16 +2,82 @@ | ||
2 | 2 | var human = require('human-time') |
3 | 3 | var avatar = require('./avatar') |
4 | 4 | var ref = require('ssb-ref') |
5 | 5 | |
6 | +var ssbKeys = require('ssb-keys') | |
7 | + | |
6 | 8 | var pull = require('pull-stream') |
7 | 9 | |
8 | 10 | var sbot = require('./scuttlebot') |
9 | 11 | |
10 | 12 | var config = require('./config')() |
11 | 13 | |
12 | 14 | var id = require('./keys').id |
13 | 15 | |
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 | + | |
14 | 80 | module.exports.star = function (msg) { |
15 | 81 | var votebutton = h('span.star:' + msg.key.substring(0,44)) |
16 | 82 | |
17 | 83 | var vote = { |
@@ -48,13 +114,15 @@ | ||
48 | 114 | pull.drain(function (link) { |
49 | 115 | if (link.key) { |
50 | 116 | sbot.get(link.key, function (err, data) { |
51 | 117 | 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 | + } | |
57 | 125 | } |
58 | 126 | }) |
59 | 127 | } |
60 | 128 | }) |
@@ -71,20 +139,24 @@ | ||
71 | 139 | pull.drain(function (link) { |
72 | 140 | if (link.key) { |
73 | 141 | sbot.get(link.key, function (err, data) { |
74 | 142 | 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 | + } | |
81 | 158 | } |
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 | - } | |
87 | 159 | }) |
88 | 160 | } |
89 | 161 | }) |
90 | 162 | ) |
@@ -116,18 +188,25 @@ | ||
116 | 188 | } |
117 | 189 | |
118 | 190 | |
119 | 191 | 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', | |
122 | 195 | h('a', {href: '#' + msg.value.author}, |
123 | 196 | h('span.avatar--small', avatar.image(msg.value.author)), |
124 | 197 | avatar.name(msg.value.author) |
125 | 198 | ) |
126 | - ), | |
127 | - exports.timestamp(msg), | |
128 | - votes(msg) | |
199 | + ) | |
129 | 200 | ) |
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 | |
130 | 209 | } |
131 | 210 | |
132 | 211 | var ref = require('ssb-ref') |
133 | 212 |
Built with git-ssb-web