Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support links with unbox key #312

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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