Skip to content

Commit

Permalink
feat: added field to know if a profile follows the Hasura user
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Feb 5, 2024
1 parent 63a3357 commit ff8e74d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions database/schema/13-profile-functions.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Function that allows to check if the current Hasura user is followed by the given profile.
*/
CREATE OR REPLACE FUNCTION is_user_followed_by_profile(profile_row profile, hasura_session json)
RETURNS BOOLEAN AS
$$
SELECT EXISTS (SELECT 1
FROM user_relationship
WHERE user_relationship.subspace_id =
CAST(COALESCE(hasura_session ->> 'x-hasura-selected-subspace-id', '0') AS BIGINT)
AND user_relationship.creator_address = profile_row.address
AND user_relationship.counterparty_address = hasura_session ->> 'x-hasura-user-address')
$$ LANGUAGE sql STABLE;

/**
* Function that allows to check if the current Hasura user is following a given profile.
*/
Expand Down
8 changes: 8 additions & 0 deletions hasura/metadata/databases/djuno/tables/public_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ computed_fields:
session_argument: hasura_session
table_argument: profile_row
comment: Computed field that tells whether the given profile has blocked the current Hasura user
- name: is_user_followed_by
definition:
function:
schema: public
name: is_user_followed_by_profile
session_argument: hasura_session
table_argument: profile_row
comment: A computed field that tells whether the given Hasura user is followed by this profile
- name: is_user_following
definition:
function:
Expand Down

0 comments on commit ff8e74d

Please sign in to comment.