return redirect_to_previous_page()
+@bp.post("/send-love")
+@auth.requires_login
+def send_love():
+ thread = db.query(
+ """
+ SELECT * FROM comment_threads
+ WHERE threadid = ?
+ """,
+ [request.args["threadid"]],
+ expect_one=True)
+
+ # Add love comment
+ content = "[l0vv3]"
+ timestamp = datetime.now(timezone.utc).isoformat()
+ userid = session["userid"]
+
+ threadid = request.args["threadid"]
+ comment = db.query(
+ """
+ INSERT INTO comments
+ (threadid, userid, replytoid, created, content)
+ VALUES (?, ?, ?, ?, ?)
+ RETURNING (commentid)
+ """,
+ args=[threadid, userid, None, timestamp, content],
+ one=True)
+ commentid = comment["commentid"]
+
+ # Notify content owner
+ notification_targets = {thread["userid"]}
+
+ # Create notifications in database
+ for target in notification_targets:
+ db.query(
+ """
+ INSERT INTO notifications
+ (objectid, objecttype, targetuserid, created)
+ VALUES (?, ?, ?, ?)
+ """,
+ [commentid, ObjectType.COMMENT, target, timestamp])
+
+ # Send push notifications
+ push_notifications.notify(
+ notification_targets,
+ title=f"{g.username} sent love!",
+ body=None,
+ url="/activity",
+ setting=push_notifications.SubscriptionSetting.LOVE)
+
+ db.commit()
+
+ return { "status": "success", "messages": ["Love sent!"] }
+
def redirect_to_previous_page():
previous_page = "/"
if "previous_page" in session:
var m_allSongs = [];
var m_songIndex = 0;
+var m_loveSent = false;
// Play a new song from the list in the player
function play(event) {
var song = m_allSongs[m_songIndex];
var songData = JSON.parse(song.dataset.song);
+ // Started new song - clear love sent flag
+ resetLove();
+
var audio = document.getElementById("player-audio");
audio.pause();
audio.src = `/song/${songData.userid}/${songData.songid}`;
}
}
+// Send love on the currently playing song
+function sendLove() {
+ if (m_loveSent) return; // Can only send love once per song
+ var song = m_allSongs[m_songIndex];
+ var songData = JSON.parse(song.dataset.song);
+ m_loveSent = true;
+ fetch(
+ `/send-love?threadid=${songData.threadid}`,
+ {method: "post"}
+ ).then(handleAjaxResponse)
+
+ var loveImage = document.getElementById("send-love-image");
+ loveImage.className = "lsp_btn_heart_fill02";
+ updateImageColors();
+}
+
+// Reset the love button
+function resetLove() {
+ m_loveSent = false;
+ var loveImage = document.getElementById("send-love-image");
+ loveImage.className = "lsp_btn_heart_line02";
+ updateImageColors();
+}
+
// Add event listeners
var m_firstLoadPlayer = true;
document.addEventListener("DOMContentLoaded", (event) => {
<!-- Song Player -->
<div class="player" id="player" hidden>
<div class="player-info">
+ <button class="player-button" onclick="sendLove()">
+ <img class="lsp_btn_heart_line02" title="Send Love" id="send-love-image">
+ </button>
<img id="player-pfp" class="small-pfp" src="" onerror="this.style.display = 'none'">
<a id="player-title"></a>
-
</div>
<div class="player-controls">
<button onclick="songPrevious()" class="player-button">
- <img class="lsp_btn_prev02" alt="Previous">
+ <img class="lsp_btn_prev02" title="Previous">
</button>
<button onclick="songPlayPause()" class="player-button">
- <img class="lsp_btn_pause02" alt="Play" id="play-pause-button">
+ <img class="lsp_btn_pause02" title="Play" id="play-pause-button">
</button>
<button onclick="songNext()" class="player-button">
- <img class="lsp_btn_next02" alt="Next">
+ <img class="lsp_btn_next02" title="Next">
</button>
<input id="position-slider" name="song-position" type="range" min="0" max="1" step="any" value="0"/>
<span class="player-time" id="player-current-time">0:00</span>