stream-django icon indicating copy to clipboard operation
stream-django copied to clipboard

follow_user and unfollow_user specify a different feed (not the user feed)

Open murdav opened this issue 8 years ago • 3 comments

Hello,

Would it be possible to add feed_type=None in: https://github.com/GetStream/stream-django/blob/master/stream_django/managers.py#L39 and https://github.com/GetStream/stream-django/blob/master/stream_django/managers.py#L45

E.g.

def follow_user(self, user_id, target_user_id, feed_type=None):
        news_feeds = self.get_news_feeds(user_id)
        target_feed = self.get_user_feed(target_user_id, feed_type)
        for feed in news_feeds.values():
            feed.follow(target_feed.slug, target_feed.user_id)

Doing so users can follow any feed. Anyway get_user_feed already has the parameter.

Usage:

@receiver(post_save, sender=UserFollowMyModel1)
@receiver(post_save, sender=UserFollowMyModel2)
def follow_feed(sender, instance, created, **kwargs):
    if created and not settings.STREAM_DISABLE_MODEL_TRACKING:
        target_unique_id = '{0}-{1}'.format(instance.target.type_id, instance.target_id)
        feed_manager.follow_user(instance.user_id, target_unique_id, 'my_custom_flat_feed')

Thanks,

Davide

murdav avatar Apr 28 '17 17:04 murdav

Perhaps it is easier to get the API client from the manager and perform the follow/unfollow directly?

tbarbugli avatar Apr 29 '17 12:04 tbarbugli

Thanks @tbarbugli for replying! It depends, currently I'm using the above-mentioned workflow and it works like a charm! For me it would be easier like this, otherwise I should do something like:

        user_feed = feed_manager.get_feed('timeline', instance.user_id)
        user_feed.follow('my_custom_flat_feed', target_unique_id)
        user_feed = feed_manager.get_feed('timeline_aggregated', instance.user_id)
        user_feed.follow('my_custom_flat_feed', target_unique_id)

Basically the same is here https://github.com/GetStream/stream-django/blob/master/stream_django/managers.py#L54

Furthermore https://github.com/GetStream/stream-django/blob/master/stream_django/managers.py#L24 already supports the param.

Am I right?

Thanks once again,

D

murdav avatar Apr 29 '17 17:04 murdav

@murdav This may be a potential solution to the concept of following other objects. I came up with this and I think it ultimately achieves at least what I am looking for. Still doing some verification though too. Instead of creating a direct "follow" relationship between two objects, i.e. one user feed follows another, my scenario is more about a feed to one unique object. The problem with letting a user try to follow one object is obviously it is one instance on a greater feed unlike as mentioned for a user those are actually full feeds. Your use case and needs could be different than what I understand, however here's mine:

What I think I'll do for my solution is make a "follow" button where they can hit that on one post. That post id is sent to the API. In the API I'll take that postid and do a lookup using the get_activities method. Once I have that post activity I can then look up the user's timeline that I want the post to live on (be followed on). Once I have that I discovered there's a method to add that object to the user's feed or timeline.

    # Add post they hit "follow" on as post that is in their timeline
    post = stream_client.get_activities(ids=[self.kwargs['postid']])['results'][0]
    user1timeline = stream_client.feed('timeline', str(request.user.pk))
    user1timeline.add_activity(post)

Now I have the post the user wanted to follow or keep track of on their user timeline. I see there is also a remove activity so I suppose if you want to also make an unfollow button somewhere you can also remove it. For my purposes I may ultimately just not have that because since it's on a one object basis eventually it will go out of scope and no longer need to be modified.

ghost avatar Sep 02 '19 20:09 ghost