Search code examples
getstream-io

Inbox with getstream.io


I am looking for the best way to implement an inbox with getstream.io

basically, just like the FB out twitter inbox. where a user can send a private message to another one.

I have the save requirement for private discussion groups.

How can I model this with getstream.io ?

Thank you


Solution

  • Stream supports this use-case very well. My suggestion is to use notification feeds, this way you have read/seen state counters out-of-the-box.

    The flow is pretty simple: when a user sends a private message to another user, all you have to do is add an activity to the recipient's notification feed.

    // John sends a message to Mike
    client = stream.connect('key', 'secret')
    activity = {'actor': 'user:jhon', 'verb': 'message', 'object': 'message:123'}
    client.feed('notification', 'mike').add_activity(activity)
    

    If you want, you can also add the same activity to both sender and recipient feeds with a single API call. In this case we add to John's user feed and to Mike's notification feed.

    client = stream.connect('key', 'secret')
    activity = {
        'actor': 'user:john',
        'verb': 'message',
        'object': 'message:123',
        'to': ['notification:mike']
    }
    client.feed('user', 'john').add_activity(activity)
    

    You can find more information about notification feeds and to targeting field on Stream documentation pages.