From 2019d65d2559ca5cb23c0ae243597af48298cf37 Mon Sep 17 00:00:00 2001
From: jsalyers <jsalyers@syncad.com>
Date: Wed, 11 Nov 2020 19:09:59 -0500
Subject: [PATCH] [JES] More updates to muting. Adding is_muted to the raw
 posts returned from the database to make it easier to determine which posts
 were muted by mods/admins

---
 .../bridge_get_account_posts_by_blog.sql      |  3 +-
 .../bridge_get_account_posts_by_comments.sql  |  3 +-
 .../bridge_get_account_posts_by_payout.sql    |  3 +-
 .../bridge_get_account_posts_by_posts.sql     |  3 +-
 .../bridge_get_account_posts_by_replies.sql   |  3 +-
 hive/db/sql_scripts/bridge_get_post.sql       |  3 +-
 .../bridge_get_ranked_post_for_all.sql        | 21 ++++++++----
 ...bridge_get_ranked_post_for_communities.sql | 24 +++++++++-----
 ...t_ranked_post_for_observer_communities.sql | 21 ++++++++----
 .../bridge_get_ranked_post_for_tag.sql        | 21 ++++++++----
 .../bridge_get_ranked_post_type.sql           |  3 +-
 .../condenser_get_by_account_comments.sql     |  3 +-
 hive/db/sql_scripts/condenser_get_by_blog.sql |  3 +-
 .../condenser_get_by_blog_without_reblog.sql  |  3 +-
 .../condenser_get_by_replies_to_account.sql   |  3 +-
 .../condenser_get_discussions_by_comments.sql |  3 +-
 hive/server/bridge_api/objects.py             | 33 +++++++++----------
 17 files changed, 97 insertions(+), 59 deletions(-)

diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql
index a4765fba5..def7c62c8 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql
@@ -58,7 +58,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     JOIN
     (
diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
index bd02c7732..f701d0fbd 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql
@@ -46,7 +46,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
     SELECT hp1.id
diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql
index 042e99367..5b54be03b 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql
@@ -50,7 +50,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
   WHERE
diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql
index 500463658..8993c684b 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql
@@ -46,7 +46,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
   WHERE
diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql
index 74a17016a..671c52651 100644
--- a/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql
+++ b/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql
@@ -46,7 +46,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
diff --git a/hive/db/sql_scripts/bridge_get_post.sql b/hive/db/sql_scripts/bridge_get_post.sql
index 7dab4549b..16b46f633 100644
--- a/hive/db/sql_scripts/bridge_get_post.sql
+++ b/hive/db/sql_scripts/bridge_get_post.sql
@@ -44,7 +44,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
   WHERE
diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
index 39585907e..3683f7135 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
@@ -43,7 +43,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -110,7 +111,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -179,7 +181,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -249,7 +252,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -320,7 +324,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -390,7 +395,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -459,7 +465,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql
index 147377f89..8ba240e61 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql
@@ -39,7 +39,8 @@ $function$
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_communities hc ON hc.id = hp.community_id
@@ -98,7 +99,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -169,7 +171,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -241,7 +244,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -311,7 +315,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -381,7 +386,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -452,7 +458,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -518,7 +525,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql
index 7e836ba76..3290228ae 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql
@@ -45,7 +45,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
@@ -109,7 +110,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
@@ -173,7 +175,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -248,7 +251,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
@@ -312,7 +316,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
@@ -377,7 +382,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -451,7 +457,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
       hive_posts_view hp
       JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
index bb8b49d34..ddbea0528 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
@@ -45,7 +45,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -117,7 +118,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -189,7 +191,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -262,7 +265,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -335,7 +339,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -407,7 +412,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
@@ -479,7 +485,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
   FROM
   (
       SELECT
diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_type.sql b/hive/db/sql_scripts/bridge_get_ranked_post_type.sql
index e486bf70c..af5aab718 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_type.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_type.sql
@@ -35,7 +35,8 @@ CREATE TYPE bridge_api_post AS (
     community_title VARCHAR,
     role_id SMALLINT,
     is_pinned BOOLEAN,
-    curator_payout_value VARCHAR
+    curator_payout_value VARCHAR,
+    is_muted BOOLEAN
 );
 
 DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE;
diff --git a/hive/db/sql_scripts/condenser_get_by_account_comments.sql b/hive/db/sql_scripts/condenser_get_by_account_comments.sql
index 572fca3c9..62687cdf3 100644
--- a/hive/db/sql_scripts/condenser_get_by_account_comments.sql
+++ b/hive/db/sql_scripts/condenser_get_by_account_comments.sql
@@ -52,7 +52,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     WHERE ( hp.author = _author ) AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) ) AND hp.depth > 0
     ORDER BY hp.id DESC
