Commit afa59d8bd5fdb35e2fc6204c459fed1a20ae6b03
rollup channel subscriptions
Matt McKegg committed on 3/18/2017, 4:15:00 AMParent: bcadbcc3325b20b2d11e736b46940303044e756c
Files changed
modules/feed/html/rollup.js | changed |
modules/feed/pull/summary.js | changed |
modules/profile/html/manyPeople.js | deleted |
modules/feed/html/rollup.js | ||
---|---|---|
@@ -23,10 +23,9 @@ | ||
23 | 23 | 'html.rollup': 'first', |
24 | 24 | 'pull.summary': 'first' |
25 | 25 | }, |
26 | 26 | profile: { |
27 | - 'html.person': 'first', | |
28 | - 'html.manyPeople': 'first' | |
27 | + 'html.person': 'first' | |
29 | 28 | } |
30 | 29 | }) |
31 | 30 | |
32 | 31 | exports.gives = nest({ |
@@ -165,15 +164,15 @@ | ||
165 | 164 | if (item.lastUpdateType === 'reply' && item.repliesFrom.size) { |
166 | 165 | meta = h('div.meta', { |
167 | 166 | title: names(item.repliesFrom) |
168 | 167 | }, [ |
169 | - api.profile.html.manyPeople(item.repliesFrom), ' replied' | |
168 | + many(item.repliesFrom, api.profile.html.person), ' replied' | |
170 | 169 | ]) |
171 | 170 | } else if (item.lastUpdateType === 'like' && item.likes.size) { |
172 | 171 | meta = h('div.meta', { |
173 | 172 | title: names(item.likes) |
174 | 173 | }, [ |
175 | - api.profile.html.manyPeople(item.likes), ' liked this message' | |
174 | + many(item.likes, api.profile.html.person), ' liked this message' | |
176 | 175 | ]) |
177 | 176 | } |
178 | 177 | |
179 | 178 | return h('FeedEvent', [ |
@@ -190,15 +189,15 @@ | ||
190 | 189 | if (item.lastUpdateType === 'reply' && item.repliesFrom.size) { |
191 | 190 | meta = h('div.meta', { |
192 | 191 | title: names(item.repliesFrom) |
193 | 192 | }, [ |
194 | - api.profile.html.manyPeople(item.repliesFrom), ' replied to ', api.message.html.link(item.messageId) | |
193 | + many(item.repliesFrom, api.profile.html.person), ' replied to ', api.message.html.link(item.messageId) | |
195 | 194 | ]) |
196 | 195 | } else if (item.lastUpdateType === 'like' && item.likes.size) { |
197 | 196 | meta = h('div.meta', { |
198 | 197 | title: names(item.likes) |
199 | 198 | }, [ |
200 | - api.profile.html.manyPeople(item.likes), ' liked ', api.message.html.link(item.messageId) | |
199 | + many(item.likes, api.profile.html.person), ' liked ', api.message.html.link(item.messageId) | |
201 | 200 | ]) |
202 | 201 | } |
203 | 202 | |
204 | 203 | if (meta || replies.length) { |
@@ -211,11 +210,21 @@ | ||
211 | 210 | return h('FeedEvent -follow', [ |
212 | 211 | h('div.meta', { |
213 | 212 | title: names(item.contacts) |
214 | 213 | }, [ |
215 | - api.profile.html.person(item.id), ' followed ', api.profile.html.manyPeople(item.contacts) | |
214 | + api.profile.html.person(item.id), ' followed ', many(item.contacts, api.profile.html.person) | |
216 | 215 | ]) |
217 | 216 | ]) |
217 | + } else if (item.type === 'subscribe') { | |
218 | + return h('FeedEvent -subscribe', [ | |
219 | + h('div.meta', { | |
220 | + title: Array.from(item.channels).map(c => `#${c}`).join('\n') | |
221 | + }, [ | |
222 | + api.profile.html.person(item.id), ' subscribed to ', many(item.channels, (channel) => { | |
223 | + return h('a', {href: `#${channel}`}, `#${channel}`) | |
224 | + }) | |
225 | + ]) | |
226 | + ]) | |
218 | 227 | } |
219 | 228 | |
220 | 229 | return h('div') |
221 | 230 | } |
@@ -234,12 +243,40 @@ | ||
234 | 243 | } |
235 | 244 | } |
236 | 245 | |
237 | 246 | function names (ids) { |
238 | - var items = map(ids, api.about.obs.name) | |
247 | + var items = map(Array.from(ids), api.about.obs.name) | |
239 | 248 | return computed([items], (names) => names.map((n) => `- ${n}`).join('\n')) |
240 | 249 | } |
241 | 250 | } |
242 | 251 | |
243 | 252 | function twoDaysAgo () { |
244 | 253 | return Date.now() - (2 * 24 * 60 * 60 * 1000) |
245 | 254 | } |
255 | + | |
256 | +function many (ids, fn) { | |
257 | + ids = Array.from(ids) | |
258 | + var featuredIds = ids.slice(-3).reverse() | |
259 | + | |
260 | + if (ids.length) { | |
261 | + if (ids.length > 3) { | |
262 | + return [ | |
263 | + fn(featuredIds[0]), ', ', | |
264 | + fn(featuredIds[1]), | |
265 | + ' and ', ids.length - 2, ' others' | |
266 | + ] | |
267 | + } else if (ids.length === 3) { | |
268 | + return [ | |
269 | + fn(featuredIds[0]), ', ', | |
270 | + fn(featuredIds[1]), ' and ', | |
271 | + fn(featuredIds[2]) | |
272 | + ] | |
273 | + } else if (ids.length === 2) { | |
274 | + return [ | |
275 | + fn(featuredIds[0]), ' and ', | |
276 | + fn(featuredIds[1]) | |
277 | + ] | |
278 | + } else { | |
279 | + return fn(featuredIds[0]) | |
280 | + } | |
281 | + } | |
282 | +} |
modules/feed/pull/summary.js | ||
---|---|---|
@@ -56,15 +56,18 @@ | ||
56 | 56 | }) |
57 | 57 | } |
58 | 58 | |
59 | 59 | function groupMessages (messages, fromTime, bumpFilter, cb) { |
60 | + var subscribes = {} | |
60 | 61 | var follows = {} |
61 | 62 | var messageUpdates = {} |
62 | 63 | reverseForEach(messages, function (msg) { |
63 | 64 | if (!msg.value) return |
64 | 65 | var c = msg.value.content |
65 | 66 | if (c.type === 'contact') { |
66 | 67 | updateContact(msg, follows) |
68 | + } else if (c.type === 'channel') { | |
69 | + updateChannel(msg, subscribes) | |
67 | 70 | } else if (c.type === 'vote') { |
68 | 71 | if (c.vote && c.vote.link) { |
69 | 72 | // only show likes of posts added in the current window |
70 | 73 | // and only for the main post |
@@ -72,12 +75,9 @@ | ||
72 | 75 | if (group) { |
73 | 76 | if (c.vote.value > 0) { |
74 | 77 | group.lastUpdateType = 'like' |
75 | 78 | group.likes.add(msg.value.author) |
76 | - // only bump when filter passes | |
77 | - if (!bumpFilter || bumpFilter(msg, group)) { | |
78 | - group.updated = msg.timestamp | |
79 | - } | |
79 | + bumpIfNeeded(group, msg, bumpFilter) | |
80 | 80 | } else { |
81 | 81 | group.likes.delete(msg.value.author) |
82 | 82 | if (group.lastUpdateType === 'like' && !group.likes.size && !group.replies.length) { |
83 | 83 | group.lastUpdateType = 'reply' |
@@ -91,15 +91,10 @@ | ||
91 | 91 | group.fromTime = fromTime |
92 | 92 | group.lastUpdateType = 'reply' |
93 | 93 | group.repliesFrom.add(msg.value.author) |
94 | 94 | SortedArray.add(group.replies, msg, compareUserTimestamp) |
95 | - //group.replies.push(msg) | |
96 | 95 | group.channel = group.channel || msg.value.content.channel |
97 | - | |
98 | - // only bump when filter passes | |
99 | - if (!bumpFilter || bumpFilter(msg, group)) { | |
100 | - group.updated = msg.timestamp || msg.value.sequence | |
101 | - } | |
96 | + bumpIfNeeded(group, msg, bumpFilter) | |
102 | 97 | } else { |
103 | 98 | const group = ensureMessage(msg.key, messageUpdates) |
104 | 99 | group.fromTime = fromTime |
105 | 100 | group.lastUpdateType = 'post' |
@@ -116,8 +111,13 @@ | ||
116 | 111 | if (follows[key].updated) { |
117 | 112 | SortedArray.add(result, follows[key], compareUpdated) |
118 | 113 | } |
119 | 114 | }) |
115 | + Object.keys(subscribes).forEach((key) => { | |
116 | + if (subscribes[key].updated) { | |
117 | + SortedArray.add(result, subscribes[key], compareUpdated) | |
118 | + } | |
119 | + }) | |
120 | 120 | Object.keys(messageUpdates).forEach((key) => { |
121 | 121 | if (messageUpdates[key].updated) { |
122 | 122 | SortedArray.add(result, messageUpdates[key], compareUpdated) |
123 | 123 | } |
@@ -125,8 +125,16 @@ | ||
125 | 125 | cb(null, result) |
126 | 126 | }) |
127 | 127 | } |
128 | 128 | |
129 | +function bumpIfNeeded (group, msg, bumpFilter) { | |
130 | + // only bump when filter passes | |
131 | + var newUpdated = msg.timestamp || msg.value.sequence | |
132 | + if (!group.updated || ((!bumpFilter || bumpFilter(msg, group)) && newUpdated > group.updated)) { | |
133 | + group.updated = newUpdated | |
134 | + } | |
135 | +} | |
136 | + | |
129 | 137 | function compareUpdated (a, b) { |
130 | 138 | return b.updated - a.updated |
131 | 139 | } |
132 | 140 | |
@@ -178,8 +186,37 @@ | ||
178 | 186 | } |
179 | 187 | } |
180 | 188 | } |
181 | 189 | |
190 | +function updateChannel (msg, groups) { | |
191 | + var c = msg.value.content | |
192 | + var id = msg.value.author | |
193 | + var group = groups[id] | |
194 | + if (typeof c.channel === 'string') { | |
195 | + if (c.subscribed) { | |
196 | + if (!group) { | |
197 | + group = groups[id] = { | |
198 | + type: 'subscribe', | |
199 | + lastUpdateType: null, | |
200 | + channels: new Set(), | |
201 | + updated: 0, | |
202 | + author: id, | |
203 | + id: id | |
204 | + } | |
205 | + } | |
206 | + group.channels.add(c.channel) | |
207 | + group.updated = msg.timestamp || msg.value.sequence | |
208 | + } else { | |
209 | + if (group) { | |
210 | + group.channels.delete(c.channel) | |
211 | + if (!group.channels.size) { | |
212 | + delete groups[id] | |
213 | + } | |
214 | + } | |
215 | + } | |
216 | + } | |
217 | +} | |
218 | + | |
182 | 219 | function ensureMessage (id, groups) { |
183 | 220 | var group = groups[id] |
184 | 221 | if (!group) { |
185 | 222 | group = groups[id] = { |
modules/profile/html/manyPeople.js | ||
---|---|---|
@@ -1,43 +1,0 @@ | ||
1 | -var nest = require('depnest') | |
2 | - | |
3 | -exports.needs = nest({ | |
4 | - 'profile.html.person': 'first' | |
5 | -}) | |
6 | - | |
7 | -exports.gives = nest({ | |
8 | - 'profile.html': [ 'manyPeople' ] | |
9 | -}) | |
10 | - | |
11 | -exports.create = function (api) { | |
12 | - return nest({ | |
13 | - 'profile.html': { manyPeople } | |
14 | - }) | |
15 | - | |
16 | - function manyPeople (ids) { | |
17 | - ids = Array.from(ids) | |
18 | - var featuredIds = ids.slice(-3).reverse() | |
19 | - | |
20 | - if (ids.length) { | |
21 | - if (ids.length > 3) { | |
22 | - return [ | |
23 | - api.profile.html.person(featuredIds[0]), ', ', | |
24 | - api.profile.html.person(featuredIds[1]), | |
25 | - ' and ', ids.length - 2, ' others' | |
26 | - ] | |
27 | - } else if (ids.length === 3) { | |
28 | - return [ | |
29 | - api.profile.html.person(featuredIds[0]), ', ', | |
30 | - api.profile.html.person(featuredIds[1]), ' and ', | |
31 | - api.profile.html.person(featuredIds[2]) | |
32 | - ] | |
33 | - } else if (ids.length === 2) { | |
34 | - return [ | |
35 | - api.profile.html.person(featuredIds[0]), ' and ', | |
36 | - api.profile.html.person(featuredIds[1]) | |
37 | - ] | |
38 | - } else { | |
39 | - return api.profile.html.person(featuredIds[0]) | |
40 | - } | |
41 | - } | |
42 | - } | |
43 | -} |
Built with git-ssb-web