git ssb

9+

cel / ssb-viewer



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 PM
Parent: 2c291337776846d8c4edf05609c74fac530254e6

Files changed

index.jschanged
index.jsView
@@ -119,8 +119,11 @@
119119 }
120120
121121 pull(
122122 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 + }),
123126 pull.collect(function (err, logs) {
124127 if (err) return respond(res, 500, err.stack || err)
125128 res.writeHead(200, {
126129 'Content-Type': ctype(ext)
@@ -149,36 +152,36 @@
149152 var channelSubscriptions = []
150153
151154 getAbout(feedId, function (err, about) {
152155 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,
179182 'user feed ' + (about ? about.name : ""))
180- })
183 + })
181184 )
182185 })
183186 }
184187
@@ -191,29 +194,29 @@
191194
192195 pull(
193196 sbot.createLogStream({ reverse: true, limit: 5000 }),
194197 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)
198201 }),
199202 pull.take(150),
200203 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 + )
216219 })
217220 )
218221 }
219222
@@ -225,23 +228,23 @@
225228
226229 pull(
227230 sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
228231 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 + )
244247 })
245248 )
246249 }
247250
@@ -278,49 +281,58 @@
278281
279282 var format = formatMsgs(id, ext, opts)
280283 if (format === null) return respond(res, 415, 'Invalid format')
281284
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)
293298 })
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 + })
304316 }
305317
306318 function addFollowAbout(msg, cb) {
307319 if (msg.value.content.contact)
308320 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)
312324 })
313325 else
314326 cb(null, msg)
315327 }
316328
317329 function addVoteMessage(msg, cb) {
318330 if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%')
319331 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)
323335 })
324336 else
325337 cb(null, msg)
326338 }
@@ -335,17 +347,17 @@
335347
336348 function addGitLinks(msg, cb) {
337349 if (msg.value.content.type == 'git-update')
338350 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)
342354 })
343355 else if (msg.value.content.type == 'issue')
344356 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)
348360 })
349361 else
350362 cb(null, msg)
351363 }
@@ -431,21 +443,25 @@
431443 fs.createReadStream(file).pipe(res)
432444 })
433445 }
434446
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