Commit 08321fdd28495d2cb08d4f7256ed2f6aab925315
respect privacy better. hides who is in a private thread, does not show private messages in user feed, also does not show like/vote as thread replies
Dominic Tarr committed on 4/15/2018, 8:15:08 PMParent: 2c291337776846d8c4edf05609c74fac530254e6
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -119,8 +119,11 @@ | ||
119 | 119 | } |
120 | 120 | |
121 | 121 | pull( |
122 | 122 | sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 : 10) }), |
123 | + pull.filter(function (data) { | |
124 | + return 'object' === typeof data.value.content | |
125 | + }), | |
123 | 126 | pull.collect(function (err, logs) { |
124 | 127 | if (err) return respond(res, 500, err.stack || err) |
125 | 128 | res.writeHead(200, { |
126 | 129 | 'Content-Type': ctype(ext) |
@@ -149,36 +152,36 @@ | ||
149 | 152 | var channelSubscriptions = [] |
150 | 153 | |
151 | 154 | getAbout(feedId, function (err, about) { |
152 | 155 | pull( |
153 | - sbot.createUserStream({ id: feedId }), | |
154 | - pull.filter((msg) => { | |
155 | - return !msg.value || | |
156 | - msg.value.content.type == 'contact' || | |
157 | - (msg.value.content.type == 'channel' && | |
158 | - typeof msg.value.content.subscribed != 'undefined') | |
159 | - }), | |
160 | - pull.collect(function (err, msgs) { | |
161 | - msgs.forEach((msg) => { | |
162 | - if (msg.value.content.type == 'contact') | |
163 | - { | |
164 | - if (msg.value.content.following) | |
165 | - following[msg.value.content.contact] = 1 | |
166 | - else | |
167 | - delete following[msg.value.content.contact] | |
168 | - } | |
169 | - else // channel subscription | |
170 | - { | |
171 | - if (msg.value.content.subscribed) | |
172 | - channelSubscriptions[msg.value.content.channel] = 1 | |
173 | - else | |
174 | - delete channelSubscriptions[msg.value.content.channel] | |
175 | - } | |
176 | - }) | |
177 | - | |
178 | - serveFeeds(req, res, following, channelSubscriptions, feedId, | |
156 | + sbot.createUserStream({ id: feedId }), | |
157 | + pull.filter((msg) => { | |
158 | + return !msg.value || | |
159 | + msg.value.content.type == 'contact' || | |
160 | + (msg.value.content.type == 'channel' && | |
161 | + typeof msg.value.content.subscribed != 'undefined') | |
162 | + }), | |
163 | + pull.collect(function (err, msgs) { | |
164 | + msgs.forEach((msg) => { | |
165 | + if (msg.value.content.type == 'contact') | |
166 | + { | |
167 | + if (msg.value.content.following) | |
168 | + following[msg.value.content.contact] = 1 | |
169 | + else | |
170 | + delete following[msg.value.content.contact] | |
171 | + } | |
172 | + else // channel subscription | |
173 | + { | |
174 | + if (msg.value.content.subscribed) | |
175 | + channelSubscriptions[msg.value.content.channel] = 1 | |
176 | + else | |
177 | + delete channelSubscriptions[msg.value.content.channel] | |
178 | + } | |
179 | + }) | |
180 | + | |
181 | + serveFeeds(req, res, following, channelSubscriptions, feedId, | |
179 | 182 | 'user feed ' + (about ? about.name : "")) |
180 | - }) | |
183 | + }) | |
181 | 184 | ) |
182 | 185 | }) |
183 | 186 | } |
184 | 187 | |
@@ -191,29 +194,29 @@ | ||
191 | 194 | |
192 | 195 | pull( |
193 | 196 | sbot.createLogStream({ reverse: true, limit: 5000 }), |
194 | 197 | pull.filter((msg) => { |
195 | - return !msg.value || | |
196 | - (msg.value.author in following || | |
197 | - msg.value.content.channel in channelSubscriptions) | |
198 | + return !msg.value || | |
199 | + (msg.value.author in following || | |
200 | + msg.value.content.channel in channelSubscriptions) | |
198 | 201 | }), |
199 | 202 | pull.take(150), |
200 | 203 | pull.collect(function (err, logs) { |
201 | - if (err) return respond(res, 500, err.stack || err) | |
202 | - res.writeHead(200, { | |
203 | - 'Content-Type': ctype("html") | |
204 | - }) | |
205 | - pull( | |
206 | - pull.values(logs), | |
207 | - paramap(addAuthorAbout, 8), | |
208 | - paramap(addFollowAbout, 8), | |
209 | - paramap(addVoteMessage, 8), | |
210 | - paramap(addGitLinks, 8), | |
211 | - pull(renderThread(feedOpts), wrapPage(name)), | |
212 | - toPull(res, function (err) { | |
213 | - if (err) console.error('[viewer]', err) | |
214 | - }) | |
215 | - ) | |
204 | + if (err) return respond(res, 500, err.stack || err) | |
205 | + res.writeHead(200, { | |
206 | + 'Content-Type': ctype("html") | |
207 | + }) | |
208 | + pull( | |
209 | + pull.values(logs), | |
210 | + paramap(addAuthorAbout, 8), | |
211 | + paramap(addFollowAbout, 8), | |
212 | + paramap(addVoteMessage, 8), | |
213 | + paramap(addGitLinks, 8), | |
214 | + pull(renderThread(feedOpts), wrapPage(name)), | |
215 | + toPull(res, function (err) { | |
216 | + if (err) console.error('[viewer]', err) | |
217 | + }) | |
218 | + ) | |
216 | 219 | }) |
217 | 220 | ) |
218 | 221 | } |
219 | 222 | |
@@ -225,23 +228,23 @@ | ||
225 | 228 | |
226 | 229 | pull( |
227 | 230 | sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), |
228 | 231 | pull.collect(function (err, logs) { |
229 | - if (err) return respond(res, 500, err.stack || err) | |
230 | - res.writeHead(200, { | |
231 | - 'Content-Type': ctype("html") | |
232 | - }) | |
233 | - pull( | |
234 | - pull.values(logs), | |
235 | - paramap(addAuthorAbout, 8), | |
236 | - paramap(addVoteMessage, 8), | |
237 | - pull(renderThread(defaultOpts, '', | |
238 | - renderShowAll(showAll, req.url)), | |
239 | - wrapPage('#' + channelId)), | |
240 | - toPull(res, function (err) { | |
241 | - if (err) console.error('[viewer]', err) | |
242 | - }) | |
243 | - ) | |
232 | + if (err) return respond(res, 500, err.stack || err) | |
233 | + res.writeHead(200, { | |
234 | + 'Content-Type': ctype("html") | |
235 | + }) | |
236 | + pull( | |
237 | + pull.values(logs), | |
238 | + paramap(addAuthorAbout, 8), | |
239 | + paramap(addVoteMessage, 8), | |
240 | + pull(renderThread(defaultOpts, '', | |
241 | + renderShowAll(showAll, req.url)), | |
242 | + wrapPage('#' + channelId)), | |
243 | + toPull(res, function (err) { | |
244 | + if (err) console.error('[viewer]', err) | |
245 | + }) | |
246 | + ) | |
244 | 247 | }) |
245 | 248 | ) |
246 | 249 | } |
247 | 250 | |
@@ -278,49 +281,58 @@ | ||
278 | 281 | |
279 | 282 | var format = formatMsgs(id, ext, opts) |
280 | 283 | if (format === null) return respond(res, 415, 'Invalid format') |
281 | 284 | |
282 | - pull( | |
283 | - sbot.links({dest: id, values: true }), | |
284 | - includeRoot && prepend(getMsg, id), | |
285 | - pull.unique('key'), | |
286 | - pull.collect(function (err, links) { | |
287 | - if (err) return respond(res, 500, err.stack || err) | |
288 | - var etag = hash(sort.heads(links).concat(appHash, ext, qs)) | |
289 | - if (req.headers['if-none-match'] === etag) return respond(res, 304) | |
290 | - res.writeHead(200, { | |
291 | - 'Content-Type': ctype(ext), | |
292 | - 'etag': etag | |
285 | + function render (links) { | |
286 | + var etag = hash(sort.heads(links).concat(appHash, ext, qs)) | |
287 | + if (req.headers['if-none-match'] === etag) return respond(res, 304) | |
288 | + res.writeHead(200, { | |
289 | + 'Content-Type': ctype(ext), | |
290 | + 'etag': etag | |
291 | + }) | |
292 | + pull( | |
293 | + pull.values(sort(links)), | |
294 | + paramap(addAuthorAbout, 8), | |
295 | + format, | |
296 | + toPull(res, function (err) { | |
297 | + if (err) console.error('[viewer]', err) | |
293 | 298 | }) |
294 | - pull( | |
295 | - pull.values(sort(links)), | |
296 | - paramap(addAuthorAbout, 8), | |
297 | - format, | |
298 | - toPull(res, function (err) { | |
299 | - if (err) console.error('[viewer]', err) | |
300 | - }) | |
301 | - ) | |
302 | - }) | |
303 | - ) | |
299 | + ) | |
300 | + } | |
301 | + | |
302 | + getMsgWithValue(sbot, id, function (err, root) { | |
303 | + if (err) return respond(res, 500, err.stack || err) | |
304 | + if('string' === typeof root.value.content) | |
305 | + return render([root]) | |
306 | + | |
307 | + pull( | |
308 | + sbot.links({dest: id, values: true, rel: 'root' }), | |
309 | + pull.unique('key'), | |
310 | + pull.collect(function (err, links) { | |
311 | + if (err) return respond(res, 500, err.stack || err) | |
312 | + render(links) | |
313 | + }) | |
314 | + ) | |
315 | + }) | |
304 | 316 | } |
305 | 317 | |
306 | 318 | function addFollowAbout(msg, cb) { |
307 | 319 | if (msg.value.content.contact) |
308 | 320 | getAbout(msg.value.content.contact, function (err, about) { |
309 | - if (err) return cb(err) | |
310 | - msg.value.content.contactAbout = about | |
311 | - cb(null, msg) | |
321 | + if (err) return cb(err) | |
322 | + msg.value.content.contactAbout = about | |
323 | + cb(null, msg) | |
312 | 324 | }) |
313 | 325 | else |
314 | 326 | cb(null, msg) |
315 | 327 | } |
316 | 328 | |
317 | 329 | function addVoteMessage(msg, cb) { |
318 | 330 | if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%') |
319 | 331 | getMsg(msg.value.content.vote.link, function (err, linkedMsg) { |
320 | - if (linkedMsg) | |
321 | - msg.value.content.vote.linkedText = linkedMsg.value.content.text | |
322 | - cb(null, msg) | |
332 | + if (linkedMsg) | |
333 | + msg.value.content.vote.linkedText = linkedMsg.value.content.text | |
334 | + cb(null, msg) | |
323 | 335 | }) |
324 | 336 | else |
325 | 337 | cb(null, msg) |
326 | 338 | } |
@@ -335,17 +347,17 @@ | ||
335 | 347 | |
336 | 348 | function addGitLinks(msg, cb) { |
337 | 349 | if (msg.value.content.type == 'git-update') |
338 | 350 | getMsg(msg.value.content.repo, function (err, gitRepo) { |
339 | - if (gitRepo) | |
340 | - msg.value.content.repoName = gitRepo.value.content.name | |
341 | - cb(null, msg) | |
351 | + if (gitRepo) | |
352 | + msg.value.content.repoName = gitRepo.value.content.name | |
353 | + cb(null, msg) | |
342 | 354 | }) |
343 | 355 | else if (msg.value.content.type == 'issue') |
344 | 356 | getMsg(msg.value.content.project, function (err, gitRepo) { |
345 | - if (gitRepo) | |
346 | - msg.value.content.repoName = gitRepo.value.content.name | |
347 | - cb(null, msg) | |
357 | + if (gitRepo) | |
358 | + msg.value.content.repoName = gitRepo.value.content.name | |
359 | + cb(null, msg) | |
348 | 360 | }) |
349 | 361 | else |
350 | 362 | cb(null, msg) |
351 | 363 | } |
@@ -431,21 +443,25 @@ | ||
431 | 443 | fs.createReadStream(file).pipe(res) |
432 | 444 | }) |
433 | 445 | } |
434 | 446 | |
435 | -function prepend(fn, arg) { | |
436 | - return function (read) { | |
437 | - return function (abort, cb) { | |
438 | - if (fn && !abort) { | |
439 | - var _fn = fn | |
440 | - fn = null | |
441 | - return _fn(arg, function (err, value) { | |
442 | - if (err) return read(err, function (err) { | |
443 | - cb(err || true) | |
444 | - }) | |
445 | - cb(null, value) | |
446 | - }) | |
447 | - } | |
448 | - read(abort, cb) | |
449 | - } | |
450 | - } | |
451 | -} | |
447 | +//function prepend(fn, arg) { | |
448 | +// return function (read) { | |
449 | +// return function (abort, cb) { | |
450 | +// if (fn && !abort) { | |
451 | +// var _fn = fn | |
452 | +// fn = null | |
453 | +// return _fn(arg, function (err, value) { | |
454 | +// if (err) return read(err, function (err) { | |
455 | +// cb(err || true) | |
456 | +// }) | |
457 | +// cb(null, value) | |
458 | +// }) | |
459 | +// } | |
460 | +// read(abort, cb) | |
461 | +// } | |
462 | +// } | |
463 | +//} | |
464 | + | |
465 | + | |
466 | + | |
467 | + |
Built with git-ssb-web