Commit acbd81c838fcbe64469a230fa95ae4ab629d8694
use messageLink from minbase, because it just works
Ev Bogue committed on 6/6/2018, 4:20:29 PMParent: f23a13c74bf56135e09fed883c61a7fdf6327a42
Files changed
tools.js | changed |
tools.js | ||
---|---|---|
@@ -24,9 +24,8 @@ | ||
24 | 24 … | onclick: function () { |
25 | 25 … | vote.vote.value = 1 |
26 | 26 … | sbot.publish(vote, function (err, voted) { |
27 | 27 … | if(err) throw err |
28 | - console.log('Starred!', voted) | |
29 | 28 … | }) |
30 | 29 … | } |
31 | 30 … | } |
32 | 31 … | ) |
@@ -36,9 +35,8 @@ | ||
36 | 35 … | onclick: function () { |
37 | 36 … | vote.vote.value = -1 |
38 | 37 … | sbot.publish(vote, function (err, voted) { |
39 | 38 … | if(err) throw err |
40 | - console.log('Unstarred!', voted) | |
41 | 39 … | }) |
42 | 40 … | } |
43 | 41 … | } |
44 | 42 … | ) |
@@ -47,14 +45,12 @@ | ||
47 | 45 … | |
48 | 46 … | pull( |
49 | 47 … | sbot.links({rel: 'vote', dest: msg.key, live: true}), |
50 | 48 … | pull.drain(function (link) { |
51 | - console.log(link) | |
52 | 49 … | if (link.key) { |
53 | 50 … | sbot.get(link.key, function (err, data) { |
54 | 51 … | if (err) throw err |
55 | 52 … | if (data.author == id) { |
56 | - console.log(data) | |
57 | 53 … | if (data.content.vote.value == 1) |
58 | 54 … | votebutton.replaceChild(unstar, star) |
59 | 55 … | if (data.content.vote.value == -1) |
60 | 56 … | votebutton.replaceChild(star, unstar) |
@@ -132,13 +128,72 @@ | ||
132 | 128 … | votes(msg) |
133 | 129 … | ) |
134 | 130 … | } |
135 | 131 … | |
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 … | + } | |
138 | 166 … | return link |
139 | 167 … | } |
140 | 168 … | |
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 … | + | |
141 | 196 … | module.exports.rawJSON = function (obj) { |
142 | 197 … | return JSON.stringify(obj, null, 2) |
143 | 198 … | .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/) |
144 | 199 … | .map(function (e) { |
Built with git-ssb-web