diff --git a/app/common b/app/common index 99e119d..201c631 160000 --- a/app/common +++ b/app/common @@ -1 +1 @@ -Subproject commit 99e119d1facbd614f7f8307f9512578e79eead8a +Subproject commit 201c631c2464927690c3fe3b1c0d26853faa9586 diff --git a/app/service/service_manager.py b/app/service/service_manager.py index 89017c6..d487584 100644 --- a/app/service/service_manager.py +++ b/app/service/service_manager.py @@ -212,3 +212,8 @@ class ServiceManager(IClientHandler): connections.append(user) return connections + + def send_message(self, email: str, message: str, ttl: int): + for user in self._subscribers: + if user.info and user.info.email == email: + user.send_message(message, ttl * 1000) diff --git a/app/service/view.py b/app/service/view.py index 943a430..741a50a 100644 --- a/app/service/view.py +++ b/app/service/view.py @@ -4,9 +4,9 @@ from flask_classy import FlaskView, route from flask import render_template, redirect, url_for, request, jsonify, Response from flask_login import login_required, current_user -from app import get_runtime_folder +from app import get_runtime_folder, servers_manager from app.common.service.forms import ServiceSettingsForm, ActivateForm, UploadM3uForm, ServerProviderForm -from app.common.subscriber.forms import SignupForm +from app.common.subscriber.forms import SignupForm, MessageForm from app.common.service.entry import ServiceSettings, ProviderPair from app.common.subscriber.entry import Subscriber from app.common.utils.m3u_parser import M3uParser @@ -271,6 +271,17 @@ class ServiceView(FlaskView): return jsonify(status='failed'), 404 + @login_required + @route('/subscriber/send_message/', methods=['GET', 'POST']) + def subscriber_send_message(self, sid): + subscriber = Subscriber.objects(id=sid).first() + form = MessageForm() + if request.method == 'POST' and form.validate_on_submit(): + servers_manager.send_message(subscriber.email, form.message.data, form.ttl.data) + return jsonify(status='ok'), 200 + + return render_template('service/subscriber/send_message.html', form=form) + @login_required @route('/add', methods=['GET', 'POST']) def add(self): diff --git a/app/templates/provider/dashboard.html b/app/templates/provider/dashboard.html index 56dd782..9fc2ea2 100644 --- a/app/templates/provider/dashboard.html +++ b/app/templates/provider/dashboard.html @@ -1087,15 +1087,5 @@ Dashboard | {{ config['PUBLIC_CONFIG'].site.title }} } }); } - - - - - - - - - - {% endblock %} diff --git a/app/templates/service/subscriber/send_message.html b/app/templates/service/subscriber/send_message.html new file mode 100644 index 0000000..6244415 --- /dev/null +++ b/app/templates/service/subscriber/send_message.html @@ -0,0 +1,34 @@ +{% from 'bootstrap/wtf.html' import form_field %} +{% macro render_bootstrap_field(field) %} +
+ +
+ {{ field(class='form-control')|safe }} +
+
+{% endmacro %} + +
+ + + +
diff --git a/app/templates/service/subscribers.html b/app/templates/service/subscribers.html index 49acf1f..cab90a5 100644 --- a/app/templates/service/subscribers.html +++ b/app/templates/service/subscribers.html @@ -59,6 +59,10 @@ Activate service | {{ config['PUBLIC_CONFIG'].site.title }} onclick="edit_subscriber('{{ subscriber.id }}')"> {% trans %}Edit{% endtrans %} +