Search code examples
activity-streamsgetstream-io

can getstream aggregation work on properties of the "object" property


I set up the aggregation rule:

{{ object.experienceId }}

on a notification feed in getstream.io expecting it to aggregate based on the object.experienceId, but instead it seems to aggregate everything into one, regardless of object.experienceId. Am I mis-understanding how aggregation works? What could be the issue?

    var activity = {
        time: new Date(),
        verb: 'created',
        actor: { id: 1, name: 'User One' },
        object: {
            id: 2,
            experienceId: 12,
            caption: 'Moment 1',
            photo:
            { id: '314e00a2-2455-11e5-b696-feff819cdc9f',
                mainColor: 'ff3333',
                width: 1000,
                height: 400 },
            createdBy: {
                id: 1, name: 'User One'
            },
            type: 'Moment' },
        context: 'http://derbyapp.co'
    };


    notifications.addActivity(activity,

Solution

  • The reason why this is not working is because the object field is expected to be a string (http://getstream.io/docs/#add-remove-activities), thus within the aggregation rule you can not reference properties of activities object field. There are multiple solutions to this problem.

    First you could supply the experienceId as a separate property of the activity object, so you can use the aggregation template {{ experienceId }}, since all the additional properties provided to an activity can be used in the aggregation rule (http://getstream.io/docs/#aggregated-feeds).

    Second you could supply an object on any additional field of the activity, for instance item. Additional fields can reference their child properties thus you could use aggregation rule {{ item.experienceId }}. But beware not to send data to the getstream.io API that is not actually needed at getstream.io's end, in this example you could also send the object's id field, instead of the entire object, and retrieve the object from your local database once you retrieve activities from the API (The same holds for the actor field). If you do not want to take care of the logic needed for this you could use one of getstream's integration libraries (there are libraries for rails/django/laravel etc.).

    var activity = {
      time: new Date(),
      verb: 'created',
      actor: 1,
      object: '1',
      experienceId: 12
    };