git ssb

2+

ev / mvd



Commit 35599c2543afac880b2c55fbf32989a543c1747f

add private block button

Ev Bogue committed on 12/14/2018, 4:28:38 PM
Parent: f7d08b7f47aa8d0d21df0611bb988bc7098d99b7

Files changed

tools.jschanged
views.jschanged
tools.jsView
@@ -202,9 +202,80 @@
202202 queueButton.appendChild(addToQueue)
203203
204204 return queueButton
205205 }
206 +module.exports.block = function (src) {
207 + var button = h('span.button')
206208
209 + var followButton = h('button.btn', 'Block (Private)', avatar.name(src), {
210 + onclick: function () {
211 + var content = {
212 + type: 'contact',
213 + contact: src,
214 + blocking: true,
215 + recps: id
216 + }
217 + sbot.publish(content, function (err, publish) {
218 + if (err) throw err
219 + console.log(publish)
220 + })
221 + }
222 + })
223 +
224 + var unfollowButton = h('button.btn', 'Unblock (Private)', avatar.name(src), {
225 + onclick: function () {
226 + var content = {
227 + type: 'contact',
228 + contact: src,
229 + blocking: false,
230 + recps: id
231 + }
232 + sbot.publish(content, function (err, publish) {
233 + if (err) throw err
234 + console.log(publish)
235 + })
236 + }
237 + })
238 +
239 + pull(
240 + sbot.query({query: [{$filter: { value: { author: id, content: {type: 'contact', contact: src}}}}], live: true}),
241 + pull.drain(function (msg) {
242 + if (msg.value) {
243 + if (msg.value.content.blocking == true) {
244 + button.removeChild(button.firstChild)
245 + button.appendChild(unfollowButton)
246 + }
247 + if (msg.value.content.blocking == false) {
248 + button.removeChild(button.firstChild)
249 + button.appendChild(followButton)
250 + }
251 + }
252 + })
253 + )
254 +
255 + button.appendChild(followButton)
256 +
257 + return button
258 +}
259 +
260 +module.exports.box = function (content) {
261 + return ssbKeys.box(content, content.recps.map(function (e) {
262 + return ref.isFeed(e) ? e : e.link
263 + }))
264 +}
265 +
266 +module.exports.publish = function (content, cb) {
267 + if(content.recps)
268 + content = exports.box(content)
269 + sbot.publish(content, function (err, msg) {
270 + if(err) throw err
271 + console.log('Published!', msg)
272 + if(cb) cb(err, msg)
273 + })
274 +}
275 +
276 +
277 +
207278 module.exports.follow = function (src) {
208279 var button = h('span.button')
209280
210281 var followButton = h('button.btn', 'Follow ', avatar.name(src), {
@@ -271,8 +342,10 @@
271342 if(cb) cb(err, msg)
272343 })
273344 }
274345
346 +
347 +
275348 module.exports.mute = function (src) {
276349 if (!localStorage[src])
277350 var cache = {mute: false}
278351 else
views.jsView
@@ -350,8 +350,9 @@
350350
351351 buttons.appendChild(writeMessage)
352352 buttons.appendChild(writePrivate)
353353 buttons.appendChild(tools.follow(src))
354 + buttons.appendChild(tools.block(src))
354355
355356 buttons.appendChild(h('button.btn', 'Generate follows', {
356357 onclick: function () {
357358 profile.firstChild.appendChild(tools.getFollowing(src))

Built with git-ssb-web