Open hadees opened 12 years ago
This is definitely a good idea, patches are welcome.
It would be a lot easier to do this if every user had their own copy of an activity but then it gets a little messy as we cache data and any change has to run through potentially hundreds of documents.
There is a fork from joe1chen that does this if you'd like to look at it.
I'm open to any ideas you have on how to make this work...
So I see a few options on how to do it but the only one that really makes any sense is to add a viewed_at
key into the receiver hash.
I'm not sure that is exactly elegant because you create that hash inside the publish method. Maybe receiver should be an embedded document?
After that I would just add some options to stream_for to only return unviewed activities. The downside with this though is you filter out the receivers array in the results so I don't think we'd be able to check if an activity is viewed or not once we returned them. I'd really like to figure out a way to be able to check activities directly. Maybe don't filter out the receivers?
Then we just need a viewed!
method that takes in an array of receivers
and that'll set the viewed_at timestamp.
What are your feelings on this approach?
Any other ideas? I'm wondering if I should just fork streama into a gem that specifically deals with the notification use case but I'm not sure they are really that different. Other then the main fact a notification only has one receiver and needs to track if it was viewed.
I guess I could build a gem on top of streama that just adds that.
Hi Evan,
Your approach of adding a viewed method to the receivers hash is a good idea and would solve your problem. An embedded document for each receiver will make it easier to access/modify but i'd have to look into the limitations with this.
Unfortunately I'm a little tied up with work at the moment to look into this in detail but if you create a fork i'll be happy to either merge your changes or promote it as an alternative.
I've noticed that streama does a pretty good job acting as a way of displaying notifications to users. The issue i'm running into is that I can't tell a user what notifications are new or not because I'm not tracking when they viewed them. I started writing a simple patch for this but I quickly realized it didn't make sense because users share activities models. So i'm open to suggestions on how best to do this. Would you even accept a patch?
I've also being thinking how hard it would be to allow a model to use streama twice. So a user model could have Activity and Notification.