From 03819d957194cfc88e96c6e3959603db69204936 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sat, 7 Feb 2026 17:40:00 -0500 Subject: [PATCH] Initial work on love - needs button --- src/littlesongplace/comments.py | 20 +++++++++++++------ src/littlesongplace/push_notifications.py | 8 ++++++-- src/littlesongplace/templates/activity.html | 19 ++++++++++-------- .../templates/comment-thread.html | 10 ++++++---- src/littlesongplace/templates/settings.html | 8 +++++++- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/littlesongplace/comments.py b/src/littlesongplace/comments.py index dfe7b19..7de0a98 100644 --- a/src/littlesongplace/comments.py +++ b/src/littlesongplace/comments.py @@ -184,12 +184,20 @@ def comment(): [commentid, ObjectType.COMMENT, target, timestamp]) # Send push notifications - push_notifications.notify( - notification_targets, - title=f"Comment from {g.username}", - body=content, - url="/activity", - setting=push_notifications.SubscriptionSetting.COMMENTS) + if content == "[l0vv3]": + push_notifications.notify( + notification_targets, + title=f"{g.username} sent love!", + body=None, + url="/activity", + setting=push_notifications.SubscriptionSetting.LOVE) + else: + push_notifications.notify( + notification_targets, + title=f"Comment from {g.username}", + body=content, + url="/activity", + setting=push_notifications.SubscriptionSetting.COMMENTS) db.commit() diff --git a/src/littlesongplace/push_notifications.py b/src/littlesongplace/push_notifications.py index 55b8cb6..32a7f65 100644 --- a/src/littlesongplace/push_notifications.py +++ b/src/littlesongplace/push_notifications.py @@ -16,6 +16,7 @@ push_threads = [] class SubscriptionSetting(enum.IntEnum): COMMENTS = 0x0001 SONGS = 0x0002 + LOVE = 0x0004 @bp.post("/subscribe") @auth.requires_login @@ -76,8 +77,9 @@ def get_settings(): comments = (row["settings"] & SubscriptionSetting.COMMENTS) > 0 songs = (row["settings"] & SubscriptionSetting.SONGS) > 0 + love = (row["settings"] & SubscriptionSetting.LOVE) > 0 - return {"comments": comments, "songs": songs} + return {"comments": comments, "songs": songs, "love": love} @bp.post("/settings") @auth.requires_login @@ -89,7 +91,7 @@ def update_settings(): bitfield = 0 settings = request.json - if ("subid" not in settings) or ("comments" not in settings) or ("songs" not in settings): + if ("subid" not in settings) or ("comments" not in settings) or ("songs" not in settings) or ("love" not in settings): abort(400) subid = settings["subid"] @@ -98,6 +100,8 @@ def update_settings(): bitfield |= SubscriptionSetting.COMMENTS if settings["songs"]: bitfield |= SubscriptionSetting.SONGS + if settings["love"]: + bitfield |= SubscriptionSetting.LOVE current_app.logger.info(f"{g.username} attempting to update push subscription settings: ({subid}) {bitfield:04x}") diff --git a/src/littlesongplace/templates/activity.html b/src/littlesongplace/templates/activity.html index ab79726..6c53f98 100644 --- a/src/littlesongplace/templates/activity.html +++ b/src/littlesongplace/templates/activity.html @@ -8,25 +8,27 @@ {% for comment in comments -%}
{{ comment['comment_username'] }} - {% if comment['replyto_content'] %} + {%- if comment['replyto_content'] %} replied to "{{ comment['replyto_content'] }}" - {% else %} + {%- elif comment['content'] == '[l0vv3]' %} + sent love + {%- else %} commented - {% endif %} + {%- endif %} on - {% if 'songid' in comment %} + {%- if 'songid' in comment %} {{ comment['title'] }} - {# Nothing to do for user profile #} - {% elif 'playlistid' in comment %} + {%- elif 'playlistid' in comment %} {{ comment['name'] }} - - {% elif 'eventid' in comment %} + {%- elif 'eventid' in comment %} {{ comment['title'] }} - - {% endif %} + {%- endif %} {{ comment['content_username'] }} + {%- if comment['content'] != '[l0vv3]' %}
{{ comment['comment_username'] }}: {{ comment['content'] }} -
{% if comment['replytoid'] %} @@ -37,6 +39,7 @@ {% endif %}
+ {%- endif %}
{% endfor %} diff --git a/src/littlesongplace/templates/comment-thread.html b/src/littlesongplace/templates/comment-thread.html index 1231e09..9ee8787 100644 --- a/src/littlesongplace/templates/comment-thread.html +++ b/src/littlesongplace/templates/comment-thread.html @@ -1,10 +1,11 @@ {% macro comment_thread(threadid, current_userid, thread_userid, comments) %}
- {% if current_userid %} + {%- if current_userid %} - {% endif %} + {%- endif %} - {% for comment in comments %} + {%- for comment in comments %} + {%- if comment['content'] != '[l0vv3]' %}
{{ comment['username'] }}: @@ -54,6 +55,7 @@ Reply
- {% endfor %} + {%- endif %} + {%- endfor %} {% endmacro %} diff --git a/src/littlesongplace/templates/settings.html b/src/littlesongplace/templates/settings.html index 2911b61..c4b7462 100644 --- a/src/littlesongplace/templates/settings.html +++ b/src/littlesongplace/templates/settings.html @@ -18,6 +18,8 @@ run in "progressive web app" mode, which enables background notifications.

+ +

@@ -37,12 +39,14 @@ function updateSelections() { r.json().then((j) => { console.log(j); document.getElementById("comment-push").checked = j.comments; + document.getElementById("love-push").checked = j.love; document.getElementById("song-push").checked = j.songs; }); }) } else { document.getElementById("comment-push").checked = false; + document.getElementById("love-push").checked = false; document.getElementById("song-push").checked = false; } } @@ -50,10 +54,11 @@ document.addEventListener("DOMContentLoaded", updateSelections()); async function updateSettings() { const comment_push_enabled = document.getElementById("comment-push").checked; + const love_push_enabled = document.getElementById("love-push").checked; const song_push_enabled = document.getElementById("song-push").checked; // Enable/subscribe to notifications - if (comment_push_enabled || song_push_enabled) + if (comment_push_enabled || love_push_enabled || song_push_enabled) { await enablePushNotifications(); } @@ -65,6 +70,7 @@ async function updateSettings() { headers: {"Content-Type": "application/json"}, body: JSON.stringify({ comments: comment_push_enabled, + love: love_push_enabled, songs: song_push_enabled, subid: window.localStorage.getItem("subid"), }) -- 2.39.5