From 48c21cc0dd3e89e2c9ec8815022f0909eeaa6bb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Thu, 25 May 2023 09:22:40 +0300
Subject: [PATCH 1/1] Fixed search with user matches; check user's enabled
notification types
IssueID #70
model.py | 45 ++++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/model.py b/model.py
index 10caab6..447af76 100644
--- a/model.py
+++ b/model.py
@@ -1074,12 +1074,12 @@ class Database:
# Notify about the new published post (but not a comment).
user = self.get_user(id=post.user)
if not post.parent:
self.notify_followers(user, post.id,
Notification.POST_BY_FOLLOWED_USER,
FOLLOW_USER, user.id)
self.notify_followers(user, post.id,
Notification.POST_IN_FOLLOWED_SUBSPACE,
FOLLOW_SUBSPACE, post.subspace)
self.notify_followers(user, post.id,
Notification.POST_BY_FOLLOWED_USER,
FOLLOW_USER, user.id)
else:
cur.execute(Database.NUM_CMTS_QUERY, (post.parent, post.parent))
self.notify_commenters(post)
@@ -1621,6 +1621,20 @@ class Database:
target_id))
self.commit()
if follow_type == FOLLOW_SUBSPACE:
pass
# cur.execute(f"""
# DELETE FROM notifs
# WHERE (type & ?) AND src=? AND post=? AND is_hidden=FALSE AND dst IN (
# SELECT user
# FROM follow
# WHERE type={FOLLOW_SUBSPACE} AND target=(
# SELECT subspace FROM posts WHERE id={post_id}
# )
# )
# """, (Notification.COMMENT_ON_COMMENTED |
# Notification.COMMENT))
def notify_new_poll(self, post: Post):
cur = self.conn.cursor()
cur.execute(f"""
@@ -1634,7 +1648,8 @@ class Database:
def count_notifications(self, user):
cur = self.conn.cursor()
cur.execute("SELECT COUNT(id) FROM notifs WHERE is_hidden=FALSE AND dst=?", (user.id,))
cur.execute("SELECT COUNT(id) FROM notifs "
"WHERE is_hidden=FALSE AND dst=? AND (type & ?)!=0", (user.id, user.notif))
for (count,) in cur:
return count
return 0
@@ -1699,7 +1714,8 @@ class Database:
# Notify post author and followers of the closing.
if add and was_changed and tag == Post.TAG_CLOSED and actor:
if post.user != actor.id:
cur.execute("INSERT IGNORE INTO notifs (type, dst, src, post) VALUES (?, ?, ?, ?)",
cur.execute("INSERT IGNORE INTO notifs (type, dst, src, post) "
"VALUES (?, ?, ?, ?)",
(Notification.ISSUE_CLOSED, post.user, actor.id, post.id))
self.notify_followers(actor, post.id, Notification.ISSUE_CLOSED, FOLLOW_POST, post.id)
@@ -1735,8 +1751,8 @@ class Database:
def get_notifications(self, user, id=None, post_id=None, include_hidden=False, clear=False,
sort_desc=False) -> list:
cond = ['dst=?']
values = [user.id]
cond = ['dst=?', '(n.type & ?)!=0']
values = [user.id, user.notif]
if id != None:
cond.append('n.id=?')
values.append(id)
@@ -1764,13 +1780,16 @@ class Database:
notifs.append(Notification(id, type, dst, src, post, subspace, is_sent, ts,
src_name, post_title, post_issueid, post_summary,
post_subname, post_subowner, subname))
if clear and notifs:
cur.execute(f"UPDATE notifs SET is_hidden=TRUE WHERE id IN ({','.join(map(lambda n: str(n.id), notifs))})", list())
# Delete archived notifications after a week.
if clear:
if notifs:
cur.execute(f"UPDATE notifs SET is_hidden=TRUE WHERE id IN ({','.join(map(lambda n: str(n.id), notifs))})", list())
# Delete archived notifications after a week, and disabled notifications immediately.
cur.execute("""
DELETE FROM notifs
WHERE is_hidden=TRUE AND TIMESTAMPDIFF(DAY, ts, CURRENT_TIMESTAMP())>=7
""")
WHERE
(is_hidden=TRUE AND TIMESTAMPDIFF(DAY, ts, CURRENT_TIMESTAMP())>=7)
OR (dst=? AND (type & ?)=0)
""", (user.id, user.notif))
self.commit()
return notifs
@@ -1943,7 +1962,7 @@ class Search:
for (ts, id, name, avatar, info, url) in cur:
self.results.append(((exact_match(name), ts),
User(id, name, info, url, avatar, None, None, None,
None, None, None, None, ts, None, None)))
None, None, None, None, None, ts, None, None, None)))
# Subspaces.
cur.execute(f"""
--
2.25.1
text/plain
This content has been proxied by September (3851b).