Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
alternative approach to #642
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Oct 10, 2017
1 parent abb85fa commit 08a7cff
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions sbot/channels.js
Expand Up @@ -5,13 +5,6 @@ module.exports = function (ssb, config) {
return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map))
}

function isActivityMessage(msg) {
var isVote = msg.value.content.type === "vote";

return !isVote && msg.value.content.subscribed !== false
&& msg.value.content.subscribed !== true;
}

function reduce (result, item) {
if (!result) result = {}
if (item) {
Expand All @@ -22,10 +15,7 @@ function reduce (result, item) {
}
value.count += 1

// We don't update the timestamp if the messsage was just somebody subscribing
// or unsubscribing from the channel, or it is a vote as we don't want it to register as
// 'recent activity'.
if (item[channel].isActivityMessage && item[channel].timestamp > value.timestamp) {
if (item[channel].timestamp > value.timestamp) {
value.timestamp = item[channel].timestamp
}
}
Expand All @@ -35,10 +25,14 @@ function reduce (result, item) {

function map (msg) {
if (msg.value.content) {
var isLike = msg.value.content.type === 'vote'
var isSubscription = msg.value.content.type === 'channel'
var channel = normalizeChannel(msg.value.content.channel)
if (channel) {

// filter out likes and subscriptions
if (channel && !isLike && !isSubscription) {
return {
[channel]: {timestamp: msg.timestamp, isActivityMessage: isActivityMessage(msg) }
[channel]: {timestamp: msg.timestamp}
}
}
}
Expand Down

0 comments on commit 08a7cff

Please sign in to comment.