Files: 46f0a41d8c409cbc4f773724e8cc576cbfc98fa8 / app / page / notifications.js
1776 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, onceTrue } = require('mutant') |
3 | const defer = require('pull-defer') |
4 | |
5 | exports.gives = nest('app.page.notifications') |
6 | |
7 | exports.needs = nest({ |
8 | 'app.html.scroller': 'first', |
9 | 'app.html.sideNav': 'first', |
10 | 'message.html.comment': 'first', |
11 | 'message.html.notification': 'first', |
12 | 'sbot.obs.connection': 'first', |
13 | 'translations.sync.strings': 'first' |
14 | }) |
15 | |
16 | const SOURCES = { |
17 | comments: 'readAllComments', |
18 | likes: 'readAllLikes', |
19 | shares: 'readAllShares' |
20 | } |
21 | |
22 | exports.create = (api) => { |
23 | return nest('app.page.notifications', function (location) { |
24 | // location here can expected to be: { page: 'notifications', section: * } |
25 | if (!Object.keys(SOURCES).includes(location.section)) return |
26 | |
27 | var scroller = api.app.html.scroller({ |
28 | classList: ['content'], |
29 | stream: createCreateStream(location.section), |
30 | render: createRender(location.section) |
31 | }) |
32 | |
33 | return h('Page -notifications', [ |
34 | api.app.html.sideNav(location), |
35 | scroller |
36 | ]) |
37 | |
38 | function createCreateStream (section) { |
39 | return function (opts) { |
40 | const source = defer.source() |
41 | var resolved = false |
42 | |
43 | onceTrue(api.sbot.obs.connection, server => { |
44 | if (resolved) return |
45 | |
46 | source.resolve(server.ticktack[SOURCES[section]](opts)) |
47 | resolved = true |
48 | }) |
49 | |
50 | return source |
51 | } |
52 | } |
53 | |
54 | function createRender (section) { |
55 | return function (msg) { |
56 | switch (section) { |
57 | case 'comments': |
58 | return api.message.html.comment({ comment: msg, showRootLink: true }) |
59 | |
60 | case 'likes': |
61 | return api.message.html.notification(msg) |
62 | |
63 | case 'shares': |
64 | return api.message.html.notification(msg) |
65 | } |
66 | } |
67 | } |
68 | }) |
69 | } |
70 |
Built with git-ssb-web