git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 3eb1b173c39d9c87c4c84a786a93eb2059417ac2

only bump an old messages in summary when you follow the person, or were mentioned

also filter out replies older than 24 hrs when you follow that user (as
they’re probably old posts freshly synced)
Matt McKegg committed on 11/1/2016, 9:36:47 PM
Parent: 13be5ee9906beb5d8c2a24db46c68ef183c78d3a

Files changed

lib/feed-summary.jschanged
modules/feed-summary.jschanged
modules/public.jschanged
lib/feed-summary.jsView
@@ -4,15 +4,17 @@
44 var SortedArray = require('sorted-array-functions')
55
66 module.exports = FeedSummary
77
8-function FeedSummary (source, windowSize, cb) {
8+function FeedSummary (source, opts, cb) {
9+ var bumpFilter = opts && opts.bumpFilter
10+ var windowSize = opts && opts.windowSize || 1000
911 var last = null
1012 var returned = false
1113 var done = false
1214 return pullNext(() => {
1315 if (!done) {
14- var next = {reverse: true, limit: windowSize || 1000, live: false}
16+ var next = {reverse: true, limit: windowSize, live: false}
1517 if (last) {
1618 next.lt = last.timestamp || last.value.sequence
1719 }
1820 var pushable = pullPushable()
@@ -22,9 +24,10 @@
2224 if (err) throw err
2325 if (!values.length) {
2426 done = true
2527 } else {
26- groupMessages(values).forEach(v => pushable.push(v))
28+ var fromTime = last && last.timestamp || Date.now()
29+ groupMessages(values, fromTime, bumpFilter).forEach(v => pushable.push(v))
2730 last = values[values.length - 1]
2831 }
2932 pushable.end()
3033 if (!returned) cb && cb()
@@ -35,9 +38,9 @@
3538 return pushable
3639 })
3740 }
3841
39-function groupMessages (messages, filter) {
42+function groupMessages (messages, fromTime, bumpFilter) {
4043 var follows = {}
4144 var messageUpdates = {}
4245 reverseForEach(messages, function (msg) {
4346 if (!msg.value) return
@@ -52,9 +55,12 @@
5255 if (group) {
5356 if (c.vote.value > 0) {
5457 group.lastUpdateType = 'dig'
5558 group.digs.add(msg.value.author)
56- group.updated = msg.timestamp
59+ // only bump when filter passes
60+ if (!bumpFilter || bumpFilter(msg, group)) {
61+ group.updated = msg.timestamp
62+ }
5763 } else {
5864 group.digs.delete(msg.value.author)
5965 if (group.lastUpdateType === 'dig' && !group.digs.size && !group.replies.length) {
6066 group.lastUpdateType = 'reply'
@@ -64,16 +70,22 @@
6470 }
6571 } else {
6672 if (c.root) {
6773 const group = ensureMessage(c.root, messageUpdates)
74+ group.fromTime = fromTime
6875 group.lastUpdateType = 'reply'
6976 group.repliesFrom.add(msg.value.author)
7077 //SortedArray.add(group.replies, msg, compareUserTimestamp)
7178 group.replies.push(msg)
7279 group.channel = group.channel || msg.value.content.channel
73- group.updated = msg.timestamp
80+
81+ // only bump when filter passes
82+ if (!bumpFilter || bumpFilter(msg, group)) {
83+ group.updated = msg.timestamp
84+ }
7485 } else {
7586 const group = ensureMessage(msg.key, messageUpdates)
87+ group.fromTime = fromTime
7688 group.lastUpdateType = 'post'
7789 group.updated = msg.timestamp
7890 group.author = msg.value.author
7991 group.channel = msg.value.content.channel
@@ -83,20 +95,20 @@
8395 })
8496
8597 var result = []
8698 Object.keys(follows).forEach((key) => {
87- SortedArray.add(result, follows[key], compareUpdated)
99+ if (follows[key].updated) {
100+ SortedArray.add(result, follows[key], compareUpdated)
101+ }
88102 })
89103 Object.keys(messageUpdates).forEach((key) => {
90- SortedArray.add(result, messageUpdates[key], compareUpdated)
104+ if (messageUpdates[key].updated) {
105+ SortedArray.add(result, messageUpdates[key], compareUpdated)
106+ }
91107 })
92108 return result
93109 }
94110
95-function compareUserTimestamp (a, b) {
96- return a.value.timestamp - b.value.timestamp
97-}
98-
99111 function compareUpdated (a, b) {
100112 return b.updated - a.updated
101113 }
102114
modules/feed-summary.jsView
@@ -24,8 +24,9 @@
2424 var sync = Value(false)
2525 var updates = Value(0)
2626
2727 var filter = opts && opts.filter
28+ var bumpFilter = opts && opts.bumpFilter
2829 var windowSize = opts && opts.windowSize
2930 var waitFor = opts && opts.waitFor || true
3031
3132 var updateLoader = m('a Notifier -loader', {
@@ -104,9 +105,9 @@
104105 var abortable = Abortable()
105106 abortLastFeed = abortable.abort
106107
107108 pull(
108- FeedSummary(getStream, windowSize, () => {
109+ FeedSummary(getStream, {windowSize, bumpFilter}, () => {
109110 sync.set(true)
110111 }),
111112 pull.asyncMap(ensureAuthor),
112113 pull.filter((item) => {
modules/public.jsView
@@ -94,20 +94,49 @@
9494 waitUntil: computed([
9595 following.sync,
9696 subscribedChannels.sync
9797 ], x => x.every(Boolean)),
98+ windowSize: 200,
9899 filter: (item) => {
99- return id === item.author ||
100+ return (
101+ id === item.author ||
100102 following().has(item.author) ||
101103 subscribedChannels().has(item.channel) ||
102104 (item.repliesFrom && item.repliesFrom.has(id))
105+ )
106+ },
107+ bumpFilter: (msg, group) => {
108+ if (!group.message) {
109+ return (
110+ isMentioned(id, msg.value.content.mentions) ||
111+ msg.value.author === id || (
112+ fromDay(msg, group.fromTime) && (
113+ following().has(msg.value.author) ||
114+ group.repliesFrom.has(id)
115+ )
116+ )
117+ )
118+ }
119+ return true
103120 }
104121 })
105122 ])
106123 ])
107124 }
108125 }
109126
127+function fromDay (msg, fromTime) {
128+ return (fromTime - msg.timestamp) < (24 * 60 * 60e3)
129+}
130+
131+function isMentioned (id, list) {
132+ if (Array.isArray(list)) {
133+ return list.includes(id)
134+ } else {
135+ return false
136+ }
137+}
138+
110139 function subscribe (id) {
111140 publish({
112141 type: 'channel',
113142 channel: id,

Built with git-ssb-web