git ssb

9+

cel / ssb-viewer



Commit 2ee923fecc38c7bee0a0f0520fae62c565d18e63

Show what people vote on inline

Anders Rune Jensen committed on 4/15/2017, 7:29:04 PM
Parent: dd5c82b06c5cfb2c717fd3b9a9598d789092587c

Files changed

index.jschanged
index.jsView
@@ -127,8 +127,9 @@
127127 pull(
128128 pull.values(logs),
129129 paramap(addAuthorAbout, 8),
130130 paramap(addFollowAbout, 8),
131 + paramap(addVoteMessage, 8),
131132 pull(renderThread(opts), wrapPage(feedId)),
132133 toPull(res, function (err) {
133134 if (err) console.error('[viewer]', err)
134135 })
@@ -181,9 +182,9 @@
181182 sbot.createLogStream({ reverse: true, limit: 1000 }),
182183 pull.filter((msg) => {
183184 return !msg.value || msg.value.author in following
184185 }),
185- pull.filter((msg) => {
186 + pull.filter((msg) => { // channel subscription
186187 return !msg.value.content.subscribed
187188 }),
188189 pull.collect(function (err, logs) {
189190 if (err) return respond(res, 500, err.stack || err)
@@ -193,8 +194,9 @@
193194 pull(
194195 pull.values(logs),
195196 paramap(addAuthorAbout, 8),
196197 paramap(addFollowAbout, 8),
198 + paramap(addVoteMessage, 8),
197199 pull(renderThread(opts), wrapPage(feedId)),
198200 toPull(res, function (err) {
199201 if (err) console.error('[viewer]', err)
200202 })
@@ -222,23 +224,21 @@
222224 renderer: new MdRenderer(opts)
223225 }
224226
225227 pull(
226- sbot.createLogStream({ reverse: true, limit: 10000 }),
228 + sbot.createLogStream({ reverse: true, limit: 2000 }),
227229 pull.filter((msg) => {
228230 return !msg.value || msg.value.content.channel == channelId
229231 }),
230- pull.filter((msg) => {
231- return !msg.value.content.subscribed
232- }),
233232 pull.collect(function (err, logs) {
234233 if (err) return respond(res, 500, err.stack || err)
235234 res.writeHead(200, {
236235 'Content-Type': ctype("html")
237236 })
238237 pull(
239238 pull.values(logs),
240239 paramap(addAuthorAbout, 8),
240 + paramap(addVoteMessage, 8),
241241 pull(renderThread(opts), wrapPage(channelId)),
242242 toPull(res, function (err) {
243243 if (err) console.error('[viewer]', err)
244244 })
@@ -256,9 +256,20 @@
256256 })
257257 else
258258 cb(null, msg)
259259 }
260-
260 +
261 + function addVoteMessage(msg, cb) {
262 + if (msg.value.content.type == 'vote')
263 + getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
264 + if (err) return cb(err)
265 + msg.value.content.vote.linkedText = linkedMsg.value.content.text
266 + cb(null, msg)
267 + })
268 + else
269 + cb(null, msg)
270 + }
271 +
261272 function serveId(req, res, id, ext, query) {
262273 var q = query ? qs.parse(query) : {}
263274 var includeRoot = !('noroot' in q)
264275 var base = q.base || conf.base
@@ -551,15 +562,21 @@
551562 function render(opts, c)
552563 {
553564 if (c.type === 'post')
554565 return renderPost(opts, c)
555- else if (c.type == 'vote' && c.vote.expression == 'Dig')
556- {
557- var channel = c.channel ? ' in #' + c.channel : ''
558- return ' dug ' + '<a href="/' + c.vote.link + '">this</a>' + channel
566 + else if (c.type == 'vote' && c.vote.expression == 'Dig') {
567 + var channel = c.channel ? ' in #' + c.channel : ''
568 + var linkedText = 'this'
569 + if (typeof c.vote.linkedText != 'undefined')
570 + linkedText = c.vote.linkedText.substring(0, 100)
571 + return ' dug ' + '<a href="/' + c.vote.link + '">' + linkedText + '</a>' + channel
559572 }
560- else if (c.type == 'vote')
561- return ' voted <a href="/' + c.vote.link + '">this</a>'
573 + else if (c.type == 'vote') {
574 + var linkedText = 'this'
575 + if (typeof c.vote.linkedText != 'undefined')
576 + linkedText = c.vote.linkedText.substring(0, 100)
577 + return ' voted <a href="/' + c.vote.link + '">' + linkedText + '</a>'
578 + }
562579 else if (c.type == 'contact' && c.following)
563580 return ' followed <a href="/user/' + c.contact + '">' + c.contactAbout.name + "</a>"
564581 else if (typeof c == 'string')
565582 return ' wrote something private '

Built with git-ssb-web