Commit 08a7cff8db13bc65b509e3ba4f53566e2cb21e6a
alternative approach to #642
Matt McKegg committed on 10/10/2017, 12:03:54 AMParent: abb85fa0947760cd74602bc9f246265ae015e3e1
Files changed
sbot/channels.js | changed |
sbot/channels.js | ||
---|---|---|
@@ -4,15 +4,8 @@ | ||
4 | 4 | module.exports = function (ssb, config) { |
5 | 5 | return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map)) |
6 | 6 | } |
7 | 7 | |
8 | -function isActivityMessage(msg) { | |
9 | - var isVote = msg.value.content.type === "vote"; | |
10 | - | |
11 | - return !isVote && msg.value.content.subscribed !== false | |
12 | - && msg.value.content.subscribed !== true; | |
13 | -} | |
14 | - | |
15 | 8 | function reduce (result, item) { |
16 | 9 | if (!result) result = {} |
17 | 10 | if (item) { |
18 | 11 | for (var channel in item) { |
@@ -21,12 +14,9 @@ | ||
21 | 14 | value = result[channel] = {count: 0, timestamp: 0} |
22 | 15 | } |
23 | 16 | value.count += 1 |
24 | 17 | |
25 | - // We don't update the timestamp if the messsage was just somebody subscribing | |
26 | - // or unsubscribing from the channel, or it is a vote as we don't want it to register as | |
27 | - // 'recent activity'. | |
28 | - if (item[channel].isActivityMessage && item[channel].timestamp > value.timestamp) { | |
18 | + if (item[channel].timestamp > value.timestamp) { | |
29 | 19 | value.timestamp = item[channel].timestamp |
30 | 20 | } |
31 | 21 | } |
32 | 22 | } |
@@ -34,12 +24,16 @@ | ||
34 | 24 | } |
35 | 25 | |
36 | 26 | function map (msg) { |
37 | 27 | if (msg.value.content) { |
28 | + var isLike = msg.value.content.type === 'vote' | |
29 | + var isSubscription = msg.value.content.type === 'channel' | |
38 | 30 | var channel = normalizeChannel(msg.value.content.channel) |
39 | - if (channel) { | |
31 | + | |
32 | + // filter out likes and subscriptions | |
33 | + if (channel && !isLike && !isSubscription) { | |
40 | 34 | return { |
41 | - [channel]: {timestamp: msg.timestamp, isActivityMessage: isActivityMessage(msg) } | |
35 | + [channel]: {timestamp: msg.timestamp} | |
42 | 36 | } |
43 | 37 | } |
44 | 38 | } |
45 | 39 | } |
Built with git-ssb-web