tools.jsView |
---|
202 | 202 | queueButton.appendChild(addToQueue) |
203 | 203 | |
204 | 204 | return queueButton |
205 | 205 | } |
| 206 | +module.exports.block = function (src) { |
| 207 | + var button = h('span.button') |
206 | 208 | |
| 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 | + |
207 | 278 | module.exports.follow = function (src) { |
208 | 279 | var button = h('span.button') |
209 | 280 | |
210 | 281 | var followButton = h('button.btn', 'Follow ', avatar.name(src), { |
271 | 342 | if(cb) cb(err, msg) |
272 | 343 | }) |
273 | 344 | } |
274 | 345 | |
| 346 | + |
| 347 | + |
275 | 348 | module.exports.mute = function (src) { |
276 | 349 | if (!localStorage[src]) |
277 | 350 | var cache = {mute: false} |
278 | 351 | else |