git ssb

2+

mixmix / ticktack



Commit bee2958f3a890cd7ecae7658ea242acbfdcfdc52

fix unread count to work with new participants concept (exclude msgs from self)

mix irving committed on 2/13/2018, 10:31:33 PM
Parent: adca29179dee2177af6fefa725c91581ffef5395

Files changed

app/html/sideNav/sideNavDiscovery.jschanged
app/html/sideNav/sideNavDiscovery.jsView
@@ -17,8 +17,9 @@
1717 'about.obs.name': 'first',
1818 'feed.pull.private': 'first',
1919 'history.sync.push': 'first',
2020 'history.obs.store': 'first',
21 + 'keys.sync.id': 'first',
2122 'message.html.subject': 'first',
2223 'message.sync.getParticipants': 'first',
2324 'sbot.obs.localPeers': 'first',
2425 'translations.sync.strings': 'first',
@@ -31,43 +32,37 @@
3132 var unreadMsgsCache = Dict() // { id: [ msgs ] }
3233
3334 return nest({
3435 // intercept markUnread and remove them from the cache.
35- 'unread.sync.markUnread': function (msg) {
36- unreadMsgsCache.get(msg.value.content.root || msg.key)
37- .delete(msg.key)
38- unreadMsgsCache.get(msg.value.author)
39- .delete(msg.key)
40- },
36 + 'unread.sync.markUnread': markUnread,
4137 'app.html.sideNav': sideNav
4238 })
4339
44- function isMatch (location) {
45- if (location.page) {
46- if (location.page.match(/^blog/)) return true
47- if (location.page.match(/^thread/)) return true
48- if (location.page.match(/^user/)) return true
49- if (location.page.match(/^channel/)) return true
50- }
51- if (location.key) {
52- return true
53- }
54- return false
40 + function markUnread (msg) {
41 + unreadMsgsCache.get(msg.value.content.root || msg.key)
42 + .delete(msg.key)
43 +
44 + const participants = api.message.sync.getParticipants(msg)
45 + unreadMsgsCache.get(participants.key)
46 + .delete(msg.key)
5547 }
5648
5749 function sideNav (location) {
58- if (!isMatch(location)) return
50 + if (!isSideNavDiscovery(location)) return
5951
6052 const strings = api.translations.sync.strings()
6153 var nearby = api.sbot.obs.localPeers()
6254 const getParticipants = api.message.sync.getParticipants
55 + const myKey = api.keys.sync.id()
6356
6457 // Unread message counts
6558 function updateCache (cache, msg) {
6659 if (api.unread.sync.isUnread(msg)) { cache.add(msg.key) } else { cache.delete(msg.key) }
6760 }
6861
6962 function updateUnreadMsgsCache (msg) {
63 + if (msg.value.author === myKey) return
64 +
7065 const participantsKey = getParticipants(msg).key
7166 updateCache(getUnreadMsgsCache(participantsKey), msg)
7267
7368 const rootKey = get(msg, 'value.content.root', msg.key)
@@ -196,10 +191,10 @@
196191
197192 function updateRecentMsgCache (soFar, newMsg) {
198193 soFar.transaction(() => {
199194 const { timestamp } = newMsg.value
200- newMsg.participantsKey = getParticipants(newMsg).key
201- const index = indexOf(soFar, (msg) => newMsg.participantsKey === resolve(msg).participantsKey)
195 + newMsg.participants = getParticipants(newMsg)
196 + const index = indexOf(soFar, (msg) => newMsg.participants.key === resolve(msg).participants.key)
202197 var object = Value()
203198
204199 if (index >= 0) {
205200 // reference already exists, lets use this instead!
@@ -347,4 +342,18 @@
347342 }
348343 }
349344 return -1
350345 }
346 +
347 +function isSideNavDiscovery (location) {
348 + if (location.page) {
349 + if (location.page.match(/^blog/)) return true
350 + if (location.page.match(/^thread/)) return true
351 + if (location.page.match(/^user/)) return true
352 + if (location.page.match(/^channel/)) return true
353 + }
354 + if (location.key) {
355 + return true
356 + }
357 + return false
358 +}
359 +

Built with git-ssb-web