Commit 7628e2e86bc23fe70db4765213ff337c9451f8de
profile: show recently updated feeds first
Matt McKegg committed on 3/14/2017, 12:54:26 AMParent: bae9ec5dfb58696c54daa0eb9621e4f386aa8631
Files changed
modules/page/html/render/profile.js | changed |
modules/profile/obs/rank.js | added |
modules/page/html/render/profile.js | ||
---|---|---|
@@ -18,8 +18,9 @@ | ||
18 | 18 | 'sbot.pull.userFeed': 'first', |
19 | 19 | 'sbot.async.publish': 'first', |
20 | 20 | 'keys.sync.id': 'first', |
21 | 21 | 'sheet.display': 'first', |
22 | + 'profile.obs.rank': 'first', | |
22 | 23 | 'contact.obs': { |
23 | 24 | followers: 'first', |
24 | 25 | following: 'first' |
25 | 26 | } |
@@ -178,8 +179,9 @@ | ||
178 | 179 | return container |
179 | 180 | }) |
180 | 181 | |
181 | 182 | function renderContactBlock (title, profiles) { |
183 | + profiles = api.profile.obs.rank(profiles) | |
182 | 184 | return [ |
183 | 185 | when(computed(profiles, x => x.length), h('h2', title)), |
184 | 186 | h('div', { |
185 | 187 | classList: 'ProfileList' |
modules/profile/obs/rank.js | ||
---|---|---|
@@ -1,0 +1,48 @@ | ||
1 | +var computed = require('mutant/computed') | |
2 | +var nest = require('depnest') | |
3 | + | |
4 | +exports.needs = nest({ | |
5 | + 'profile.obs.recentlyUpdated': 'first' | |
6 | +}) | |
7 | + | |
8 | +exports.gives = nest('profile.obs.rank') | |
9 | + | |
10 | +exports.create = function (api) { | |
11 | + return nest('profile.obs.rank', function (ids, max) { | |
12 | + var recent = api.profile.obs.recentlyUpdated() | |
13 | + | |
14 | + var result = computed([ids, recent], (ids, recent) => { | |
15 | + var result = [] | |
16 | + ids.forEach((id) => { | |
17 | + if (recent.has(id)) { | |
18 | + result.push(id) | |
19 | + } | |
20 | + }) | |
21 | + ids.forEach((id) => { | |
22 | + if (!recent.has(id)) { | |
23 | + result.push(id) | |
24 | + } | |
25 | + }) | |
26 | + if (max) { | |
27 | + result = result.slice(0, max) | |
28 | + } | |
29 | + return result | |
30 | + }, {nextTick: true}) | |
31 | + | |
32 | + result.sync = recent.sync | |
33 | + | |
34 | + return result | |
35 | + }) | |
36 | +} | |
37 | + | |
38 | +function compare (a, b, recent) { | |
39 | + var hasA = recent.has(a) | |
40 | + var hasB = recent.has(b) | |
41 | + if (hasA && hasB) { | |
42 | + return 0 | |
43 | + } else if (hasA && !hasB) { | |
44 | + return -1 | |
45 | + } else { | |
46 | + return 1 | |
47 | + } | |
48 | +} |
Built with git-ssb-web