Files: 88bcef2c47152d262482939fdd24ec33701ee23a / post / page / inbox.js
2652 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | const Scroller = require('pull-scroll') |
5 | const next = require('pull-next-step') |
6 | const ref = require('ssb-ref') |
7 | |
8 | exports.gives = nest({ |
9 | 'post.page.inbox': true, |
10 | 'app.html.menuItem': true |
11 | }) |
12 | |
13 | exports.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 | |
28 | exports.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' }) |
38 | }, '/inbox') |
39 | } |
40 | |
41 | function page (location) { |
42 | const id = api.keys.sync.id() |
43 | |
44 | // TODO - create a postNew page |
45 | // const composer = api.message.html.compose({ |
46 | // meta: { type: 'post' }, |
47 | // prepublish: meta => { |
48 | // meta.recps = [id, ...(meta.mentions || [])] |
49 | // .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link)) |
50 | // return meta |
51 | // }, |
52 | // placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'} |
53 | // ) |
54 | |
55 | const newMsgCount = Value(0) |
56 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
57 | const { container, content } = api.app.html.scroller({ prepend: [ |
58 | h('div', { style: {'margin-left': '9rem', display: 'flex', 'align-items': 'baseline'} }, [ |
59 | h('button', { 'ev-click': draw, stlye: {'margin-left': 0} }, 'REFRESH'), |
60 | h('span', ['New Messages: ', newMsgCount]), |
61 | ]), |
62 | filterMenu |
63 | ] }) |
64 | |
65 | function draw () { |
66 | newMsgCount.set(0) |
67 | resetFeed({ container, content }) |
68 | |
69 | pull( |
70 | next(api.feed.pull.private, {old: false, limit: 100, property: ['value', 'timestamp']}), |
71 | filterDownThrough(), |
72 | pull.drain(msg => newMsgCount.set(newMsgCount() + 1)) |
73 | // TODO - better NEW MESSAGES |
74 | ) |
75 | |
76 | pull( |
77 | next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
78 | filterUpThrough(), |
79 | pull.filter(msg => msg.value.content.recps), |
80 | api.feed.pull.rollup(), |
81 | Scroller(container, content, render, false, false) |
82 | ) |
83 | } |
84 | draw() |
85 | |
86 | function render (msgRollup) { |
87 | return api.message.html.render(msgRollup, { layout: 'inbox' }) |
88 | } |
89 | |
90 | container.title = '/inbox' |
91 | return container |
92 | } |
93 | } |
94 | |
95 | |
96 |
Built with git-ssb-web