git ssb

16+

Dominic / patchbay



Tree: 16d4fed8035a33d71d29eb20773bfe59fa2100f0

Files: 16d4fed8035a33d71d29eb20773bfe59fa2100f0 / app / html / page / thread.js

2654 bytesRaw
1const { h, Struct, Value, when, map, resolve, onceTrue } = require('mutant')
2const nest = require('depnest')
3const { isMsg, isFeed } = require('ssb-ref')
4
5exports.gives = nest('app.html.page')
6
7exports.needs = nest({
8 'about.html.avatar': 'first',
9 'app.html.scroller': 'first',
10 'contact.obs.following': 'first',
11 'feed.obs.thread': 'first',
12 'keys.sync.id': 'first',
13 message: {
14 html: {
15 compose: 'first',
16 render: 'first'
17 },
18 'async.name': 'first',
19 'sync.unbox': 'first'
20 },
21 sbot: {
22 'async.get': 'first',
23 'pull.links': 'first'
24 }
25})
26
27exports.create = function (api) {
28 return nest('app.html.page', threadPage)
29
30 function threadPage (id) {
31 if (!isMsg(id)) return
32
33 const myId = api.keys.sync.id()
34 const ImFollowing = api.contact.obs.following(myId)
35 const { messages, isPrivate, rootId, lastId, channel, recps } = api.feed.obs.thread(id)
36 const meta = Struct({
37 type: 'post',
38 root: rootId,
39 branch: lastId,
40 channel,
41 recps
42 })
43 const contactWarning = Value(false)
44 const header = when(isPrivate, [
45 h('section.recipients', map(recps, r => {
46 const id = isFeed(r) ? r : r.link
47
48 var className
49 if (contactIsTrouble(id)) {
50 className = 'warning'
51 contactWarning.set(true)
52 }
53 return h('div', { className }, api.about.html.avatar(id))
54 })),
55 when(contactWarning,
56 h('section.info -warning', 'There is a person in this thread you do not follow (bordered in red). If you think you know this person it might be worth checking their profile to confirm they are who they say they are.'),
57 h('section.info', 'These are the other participants in this thread. Once a private thread is started you cannot add people to it.')
58 )
59 ])
60 function contactIsTrouble (id) {
61 if (id === myId) return false
62 if (Array.from(ImFollowing()).includes(id)) return false
63 return true
64 }
65
66 const composer = api.message.html.compose({
67 meta,
68 placeholder: 'Write a reply',
69 shrink: false
70 })
71 const content = h('section.content', map(messages, m => {
72 return api.message.html.render(resolve(m))
73 }))
74 const { container } = api.app.html.scroller({ prepend: header, content, append: composer })
75
76 container.classList.add('Thread')
77 api.message.async.name(id, (err, name) => {
78 if (err) throw err
79 container.title = name
80 })
81
82 onceTrue(channel, ch => {
83 const channelInput = composer.querySelector('input')
84 channelInput.value = `#${ch}`
85 channelInput.disabled = true
86 })
87
88 return container
89 }
90}
91
92

Built with git-ssb-web