git ssb

2+

mixmix / ticktack



Commit 7e24f761d4772ef1ac78ab33da6743bb7e1d821d

get unread working roughly correctly

Dominic Tarr committed on 10/20/2017, 3:29:29 AM
Parent: 23c8bbd3f9f930a0a1fb464a50c47d9218e80173

Files changed

app/html/context.jschanged
app/page/threadShow.jschanged
unread.jschanged
app/html/context.jsView
@@ -16,8 +16,9 @@
1616 'history.sync.push': 'first',
1717 'message.html.subject': 'first',
1818 'sbot.obs.localPeers': 'first',
1919 'translations.sync.strings': 'first',
20+ 'unread.sync.isUnread': 'first'
2021 })
2122
2223
2324 exports.create = (api) => {
@@ -29,21 +30,21 @@
2930 var nearby = api.sbot.obs.localPeers()
3031 var recentPeersContacted = Dict()
3132 // TODO - extract as contact.obs.recentPrivate or something
3233
34+ var m = {}
35+
3336 pull(
3437 next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
3538 pull.filter(msg => msg.value.content.type === 'post'), // TODO is this the best way to protect against votes?
3639 pull.filter(msg => msg.value.content.recps),
3740 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)
4647 })
4748 )
4849
4950 return h('Context -feed', [
@@ -72,8 +73,9 @@
7273 computed(nearby, n => !isEmpty(n) ? h('hr') : null),
7374
7475 // Discover
7576 Option({
77+ //XXX not a random number of notifications!
7678 notifications: Math.floor(Math.random()*5+1),
7779 imageEl: h('i.fa.fa-binoculars'),
7880 label: strings.blogIndex.title,
7981 selected: PAGES_UNDER_DISCOVER.includes(location.page),
@@ -86,9 +88,11 @@
8688 const lastMsg = value()
8789 if (nearby.has(feedId)) return
8890
8991 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
9195 imageEl: api.about.html.avatar(feedId),
9296 label: api.about.obs.name(feedId),
9397 selected: location.feed === feedId,
9498 location: Object.assign({}, lastMsg, { feed: feedId }) // TODO make obs?
app/page/threadShow.jsView
@@ -7,9 +7,10 @@
77
88 exports.needs = nest({
99 'app.html.context': 'first',
1010 'app.html.thread': 'first',
11- 'message.html.compose': 'first'
11+ 'message.html.compose': 'first',
12+ 'unread.sync.markRead': 'first'
1213 })
1314
1415 exports.create = (api) => {
1516 return nest('app.page.threadShow', threadShow)
@@ -21,11 +22,16 @@
2122 const channel = get(value, 'content.channel')
2223
2324 const thread = api.app.html.thread(root)
2425
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+
2530 const meta = {
2631 type: 'post',
2732 root,
33+ //XXX incorrect branch
2834 branch: get(last(location.replies), 'key'),
2935 // >> lastId? CHECK THIS LOGIC
3036 channel,
3137 recps: get(location, 'value.content.recps')
@@ -43,4 +49,5 @@
4349 }
4450 }
4551
4652
53+
unread.jsView
@@ -28,29 +28,28 @@
2828 if(timer) return
2929
3030 timer = setTimeout(function () {
3131 timer = null
32+ console.log('save!', Object.keys(unread.filter).length)
3233 localStorage.unread = JSON.stringify(unread)
3334 }, 2e3)
3435 }
3536
3637 function isUnread(msg) {
3738 //ignore messages which do not have timestamps
39+
3840 if(!msg.timestamp) return false
3941 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]
4443 }
4544
4645 function markRead(msg) {
47- if('string' === typeof msg.key) {
48- //if(isUnread(msg)) {
46+ if(msg && 'string' === typeof msg.key) {
47+ if(isUnread(msg)) {
4948 unread.filter[msg.key] = true
5049 save()
5150 return true
52- //}
51+ }
5352 }
5453 }
5554
5655 document.body.onunload = save

Built with git-ssb-web