git ssb

9+

cel / ssb-viewer



Commit b422fc1e8e938b340e5961d30a2d16edb54dd647

show channel when rendering post, show all followed channels in user-feed

Anders Rune Jensen committed on 4/15/2017, 7:48:09 PM
Parent: 2ee923fecc38c7bee0a0f0520fae62c565d18e63

Files changed

index.jschanged
index.jsView
@@ -142,28 +142,42 @@
142142 var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
143143 console.log("serving user feed: " + feedId)
144144
145145 var following = []
146 + var channelSubscriptions = []
146147
147148 pull(
148149 sbot.createUserStream({ id: feedId }),
149150 pull.filter((msg) => {
150- return !msg.value || msg.value.content.type == 'contact'
151 + return !msg.value ||
152 + msg.value.content.type == 'contact' ||
153 + (msg.value.content.type == 'channel' &&
154 + typeof msg.value.content.subscribed != 'undefined')
151155 }),
152156 pull.collect(function (err, msgs) {
153157 msgs.forEach((msg) => {
154- if (msg.value.content.following)
155- following[msg.value.content.contact] = 1
156- else
157- delete following[msg.value.content.contact]
158 + if (msg.value.content.type == 'contact')
159 + {
160 + if (msg.value.content.following)
161 + following[msg.value.content.contact] = 1
162 + else
163 + delete following[msg.value.content.contact]
164 + }
165 + else // channel subscription
166 + {
167 + if (msg.value.content.subscribed)
168 + channelSubscriptions[msg.value.content.channel] = 1
169 + else
170 + delete following[msg.value.content.channel]
171 + }
158172 })
159173
160- serveFeeds(req, res, following, feedId)
174 + serveFeeds(req, res, following, channelSubscriptions, feedId)
161175 })
162176 )
163177 }
164178
165- function serveFeeds(req, res, following, feedId) {
179 + function serveFeeds(req, res, following, channelSubscriptions, feedId) {
166180 var opts = defaultOpts
167181
168182 opts.marked = {
169183 gfm: true,
@@ -180,9 +194,11 @@
180194
181195 pull(
182196 sbot.createLogStream({ reverse: true, limit: 1000 }),
183197 pull.filter((msg) => {
184- return !msg.value || msg.value.author in following
198 + return !msg.value ||
199 + (msg.value.author in following ||
200 + msg.value.content.channel in channelSubscriptions)
185201 }),
186202 pull.filter((msg) => { // channel subscription
187203 return !msg.value.content.subscribed
188204 }),
@@ -228,8 +244,11 @@
228244 sbot.createLogStream({ reverse: true, limit: 2000 }),
229245 pull.filter((msg) => {
230246 return !msg.value || msg.value.content.channel == channelId
231247 }),
248 + pull.filter((msg) => { // channel subscription
249 + return !msg.value.content.subscribed
250 + }),
232251 pull.collect(function (err, logs) {
233252 if (err) return respond(res, 500, err.stack || err)
234253 res.writeHead(200, {
235254 'Content-Type': ctype("html")
@@ -560,12 +579,13 @@
560579 }
561580
562581 function render(opts, c)
563582 {
564- if (c.type === 'post')
565- return renderPost(opts, c)
566- else if (c.type == 'vote' && c.vote.expression == 'Dig') {
583 + if (c.type === 'post') {
567584 var channel = c.channel ? ' in #' + c.channel : ''
585 + return channel + renderPost(opts, c)
586 + } else if (c.type == 'vote' && c.vote.expression == 'Dig') {
587 + var channel = c.channel ? ' in #' + c.channel : ''
568588 var linkedText = 'this'
569589 if (typeof c.vote.linkedText != 'undefined')
570590 linkedText = c.vote.linkedText.substring(0, 100)
571591 return ' dug ' + '<a href="/' + c.vote.link + '">' + linkedText + '</a>' + channel

Built with git-ssb-web