git ssb

9+

cel / ssb-viewer



Commit b297b362d0c731be395de001bbb7ed5d9994f8c4

serve user feed which is a way of showing only messages of people you follow

Anders Rune Jensen committed on 4/15/2017, 11:15:25 AM
Parent: a234f1b2abb6ca0329e9f4bc64cb21a99c9c47a5

Files changed

index.jschanged
index.jsView
@@ -85,10 +85,11 @@
8585 }
8686
8787 var m = urlIdRegex.exec(req.url)
8888
89- if (req.url.startsWith('/user')) return serveFeed(req, res, m[4])
90- else if (req.url.startsWith('/channel')) return serveChannel(req, res, m[4])
89 + if (req.url.startsWith('/user/')) return serveFeed(req, res, m[4])
90 + else if (req.url.startsWith('/user-feed/')) return serveUserFeed(req, res, m[4])
91 + else if (req.url.startsWith('/channel/')) return serveChannel(req, res, m[4])
9192
9293 switch (m[2]) {
9394 case '%25': m[2] = '%'; m[1] = decodeURIComponent(m[1])
9495 case '%': return serveId(req, res, m[1], m[3], m[5])
@@ -135,8 +136,74 @@
135136 })
136137 )
137138 }
138139
140 + function serveUserFeed(req, res, url) {
141 + var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
142 + console.log("serving user feed: " + feedId)
143 +
144 + var following = []
145 +
146 + pull(
147 + sbot.createUserStream({ id: feedId }),
148 + pull.filter((msg) => {
149 + return !msg.value || msg.value.content.type == 'contact'
150 + }),
151 + pull.collect(function (err, msgs) {
152 + msgs.forEach((msg) => {
153 + if (msg.value.content.following)
154 + following[msg.value.content.contact] = 1
155 + else
156 + delete following[msg.value.content.contact]
157 + })
158 +
159 + serveFeeds(req, res, following, feedId)
160 + })
161 + )
162 + }
163 +
164 + function serveFeeds(req, res, following, feedId) {
165 + var opts = defaultOpts
166 +
167 + opts.marked = {
168 + gfm: true,
169 + mentions: true,
170 + tables: true,
171 + breaks: true,
172 + pedantic: false,
173 + sanitize: true,
174 + smartLists: true,
175 + smartypants: false,
176 + emoji: renderEmoji,
177 + renderer: new MdRenderer(opts)
178 + }
179 +
180 + pull(
181 + sbot.createLogStream({ reverse: true, limit: 1000 }),
182 + pull.filter((msg) => {
183 + return !msg.value || msg.value.author in following
184 + }),
185 + pull.filter((msg) => {
186 + return !msg.value.content.subscribed
187 + }),
188 + pull.collect(function (err, logs) {
189 + if (err) return respond(res, 500, err.stack || err)
190 + res.writeHead(200, {
191 + 'Content-Type': ctype("html")
192 + })
193 + pull(
194 + pull.values(logs),
195 + paramap(addAuthorAbout, 8),
196 + paramap(addFollowAbout, 8),
197 + pull(renderThread(opts), wrapPage(feedId)),
198 + toPull(res, function (err) {
199 + if (err) console.error('[viewer]', err)
200 + })
201 + )
202 + })
203 + )
204 + }
205 +
139206 function serveChannel(req, res, url) {
140207 var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
141208 console.log("serving channel: " + channelId)
142209

Built with git-ssb-web