git ssb

2+

ev / mvd



Commit acbd81c838fcbe64469a230fa95ae4ab629d8694

use messageLink from minbase, because it just works

Ev Bogue committed on 6/6/2018, 4:20:29 PM
Parent: f23a13c74bf56135e09fed883c61a7fdf6327a42

Files changed

tools.jschanged
tools.jsView
@@ -24,9 +24,8 @@
2424 onclick: function () {
2525 vote.vote.value = 1
2626 sbot.publish(vote, function (err, voted) {
2727 if(err) throw err
28- console.log('Starred!', voted)
2928 })
3029 }
3130 }
3231 )
@@ -36,9 +35,8 @@
3635 onclick: function () {
3736 vote.vote.value = -1
3837 sbot.publish(vote, function (err, voted) {
3938 if(err) throw err
40- console.log('Unstarred!', voted)
4139 })
4240 }
4341 }
4442 )
@@ -47,14 +45,12 @@
4745
4846 pull(
4947 sbot.links({rel: 'vote', dest: msg.key, live: true}),
5048 pull.drain(function (link) {
51- console.log(link)
5249 if (link.key) {
5350 sbot.get(link.key, function (err, data) {
5451 if (err) throw err
5552 if (data.author == id) {
56- console.log(data)
5753 if (data.content.vote.value == 1)
5854 votebutton.replaceChild(unstar, star)
5955 if (data.content.vote.value == -1)
6056 votebutton.replaceChild(star, unstar)
@@ -132,13 +128,72 @@
132128 votes(msg)
133129 )
134130 }
135131
136-module.exports.messageLink = function (msglink) {
137- var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...'))
132 +var ref = require('ssb-ref')
133 +
134 +module.exports.messageName = function (id, cb) {
135 + // gets the first few characters of a message, for message-link
136 + function title (s) {
137 + var m = /^\n*([^\n]{0,40})/.exec(s)
138 + return m && (m[1].length == 40 ? m[1]+'...' : m[1])
139 + }
140 +
141 + sbot.get(id, function (err, value) {
142 + if(err && err.name == 'NotFoundError')
143 + return cb(null, id.substring(0, 10)+'...(missing)')
144 + if(value.content.type === 'post' && 'string' === typeof value.content.text)
145 + return cb(null, title(value.content.text))
146 + else if('string' === typeof value.content.text)
147 + return cb(null, value.content.type + ':'+title(value.content.text))
148 + else
149 + return cb(null, id.substring(0, 10)+'...')
150 + })
151 +}
152 +
153 +var messageName = exports.messageName
154 +var ref = require('ssb-ref')
155 +
156 +module.exports.messageLink = function (id) {
157 + if (ref.isMsg(id)) {
158 + var link = h('a', {href: '#'+id}, id.substring(0, 10)+'...')
159 + messageName(id, function (err, name) {
160 + if(err) console.error(err)
161 + else link.textContent = name
162 + })
163 + } else {
164 + var link = id
165 + }
138166 return link
139167 }
140168
169 +
170 +/*module.exports.messageLink = function (msglink) {
171 + var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 44) + '...'))
172 +
173 + if (ref.isMsg(msglink)) {
174 + pull(
175 + sbot.get(msglink, function (err, data) {
176 + console.log(data)
177 + if(err && err.name == 'NotFoundError') {
178 + var newlink = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 35) + ' (Missing)...'))
179 + }
180 + if(data.content.type === 'post' && 'string' === typeof data.content.text) {
181 + var newlink = h('span', h('a', {href: '#' + msglink}, data.content.text.substring(0, 44) + '...'))
182 + }
183 + else {
184 + var newlink = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 44) + '...'))
185 + }
186 + if (link) {
187 + link.parentNode.replaceChild(newlink, link)
188 + }
189 + })
190 + )
191 + }
192 +
193 + return link
194 +}*/
195 +
141196 module.exports.rawJSON = function (obj) {
142197 return JSON.stringify(obj, null, 2)
143198 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
144199 .map(function (e) {

Built with git-ssb-web