Guides

Profile Operations

Query the state of different profile based operations.

The Profile type contains a operations field which includes the state of different operations that can be performed on a profile based on the currently authenticated profile.

For example:

  • lens/jane views lens/john's profile in any app that is integrated with Lens Protocol
  • to get the data for lens/john's profile, the app will call a method that returns a Profile type
  • the Profile type will contain a operations field which will contain the state of different operations that can be performed on lens/john's profile based on the currently authenticated profile (lens/jane)
  • the app can use this data to determine how to display different elements of it's UI to lens/jane (e.g. using the Profile.operations.isFollowedByMe field, the app can make a decision on how to render the follow/unfollow button)

The operation fields are available on all methods that contain Profile types in their response but here we will explore this in detail.

Invocation

The operations field is available on all methods that return a Profile type. For example, profile methods like profile.fetch, profile.fetchAll etc. and publication methods like publication.fetch, publication.fetchAll etc. where the profile is included in the response.

const { operations } = await lensClient.profile.fetch({
  profileId: "PROFILE_ID",
})
query Profile {
  profile(request: { profileId: "PROFILE_ID" }) {
    # other profile fields are available
    operations {
      # ...ProfileOperations
    }
  }
}

Response

{
  // ...other profile fields are available
  "operations": {
    "isFollowedByMe": {
      "value": true,
      "isFinalisedOnchain": true
    },
    "isBlockedByMe": {
      "value": true,
      "isFinalisedOnchain": true
    },
    "isFollowingMe": {
      "value": true,
      "isFinalisedOnchain": true
    },
    "canFollow": "YES", // YES | NO | UNKNOWN
    "canUnfollow": false,
    "canBlock": true,
    "canUnblock": false
  }
}