git ssb

10+

Matt McKegg / patchwork



Commit 03d17cff841c2fed3e864e0b507f5e8045e4a356

add channel page viewer

Matt McKegg committed on 2/15/2017, 12:18:36 PM
Parent: 5eaed9654b9fe9dd9e0038fe8d0cffbe584237d3

Files changed

modules/page/html/render/channel.jsadded
modules/page/html/render/channel.jsView
@@ -1,0 +1,77 @@
1 +var { h, when, send } = require('mutant')
2 +var pull = require('pull-stream')
3 +var nest = require('depnest')
4 +
5 +exports.needs = nest({
6 + 'channel.obs.subscribed': 'first',
7 + 'feed.html.rollup': 'first',
8 + 'sbot.pull.log': 'first',
9 + 'sbot.async.publish': 'first',
10 + 'keys.sync.id': 'first'
11 +})
12 +
13 +exports.gives = nest('page.html.render')
14 +
15 +exports.create = function (api) {
16 + return nest('page.html.render', function channel (path) {
17 + if (path[0] !== '#') return
18 +
19 + var channel = path.substr(1)
20 + var subscribedChannels = api.channel.obs.subscribed(api.keys.sync.id())
21 +
22 + var prepend = [
23 + h('div', {className: 'PageHeading'}, [
24 + h('h1', `#${channel}`),
25 + h('div.meta', [
26 + when(subscribedChannels.has(channel),
27 + h('a -unsubscribe', {
28 + 'href': '#',
29 + 'title': 'Click to unsubscribe',
30 + 'ev-click': send(unsubscribe, channel)
31 + }, 'Subscribed'),
32 + h('a -subscribe', {
33 + 'href': '#',
34 + 'ev-click': send(subscribe, channel)
35 + }, 'Subscribe')
36 + )
37 + ])
38 + ]),
39 + //api.message.html.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'})
40 + ]
41 +
42 + return api.feed.html.rollup((opts) => {
43 + return pull(
44 + api.sbot.pull.log(opts),
45 + pull.map(matchesChannel)
46 + )
47 + }, { prepend })
48 +
49 + // scoped
50 +
51 + function matchesChannel (msg) {
52 + if (msg.sync) return
53 + var c = msg && msg.value && msg.value.content
54 + if (c && c.channel === channel) {
55 + return msg
56 + } else {
57 + return {timestamp: msg.timestamp}
58 + }
59 + }
60 + })
61 +
62 + function subscribe (id) {
63 + api.sbot.async.publish({
64 + type: 'channel',
65 + channel: id,
66 + subscribed: true
67 + })
68 + }
69 +
70 + function unsubscribe (id) {
71 + api.sbot.async.publish({
72 + type: 'channel',
73 + channel: id,
74 + subscribed: false
75 + })
76 + }
77 +}

Built with git-ssb-web