Enrichment

Enrichment of Collection Entries

Objects stored inside collections can be embedded inside activities or user objects. This allows you to integrate with Stream without building a complex integration with another database. Stream’s collections can be used as your data source for data enrichment.

// first we add our object to the food collection
let cheeseBurger = Food(name: "Cheese Burger", rating: 4, id: "cheese-burger")

// setup an enriched activity type
typealias UserFoodActivity = EnrichedActivity<user, food,="" string="">

client.add(collectionObject: cheeseBurger) { _ in
  // the object returned by .add can be embedded directly inside of an activity
  userFeed.add(UserFoodActivity(actor: client.currentUser!, verb: 'grill', object: cheeseBurger)) { _ in
    // if we now read the feed, the activity we just added will include the entire full object
    userFeed.get(typeOf: UserFoodActivity.self) { result in
      let activities = try! result.get().results
      
      // we can then update the object and Stream will propagate the change to all activities
      cheeseBurger.name = "Amazing Cheese Burger"
      client.update(collectionObject: cheeseBurger) { result in /* ... */ }
    }
  }
}</user,>
© Getstream.io, Inc. All Rights Reserved.