git ssb

10+

Matt McKegg / patchwork



Commit 8d409051a8f9c8f004d964d1c5cac5e5b8649a01

use message.sync.root for all root detection to fix about message replies/forks

fixes #659
Matt McKegg committed on 10/28/2017, 9:49:30 AM
Parent: 617b5bc9c154d8d591ff115bda4787ab93113d1b

Files changed

modules/message/html/backlinks.jschanged
modules/page/html/render/message.jschanged
modules/message/html/backlinks.jsView
@@ -2,8 +2,9 @@
22 var ref = require('ssb-ref')
33 var { h, map, computed } = require('mutant')
44
55 exports.needs = nest({
6+ 'message.sync.root': 'first',
67 'message.obs': {
78 backlinks: 'first',
89 name: 'first',
910 author: 'first'
@@ -17,11 +18,14 @@
1718 exports.create = function (api) {
1819 const i18n = api.intl.sync.i18n
1920 return nest('message.html.backlinks', function (msg, {includeReferences = true, includeForks = true} = {}) {
2021 if (!ref.type(msg.key)) return []
22+
23+ var rootId = api.message.sync.root(msg)
2124 var backlinks = api.message.obs.backlinks(msg.key)
2225 var references = includeReferences ? computed([backlinks, msg], onlyReferences) : []
23- var forks = (includeForks && msg.value.content.root) ? computed([backlinks, msg], onlyForks) : []
26+ var forks = (includeForks && rootId) ? computed([backlinks, msg], onlyForks) : []
27+
2428 return [
2529 map(forks, link => {
2630 return h('a.backlink', {
2731 href: msg.key, anchor: link.id
@@ -43,16 +47,16 @@
4347 ])
4448 })
4549 ]
4650 })
47-}
4851
49-function onlyReferences (backlinks, msg) {
50- return backlinks.filter(link => link.root !== msg.key && !includeOrEqual(link.branch, msg.key))
51-}
52+ function onlyReferences (backlinks, msg) {
53+ return backlinks.filter(link => link.root !== msg.key && !includeOrEqual(link.branch, msg.key))
54+ }
5255
53-function onlyForks (backlinks, msg) {
54- return backlinks.filter(link => link.root === msg.key && includeOrEqual(link.branch, msg.key) && msg.value.content && msg.value.content.root)
56+ function onlyForks (backlinks, msg) {
57+ return backlinks.filter(link => link.root === msg.key && includeOrEqual(link.branch, msg.key) && api.message.sync.root(msg))
58+ }
5559 }
5660
5761 function includeOrEqual (valueOrArray, item) {
5862 if (Array.isArray(valueOrArray)) {
modules/page/html/render/message.jsView
@@ -6,8 +6,9 @@
66 exports.needs = nest({
77 'keys.sync.id': 'first',
88 'feed.obs.thread': 'first',
99 'message.sync.unbox': 'first',
10+ 'message.sync.root': 'first',
1011 'message.html': {
1112 render: 'first',
1213 compose: 'first'
1314 },
@@ -64,13 +65,14 @@
6465
6566 // what happens in private stays in private!
6667 meta.recps.set(value.content.recps)
6768
68- var isReply = !!value.content.root
69+ var root = api.message.sync.root({key: id, value}) || id
70+ var isReply = id !== root
6971 var thread = api.feed.obs.thread(id, {branch: isReply})
7072
7173 meta.channel.set(value.content.channel)
72- meta.root.set(value.content.root || thread.rootId)
74+ meta.root.set(root || thread.rootId)
7375
7476 // if root thread, reply to last post
7577 meta.branch.set(isReply ? thread.branchId : thread.lastId)
7678

Built with git-ssb-web