]> littlesong.place Git - littlesongplace.git/commitdiff
Fix comment notifications for jam events
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 19 Apr 2025 12:12:08 +0000 (08:12 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 19 Apr 2025 12:12:08 +0000 (08:12 -0400)
src/littlesongplace/activity.py
src/littlesongplace/templates/activity.html
test/conftest.py
test/test_activity.py
test/test_comments.py
test/test_jams.py

index 4a73608bd8029b8e1dd54545ff6e5f169b778fc2..4c847888080b11d7ae6efe4c3a418a898ba49301 100644 (file)
@@ -62,6 +62,19 @@ def activity():
             comment["name"] = playlist["name"]
             comment["content_userid"] = playlist["userid"]
             comment["content_username"] = playlist["username"]
+        elif threadtype == comments.ThreadType.JAM_EVENT:
+            jam_event = db.query(
+                    """\
+                    SELECT * FROM jam_events
+                    INNER JOIN jams ON jam_events.jamid = jams.jamid
+                    INNER JOIN users ON jams.ownerid = users.userid
+                    WHERE jam_events.threadid = ?
+                    """, [comment["threadid"]], one=True)
+            comment["eventid"] = jam_event["eventid"]
+            comment["jamid"] = jam_event["jamid"]
+            comment["title"] = jam_event["title"]
+            comment["content_userid"] = jam_event["userid"]
+            comment["content_username"] = jam_event["username"]
 
     timestamp = datetime.now(timezone.utc).isoformat()
     db.query(
index 0837b6b90b690604ce44d28031d4406fec6f58bc..d4ceb76cb7180403c73495c2fa545572ce3cd1b0 100644 (file)
@@ -20,7 +20,9 @@
             <a href="/song/{{ comment['content_userid'] }}/{{ comment['songid'] }}?action=view">{{ comment['title'] }}</a> -
             {# Nothing to do for user profile #}
             {% elif 'playlistid' in comment %}
-            <a href="/playlists/{{ comment['playlistid'] }}?action=view">{{ comment['name'] }}</a> -
+            <a href="/playlists/{{ comment['playlistid'] }}">{{ comment['name'] }}</a> -
+            {% elif 'eventid' in comment %}
+            <a href="/jams/{{ comment['jamid']}}/events/{{ comment['eventid'] }}">{{ comment['title'] }}</a> -
             {% endif %}
             <a href="/users/{{ comment['content_username'] }}" class="profile-link">{{ comment['content_username'] }}</a>
             <div class="top-level-comment">
index 1d7428da881a8fa3ad2de0e486c4da36b961aeb1..476a0233d6f4dd4590e9937637becc08bd753bf9 100644 (file)
@@ -10,7 +10,7 @@ import pytest
 
 pytest.register_assert_rewrite("test.utils")
 
-from .utils import login
+from .utils import login, create_user
 
 fresh_db = None
 
@@ -55,6 +55,21 @@ def session():
     login(session, "user", "1234asdf!@#$")
     yield session
 
+@pytest.fixture
+def user(client):
+    create_user(client, "user", login=True)
+    yield "user"
+
+@pytest.fixture
+def jam(client, user):
+    client.get("/jams/create")
+    return 1
+
+@pytest.fixture
+def event(client, jam):
+    client.get(f"/jams/{jam}/events/create")
+    return 1
+
 def pytest_addoption(parser):
     parser.addoption("--yt", action="store_true", help="run youtube importer tests")
 
index f66edd5528f6a452e6e9be7e52642d99324ee27b..6335843e73e1038ff5eea6d44a7b8adcbb18b686 100644 (file)
@@ -21,6 +21,15 @@ def test_activity_for_comment_on_song(client):
     response = client.get("/activity")
     assert b"hey cool song" in response.data
 
+def test_activity_for_comment_on_jam_event(client, user, event):
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool event"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/activity")
+    assert b"New Event" in response.data, response.data.decode()
+    assert b"hey cool event" in response.data, response.data.decode()
+
 def test_activity_for_reply_to_comment(client):
     create_user_and_song(client)
     create_user(client, "user2", login=True)
index fb8fd7d6e23a9c80d623e16fb97e5a8111e7e87b..ea7fd32877414785acbf9778673ffb6aa115e38d 100644 (file)
@@ -71,6 +71,11 @@ def test_comment_on_playlist(client):
     assert response.request.path == "/playlists/1"
     assert b"comment on playlist" in response.data
 
+def test_comment_on_jam_event(client, user, jam, event):
+    response = client.get("/comment?threadid=2", headers={"Referer": f"/jams/{jam}/events/{event}"})
+    response = client.post("/comment?threadid=2", data={"content": "comment on event"}, follow_redirects=True)
+    assert b"comment on event" in response.data, response.data.decode()
+
 # Comments - Auth Status and Errors ############################################
 
 def test_comment_page_redirects_when_not_logged_in(client):
index 94c7b878217fbb1a15f87c964ef2185da8ad0929..f6393f2f364436bd908d988ef7ef2c1ad9f9fae2 100644 (file)
@@ -9,21 +9,6 @@ today = datetime.now(timezone.utc)
 yesterday = (today - timedelta(days=1)).isoformat()
 tomorrow = (today + timedelta(days=1)).isoformat()
 
-@pytest.fixture
-def user(client):
-    create_user(client, "user", login=True)
-    yield "user"
-
-@pytest.fixture
-def jam(client, user):
-    client.get("/jams/create")
-    return 1
-
-@pytest.fixture
-def event(client, jam):
-    client.get(f"/jams/{jam}/events/create")
-    return 1
-
 # Jams #########################################################################
 
 def test_view_invalid_jam(client):