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

User specific channel #186

Open
akhilkochuveettilanilkumar opened this issue Dec 17, 2015 · 6 comments
Open

User specific channel #186

akhilkochuveettilanilkumar opened this issue Dec 17, 2015 · 6 comments

Comments

@akhilkochuveettilanilkumar

Hi, I'm woking on a project (runs on django 1.8 ) in which I require user specific push notification. I have successfully created a channel and broadcast data to all user using publish_data(). At present we have 10 million users. So I need to send a user specific push notification. I have used the following example to setup the swampdragon user specific notification:
https://github.com/CptLemming/swampdragon_notification_example
Using the above example I tried setting up swampdragon in my project. When I execute my project I'm not getting any notification or error regarding it.

My models.py:

    from swampdragon.models import SelfPublishModel
    from swampdragon_serializer import NotificationSerializer

   class Mymodel(SelfPublishModel, BaseModel):        
        serializer_class = NotificationSerializer
        message = models.TextField()
        user = models.ForeignKey(User)

My swampdragon_serializer.py (I'm using this file because models.py is already imported in the serializers.py so I won't be able to import serializers.py to my models.py for swamp dragon)

    from swampdragon.serializers.model_serializer import ModelSerializer

    class NotificationSerializer(ModelSerializer):
        class Meta:
            model = 'app.Mymodel'
            publish_fields = ('message', )
            update_fields = ('message', )

My router.py and notification.js looks the same as the example in the url mentioned above.
When I execute my project I'm not getting any notification or error.
I'm getting values from http://localhost:9999/data/info
My app is also not able to subscribe the channel. Since its not showing the console.log() (mentioned in the subscribe() ) in the browser console.

@AlexejStukov
Copy link

Hi @Wineartist ,
paste the following code inside your settings.py to enable error logging:

if DEBUG:
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'simple'
            },
        },
        'loggers': {
            'tornado.general': {
                'handlers': ['console'],
                'level': 'ERROR',
                'propagate': True,
            }
        }
    }

@ZuSe
Copy link

ZuSe commented Dec 21, 2015

@Wineartist

Do you have swampdragon auth installed and HttpDataConnection set?

We also use user specific push notifications in our projects. Here is an example for a router that pushes generic notifications to users defined as targets in the proper model

class GenericNotificationsRouter(ModelRouter):
    valid_verbs = ['subscribe']
    route_name = 'generic-notifications'
    model = GenericNotification
    serializer_class = GenericNotificationSDSerializer

    @login_required
    def subscribe(self, **kwargs):
        super().subscribe(**kwargs)

    def get_subscription_contexts(self, **kwargs):
        return {'receivers__id__exact': self.connection.user.pk}

route_handler.register(GenericNotificationsRouter)

Hope that helps you to understand the basic principle.

@denizs
Copy link

denizs commented Jan 26, 2016

@ZuSe

I assume that your GenericNotification has a field called receivers, right? Does this field contain a list of users or solely one? I'm currently working on a private messaging app, trying to figure out how to restrict the broadcast of new messages to only the author/recepient.

@ZuSe
Copy link

ZuSe commented Jan 26, 2016

This field does contain a list of users.
But you can use the same approach for only one user.
'''
return {'receiver_id': self.connection.user.pk}
'''

@denizs
Copy link

denizs commented Jan 26, 2016

@ZuSe
Thanks for the info. 👍

@metazet
Copy link

metazet commented Jan 27, 2016

Hi all,
I'm trying to make pushing messages to separated channels and can't understand why swampdragon send all messages via one socket.
Here is my simple route:

from swampdragon.route_handler import BaseRouter
class OliveRouter(BaseRouter):
    route_name = 'olive-integration'

    def get_subscription_channels(self, **kwargs):
        return ['olive-GB104']
route_handler.register(OliveRouter)

I subscribe on UI to channel 'olive-GB699', then send message to channel 'olive-GB104' and see this message in both channels! Look at screenshot:
screenshot 2016-01-27 18 53 50
May be I do something wrong?
I send message like that:

from swampdragon.pubsub_providers.data_publisher import publish_data
publish_data(channel='olive-{code}'.format(code=receiver_code), data={...})

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

5 participants