Skip to content

Commit

Permalink
Merge pull request #312 from ssbc/support-unbox-links
Browse files Browse the repository at this point in the history
Support links with unbox key
  • Loading branch information
christianbundy committed Apr 2, 2019
2 parents 09faa08 + 6c59c79 commit ead85ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 8 additions & 2 deletions app/page/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ exports.create = function (api) {
return nest('app.page.thread', threadPage)

function threadPage (location) {
const root = get(location, 'value.content.root') || get(location, 'value.content.about') || location.key
let root = get(location, 'value.content.root') || get(location, 'value.content.about') || location.key
if (location.value && location.value.unbox) // direct link with unbox key
root = location.key
const msg = location.key
if (msg !== root) scrollDownToMessage(msg)

Expand All @@ -41,14 +43,18 @@ exports.create = function (api) {
placeholder: 'Write a reply',
shrink: false
})

onceTrue(channel, ch => {
const channelInput = composer.querySelector('input')
channelInput.value = `#${ch}`
channelInput.disabled = true
})

const content = map(messages, m => {
const message = api.message.html.render(resolve(m), { pageId: root })
let msg = resolve(m)
if (msg.key == location.key && location.value && location.value.unbox) // we have an unbox key, so message is already unboxed
msg = location
const message = api.message.html.render(msg, { pageId: root })
markReadWhenVisible(message)
return message
}, { comparer })
Expand Down
2 changes: 1 addition & 1 deletion message/html/render/about.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const nest = require('depnest')
const extend = require('xtend')
const { isFeed, isMsg, isBlob } = require('ssb-ref')
const { isFeed, isBlob } = require('ssb-ref')
const { h } = require('mutant')

exports.gives = nest('message.html.render')
Expand Down
15 changes: 11 additions & 4 deletions router/async/normalise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const nest = require('depnest')
const { isBlobLink, isFeed, isMsg } = require('ssb-ref')
const { isBlobLink, isFeed, isMsg, parseLink } = require('ssb-ref')
const ssbUri = require('ssb-uri')

exports.gives = nest('router.async.normalise')
Expand Down Expand Up @@ -31,12 +31,19 @@ exports.create = (api) => {
}
}

if (isMsg(location)) {
api.sbot.async.get(location, (err, value) => {
var link = parseLink(location)

if (link && isMsg(link.link)) {
var params = { id: link.link }
if (link.query && link.query.unbox) {
params.private = true
params.unbox = link.query.unbox
}
api.sbot.async.get(params, function (err, value) {
if (err) cb(err)
else {
if (typeof value.content === 'string') value = api.message.sync.unbox(value)
cb(null, { key: location, value })
cb(null, { key: link.link, value })
}
})
} else if (isBlobLink(location)) {
Expand Down

0 comments on commit ead85ed

Please sign in to comment.