diff --git a/.cred b/.cred index f48eb16..1c137ce 100644 --- a/.cred +++ b/.cred @@ -2,3 +2,4 @@ https://holger.trampe:Zerogoogle123_@git.vhevents.de/ https://holger.trampe:Zerogoogle123_@git.vhevents.de/ https://holger.trampe:Zerogoogle123_@git.vhevents.de/ https://holger.trampe:Zerogoogle123_@git.vhevents.de/ +https://holger.trampe:Zerogoogle123_@git.vhevents.de/ diff --git a/users/mainwebsocket.py b/users/mainwebsocket.py index e379abc..21cfa07 100644 --- a/users/mainwebsocket.py +++ b/users/mainwebsocket.py @@ -70,7 +70,9 @@ class UsersConsumer(WebsocketConsumer): # NEW AGENCY NEWS def agency_newnews(self, event): - self.send("Neue Agenturnews!") + print(event["pushtext"]) + self.send("pushnotification__news__" + event["pushtext"]) + #self.send("Neue Agenturnews!") # SOMETHING IN PRESENCE CHANGED def update_presence_live(self, event): diff --git a/users/signals.py b/users/signals.py index b9976e1..c6602a5 100644 --- a/users/signals.py +++ b/users/signals.py @@ -267,15 +267,16 @@ def save_standard(sender, instance, **kwargs): def save_news(sender, instance, **kwargs): GLOBALSENDMAILS = True if(kwargs["created"]): - - # Hier wird allen verbundenne Agenturmitgliedern die Info geschickt, dass es neue Agenturnews gibt + + # Hier wird an alle in der Agentur geschickt, lokal wird geprüft, ob der User diese Push-Info haben will channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("agency_" + str(instance.agency.pk), {'type' : 'agency_newnews'}) + async_to_sync(channel_layer.group_send)("agency_" + str(instance.agency.pk), {'type' : 'agency_newnews', 'pushtext' : "Neue Agenturnews | " + instance.name}) usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk) targeturl = settings.BASE_URL + "news/news/" + str(instance.pk) + "/single" - + + # Prüfung, ob die News SOFORT online geht oder später if(instance.go_online_on < timezone.now() and instance.agnotify): for user in usersofagency: @@ -296,18 +297,23 @@ def save_news(sender, instance, **kwargs): html_message=msg_html, fail_silently=True ) - + if(user.profile.news_push): newnotification = UserNotification(touser=user, notificationtext="Neue Agenturnews: " + instance.name, notificationtype="agencynews", elementid=instance.pk) newnotification.save() + + else: instance.agnotify = False instance.save() - else: - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("agency_" + str(instance.agency.pk), {'type' : 'agency_newnews'}) + # News wurden aktualisiert + else: + pass + # Hier wird an alle in der Agentur geschickt, lokal wird geprüft, ob der User diese Push-Info haben will + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("agency_" + str(instance.agency.pk), {'type' : 'agency_newnews', 'pushtext' : "Neue Agenturnews | " + instance.name}) diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 160be42..3619047 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -602,33 +602,6 @@ $( window ).resize(function() { sidebar_hidden = true; } }); -/* -delay = 250; -throttled = false; -function getDimensions() { - width = window.innerWidth; - - if(width >= 768){ - $("#content-wrapper").css("margin-left" , "212px"); - } - else{ - $("#content-wrapper").css("margin-left" , "105px"); - } -} - -// window.resize event listener -window.addEventListener('resize', function() { - if (!throttled) { // nur wenn throttled nicht gesetzt ist - getDimensions(); // Callback-Aktion - throttled = true; // Jetzt wird wieder ausgebremst - setTimeout(function() { // Timeout - throttled = false; - }, delay); - } -}); - -getDimensions(); -*/ /* AJAX CALL FOR NOTIFICATIONS @@ -733,9 +706,20 @@ $(document).ready(function(){ mainwebsocket.onmessage = function(e) { if(e["data"] != "presence_update") { - var notify = new Notification('Digitale Agentur', { - body: e["data"] - }); + //HANDLER FOR ALL PUSHNOTIFICATIONS + if(e["data"].split("__")[0] == "pushnotification"){ + + + {% if user.profile.news_push %} + // USER WANTS TO SEE NEWS PUSH + if(e["data"].split("__")[1] == "news"){ + var notify = new Notification('Digitale Agentur', { + body: e["data"].split("__")[2] + }); + } + {% endif %} + + } loadUnsendNotifications(); loadUnviewnNotifications(); }