Module: X::Resources::Relationships
- Included in:
- User
- Defined in:
- x-resources/lib/x/resources/relationships.rb
Overview
The relationships of a user with other users, read as the authenticated user sees them
It reads them and changes none: a relationship changes as the authenticated user alone, so the client changes it, as in client.follow(user), rather than a user, which may be anyone.
Internal to x-resources: the methods it gives a user, such as follows?, are public API, but the module is only how they are shared, and which classes extend or include it can change within 1.x.
Instance Method Summary collapse
-
#follows?(user, max_pages: nil) ⇒ Boolean
Check whether this user follows a user.
Instance Method Details
#follows?(user, max_pages: nil) ⇒ Boolean
Check whether this user follows a user
When either user is the authenticated user, one lookup of the other's connection_status answers. Otherwise the users this user follows are scanned until one matches, up to 1,000 a page, and the API bills every user returned, so checking an account that follows thousands can cost dollars, and max_pages limits the pages the scan reads, raising PageLimitReached rather than read past them. A client that authenticates as the app alone has no authenticated user, which the API refuses to look up, so it scans. Any other failure to look the authenticated user up raises, rather than scan every user this one follows.
38 39 40 41 42 43 44 45 |
# File 'x-resources/lib/x/resources/relationships.rb', line 38 def follows?(user, max_pages: nil) target, max_pages = User.from_id(user), PageLimit.check!(max_pages) case authenticated_user_id when id then connection_status_of(target).include?("following") when target.id then connection_status_of(self).include?("followed_by") else PageLimit.scan(following.stubs, target, what: "User#follows?", max_pages:) end end |