Browse Source

ui update - inline a snippet of the parent post in replies, in feed-view

Paul Frazee 4 years ago
parent
commit
1c140ceb1a
1 changed files with 21 additions and 2 deletions
  1. 21
    2
      ui/lib/com/message.js

+ 21
- 2
ui/lib/com/message.js View File

@@ -25,7 +25,6 @@ module.exports = function (msg, opts) {
25 25
     h('.message-inner',
26 26
       h('ul.message-header.list-inline',
27 27
         h('li', com.user(msg.value.author)),
28
-        (mlib.link(msg.value.content.root)) ? h('li', h('em', h('a.text-muted', { href: '#/msg/'+mlib.link(msg.value.content.root).link }, 'replies to...'))) : '',
29 28
         !msg.plaintext ? h('li', com.icon('lock')) : '',
30 29
         h('li.pull-right', h('a', { href: '#', onclick: onflag(msg), title: 'Flag this post' }, com.icon('flag'))),
31 30
         h('li.favorite.pull-right',
@@ -33,7 +32,7 @@ module.exports = function (msg, opts) {
33 32
           h('a', { href: '#', onclick: onfavorite(msg), title: 'Favorite this post' }, com.icon('star'))
34 33
         )
35 34
       ),
36
-      h('.message-body', (typeof msg.value.content != 'string') ? com.messageContent(msg) : ''),
35
+      h('.message-body', fetchAndRenderReplyLink(msg), (typeof msg.value.content != 'string') ? com.messageContent(msg) : ''),
37 36
       h('ul.message-footer.list-inline',
38 37
         (!(opts && opts.fullview)) ?
39 38
           h('li', com.a('#/msg/'+msg.key, h('small.comment-count-digits'))) :
@@ -374,6 +373,26 @@ function renderSignals (el, msg) {
374 373
   }
375 374
 }
376 375
 
376
+function fetchAndRenderReplyLink (msg) {
377
+  var root   = mlib.link(msg.value.content.root)
378
+  var branch = mlib.link(msg.value.content.branch)
379
+  if (!root) return ''
380
+
381
+  var anchor = h('a.text-muted', { href: '#/msg/'+root.link }, 'replies to...')
382
+  app.ssb.get((branch && branch.link) ? branch.link : root.link, function (err, msg) {
383
+    if (!msg) return
384
+
385
+    var text = '@' + com.userName(msg.author)
386
+    if (msg.content.text && typeof msg.content.text == 'string')
387
+      text += ': ' + msg.content.text
388
+    if (text.length > 60)
389
+      text = text.slice(0, 57) + '...'
390
+
391
+    anchor.textContent = text
392
+  })
393
+  return h('p', { style: 'margin-bottom: 1em; background: #fafafa; padding: 5px' }, anchor)
394
+}
395
+
377 396
 function renderMention (m) {
378 397
   var text = m.value.content.text
379 398
   if (text.length > 40)

Loading…
Cancel
Save