# Push Subscriptions
+ async def is_subscribed(self):
+ """
+ Returns True if the user is subscribed.
+ """
+ subscriptions = await self.get_subscriptions()
+
+ return True if subscriptions else False
+
async def get_subscriptions(self):
"""
Fetches all current subscriptions
sqlalchemy
.select(
UserPushSubscription,
- ).where(
+ )
+ .where(
UserPushSubscription.user == self,
)
.order_by(
# Send a message
await subscription.send(
- _("Hello, %s!") % self.current_user,
+ _("Hello, %s!") % self,
_("You have successfully subscribed to push notifications."),
)
{% extends "base.html" %}
{% from "jobs/macros.html" import JobQueue with context %}
+{% from "users/macros.html" import UserPushSubscribeButton with context %}
{% block title %}{{ _("Welcome!") }}{% endblock %}
{% block body %}
- <section class="hero is-medium is-primary">
- <div class="hero-body">
- <div class="container">
- <p class="title">
- {{ _("Pakfire Build Service") }}
- </p>
- <p class="subtitle">
- {{ _("Development Powered By Community") }}
- </p>
+ {# Show some personal stuff to logged in users #}
+ {% if current_user %}
+ {# Ask to enable push notifications #}
+ {% if not current_user.is_subscribed() %}
+ <section class="hero is-small is-success">
+ <div class="hero-body">
+ <div class="container">
+ <div class="columns is-vcentered">
+ <div class="column">
+ <p>
+ <strong>{{ _("Never Miss A Beat!") }}</strong>
+
+ {{ _("Enable Push Notifications and let the Pakfire Build Service "
+ "notify you about all important things.") }}
+ </p>
+ </div>
+
+ <div class="column is-narrow">
+ {{ UserPushSubscribeButton("is-success is-inverted") }}
+ </div>
+ </div>
+ </div>
+ </div>
+ </section>
+ {% endif %}
+
+ {# Show a big banner to new users #}
+ {% else %}
+ <section class="hero is-medium is-primary">
+ <div class="hero-body">
+ <div class="container">
+ <p class="title">
+ {{ _("Pakfire Build Service") }}
+ </p>
+ <p class="subtitle">
+ {{ _("Development Powered By Community") }}
+ </p>
+ </div>
</div>
- </div>
- </section>
+ </section>
+ {% endif %}
{# Show a status bar with running/finished jobs #}
{% if jobs %}
{% endfor %}
{% endmacro %}
-{% macro UserPushSubscribeButton() %}
+{% macro UserPushSubscribeButton(classes="is-primary is-fullwidth") %}
{# Application Server Key #}
{% set application_server_key = backend.users.get_application_server_key() %}
- <button id="push-subscribe-button" class="button is-primary is-fullwidth"
+ <button id="push-subscribe-button" class="button {{ classes }}"
data-application-server-key="{{ application_server_key }}">
{{ _("Subscribe") }}
</button>