]> littlesong.place Git - littlesongplace.git/commitdiff
Working on activity log - incomplete
authorChris Fulljames <christianfulljames@gmail.com>
Mon, 27 Jan 2025 01:13:11 +0000 (20:13 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Mon, 27 Jan 2025 01:13:11 +0000 (20:13 -0500)
main.py
schema.sql
static/styles.css
templates/base.html
templates/comment.html
templates/song-list.html

diff --git a/main.py b/main.py
index 19035eff4a246857bd4d0186176c3652cdbec73e..a56db5feac9e07a92c9650d5b0d8d694da78ef31 100644 (file)
--- 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")
index be54410511996f9b2e71087f9fb954664a62f630..d637cd8368fa7386be7ecfd32185b6fb9bef7b41 100644 (file)
@@ -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);
 
index 286495239c66bf0364e2fb99c92d006c2e8da9d5..ba1a70ebf45421c13143fe1b48e71e4967615887 100644 (file)
@@ -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;
index 0c718a3adea959f009898162f208257324f4446a..04bce6e46e4a375fe4210e468958182cfa1a12db 100644 (file)
@@ -21,6 +21,7 @@
                 <a href="/site-news">News</a>
                 {% if "username" in session %}
                     <a href="/users/{{ session["username"] }}">My Profile</a>
+                    <a href="/activity">Activity</a>
                     <a href="/logout">Sign Out</a>
                 {% else %}
                     <a href="/signup">Create Account</a>
index ed020c12f7dd200899d47e33ade34073519d0bdc..e005d727db6c5ef124bdf5944dff7b9bf99c494f 100644 (file)
 Commenting on {{ song.title }} by <a href="/users/{{ song.username }}" class="profile-link">{{ song.username }}</a>
 </p>
 
-{% if comment %}
+{% if replyto %}
 <p>
-In reply to:
-<a href="/users/{{ comment['username'] }}" class="profile-link">{{ comment['username'] }}</a>
-<br>
-{{ comment['content'] }}
+In reply to
+<a href="/users/{{ replyto['username'] }}" class="profile-link">{{ replyto['username'] }}</a>:
+{{ replyto['content'] }}
 </p>
 {% endif %}
 
index 206bbf8e39dde28a10246a4dcf94c4a572724b83..062495e02e263d79c00802d59344471566a5f9ad 100644 (file)
@@ -71,7 +71,7 @@
                 {% for comment in song.get_comments() %}
                 <div class="top-level-comment">
 
-                    <a href="/users/{{ comment['username'] }}" class="profile-link">{{ comment['username'] }}:</a>
+                    <a href="/users/{{ comment['username'] }}" class="profile-link">{{ comment['username'] }}</a>:
                     {{ comment['content'] }}
 
                     {% if session['userid'] == comment['userid'] or session['userid'] == song.userid %}
@@ -99,7 +99,7 @@
                     {% for reply in comment['replies'] %}
                     <div class="reply-comment">
 
-                        <a href="/users/{{ reply['username'] }}" class="profile-link">{{ reply['username'] }}:</a>
+                        <a href="/users/{{ reply['username'] }}" class="profile-link">{{ reply['username'] }}</a>:
                         {{ reply['content'] }}
 
                         {% if session['userid'] == reply['userid'] or session['userid'] == song.userid %}