git ssb

16+

cel / patchfoo



Commit 96a59d5c06ebb52095fe1c1f46f0181cffcd20fe

Add mentions

cel committed on 4/9/2017, 3:18:22 AM
Parent: 57c80659bb02d029c077c0658b1353cfcbe41e30

Files changed

lib/app.jschanged
lib/serve.jschanged
lib/app.jsView
@@ -199,4 +199,73 @@
199199 cb(null, pull.values(peers))
200200 })
201201 })
202202 }
203 +
204 +function isMentioned(links, id) {
205 + for (var i = 0; i < links && links.length; i++)
206 + if (links[i].link === id)
207 + return true
208 +}
209 +
210 +App.prototype.filterMentions = function (myId) {
211 + var self = this
212 +
213 + return pull(
214 + pull.asyncMap(function (msg, cb) {
215 + var c = msg && msg.value && msg.value.content
216 + if (!c || typeof c != 'object') return cb()
217 +
218 + // ignore own messages
219 + if (msg.value.author === myId) return cb()
220 +
221 + switch (c.type) {
222 + case 'post':
223 + if (msg.private) {
224 + return cb(null, msg)
225 +
226 + } else if (isMentioned(c.mentions, myId)) {
227 + return cb(null, msg)
228 +
229 + } else if (c.root || c.branch) {
230 + // check if this is a reply to one of our messages
231 + var done = multicb({ pluck: 1, spread: true })
232 + self.getMsg(c.root, done())
233 + self.getMsg(c.branch, done())
234 + return done(function (err, root, branch) {
235 + if (err) return cb(new Error(err.stack))
236 + var isReply = (root && root.value.author === myId)
237 + || (branch && branch.value.author === myId)
238 + cb(null, isReply && msg)
239 + })
240 + }
241 + return cb()
242 +
243 + case 'contact':
244 + return cb(null, u.linkDest(c.contact) === myId && msg)
245 +
246 + case 'vote':
247 + var vote = c.vote
248 + if (!vote || typeof vote.value !== 'number')
249 + return cb()
250 + return self.getMsg(u.linkDest(vote), function (err, subject) {
251 + if (err) {
252 + if (err.name == 'NotFoundError') return cb()
253 + else return cb(new Error(err.stack))
254 + }
255 + cb(null, subject && subject.value.author === myId && msg)
256 + })
257 +
258 + case 'pull-request':
259 + case 'issue':
260 + return self.getMsg(c.repo || c.project, function (err, repo) {
261 + if (err) return cb(new Error(err.stack))
262 + cb(null, repo && repo.value.author === myId && msg)
263 + })
264 +
265 + default:
266 + cb()
267 + }
268 + }),
269 + pull.filter(Boolean)
270 + )
271 +}
lib/serve.jsView
@@ -209,8 +209,9 @@
209209 m = /^([^.]*)(?:\.(.*))?$/.exec(url)
210210 switch (m[1]) {
211211 case '/public': return this.public(m[2])
212212 case '/private': return this.private(m[2])
213 + case '/mentions': return this.mentions(m[2])
213214 case '/search': return this.search(m[2])
214215 case '/vote': return this.vote(m[2])
215216 case '/peers': return this.peers(m[2])
216217 }
@@ -281,8 +282,34 @@
281282 })
282283 )
283284 }
284285
286 +Serve.prototype.mentions = function (ext) {
287 + var q = this.query
288 + var opts = {
289 + reverse: !q.forwards,
290 + sortByTimestamp: q.sort === 'claimed',
291 + lt: Number(q.lt) || Date.now(),
292 + gt: Number(q.gt) || -Infinity,
293 + }
294 + var limit = Number(q.limit) || 12
295 +
296 + pull(
297 + this.app.createLogStream(opts),
298 + paramap(this.app.unboxMsg, 16),
299 + pull.filter(isMsgReadable),
300 + this.app.filterMentions(this.app.sbot.id),
301 + pull.take(limit),
302 + this.renderThreadPaginated(opts, null, q),
303 + this.wrapMessages(),
304 + this.wrapPrivate(opts),
305 + this.wrapPage('mentions'),
306 + this.respondSink(200, {
307 + 'Content-Type': ctype(ext)
308 + })
309 + )
310 +}
311 +
285312 Serve.prototype.search = function (ext) {
286313 var searchQ = (this.query.q || '').trim()
287314 var self = this
288315
@@ -737,8 +764,9 @@
737764 h('body',
738765 h('nav.nav-bar', h('form', {action: render.toUrl('/search'), method: 'get'},
739766 h('a', {href: render.toUrl('/public')}, 'public'), ' ',
740767 h('a', {href: render.toUrl('/private')}, 'private') , ' ',
768 + h('a', {href: render.toUrl('/mentions')}, 'mentions') , ' ',
741769 h('a', {href: render.toUrl('/peers')}, 'peers') , ' ',
742770 render.idLink(self.app.sbot.id, done()), ' ',
743771 h('input.search-input', {name: 'q', value: searchQ,
744772 placeholder: 'search'})

Built with git-ssb-web