From: Chris Fulljames
Date: Mon, 27 Jan 2025 01:13:11 +0000 (-0500)
Subject: Working on activity log - incomplete
X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3698eec858669e0b6aaa8fe4adc7ffe79253f95;p=littlesongplace.git
Working on activity log - incomplete
---
diff --git a/main.py b/main.py
index 19035ef..a56db5f 100644
--- a/main.py
+++ b/main.py
@@ -552,6 +552,69 @@ def comment_delete(commentid):
return redirect(request.referrer)
+@app.get("/activity")
+def activity():
+ if not "userid" in session:
+ return redirect("/login")
+
+ # For all:
+ # - Comment content
+ # - Comment created time
+ # - Commenter username
+ # - Song name
+ # - Song username
+
+ # For replies:
+ # - Parent username
+ # - Parent comment
+
+ # Get comments on user's songs
+ comments_on_songs = query_db(
+ """\
+ select c.content, c.created, cu.username as comment_username, s.title, su.username as song_username
+ from song_comments as c
+ inner join songs as s on c.songid == s.songid
+ inner join users as su on su.userid == s.userid
+ inner join users as cu on cu.userid == c.userid
+ where s.userid = ?""",
+ [session["userid"]])
+
+ # Get replies to user's comments
+ replies_to_user = query_db(
+ """\
+ select c.content, c.created, cu.username as comment_username, s.title, su.username as song_username, pu.username as parent_username, p.content as parent_content
+ from song_comments as c
+ inner join songs as s on c.songid == s.songid
+ inner join users as su on su.userid == s.userid
+ inner join users as cu on cu.userid == c.userid
+ inner join song_comments as p on c.replytoid == p.commentid
+ inner join users as pu on pu.userid == p.userid
+ where p.userid == ?""",
+ [session["userid"]])
+
+ # Get comments user has replied to
+ comments_user_replied_to = query_db(
+ "select * from song_comments where (replytoid is not null) and (userid == ?)",
+ [session["userid"]])
+
+
+ # Get replies to comments user has also replied to
+ # TODO:
+ # replies_to_user = query_db(
+ # """\
+ # select c.content, c.created, cu.username as comment_username, s.title, su.username as song_username, pu.username as parent_username, p.content as parent_content
+ # from song_comments as c
+ # inner join songs as s on c.songid == s.songid
+ # inner join users as su on su.userid == s.userid
+ # inner join users as cu on cu.userid == c.userid
+ # inner join song_comments as p on c.replytoid == p.commentid
+ # inner join users as pu on pu.userid == p.userid
+ # where p.userid == ?""",
+ # [session["userid"]])
+
+ # Filter duplicates
+ return [dict(c) for c in comments_on_songs] + [dict(c) for c in replies_to_user]
+
@app.get("/site-news")
def site_news():
return render_template("news.html")
diff --git a/schema.sql b/schema.sql
index be54410..d637cd8 100644
--- a/schema.sql
+++ b/schema.sql
@@ -17,6 +17,7 @@ CREATE TABLE songs (
description TEXT,
FOREIGN KEY(userid) REFERENCES users(userid)
);
+CREATE INDEX idx_songs_by_user ON songs(userid);
DROP TABLE IF EXISTS song_collaborators;
CREATE TABLE song_collaborators (
@@ -47,4 +48,5 @@ CREATE TABLE song_comments (
FOREIGN KEY(userid) REFERENCES users(userid)
);
CREATE INDEX idx_comments_by_song ON song_comments(songid);
+CREATE INDEX idx_comments_by_user ON song_comments(userid);
diff --git a/static/styles.css b/static/styles.css
index 2864952..ba1a70e 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -46,7 +46,7 @@ input[type=text], input[type=password] {
background: var(--yellow);
font-family: sans-serif;
font-weight: bold;
- color: var(--purple);
+ color: var(--black);
border: 3px solid var(--purple);
border-radius: 10px;
padding: 5px;
diff --git a/templates/base.html b/templates/base.html
index 0c718a3..04bce6e 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -21,6 +21,7 @@
News
{% if "username" in session %}
My Profile
+ Activity
Sign Out
{% else %}
Create Account
diff --git a/templates/comment.html b/templates/comment.html
index ed020c1..e005d72 100644
--- a/templates/comment.html
+++ b/templates/comment.html
@@ -10,12 +10,11 @@
Commenting on {{ song.title }} by {{ song.username }}
-{% if comment %}
+{% if replyto %}
-In reply to:
-{{ comment['username'] }}
-
-{{ comment['content'] }}
+In reply to
+{{ replyto['username'] }}:
+{{ replyto['content'] }}
{% endif %}
diff --git a/templates/song-list.html b/templates/song-list.html
index 206bbf8..062495e 100644
--- a/templates/song-list.html
+++ b/templates/song-list.html
@@ -71,7 +71,7 @@
{% for comment in song.get_comments() %}