[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()
class SubscriptionSetting(enum.IntEnum):
COMMENTS = 0x0001
SONGS = 0x0002
+ LOVE = 0x0004
@bp.post("/subscribe")
@auth.requires_login
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
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"]
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}")
{% for comment in comments -%}
<div class="boxy">
<a href="/users/{{ comment['comment_username'] }}" class="profile-link">{{ comment['comment_username'] }}</a>
- {% 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 %}
<a href="/song/{{ comment['content_userid'] }}/{{ comment['songid'] }}?action=view">{{ comment['title'] }}</a> -
{# Nothing to do for user profile #}
- {% elif 'playlistid' in comment %}
+ {%- elif 'playlistid' in comment %}
<a href="/playlists/{{ comment['playlistid'] }}">{{ comment['name'] }}</a> -
- {% elif 'eventid' in comment %}
+ {%- elif 'eventid' in comment %}
<a href="/jams/{{ comment['jamid']}}/events/{{ comment['eventid'] }}">{{ comment['title'] }}</a> -
- {% endif %}
+ {%- endif %}
<a href="/users/{{ comment['content_username'] }}" class="profile-link">{{ comment['content_username'] }}</a>
+ {%- if comment['content'] != '[l0vv3]' %}
<div class="boxy-lite">
<a href="/users/{{ comment['comment_username'] }}" class="profile-link">{{ comment['comment_username'] }}</a>:
{{ comment['content'] }}
-
<div class="comment-button-container">
{% if comment['replytoid'] %}
<!-- Comment is already part of a thread; reply to the same thread -->
{% endif %}
</div>
</div>
+ {%- endif %}
</div>
{% endfor %}
{% macro comment_thread(threadid, current_userid, thread_userid, comments) %}
<div class="comment-thread">
- {% if current_userid %}
+ {%- if current_userid %}
<a href="/comment?threadid={{ threadid }}" class="song-list-button" title="Add a Comment"><img class="lsp_btn_add02" /></a>
- {% endif %}
+ {%- endif %}
- {% for comment in comments %}
+ {%- for comment in comments %}
+ {%- if comment['content'] != '[l0vv3]' %}
<div class="boxy-lite">
<a href="/users/{{ comment['username'] }}" class="profile-link">{{ comment['username'] }}</a>:
<a href="/comment?threadid={{ threadid }}&replytoid={{ comment['commentid'] }}">Reply</a>
</div>
</div>
- {% endfor %}
+ {%- endif %}
+ {%- endfor %}
</div>
{% endmacro %}
<br/>
<label><input type="checkbox" onclick="updateSettings()" id="comment-push">I get a new comment</label>
<br/>
+ <label><input type="checkbox" onclick="updateSettings()" id="love-push">Someone sends me love</label>
+ <br/>
<label><input type="checkbox" onclick="updateSettings()" id="song-push">Anyone uploads a new song (at most once per day)</label>
</div>
<br/>
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;
}
}
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();
}
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"),
})