3

I am using the GetStream Django package to interact with getstream.io. I have had success using the Enricher() class to enrich my activity feed with Django model information for the feed_manager.get_user_feed(), but cannot get similar results with feed_manager.get_notification_feed()

Here is a shortened version of my model.

class Task(models.Model, Activity):
    title = models.CharField()
    assigned_to = models.ForeignKey(User)
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User)

    @property
    def activity_object_attr(self):
        return self
    @property
    def activity_actor_attr(self):
        return self.assigned_to
    @property
    def activity_notify(self):
        return [feed_manager.get_notification_feed(self.assigned_to.id),]

If my view grabs the user feed:

enricher = Enrich()
feed = feed_manager.get_user_feed(request.user.id)
# feed = feed_manager.get_notification_feed(request.user.id)
activities = feed.get(limit=25)['results']
enriched_activities = enricher.enrich_activities(activities)

My output works as expected, and each of these gets populated with the proper data in my template:

Actor: {{ activity.actor }}<br>
Title: {{ activity.title }}<br>
Time: {{ activity.time|timesince }}<br>

However, if I switch to the notification feed (note the change in commenting out of lines):

enricher = Enrich()
# feed = feed_manager.get_user_feed(request.user.id)
feed = feed_manager.get_notification_feed(request.user.id)
activities = feed.get(limit=25)['results']
enriched_activities = enricher.enrich_activities(activities)

Then, the only field I can get data from is activity.created_at.

The output of activity.keys shows the following:

[u'activities', u'group', u'activity_count', u'created_at', u'updated_at', u'actor_count', u'verb', u'is_seen', u'id', u'is_read']

It seems like perhaps for the notification feed, the actor and object are NOT being reported back to GetStream:

enter image description here

But, it is for the user feed:

enter image description here

I am stumped as to why. What am I missing?

Adam Hopkins
  • 6,837
  • 6
  • 32
  • 52

1 Answers1

6

Okay ... so I figured out my mistake. I was operating under the assumption all along that the notification_feed was a flat feed. Whoops, by bad. It is actually aggregated. Therefore, I was able to make fixes as follows:

Instead of:

activities = enricher.enrich_activities(activities)

I used:

enriched_activities = enricher.enrich_aggregated_activities(activities)

Then, in my base template:

{% for enriched_activity in enriched_activities %}
    {% render_activity enriched_activity %}
{% endfor %}

Which looks in /activity/aggregated/task.html

{% for activity in enriched_activity.activities %}
    {% render_activity activity %}
{% endfor %}

And finally inside /activity/task.html I see the output as expected from these items.

Actor: {{ activity.actor.first_name }}<br>
Title: {{ activity.object.title }}<br>
Time: {{ activity.time|timesince }}<br>
Adam Hopkins
  • 6,837
  • 6
  • 32
  • 52