git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 8bd323651fb1b0b76a2af4d86690309d221f6ab1

show message "in reply to" if it differs from previous

Matt McKegg committed on 11/1/2016, 10:54:12 AM
Parent: 1e2e9d73bfe05a81e44492a60cd9223bcbd926cc

Files changed

modules/feed-summary.jschanged
modules/message.jschanged
modules/thread.jsadded
package.jsonchanged
modules/feed-summary.jsView
@@ -137,9 +137,14 @@
137137
138138 function renderItem (item) {
139139 if (item.type === 'message') {
140140 var meta = null
141- var replies = item.replies.slice(-4).map(m => message_render(m, true))
141+ var lastId = item.messageId
142+ var replies = item.replies.slice(-4).map((msg) => {
143+ var result = message_render(msg, true, lastId)
144+ lastId = msg.key
145+ return result
146+ })
142147 var renderedMessage = item.message ? message_render(item.message, true) : null
143148 if (renderedMessage) {
144149 if (item.lastUpdateType === 'reply' && item.repliesFrom.size) {
145150 meta = m('div.meta', {
modules/message.jsView
@@ -12,9 +12,9 @@
1212 var message_main_meta = plugs.map(exports.message_main_meta = [])
1313 var message_action = plugs.map(exports.message_action = [])
1414 var contextMenu = require('../lib/context-menu')
1515
16-exports.message_render = function (msg, inContext) {
16+exports.message_render = function (msg, inContext, previousId) {
1717 var elMini = message_content_mini(msg)
1818 if (elMini) {
1919 var div = h('Message', {
2020 'ev-contextmenu': contextMenu.bind(null, msg)
@@ -40,8 +40,10 @@
4040 if (msg.value.content.root) {
4141 classList.push('-reply')
4242 if (!inContext) {
4343 replyInfo = h('span', ['in reply to ', message_link(msg.value.content.root)])
44+ } else if (previousId && last(msg.value.content.branch) && previousId !== last(msg.value.content.branch)) {
45+ replyInfo = h('span', ['in reply to ', message_link(last(msg.value.content.branch))])
4446 }
4547 }
4648
4749 var element = h('Message', {
@@ -82,4 +84,12 @@
8284 element.setAttribute('tabindex', '0')
8385
8486 return element
8587 }
88+
89+function last (array) {
90+ if (Array.isArray(array)) {
91+ return array[array.length - 1]
92+ } else {
93+ return array
94+ }
95+}
modules/thread.jsView
@@ -1,0 +1,127 @@
1+var ui = require('patchbay/ui')
2+var pull = require('pull-stream')
3+var Cat = require('pull-cat')
4+var sort = require('ssb-sort')
5+var ref = require('ssb-ref')
6+var h = require('hyperscript')
7+var u = require('patchbay/util')
8+var Scroller = require('pull-scroll')
9+
10+
11+function once (cont) {
12+ var ended = false
13+ return function (abort, cb) {
14+ if(abort) return cb(abort)
15+ else if (ended) return cb(ended)
16+ else
17+ cont(function (err, data) {
18+ if(err) return cb(ended = err)
19+ ended = true
20+ cb(null, data)
21+ })
22+ }
23+}
24+
25+var plugs = require('patchbay/plugs')
26+
27+var message_render = plugs.first(exports.message_render = [])
28+var message_name = plugs.first(exports.message_name = [])
29+var message_compose = plugs.first(exports.message_compose = [])
30+var message_unbox = plugs.first(exports.message_unbox = [])
31+
32+var sbot_get = plugs.first(exports.sbot_get = [])
33+var sbot_links = plugs.first(exports.sbot_links = [])
34+var get_id = plugs.first(exports.get_id = [])
35+
36+function getThread (root, cb) {
37+ //in this case, it's inconvienent that panel only takes
38+ //a stream. maybe it would be better to accept an array?
39+
40+ sbot_get(root, function (err, value) {
41+ var msg = {key: root, value: value}
42+// if(value.content.root) return getThread(value.content.root, cb)
43+
44+ pull(
45+ sbot_links({rel: 'root', dest: root, values: true, keys: true}),
46+ pull.collect(function (err, ary) {
47+ if(err) return cb(err)
48+ ary.unshift(msg)
49+ cb(null, ary)
50+ })
51+ )
52+ })
53+
54+}
55+
56+exports.screen_view = function (id) {
57+ if(ref.isMsg(id)) {
58+ var meta = {
59+ type: 'post',
60+ root: id,
61+ branch: id //mutated when thread is loaded.
62+ }
63+
64+ var lastId = id
65+ var content = h('div.column.scroller__content')
66+ var div = h('div.column.scroller',
67+ {style: {'overflow-y': 'auto'}},
68+ h('div.scroller__wrapper',
69+ content,
70+ message_compose(meta, {shrink: false, placeholder: 'Write a reply'})
71+ )
72+ )
73+
74+ message_name(id, function (err, name) {
75+ div.title = name
76+ })
77+
78+ pull(
79+ sbot_links({
80+ rel: 'root', dest: id, keys: true, old: false
81+ }),
82+ pull.drain(function (msg) {
83+ loadThread() //redraw thread
84+ }, function () {} )
85+ )
86+
87+
88+ function loadThread () {
89+ getThread(id, function (err, thread) {
90+ //would probably be better keep an id for each message element
91+ //(i.e. message key) and then update it if necessary.
92+ //also, it may have moved (say, if you received a missing message)
93+ content.innerHTML = ''
94+ //decrypt
95+ thread = thread.map(function (msg) {
96+ return 'string' === typeof msg.value.content ? message_unbox(msg) : msg
97+ })
98+
99+ if(err) return content.appendChild(h('pre', err.stack))
100+ sort(thread).map((msg) => {
101+ var result = message_render(msg, true, lastId)
102+ lastId = msg.key
103+ return result
104+ }).filter(Boolean).forEach(function (el) {
105+ content.appendChild(el)
106+ })
107+
108+ var branches = sort.heads(thread)
109+ meta.branch = branches.length > 1 ? branches : branches[0]
110+ meta.root = thread[0].value.content.root || thread[0].key
111+ meta.channel = thread[0].value.content.channel
112+
113+ var recps = thread[0].value.content.recps
114+ var private = thread[0].value.private
115+ if(private) {
116+ if(recps)
117+ meta.recps = recps
118+ else
119+ meta.recps = [thread[0].value.author, get_id()]
120+ }
121+ })
122+ }
123+
124+ loadThread()
125+ return div
126+ }
127+}
package.jsonView
@@ -32,7 +32,8 @@
3232 "ssb-blobs": "~0.1.7",
3333 "ssb-keys": "~7.0.0",
3434 "ssb-links": "~2.0.0",
3535 "ssb-query": "~0.1.1",
36- "ssb-ref": "~2.6.2"
36+ "ssb-ref": "~2.6.2",
37+ "ssb-sort": "^1.0.0"
3738 }
3839 }

Built with git-ssb-web