git ssb

2+

mixmix / ticktack



Tree: 17e939d97aceac4619d4a5ad7698fea625d570c7

Files: 17e939d97aceac4619d4a5ad7698fea625d570c7 / message / html / notification.js

2025 bytesRaw
1const nest = require('depnest')
2const { h, Value, onceTrue } = require('mutant')
3const get = require('lodash/get')
4const getType = (msg) => get(msg, 'value.content.type')
5const getLikeRoot = (msg) => get(msg, 'value.content.vote.link')
6const getShareRoot = (msg) => get(msg, 'value.content.share.link')
7const getRoot = (msg) => {
8 switch (getType(msg)) {
9 case 'vote':
10 return getLikeRoot(msg)
11 case 'share':
12 return getShareRoot(msg)
13 }
14}
15
16exports.gives = nest('message.html.notification')
17
18exports.needs = nest({
19 'about.html.avatar': 'first',
20 'about.obs.name': 'first',
21 'blog.html.title': 'first',
22 // 'message.html.markdown': 'first',
23 'message.html.timeago': 'first',
24 'message.html.likes': 'first',
25 'unread.sync.markRead': 'first',
26 'unread.sync.isUnread': 'first',
27 'sbot.obs.connection': 'first',
28 'translations.sync.strings': 'first'
29})
30
31exports.create = (api) => {
32 return nest('message.html.notification', Notification)
33
34 function Notification (msg) {
35 var root = getRoot(msg)
36 if (!root) return
37
38 const { author } = msg.value
39
40 var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
41 api.unread.sync.markRead(msg)
42
43 var title = Value()
44 processMessage(root, msg => {
45 var t = api.blog.html.title(msg)
46 title.set(t.innerText ? t.innerText : t)
47 })
48
49 return h('Notification', { className }, [
50 h('div.left', api.about.html.avatar(author, 'tiny')),
51 h('div.right', [
52 h('section.context', [
53 h('div.name', api.about.obs.name(author)),
54 api.message.html.timeago(msg),
55 h('a.rootLink', {href: root}, ['<< ', title, ' >>'])
56 ])
57 // TODO display the share text ??
58 // h('section.content', api.message.html.markdown(get(msg, 'value.content.text'))),
59 ])
60 ])
61 }
62
63 function processMessage (key, fn) {
64 onceTrue(api.sbot.obs.connection, server => server.get(key, (err, value) => {
65 if (err) return console.error(err)
66 fn({ key, value })
67 }))
68 }
69}
70

Built with git-ssb-web