git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: a5417350593eb41e7c3b56c8edf96aa895411fb2

Files: a5417350593eb41e7c3b56c8edf96aa895411fb2 / modules / channel.js

1186 bytesRaw
1var plugs = require('patchbay/plugs')
2var extend = require('xtend')
3var message_compose = plugs.first(exports.message_compose = [])
4var sbot_log = plugs.first(exports.sbot_log = [])
5var feed_summary = plugs.first(exports.feed_summary = [])
6var h = require('hyperscript')
7var pull = require('pull-stream')
8var sbot_query = plugs.first(exports.sbot_query = [])
9
10exports.screen_view = function (path, sbot) {
11 if (path[0] === '#') {
12 var channel = path.substr(1)
13 return feed_summary((opts) => {
14 if (opts.old === false) {
15 return pull(
16 sbot_log(opts),
17 pull.filter(matchesChannel)
18 )
19 } else {
20 return sbot_query(extend(opts, {query: [
21 {$filter: {value: {content: {channel: channel}}}}
22 ]}))
23 }
24 }, [
25 message_compose({type: 'post', channel: channel})
26 ])
27 }
28
29 // scoped
30
31 function matchesChannel (msg) {
32 if (msg.sync) console.error('SYNC', msg)
33 var c = msg && msg.value && msg.value.content
34 return c && c.channel === channel
35 }
36}
37
38exports.message_meta = function (msg) {
39 var chan = msg.value.content.channel
40 if (chan) {
41 return h('a', {href: '##' + chan}, '#' + chan)
42 }
43}
44

Built with git-ssb-web