Commit 7e24f761d4772ef1ac78ab33da6743bb7e1d821d
get unread working roughly correctly
Dominic Tarr committed on 10/20/2017, 3:29:29 AMParent: 23c8bbd3f9f930a0a1fb464a50c47d9218e80173
Files changed
app/html/context.js | changed |
app/page/threadShow.js | changed |
unread.js | changed |
app/html/context.js | ||
---|---|---|
@@ -16,8 +16,9 @@ | ||
16 | 16 | 'history.sync.push': 'first', |
17 | 17 | 'message.html.subject': 'first', |
18 | 18 | 'sbot.obs.localPeers': 'first', |
19 | 19 | 'translations.sync.strings': 'first', |
20 | + 'unread.sync.isUnread': 'first' | |
20 | 21 | }) |
21 | 22 | |
22 | 23 | |
23 | 24 | exports.create = (api) => { |
@@ -29,21 +30,21 @@ | ||
29 | 30 | var nearby = api.sbot.obs.localPeers() |
30 | 31 | var recentPeersContacted = Dict() |
31 | 32 | // TODO - extract as contact.obs.recentPrivate or something |
32 | 33 | |
34 | + var m = {} | |
35 | + | |
33 | 36 | pull( |
34 | 37 | next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']), |
35 | 38 | pull.filter(msg => msg.value.content.type === 'post'), // TODO is this the best way to protect against votes? |
36 | 39 | pull.filter(msg => msg.value.content.recps), |
37 | 40 | pull.drain(msg => { |
38 | - msg.value.content.recps | |
39 | - .map(recp => typeof recp === 'object' ? recp.link : recp) | |
40 | - .filter(recp => recp != myKey) | |
41 | - .forEach(recp => { | |
42 | - if (recentPeersContacted.has(recp)) return | |
43 | - | |
44 | - recentPeersContacted.put(recp, msg) | |
45 | - }) | |
41 | + var author = msg.value.author | |
42 | + if(api.unread.sync.isUnread(msg)) | |
43 | + recentPeersContacted | |
44 | + .put(author, (recentPeersContacted.get(author)||0)+1) | |
45 | + else | |
46 | + recentPeersContacted.put(author, 0) | |
46 | 47 | }) |
47 | 48 | ) |
48 | 49 | |
49 | 50 | return h('Context -feed', [ |
@@ -72,8 +73,9 @@ | ||
72 | 73 | computed(nearby, n => !isEmpty(n) ? h('hr') : null), |
73 | 74 | |
74 | 75 | // Discover |
75 | 76 | Option({ |
77 | + //XXX not a random number of notifications! | |
76 | 78 | notifications: Math.floor(Math.random()*5+1), |
77 | 79 | imageEl: h('i.fa.fa-binoculars'), |
78 | 80 | label: strings.blogIndex.title, |
79 | 81 | selected: PAGES_UNDER_DISCOVER.includes(location.page), |
@@ -86,9 +88,11 @@ | ||
86 | 88 | const lastMsg = value() |
87 | 89 | if (nearby.has(feedId)) return |
88 | 90 | |
89 | 91 | return Option({ |
90 | - notifications: Math.random() > 0.7 ? Math.floor(Math.random()*9+1) : 0, // TODO | |
92 | + //XXX not a random number of notifications. | |
93 | + notifications: value, | |
94 | + //Math.random() > 0.7 ? Math.floor(Math.random()*9+1) : 0, // TODO | |
91 | 95 | imageEl: api.about.html.avatar(feedId), |
92 | 96 | label: api.about.obs.name(feedId), |
93 | 97 | selected: location.feed === feedId, |
94 | 98 | location: Object.assign({}, lastMsg, { feed: feedId }) // TODO make obs? |
app/page/threadShow.js | ||
---|---|---|
@@ -7,9 +7,10 @@ | ||
7 | 7 | |
8 | 8 | exports.needs = nest({ |
9 | 9 | 'app.html.context': 'first', |
10 | 10 | 'app.html.thread': 'first', |
11 | - 'message.html.compose': 'first' | |
11 | + 'message.html.compose': 'first', | |
12 | + 'unread.sync.markRead': 'first' | |
12 | 13 | }) |
13 | 14 | |
14 | 15 | exports.create = (api) => { |
15 | 16 | return nest('app.page.threadShow', threadShow) |
@@ -21,11 +22,16 @@ | ||
21 | 22 | const channel = get(value, 'content.channel') |
22 | 23 | |
23 | 24 | const thread = api.app.html.thread(root) |
24 | 25 | |
26 | + //mark the thread as read, as it's being displayed. | |
27 | + api.unread.sync.markRead(location) | |
28 | + location.replies.forEach(api.unread.sync.markRead) | |
29 | + | |
25 | 30 | const meta = { |
26 | 31 | type: 'post', |
27 | 32 | root, |
33 | + //XXX incorrect branch | |
28 | 34 | branch: get(last(location.replies), 'key'), |
29 | 35 | // >> lastId? CHECK THIS LOGIC |
30 | 36 | channel, |
31 | 37 | recps: get(location, 'value.content.recps') |
@@ -43,4 +49,5 @@ | ||
43 | 49 | } |
44 | 50 | } |
45 | 51 | |
46 | 52 | |
53 | + |
unread.js | ||
---|---|---|
@@ -28,29 +28,28 @@ | ||
28 | 28 | if(timer) return |
29 | 29 | |
30 | 30 | timer = setTimeout(function () { |
31 | 31 | timer = null |
32 | + console.log('save!', Object.keys(unread.filter).length) | |
32 | 33 | localStorage.unread = JSON.stringify(unread) |
33 | 34 | }, 2e3) |
34 | 35 | } |
35 | 36 | |
36 | 37 | function isUnread(msg) { |
37 | 38 | //ignore messages which do not have timestamps |
39 | + | |
38 | 40 | if(!msg.timestamp) return false |
39 | 41 | if(msg.timestamp < unread.timestamp) return false |
40 | - if(unread.filter[msg.key]) { | |
41 | - return false | |
42 | - } | |
43 | - return true | |
42 | + return !unread.filter[msg.key] | |
44 | 43 | } |
45 | 44 | |
46 | 45 | function markRead(msg) { |
47 | - if('string' === typeof msg.key) { | |
48 | - //if(isUnread(msg)) { | |
46 | + if(msg && 'string' === typeof msg.key) { | |
47 | + if(isUnread(msg)) { | |
49 | 48 | unread.filter[msg.key] = true |
50 | 49 | save() |
51 | 50 | return true |
52 | - //} | |
51 | + } | |
53 | 52 | } |
54 | 53 | } |
55 | 54 | |
56 | 55 | document.body.onunload = save |
Built with git-ssb-web