Files: bc8a6a0724c1be92a17b4d3eaeeadc5c756aca4e / modules / channel.js
2292 bytesRaw
1 | var when = require('@mmckegg/mutant/when') |
2 | var send = require('@mmckegg/mutant/send') |
3 | var plugs = require('patchbay/plugs') |
4 | var message_compose = plugs.first(exports.message_compose = []) |
5 | var sbot_log = plugs.first(exports.sbot_log = []) |
6 | var feed_summary = plugs.first(exports.feed_summary = []) |
7 | var h = require('../lib/h') |
8 | var pull = require('pull-stream') |
9 | var obs_subscribed_channels = plugs.first(exports.obs_subscribed_channels = []) |
10 | var get_id = plugs.first(exports.get_id = []) |
11 | var publish = plugs.first(exports.sbot_publish = []) |
12 | |
13 | exports.screen_view = function (path, sbot) { |
14 | if (path[0] === '#') { |
15 | var channel = path.substr(1) |
16 | var subscribedChannels = obs_subscribed_channels(get_id()) |
17 | |
18 | return feed_summary((opts) => { |
19 | return pull( |
20 | sbot_log(opts), |
21 | pull.map(matchesChannel) |
22 | ) |
23 | }, [ |
24 | h('PageHeading', [ |
25 | h('h1', `#${channel}`), |
26 | h('div.meta', [ |
27 | when(subscribedChannels.has(channel), |
28 | h('a -unsubscribe', { |
29 | 'href': '#', |
30 | 'title': 'Click to unsubscribe', |
31 | 'ev-click': send(unsubscribe, channel) |
32 | }, 'Subscribed'), |
33 | h('a -subscribe', { |
34 | 'href': '#', |
35 | 'ev-click': send(subscribe, channel) |
36 | }, 'Subscribe') |
37 | ) |
38 | ]) |
39 | ]), |
40 | message_compose({type: 'post', channel: channel}, {placeholder: 'Write a message in this channel\n\n\n\nPeople who follow you or subscribe to this channel will also see this message in their main feed.\n\nTo create a new channel, type the channel name (preceded by a #) into the search box above. e.g #cat-pics'}) |
41 | ]) |
42 | } |
43 | |
44 | // scoped |
45 | |
46 | function matchesChannel (msg) { |
47 | if (msg.sync) console.error('SYNC', msg) |
48 | var c = msg && msg.value && msg.value.content |
49 | if (c && c.channel === channel) { |
50 | return msg |
51 | } else { |
52 | return {timestamp: msg.timestamp} |
53 | } |
54 | } |
55 | } |
56 | |
57 | exports.message_meta = function (msg) { |
58 | var chan = msg.value.content.channel |
59 | if (chan) { |
60 | return h('a.channel', {href: '##' + chan}, '#' + chan) |
61 | } |
62 | } |
63 | |
64 | function subscribe (id) { |
65 | publish({ |
66 | type: 'channel', |
67 | channel: id, |
68 | subscribed: true |
69 | }) |
70 | } |
71 | |
72 | function unsubscribe (id) { |
73 | publish({ |
74 | type: 'channel', |
75 | channel: id, |
76 | subscribed: false |
77 | }) |
78 | } |
79 |
Built with git-ssb-web