git ssb

0+

wanderer🌟 / %yCkm4no/U8C2k0Z658j…



forked from mixmix / patch-inbox

Tree: fe4f82b063f543b0c2ad3939e98df4a267a20759

Files: fe4f82b063f543b0c2ad3939e98df4a267a20759 / post / page / inbox.js

2992 bytesRaw
1const nest = require('depnest')
2const { h, Value } = require('mutant')
3const pull = require('pull-stream')
4const Scroller = require('pull-scroll')
5const next = require('pull-next-step')
6const ref = require('ssb-ref')
7
8exports.gives = nest({
9 'post.page.inbox': true,
10 'app.html.menuItem': true
11})
12
13exports.needs = nest({
14 'app.html': {
15 filter: 'first',
16 scroller: 'first'
17 },
18 'app.sync.goTo': 'first',
19 'feed.pull.private': 'first',
20 'feed.pull.rollup': 'first',
21 'keys.sync.id': 'first',
22 'message.html': {
23 // compose: 'first',
24 render: 'first'
25 }
26})
27
28exports.create = function (api) {
29 return nest({
30 'post.page.inbox': page,
31 'app.html.menuItem': menuItem
32 })
33
34 function menuItem () {
35 return h('a', {
36 style: { order: 2 },
37 'ev-click': () => api.app.sync.goTo({ page: 'inbox' }) // TODO goTo is patchbay
38 }, '/inbox')
39 }
40
41 function page (location) {
42 const id = api.keys.sync.id()
43
44 // TODO - create a postNew page
45 //
46 // const composer = api.message.html.compose({
47 // meta: { type: 'post' },
48 // prepublish: meta => {
49 // meta.recps = [id, ...(meta.mentions || [])]
50 // .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link))
51 // return meta
52 // },
53 // placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'}
54 // )
55
56 const newMsgCount = Value(0)
57 const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) // TODO dep on patchbay
58
59 // TODO - develop a better way to do styled pages with scroller
60 const { container, content } = api.app.html.scroller({ prepend: [ // TODO dep on patchbay
61 h('div', { style: {'margin-left': '9rem', display: 'flex', 'align-items': 'baseline'} }, [
62 h('button.new', {
63 style: { 'margin-right': 'auto' },
64 'ev-click': () => api.app.sync.goTo({ page: 'private' }) // TODO replace with custom page
65 }, 'New'),
66 h('span', [newMsgCount, ' new messages']),
67 h('button.refresh', { 'ev-click': draw, stlye: {'margin-left': 0} }, 'REFRESH'),
68 ]),
69 filterMenu
70 ] })
71
72 function draw () {
73 newMsgCount.set(0)
74 resetFeed({ container, content })
75
76 pull(
77 next(api.feed.pull.private, {old: false, limit: 100, property: ['value', 'timestamp']}),
78 filterDownThrough(),
79 pull.drain(msg => newMsgCount.set(newMsgCount() + 1))
80 // TODO - better NEW MESSAGES
81 )
82
83 pull(
84 next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
85 filterUpThrough(),
86 pull.filter(msg => msg.value.content.recps),
87 api.feed.pull.rollup(),
88 Scroller(container, content, render, false, false)
89 )
90 }
91 draw()
92
93 function render (msgRollup) {
94 return api.message.html.render(msgRollup, { layout: 'inbox' })
95 }
96
97 container.title = '/inbox'
98 return container
99 }
100}
101
102

Built with git-ssb-web