git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit afa59d8bd5fdb35e2fc6204c459fed1a20ae6b03

rollup channel subscriptions

Matt McKegg committed on 3/18/2017, 4:15:00 AM
Parent: bcadbcc3325b20b2d11e736b46940303044e756c

Files changed

modules/feed/html/rollup.jschanged
modules/feed/pull/summary.jschanged
modules/profile/html/manyPeople.jsdeleted
modules/feed/html/rollup.jsView
@@ -23,10 +23,9 @@
2323 'html.rollup': 'first',
2424 'pull.summary': 'first'
2525 },
2626 profile: {
27- 'html.person': 'first',
28- 'html.manyPeople': 'first'
27+ 'html.person': 'first'
2928 }
3029 })
3130
3231 exports.gives = nest({
@@ -165,15 +164,15 @@
165164 if (item.lastUpdateType === 'reply' && item.repliesFrom.size) {
166165 meta = h('div.meta', {
167166 title: names(item.repliesFrom)
168167 }, [
169- api.profile.html.manyPeople(item.repliesFrom), ' replied'
168+ many(item.repliesFrom, api.profile.html.person), ' replied'
170169 ])
171170 } else if (item.lastUpdateType === 'like' && item.likes.size) {
172171 meta = h('div.meta', {
173172 title: names(item.likes)
174173 }, [
175- api.profile.html.manyPeople(item.likes), ' liked this message'
174+ many(item.likes, api.profile.html.person), ' liked this message'
176175 ])
177176 }
178177
179178 return h('FeedEvent', [
@@ -190,15 +189,15 @@
190189 if (item.lastUpdateType === 'reply' && item.repliesFrom.size) {
191190 meta = h('div.meta', {
192191 title: names(item.repliesFrom)
193192 }, [
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)
195194 ])
196195 } else if (item.lastUpdateType === 'like' && item.likes.size) {
197196 meta = h('div.meta', {
198197 title: names(item.likes)
199198 }, [
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)
201200 ])
202201 }
203202
204203 if (meta || replies.length) {
@@ -211,11 +210,21 @@
211210 return h('FeedEvent -follow', [
212211 h('div.meta', {
213212 title: names(item.contacts)
214213 }, [
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)
216215 ])
217216 ])
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+ ])
218227 }
219228
220229 return h('div')
221230 }
@@ -234,12 +243,40 @@
234243 }
235244 }
236245
237246 function names (ids) {
238- var items = map(ids, api.about.obs.name)
247+ var items = map(Array.from(ids), api.about.obs.name)
239248 return computed([items], (names) => names.map((n) => `- ${n}`).join('\n'))
240249 }
241250 }
242251
243252 function twoDaysAgo () {
244253 return Date.now() - (2 * 24 * 60 * 60 * 1000)
245254 }
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.jsView
@@ -56,15 +56,18 @@
5656 })
5757 }
5858
5959 function groupMessages (messages, fromTime, bumpFilter, cb) {
60+ var subscribes = {}
6061 var follows = {}
6162 var messageUpdates = {}
6263 reverseForEach(messages, function (msg) {
6364 if (!msg.value) return
6465 var c = msg.value.content
6566 if (c.type === 'contact') {
6667 updateContact(msg, follows)
68+ } else if (c.type === 'channel') {
69+ updateChannel(msg, subscribes)
6770 } else if (c.type === 'vote') {
6871 if (c.vote && c.vote.link) {
6972 // only show likes of posts added in the current window
7073 // and only for the main post
@@ -72,12 +75,9 @@
7275 if (group) {
7376 if (c.vote.value > 0) {
7477 group.lastUpdateType = 'like'
7578 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)
8080 } else {
8181 group.likes.delete(msg.value.author)
8282 if (group.lastUpdateType === 'like' && !group.likes.size && !group.replies.length) {
8383 group.lastUpdateType = 'reply'
@@ -91,15 +91,10 @@
9191 group.fromTime = fromTime
9292 group.lastUpdateType = 'reply'
9393 group.repliesFrom.add(msg.value.author)
9494 SortedArray.add(group.replies, msg, compareUserTimestamp)
95- //group.replies.push(msg)
9695 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)
10297 } else {
10398 const group = ensureMessage(msg.key, messageUpdates)
10499 group.fromTime = fromTime
105100 group.lastUpdateType = 'post'
@@ -116,8 +111,13 @@
116111 if (follows[key].updated) {
117112 SortedArray.add(result, follows[key], compareUpdated)
118113 }
119114 })
115+ Object.keys(subscribes).forEach((key) => {
116+ if (subscribes[key].updated) {
117+ SortedArray.add(result, subscribes[key], compareUpdated)
118+ }
119+ })
120120 Object.keys(messageUpdates).forEach((key) => {
121121 if (messageUpdates[key].updated) {
122122 SortedArray.add(result, messageUpdates[key], compareUpdated)
123123 }
@@ -125,8 +125,16 @@
125125 cb(null, result)
126126 })
127127 }
128128
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+
129137 function compareUpdated (a, b) {
130138 return b.updated - a.updated
131139 }
132140
@@ -178,8 +186,37 @@
178186 }
179187 }
180188 }
181189
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+
182219 function ensureMessage (id, groups) {
183220 var group = groups[id]
184221 if (!group) {
185222 group = groups[id] = {
modules/profile/html/manyPeople.jsView
@@ -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