References

When you add a user or a collection object to an activity, Stream stores the unique reference and replaces it at read time. In some complex cases, you need to be able to generate a reference to an existing object and embed that inside of an activity.

// First create a collection entry with upsert api
let cheeseBurger = Food(name: "Cheese Burger", rating: 4, id: "cheese-burger")

client.add(collectionObject: cheeseBurger) { _ in
  // Then create a user
  let user = User(id: "john-doe")
  client.create(user: user) { _ in
    // Since we know their IDs we can create references to both without reading from APIs
    // The `CollectionObjectProtocol` and `UserProtocol` conformed to the `Enrichable` protocol.
    let cheeseBurgerRef = cheeseBurger.referenceId
    let johnDoeRef = user.referenceId

    client.flatFeed(feedSlug: "user", userId: "john")
       .add(Activity(actor: johnDoeRef, verb: "eat", object: cheeseBurgerRef)) { result in /* ... */ }
  }
}

If you are using the APIs on web / mobile (see auth section) you must set activity.actor to the reference of the current user or otherwise you will get a permission error (see examples above).

© Getstream.io, Inc. All Rights Reserved.