Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic feed slug support #89

Closed
ilovenwd opened this issue Oct 21, 2014 · 13 comments
Closed

dynamic feed slug support #89

ilovenwd opened this issue Oct 21, 2014 · 13 comments

Comments

@ilovenwd
Copy link

It's not very clear how to implement getstream.io dynamic feed slug feature.
Create dynamic feed class? or merge feed_slug into user_id like Feed(user_id="%(feed_slug)s:%(user_id)s") ? this is too hack.

@tschellenbach
Copy link
Owner

So the Stream Framework and getstream.io are two different things.

  • Stream Framework is a python framework with which you can build newsfeeds.
  • GetStream.io is a hosted solution which you talk to via a rest api.

For stream framework this example app shows how to set things up:
https://github.com/tbarbugli/stream_framework_example/blob/master/core/pin_feed.py
https://github.com/tbarbugli/stream_framework_example/blob/master/core/feed_managers.py

@ilovenwd
Copy link
Author

So, GetStream.io is a wrapper/api of open sourced Stream Framework, or based on a internal version of Stream Framework?
It seems I need to change a lot of code to support slug feature.

@tschellenbach
Copy link
Owner

Not really, the user id just gets used to format a key, something like
key = 'flat:%(user_id)s' % dict(user_id=user_id)
If you need to change how the key gets set simply subclass the feed class.

But I wonder why do you want to use the slug?
If it's only to separate out the feeds into a few different feeds you're better of using the example you see in:
https://github.com/tbarbugli/stream_framework_example/blob/master/core/pin_feed.py

@ilovenwd
Copy link
Author

I'm considering using Stream-Framework for a simple chat system, where the slug is the chat group name.
Also the feed would behave diff from normal feeds. I'm still in navigating the possibility.

@ilovenwd
Copy link
Author

key = 'flat:%(user_id)s' % dict(user_id=user_id)
from the code, the key_format is bind to a class.
so dynamic slug would require create dynamic class, it's doable but hacky.

What I want to do is stream_framework.feed_manager.Manger.add_user_activity(self, user_id, activity):
accept a slug param.

@tbarbugli
Copy link
Collaborator

can you elaborate a bit more on your use case? why is it not enough to consider the chat group name as
user_id?

@ilovenwd
Copy link
Author

Imaging we have multiple topics(cannot predefined), like health, science, python, etc. each user can subscribe/publish to a topic.
we need some api like getstream.io /topics/:feed_slug/:user_id but some details are different.
It is something like a interest group

@tbarbugli
Copy link
Collaborator

why isn't topics:python enough for your use case?

for example:
user x follows topic python -> feed 'user:x' follows feed 'topic:python'
user x says "helloworld" on python -> add activity {...hello..} on feed 'topic:python'

@ilovenwd
Copy link
Author

ok. I understand now.
Just user_id=python is a little strange.
Thanks for your help.

@tbarbugli
Copy link
Collaborator

the user_id parameter can be a bit misleading when the feed is not a user feed but a channel or topic feed; @tschellenbach perhaps we can improve this by adding some example in the docs and/or docstrings?

@ilovenwd
Copy link
Author

but another case is that

user x follows topic python posted by user y -> feed 'user:x' follows feed 'topic:python:y'
user y says "helloworld" on python -> add activity {...hello..} on feed 'topic:python:y'

this case still need dynamic feed slug. Think topic as a sub namespace of a tweet stream.
I do think dynamic feed slug is useful for some advanced cases.
A strange thing is that getstream.io seems support dynamic slug, why stream-framework doesn't?
I mean stream-framework can support like user_id='topic_python:user_id' but seems too hack

@tbarbugli
Copy link
Collaborator

if you need to keep one feed per channel and user then you need something more than "python" but indeed "python:X".

I am not sure why you are calling this as dynamic feed slug; I think it makes this makes look the issue more complex than it actually is :) My suggestion is to add methods in your feed manager implementation that provide you with the right feed_id. For example you would have a method that gives you the feed's user_id for a topic ("python") and another method that gives you the user topic feed's id ("python:42").

for example:

def get_topic_feed_id(self, topic):
    return topic

def get_user_topic_feed_id(self, topic, user):
    return "%s:%s" % (topic, user.id)

@ilovenwd
Copy link
Author

I think I have understand the problem. Thanks all of you for help.
The thing fools me is the user_id param name and the getstream.io api (which has feed_type and feed_slug).
Hope this issue will help others as well.
Stream-Framework is a well designed lib :) -- that's why I don't want to patch it a lot to support so called dynamic slug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants