git ssb

10+

Matt McKegg / patchwork



Tree: 13be5ee9906beb5d8c2a24db46c68ef183c78d3a

Files: 13be5ee9906beb5d8c2a24db46c68ef183c78d3a / modules / channel.js

2224 bytesRaw
1var when = require('@mmckegg/mutant/when')
2var send = require('@mmckegg/mutant/send')
3var plugs = require('patchbay/plugs')
4var extend = require('xtend')
5var message_compose = plugs.first(exports.message_compose = [])
6var sbot_log = plugs.first(exports.sbot_log = [])
7var feed_summary = plugs.first(exports.feed_summary = [])
8var h = require('../lib/h')
9var pull = require('pull-stream')
10var sbot_query = plugs.first(exports.sbot_query = [])
11var obs_subscribed_channels = plugs.first(exports.obs_subscribed_channels = [])
12var get_id = plugs.first(exports.get_id = [])
13var publish = plugs.first(exports.sbot_publish = [])
14
15exports.screen_view = function (path, sbot) {
16 if (path[0] === '#') {
17 var channel = path.substr(1)
18 var subscribedChannels = obs_subscribed_channels(get_id())
19
20 return feed_summary((opts) => {
21 if (opts.old === false) {
22 return pull(
23 sbot_log(opts),
24 pull.filter(matchesChannel)
25 )
26 } else {
27 return sbot_query(extend(opts, {query: [
28 {$filter: {value: {content: {channel: channel}}}}
29 ]}))
30 }
31 }, [
32 h('PageHeading', [
33 h('h1', `#${channel}`),
34 h('div.meta', [
35 when(subscribedChannels.has(channel),
36 h('a -unsubscribe', {
37 'href': '#',
38 'title': 'Click to unsubscribe',
39 'ev-click': send(unsubscribe, channel)
40 }, 'Subscribed'),
41 h('a -subscribe', {
42 'href': '#',
43 'ev-click': send(subscribe, channel)
44 }, 'Subscribe')
45 )
46 ])
47 ]),
48 message_compose({type: 'post', channel: channel})
49 ])
50 }
51
52 // scoped
53
54 function matchesChannel (msg) {
55 if (msg.sync) console.error('SYNC', msg)
56 var c = msg && msg.value && msg.value.content
57 return c && c.channel === channel
58 }
59}
60
61exports.message_meta = function (msg) {
62 var chan = msg.value.content.channel
63 if (chan) {
64 return h('a.channel', {href: '##' + chan}, '#' + chan)
65 }
66}
67
68function subscribe (id) {
69 publish({
70 type: 'channel',
71 channel: id,
72 subscribed: true
73 })
74}
75
76function unsubscribe (id) {
77 publish({
78 type: 'channel',
79 channel: id,
80 subscribed: false
81 })
82}
83

Built with git-ssb-web