From 39f34bc6e6f273f48376b8a049c66486631bfa11 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 22 Mar 2021 20:32:59 -0700 Subject: [PATCH] Adds activity stream utility for adding and removing statuses --- bookwyrm/activitystreams.py | 21 +++++++++++++++++++++ bookwyrm/models/relationship.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index aecad727..7a959df9 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -38,6 +38,27 @@ class ActivityStream(ABC): # and go! pipeline.execute() + def remove_status(self, status): + """ remove a status from all feeds """ + pipeline = r.pipeline() + for user in self.stream_users(status): + pipeline.lrem(self.stream_id(user), -1, status.id) + pipeline.execute() + + def add_user_statuses(self, user, viewer): + """ add a user's statuses to another user's feed """ + pipeline = r.pipeline() + for status in user.status_set.objects.all()[: settings.MAX_STREAM_LENGTH]: + pipeline.lpush(self.stream_id(viewer), status.id) + pipeline.execute() + + def remove_user_statuses(self, user, viewer): + """ remove a user's status from another user's feed """ + pipeline = r.pipeline() + for status in user.status_set.objects.all()[: settings.MAX_STREAM_LENGTH]: + pipeline.lrem(self.stream_id(viewer), status.id) + pipeline.execute() + def get_activity_stream(self, user): """ load the ids for statuses to be displayed """ # clear unreads for this feed diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index df99d216..998d7bed 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -62,7 +62,7 @@ class UserFollows(ActivityMixin, UserRelationship): status = "follows" - def to_activity(self): + def to_activity(self): # pylint: disable=arguments-differ """ overrides default to manually set serializer """ return activitypub.Follow(**generate_activity(self))