git ssb

16+

Dominic / patchbay



Commit ead85ed3a63a22c9fc634e596226037135a8f814

Merge pull request #312 from ssbc/support-unbox-links

Support links with unbox key
Christian Bundy authored on 4/2/2019, 5:57:01 PM
GitHub committed on 4/2/2019, 5:57:01 PM
Parent: 09faa08d041f29280c535b5995600d3170b76fc2
Parent: 6c59c792588683040c22962f3e654c84ed584313

Files changed

app/page/thread.jschanged
message/html/render/about.jschanged
router/async/normalise.jschanged
app/page/thread.jsView
@@ -22,9 +22,11 @@
2222 exports.create = function (api) {
2323 return nest('app.page.thread', threadPage)
2424
2525 function threadPage (location) {
26- const root = get(location, 'value.content.root') || get(location, 'value.content.about') || location.key
26 + let root = get(location, 'value.content.root') || get(location, 'value.content.about') || location.key
27 + if (location.value && location.value.unbox) // direct link with unbox key
28 + root = location.key
2729 const msg = location.key
2830 if (msg !== root) scrollDownToMessage(msg)
2931
3032 const { messages, isPrivate, rootId, lastId, channel, recps } = api.feed.obs.thread(root)
@@ -40,16 +42,20 @@
4042 feedIdsInThread: computed(messages, msgs => msgs.map(m => m.value.author)),
4143 placeholder: 'Write a reply',
4244 shrink: false
4345 })
46 +
4447 onceTrue(channel, ch => {
4548 const channelInput = composer.querySelector('input')
4649 channelInput.value = `#${ch}`
4750 channelInput.disabled = true
4851 })
4952
5053 const content = map(messages, m => {
51- const message = api.message.html.render(resolve(m), { pageId: root })
54 + let msg = resolve(m)
55 + if (msg.key == location.key && location.value && location.value.unbox) // we have an unbox key, so message is already unboxed
56 + msg = location
57 + const message = api.message.html.render(msg, { pageId: root })
5258 markReadWhenVisible(message)
5359 return message
5460 }, { comparer })
5561
message/html/render/about.jsView
@@ -1,7 +1,7 @@
11 const nest = require('depnest')
22 const extend = require('xtend')
3-const { isFeed, isMsg, isBlob } = require('ssb-ref')
3 +const { isFeed, isBlob } = require('ssb-ref')
44 const { h } = require('mutant')
55
66 exports.gives = nest('message.html.render')
77
router/async/normalise.jsView
@@ -1,6 +1,6 @@
11 const nest = require('depnest')
2-const { isBlobLink, isFeed, isMsg } = require('ssb-ref')
2 +const { isBlobLink, isFeed, isMsg, parseLink } = require('ssb-ref')
33 const ssbUri = require('ssb-uri')
44
55 exports.gives = nest('router.async.normalise')
66
@@ -30,14 +30,21 @@
3030 cb(err)
3131 }
3232 }
3333
34- if (isMsg(location)) {
35- api.sbot.async.get(location, (err, value) => {
34 + var link = parseLink(location)
35 +
36 + if (link && isMsg(link.link)) {
37 + var params = { id: link.link }
38 + if (link.query && link.query.unbox) {
39 + params.private = true
40 + params.unbox = link.query.unbox
41 + }
42 + api.sbot.async.get(params, function (err, value) {
3643 if (err) cb(err)
3744 else {
3845 if (typeof value.content === 'string') value = api.message.sync.unbox(value)
39- cb(null, { key: location, value })
46 + cb(null, { key: link.link, value })
4047 }
4148 })
4249 } else if (isBlobLink(location)) {
4350 // handles public & private blobs

Built with git-ssb-web