Bubble [main]

Filter likes and reactions based on muted users

=> 4c6157d0573e37643a466d63f7f43530c2f81a0e

diff --git a/feeds.py b/feeds.py
index 7db831c..6950efe 100644
--- a/feeds.py
+++ b/feeds.py
@@ -329,10 +329,10 @@ def make_post_page(session, post):
         if session.is_likes_enabled():
             liked = []
             if post.num_likes:
-                liked = db.get_likes(post)
+                liked = db.get_likes(post, session.user_mutes)
                 page += ' ยท ๐Ÿ‘ ' + ', '.join(liked)
         if session.is_reactions_enabled():
-            reactions = db.get_reactions(post)
+            reactions = db.get_reactions(post, session.user_mutes)
             listed = []
             for r in reactions:
                 listed.append(f'{reactions[r]} {r}')
diff --git a/model.py b/model.py
index e4aeada..09e9816 100644
--- a/model.py
+++ b/model.py
@@ -1912,13 +1912,15 @@ class Database:
                         (Notification.REACTION, user.id, post.user, post.id))
         self.commit()
 
-    def get_reactions(self, post) -> dict:
+    def get_reactions(self, post, user_mutes=set()) -> dict:
         """Returns a dictionary of {reactions: count}."""
 
         cur = self.conn.cursor()
-        cur.execute("SELECT reaction FROM reactions WHERE post=?", (post.id,))
+        cur.execute("SELECT reaction, user FROM reactions WHERE post=?", (post.id,))
         counts = {}
-        for (r,) in cur:
+        for (r, user_id) in cur:
+            if (MUTE_USER, user_id) in user_mutes:
+                continue
             if r not in counts:
                 counts[r] = 1
             else:
@@ -1931,17 +1933,18 @@ class Database:
         for (r,) in cur: return r
         return None
 
-    def get_likes(self, post):
+    def get_likes(self, post, user_mutes=set()):
         cur = self.conn.cursor()
         cur.execute("""
-            SELECT u.name
+            SELECT u.name, u.id
             FROM likes
                 JOIN users u ON likes.user=u.id
             WHERE likes.post=?
             """, (post.id,))
         users = []
-        for (name,) in cur:
-            users.append(name)
+        for (name, liker_id) in cur:
+            if not (MUTE_USER, liker_id) in user_mutes:
+                users.append(name)
         return users
 
     def get_tags(self, post):
Proxy Information
Original URL
gemini://git.skyjake.fi/bubble/main/cdiff/4c6157d0573e37643a466d63f7f43530c2f81a0e
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
28.339691 milliseconds
Gemini-to-HTML Time
0.439045 milliseconds

This content has been proxied by September (ba2dc).