git ssb

30+

cel / git-ssb-web



Commit e18e404a95ff6bf668905140f3b4c627530879a0

wip

cel committed on 12/22/2016, 10:19:44 PM
Parent: f895a8b36bcd47ba80f3f899f54f971b15fbe5b3

Files changed

lib/index-cache.jschanged
lib/index-cache.jsView
@@ -4,9 +4,8 @@
44 var multicb = require('multicb')
55 var ssbMsgs = require('ssb-msgs')
66 var ssbSort = require('ssb-sort')
77 var many = require('pull-many')
8-var multicb = require('multicb')
98 var u = require('./util')
109
1110 // work around sync not getting emitted
1211 function logt(sbot, opt) {
@@ -44,20 +43,8 @@
4443 return !msg.sync || void (!--count && cb())
4544 })
4645 }
4746
48-function indexLinks(linksTo, linksFrom) {
49- return function (msg) {
50- if (msg.key in linksFrom) return // duplicate
51- var linksFromMsg = linksFrom[msg.key] = []
52- ssbMsgs.indexLinks(msg, {msg: true}, function (link) {
53- var linksToMsg = linksTo[link.link] || (linksTo[link.link] = [])
54- linksToMsg.push(msg.key)
55- linksFromMsg.push(link.link)
56- })
57- }
58-}
59-
6047 module.exports = function (sbot, web) {
6148 var start = new Date
6249 var feedId
6350
@@ -66,21 +53,19 @@
6653 var repoIssues = {/* repo id : {issue id:, count: int} */}
6754 var repoPRs = {/* repo id : {pr id:, count: int} */}
6855 var closed = {/* issue/pr id */}
6956 var issuesReady = false
70- var issuesPRsDone = multicb({ pluck: 1, spread: true })
71- var issuesPRsCb = issuesPRsDone()
7257 var threads = {/* id */}
7358 var myRepos = {/* id */}
7459 var notifications = [/* msg */]
7560 var notificationIds = {/* id */}
7661 var notificationsCount = 0
7762 var notificationsReady = false
7863
79- var linksTo = {/* key: [key] */}
80- var linksFrom = {/* key: [key] */}
64 + var notifs = require('./notifications')()
8165
8266 function indexIssue(msg) {
67 + notifs.addRoot(msg)
8368 if (msg.key in closed) return delete closed[msg.key]
8469 var repoId = msg.value.content.project || msg.value.content.repo
8570 var issues = repoIssues[repoId] || (repoIssues[repoId] = {count: 0})
8671 issues[msg.key] = true
@@ -88,8 +73,9 @@
8873 issues.count++
8974 }
9075
9176 function indexPR(msg) {
77 + notifs.addRoot(msg)
9278 if (msg.key in closed) return delete closed[msg.key]
9379 var repoId = msg.value.content.repo
9480 var prs = repoPRs[repoId] || (repoPRs[repoId] = {count: 0})
9581 prs[msg.key] = true
@@ -98,11 +84,15 @@
9884 }
9985
10086 function indexIssueEdit(msg) {
10187 var updates = msg.value.content.issues || []
88 + notifs.addEdit(msg)
10289 for (var i = 0; i < updates.length; i++) {
10390 var update = updates[i]
104- if (update.open !== false) continue // TODO: handle re-opens
91 + if (update.open !== false) {
92 + // reopenMsgs[msg.key] = true
93 + continue // TODO: handle re-opens
94 + }
10595 var id = update.link
10696 var repoId = repos[id]
10797 if (repoId) {
10898 var issues, prs
@@ -141,36 +131,25 @@
141131 indexIssuesPRs()
142132 }
143133 }
144134
145- // get issue edits
146- pull(
147- sbot.links({
148- rel: 'issues',
149- values: true,
150- live: true,
151- }),
152- sync(1, issuesPRsDone),
153- pull.drain(function (msg) {
154- indexIssueEdit(msg)
155- }, function (err) {
156- if (err) console.error(err.stack || err)
157- })
158- )
135 + var editsDone = multicb({ pluck: 1, spread: true })
136 + getIssueEdits(editsDone())
137 + var editsDoneCb = editsDone()
159138
160- issuesPRsDone(function () {
139 + editsDone(function () {
161140 issuesReady = true
162141 console.log('Issues synced', (new Date - start)/1000 + 's')
163142 })
164143
165144 function indexIssuesPRs() {
166145 if (web.isPublic) {
167- getIssues(issuesPRsCb)
146 + getIssues(editsDoneCb)
168147 } else {
169148 getRepos(function () {
170149 getIssues(function () {
171- issuesPRsCb()
172150 getNewLinks()
151 + editsDoneCb()
173152 removeLinked(function () {
174153 notificationsReady = true
175154 ssbSort(notifications).reverse()
176155 console.log('Notifications ready', (new Date - start)/1000 + 's')
@@ -179,8 +158,24 @@
179158 })
180159 }
181160 }
182161
162 + function getIssueEdits(cb) {
163 + pull(
164 + sbot.links({
165 + rel: 'issues',
166 + values: true,
167 + live: true,
168 + }),
169 + sync(1, cb),
170 + pull.drain(function (msg) {
171 + indexIssueEdit(msg)
172 + }, function (err) {
173 + if (err) console.error(err.stack || err)
174 + })
175 + )
176 + }
177 +
183178 function getRepos(cb) {
184179 pull(
185180 logt(sbot, {
186181 type: 'git-repo',
@@ -230,10 +225,9 @@
230225 pull.through(function (msg) {
231226 threads[msg.key] = true
232227 }),
233228 withThreads(sbot),
234- // pull.through(indexLinks(linksTo, linksFrom)),
235- pull.drain(gotNotification, function (err) {
229 + pull.drain(indexMsg, function (err) {
236230 if (err) console.error(err.stack || err)
237231 })
238232 )
239233 }
@@ -248,20 +242,23 @@
248242 }),
249243 pull.filter(function (msg) {
250244 return msg.value.content.root in threads
251245 }),
252- pull.drain(gotNotification, function (err) {
246 + pull.drain(indexMsg, function (err) {
253247 if (err) console.error(err.stack || err)
254248 })
255249 )
256250 }
257251
258- function gotNotification(msg) {
252 + function indexMsg(msg) {
253 + notifs.addReply(msg)
254 + /*
259255 if (msg.value.author === feedId) return
260256 if (notificationIds[msg.key]) return
261257 notificationIds[msg.key] = true
262258 notifications.unshift(msg)
263259 notificationsCount++
260 + */
264261 }
265262
266263 function removeLinked(cb) {
267264 // remove messages that we acknowledged
@@ -293,8 +290,9 @@
293290 delete notificationIds[id]
294291 var msg = takeMsg(notifications, id)
295292 if (msg) {
296293 notificationsCount--
294 + // remove messages that this message points to, recursively
297295 ssbMsgs.indexLinks(msg, {msg: true}, removeLink)
298296 }
299297 }
300298

Built with git-ssb-web