Commit abb85fa0947760cd74602bc9f246265ae015e3e1
Don't register channel subscription / unsubscription or vote messages as 'recent channel activity.'
Gordon Martin committed on 10/7/2017, 7:31:49 PMParent: 5bd646e5318c724c8523f74e3cbcb3712bfbb20f
Files changed
sbot/channels.js | changed |
sbot/channels.js | ||
---|---|---|
@@ -4,8 +4,15 @@ | ||
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 | + | |
8 | 15 | function reduce (result, item) { |
9 | 16 | if (!result) result = {} |
10 | 17 | if (item) { |
11 | 18 | for (var channel in item) { |
@@ -13,9 +20,13 @@ | ||
13 | 20 | if (!value) { |
14 | 21 | value = result[channel] = {count: 0, timestamp: 0} |
15 | 22 | } |
16 | 23 | value.count += 1 |
17 | - if (item[channel].timestamp > value.timestamp) { | |
24 | + | |
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 | 29 | value.timestamp = item[channel].timestamp |
19 | 30 | } |
20 | 31 | } |
21 | 32 | } |
@@ -26,9 +37,9 @@ | ||
26 | 37 | if (msg.value.content) { |
27 | 38 | var channel = normalizeChannel(msg.value.content.channel) |
28 | 39 | if (channel) { |
29 | 40 | return { |
30 | - [channel]: {timestamp: msg.timestamp} | |
41 | + [channel]: {timestamp: msg.timestamp, isActivityMessage: isActivityMessage(msg) } | |
31 | 42 | } |
32 | 43 | } |
33 | 44 | } |
34 | 45 | } |
Built with git-ssb-web