From afde00cd5d7f9eec506b3da38a8feeb8976f9769 Mon Sep 17 00:00:00 2001
From: jsalyers <jsalyers@syncad.com>
Date: Thu, 4 Jun 2020 18:17:36 -0400
Subject: [PATCH] [JES] New method to determine the relationship between 2
 accounts

---
 hive/server/bridge_api/methods.py | 36 +++++++++++++++++++++++++++++++
 hive/server/serve.py              |  1 +
 2 files changed, 37 insertions(+)

diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py
index 8949875a9..de78443b9 100644
--- a/hive/server/bridge_api/methods.py
+++ b/hive/server/bridge_api/methods.py
@@ -292,3 +292,39 @@ async def get_account_posts(context, sort, account, start_author='', start_perml
         post = await append_statistics_to_post(post, row, False, observer, context, blacklists_for_user)
         posts.append(post)
     return posts
+
+@return_error_info
+async def get_relationship_between_accounts(context, account1, account2, observer=None):
+    valid_account(account1)
+    valid_account(account2)
+
+    db = context['db']
+
+    sql = """
+        SELECT state, blacklisted, follows_blacklists FROM hive_follows WHERE
+        follower = (SELECT id FROM hive_accounts WHERE name = :account1) AND 
+        following = (SELECT id FROM hive_accounts WHERE name = :account2)
+    """
+
+    sql_result = db.query_all(sql, account1=account1, account2=account2)
+
+    result = {
+        'follows': False,
+        'ignores': False,
+        'blacklisted': False,
+        'follows_blacklists': False
+    }
+
+    for row in sql_result:
+        state = row['state']
+        if state == 1:
+            result['follows'] = True
+        elif state == 2:
+            result['ignores'] = True
+        
+        if row['blacklisted']:
+            result['blacklisted'] = True
+        if row['follows_blacklists']:
+            result['follows_blacklists'] = True
+
+    return result
\ No newline at end of file
diff --git a/hive/server/serve.py b/hive/server/serve.py
index a43c8e8da..c83053f74 100644
--- a/hive/server/serve.py
+++ b/hive/server/serve.py
@@ -122,6 +122,7 @@ def build_methods():
         bridge_api.get_ranked_posts,
         bridge_api.get_profile,
         bridge_api.get_trending_topics,
+        bridge_api.get_relationship_between_accounts,
         hive_api_notify.post_notifications,
         hive_api_notify.account_notifications,
         hive_api_notify.unread_notifications,
-- 
GitLab