PhoenixKitUserConnections (PhoenixKitUserConnections v0.1.2)

Copy Markdown View Source

User connections module — social relationships system.

Provides a complete social relationships system with two types of relationships:

  1. Follows - One-way relationships (User A follows User B, no consent needed)
  2. Connections - Two-way mutual relationships (both users must accept)

Plus blocking functionality to prevent unwanted interactions.

Usage Examples

In a User Profile Page

# Get relationship for rendering follow/connect buttons
relationship = PhoenixKitUserConnections.get_relationship(current_user, profile_user)

# Display counts
followers = PhoenixKitUserConnections.followers_count(profile_user)
following = PhoenixKitUserConnections.following_count(profile_user)
connections = PhoenixKitUserConnections.connections_count(profile_user)

Business Rules

Following

  • Cannot follow yourself
  • Cannot follow if blocked (either direction)
  • Instant, no approval needed

Connections

  • Cannot connect with yourself
  • Cannot connect if blocked
  • Requires acceptance from recipient
  • If A requests B while B has pending request to A → auto-accept both

Blocking

  • Blocking removes any existing follow/connection between the users
  • Blocked user cannot follow, connect, or view profile
  • Blocking is one-way (A blocks B doesn't mean B blocks A)

Summary

Functions

Accepts a pending connection request.

Blocks a user. Blocking removes any existing follows and connections.

Checks if user A has blocked user B.

Checks if user is blocked by other user.

Returns the count of users blocked by a user.

Checks if two users can interact (neither has blocked the other).

Cancels a pending outgoing connection request.

Checks if two users are connected (mutual connection exists).

Returns the count of connections for a user.

Creates a follow relationship.

Returns the count of followers for a user.

Checks if user A is following user B.

Returns the count of users that a user is following.

Gets the full relationship status between two users in one call.

Returns statistics for the admin overview page.

Returns all users blocked by a user.

Returns all connections for a user.

Returns all followers of a user.

Returns all users that a user is following.

Returns pending incoming connection requests for a user.

Returns pending outgoing connection requests sent by a user.

Returns the count of pending incoming connection requests for a user.

Rejects a pending connection request.

Removes an existing connection between two users.

Sends a connection request from requester to recipient.

Removes a block.

Removes a follow relationship.

Functions

accept_connection(connection)

Accepts a pending connection request.

block(blocker, blocked, reason \\ nil)

Blocks a user. Blocking removes any existing follows and connections.

blocked?(blocker, blocked)

Checks if user A has blocked user B.

blocked_by?(user, other)

Checks if user is blocked by other user.

blocked_count(user)

Returns the count of users blocked by a user.

can_interact?(user_a, user_b)

Checks if two users can interact (neither has blocked the other).

cancel_request(requester, connection_uuid)

Cancels a pending outgoing connection request.

connected?(user_a, user_b)

Checks if two users are connected (mutual connection exists).

connections_count(user)

Returns the count of connections for a user.

follow(follower, followed)

Creates a follow relationship.

User A follows User B. No consent is required from User B.

followers_count(user)

Returns the count of followers for a user.

following?(follower, followed)

Checks if user A is following user B.

following_count(user)

Returns the count of users that a user is following.

get_relationship(user_a, user_b)

Gets the full relationship status between two users in one call.

get_stats()

Returns statistics for the admin overview page.

list_blocked(user, opts \\ [])

Returns all users blocked by a user.

list_connections(user, opts \\ [])

Returns all connections for a user.

list_followers(user, opts \\ [])

Returns all followers of a user.

list_following(user, opts \\ [])

Returns all users that a user is following.

list_pending_requests(user, opts \\ [])

Returns pending incoming connection requests for a user.

list_sent_requests(user, opts \\ [])

Returns pending outgoing connection requests sent by a user.

pending_requests_count(user)

Returns the count of pending incoming connection requests for a user.

reject_connection(connection)

Rejects a pending connection request.

remove_connection(user_a, user_b)

Removes an existing connection between two users.

request_connection(requester, recipient)

Sends a connection request from requester to recipient.

If recipient already has a pending request to requester, both requests are automatically accepted.

unblock(blocker, blocked)

Removes a block.

unfollow(follower, followed)

Removes a follow relationship.