git ssb

10+

Matt McKegg / patchwork



Tree: bc8a6a0724c1be92a17b4d3eaeeadc5c756aca4e

Files: bc8a6a0724c1be92a17b4d3eaeeadc5c756aca4e / modules / channel.js

2292 bytesRaw
1var when = require('@mmckegg/mutant/when')
2var send = require('@mmckegg/mutant/send')
3var plugs = require('patchbay/plugs')
4var message_compose = plugs.first(exports.message_compose = [])
5var sbot_log = plugs.first(exports.sbot_log = [])
6var feed_summary = plugs.first(exports.feed_summary = [])
7var h = require('../lib/h')
8var pull = require('pull-stream')
9var obs_subscribed_channels = plugs.first(exports.obs_subscribed_channels = [])
10var get_id = plugs.first(exports.get_id = [])
11var publish = plugs.first(exports.sbot_publish = [])
12
13exports.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
57exports.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
64function subscribe (id) {
65 publish({
66 type: 'channel',
67 channel: id,
68 subscribed: true
69 })
70}
71
72function unsubscribe (id) {
73 publish({
74 type: 'channel',
75 channel: id,
76 subscribed: false
77 })
78}
79

Built with git-ssb-web