diff --git a/hive/db/sql_scripts/condenser_get_by_blog.sql b/hive/db/sql_scripts/condenser_get_by_blog.sql
index f3139ed7b..719badc99 100644
--- a/hive/db/sql_scripts/condenser_get_by_blog.sql
+++ b/hive/db/sql_scripts/condenser_get_by_blog.sql
@@ -62,7 +62,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     JOIN hive_feed_cache hfc ON hp.id = hfc.post_id
     WHERE hfc.account_id = __account_id AND ( ( __post_id = 0 ) OR ( hfc.created_at <= __created_at ) )
diff --git a/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql b/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql
index c952296f2..588272fcb 100644
--- a/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql
+++ b/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql
@@ -52,7 +52,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     WHERE ( hp.author = _author ) AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) ) AND hp.depth = 0
     ORDER BY hp.id DESC
diff --git a/hive/db/sql_scripts/condenser_get_by_replies_to_account.sql b/hive/db/sql_scripts/condenser_get_by_replies_to_account.sql
index a18cd7e97..690723687 100644
--- a/hive/db/sql_scripts/condenser_get_by_replies_to_account.sql
+++ b/hive/db/sql_scripts/condenser_get_by_replies_to_account.sql
@@ -62,7 +62,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     JOIN
     (
diff --git a/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql b/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql
index 2da2db5b8..cc8ea3c82 100644
--- a/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql
+++ b/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql
@@ -52,7 +52,8 @@ BEGIN
       hp.community_title,
       hp.role_id,
       hp.is_pinned,
-      hp.curator_payout_value
+      hp.curator_payout_value,
+      hp.is_muted
     FROM hive_posts_view hp
     WHERE
         hp.author = _author AND hp.depth > 0 AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) )
diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py
index 5c6fa3d1d..f624947c1 100644
--- a/hive/server/bridge_api/objects.py
+++ b/hive/server/bridge_api/objects.py
@@ -15,21 +15,19 @@ log = logging.getLogger(__name__)
 
 # pylint: disable=too-many-lines
 
-def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=None, override_gray=False):
+def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=[], override_gray=False):
     """ apply information such as blacklists and community names/roles to a given post """
-    if not blacklists_for_user:
-        post['blacklists'] = Mutes.lists(row['author'], row['author_rep'])
-    else:
-        post['blacklists'] = []
-        if row['author'] in blacklists_for_user:
-            blacklists = blacklists_for_user[row['author']]
-            for blacklist in blacklists:
-                post['blacklists'].append(blacklist)
-        reputation = row['author_rep']
-        if reputation < 1:
-            post['blacklists'].append('reputation-0')
-        elif reputation  == 1:
-            post['blacklists'].append('reputation-1')
+    
+    post['blacklists'] = []
+    if row['author'] in blacklists_for_user:
+        blacklists = blacklists_for_user[row['author']]
+        for blacklist in blacklists:
+            post['blacklists'].append(blacklist)
+    reputation = row['author_rep']
+    if reputation < 1:
+        post['blacklists'].append('reputation-0')
+    elif reputation  == 1:
+        post['blacklists'].append('reputation-1')
 
     if 'community_title' in row and row['community_title']:
         post['community'] = row['category']
@@ -40,11 +38,10 @@ def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=None, ov
         else:
             post['author_role'] = 'guest'
             post['author_title'] = ''
-    elif override_gray:
-        post['stats']['gray'] = ('irredeemables' in post['blacklists'] or len(post['blacklists']) >= 2)
-    else:
-        post['stats']['gray'] = row['is_grayed']
 
+    post['stats']['gray'] = row['is_grayed']
+    if 'is_muted' in row and row['is_muted']:
+        post['stats']['gray'] = True
     post['stats']['hide'] = 'irredeemables' in post['blacklists']
       # it overrides 'is_hidden' flag from post, is that the intent?
     if is_pinned:
-- 
GitLab