Merge pull request #182 from christianbundy/social-filter-fix

Fix and document `socialFilter()`
This commit is contained in:
Cinnamon 2020-02-08 16:04:06 -08:00 committed by GitHub
commit 1b489ba485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 8 deletions

View File

@ -270,6 +270,14 @@ module.exports = cooler => {
});
};
/**
* Returns a function that filters messages based on who published the message.
*
* `null` means we don't care, `true` means it must be true, and `false` means
* that the value must be false. For example, if you set `me = true` then it
* will only allow messages that are from you. If you set `blocking = true`
* then you only see message from people you block.
*/
const socialFilter = async ({
following = null,
blocking = false,
@ -289,14 +297,18 @@ module.exports = cooler => {
.filter(([, val]) => val === false)
.map(([key]) => key);
return pull.filter(
message =>
(following === null ||
followingList.includes(message.value.author) === following) &&
(blocking === null ||
blockingList.includes(message.value.author) === blocking) &&
(me === null || (message.value.author === id) === me)
);
return pull.filter(message => {
if (message.value.author === id) {
return me !== false;
} else {
return (
(following === null ||
followingList.includes(message.value.author) === following) &&
(blocking === null ||
blockingList.includes(message.value.author) === blocking)
);
}
});
};
const transform = (ssb, messages, myFeedId) =>
Promise.all(