git ssb

30+

cel / git-ssb-web



Commit 74b228c1c5b0fdbb83ac992185d15708791387ec

Put new notifications at the top of the list

cel committed on 12/1/2016, 4:55:54 AM
Parent: ef3f554c1d8d87d0d93d1c6b0f3cc21dfdc5022b

Files changed

lib/index-cache.jschanged
lib/index-cache.jsView
@@ -56,20 +56,8 @@
5656 })
5757 }
5858 }
5959
60-function sortMsgs(obj) {
61- // sort the notifications, but keep them in an object.
62- // usually the javascript engine preserves the order of the keys.
63- var out = {}
64- ssbSort(Object.keys(obj).map(function (id) {
65- return obj[id]
66- })).reverse().forEach(function (msg) {
67- out[msg.key] = msg
68- })
69- return out
70-}
71-
7260 module.exports = function (sbot, web) {
7361 var start = new Date
7462 var feedId
7563
@@ -82,9 +70,10 @@
8270 var issuesPRsDone = multicb({ pluck: 1, spread: true })
8371 var issuesPRsCb = issuesPRsDone()
8472 var threads = {/* id */}
8573 var myRepos = {/* id */}
86- var notifications = {/* id: msg */}
74 + var notifications = [/* msg */]
75 + var notificationIds = {/* id */}
8776 var notificationsCount = 0
8877 var notificationsReady = false
8978
9079 var linksTo = {/* key: [key] */}
@@ -182,9 +171,9 @@
182171 issuesPRsCb()
183172 getNewLinks()
184173 removeLinked(function () {
185174 notificationsReady = true
186- notifications = sortMsgs(notifications)
175 + ssbSort(notifications).reverse()
187176 console.log('Notifications ready', (new Date - start)/1000 + 's')
188177 })
189178 })
190179 })
@@ -267,11 +256,12 @@
267256 }
268257
269258 function gotNotification(msg) {
270259 if (msg.value.author === feedId) return
271- if (notifications[msg.key]) return
260 + if (notificationIds[msg.key]) return
261 + notificationIds[msg.key] = true
262 + notifications.unshift(msg)
272263 notificationsCount++
273- notifications[msg.key] = msg
274264 }
275265
276266 function removeLinked(cb) {
277267 // remove messages that we acknowledged
@@ -288,12 +278,21 @@
288278 })
289279 )
290280 }
291281
282 + function takeMsg(arr, id) {
283 + for (var i = 0; i < arr.length; i++) {
284 + if (arr[i].key === id) {
285 + return arr.splice(i, 1)[0]
286 + }
287 + }
288 + }
289 +
292290 function removeLink(link) {
293291 var id = link.dest || link.link
294- var msg = notifications[id]
295- delete notifications[id]
292 + if (!notificationIds[id]) return
293 + delete notificationIds[id]
294 + var msg = takeMsg(notifications, id)
296295 if (msg) {
297296 notificationsCount--
298297 ssbMsgs.indexLinks(msg, {msg: true}, removeLink)
299298 }

Built with git-ssb-web