Benachrichtigungen Chat PUSH fertig
This commit is contained in:
parent
f2f1cbe12f
commit
3b15847ce6
|
|
@ -6,22 +6,17 @@ from django.utils import timezone
|
||||||
from django_cryptography.fields import encrypt
|
from django_cryptography.fields import encrypt
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
MODEL ChatMessage
|
MODEL ChatMessage
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
class ChatMessage(models.Model):
|
class ChatMessage(models.Model):
|
||||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
content = encrypt(models.CharField(max_length=5000, blank=False, default=""))
|
content = encrypt(models.CharField(max_length=5000, blank=False, default=""))
|
||||||
sendtime = models.DateTimeField(default=timezone.now, blank=True)
|
sendtime = models.DateTimeField(default=timezone.now, blank=True)
|
||||||
room = models.ForeignKey("ChatRoom", on_delete=models.CASCADE)
|
room = models.ForeignKey("ChatRoom", on_delete=models.CASCADE)
|
||||||
'''
|
|
||||||
|
|
||||||
|
'''
|
||||||
Model ChatRoom
|
Model ChatRoom
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class ChatRoom(models.Model):
|
class ChatRoom(models.Model):
|
||||||
|
|
||||||
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ $(document).ready(function(){
|
||||||
chatwebsocket.onmessage = function(e) {
|
chatwebsocket.onmessage = function(e) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
datainfo = e["data"].split("__");
|
datainfo = e["data"].split("__");
|
||||||
|
|
||||||
if(datainfo[0] == "starttyping")
|
if(datainfo[0] == "starttyping")
|
||||||
|
|
@ -137,7 +138,6 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(datainfo)
|
|
||||||
if(datainfo[0] == "delete_message"){
|
if(datainfo[0] == "delete_message"){
|
||||||
$("#usermessage_" + datainfo[1]).remove();
|
$("#usermessage_" + datainfo[1]).remove();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,6 @@ $(document).ready(function(){
|
||||||
|
|
||||||
chatwebsocket.onmessage = function(e) {
|
chatwebsocket.onmessage = function(e) {
|
||||||
|
|
||||||
|
|
||||||
datainfo = e["data"].split("__");
|
datainfo = e["data"].split("__");
|
||||||
if(datainfo[0] == "starttyping")
|
if(datainfo[0] == "starttyping")
|
||||||
{
|
{
|
||||||
|
|
@ -253,4 +252,4 @@ $(document).on('keypress',function(e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -31,6 +31,7 @@ from channels_presence.models import Room
|
||||||
from channels_presence.models import Presence
|
from channels_presence.models import Presence
|
||||||
from channels_presence.signals import presence_changed
|
from channels_presence.signals import presence_changed
|
||||||
from organizer.models import *
|
from organizer.models import *
|
||||||
|
from chat.models import ChatMessage
|
||||||
|
|
||||||
def loadingFreeDays(plz, year):
|
def loadingFreeDays(plz, year):
|
||||||
# Getting land
|
# Getting land
|
||||||
|
|
@ -675,6 +676,38 @@ def save_newabsence(sender, instance, **kwargs):
|
||||||
|
|
||||||
post_save.connect(save_newabsence, sender=sender)
|
post_save.connect(save_newabsence, sender=sender)
|
||||||
|
|
||||||
|
# Neue Chatnachricht wurde verschickt - Hier Reaktion NUR auf PUSH!
|
||||||
|
@receiver(signal=post_save, sender=ChatMessage)
|
||||||
|
def new_chat_message(sender, instance, **kwargs):
|
||||||
|
# GRUPPENCHAT
|
||||||
|
if instance.room.chatroomtype == 1:
|
||||||
|
|
||||||
|
sended_users = []
|
||||||
|
|
||||||
|
for u in instance.room.chatmembers.all():
|
||||||
|
if u != instance.author:
|
||||||
|
if u.usernotifications.chat_received_push and u not in sended_users:
|
||||||
|
channel_layer = channels.layers.get_channel_layer()
|
||||||
|
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Chat | Neue Nachricht im Gruppenchat " + instance.room.roomname + " von " + instance.author.first_name + " " + instance.author.last_name + ": " + instance.content})
|
||||||
|
sended_users.append(u)
|
||||||
|
|
||||||
|
for u in instance.room.chatmembers_admin.all():
|
||||||
|
if u != instance.author:
|
||||||
|
if u.usernotifications.chat_received_push and u not in sended_users:
|
||||||
|
channel_layer = channels.layers.get_channel_layer()
|
||||||
|
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Chat | Neue Nachricht im Gruppenchat " + instance.room.roomname + " von " + instance.author.first_name + " " + instance.author.last_name + ": " + instance.content})
|
||||||
|
sended_users.append(u)
|
||||||
|
|
||||||
|
|
||||||
|
elif instance.room.chatroomtype == 0:
|
||||||
|
|
||||||
|
u = instance.room.chatmember_single
|
||||||
|
|
||||||
|
if u.usernotifications.chat_received_push and u != instance.author:
|
||||||
|
channel_layer = channels.layers.get_channel_layer()
|
||||||
|
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Chat | Neue Nachricht von " + instance.author.first_name + " " + instance.author.last_name + ": " + instance.content})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(signal=pre_delete, sender=Absence)
|
@receiver(signal=pre_delete, sender=Absence)
|
||||||
def delete_absence(sender, instance, **kwargs):
|
def delete_absence(sender, instance, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -615,9 +615,6 @@ $( window ).resize(function() {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
newunknownotificationscounter = 0;
|
newunknownotificationscounter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function loadUnsendNotifications(){
|
function loadUnsendNotifications(){
|
||||||
$.ajax(
|
$.ajax(
|
||||||
{
|
{
|
||||||
|
|
@ -720,9 +717,44 @@ $(document).ready(function(){
|
||||||
//HANDLER FOR ALL PUSHNOTIFICATIONS
|
//HANDLER FOR ALL PUSHNOTIFICATIONS
|
||||||
if(e["data"].split("__")[0] == "pushnotification"){
|
if(e["data"].split("__")[0] == "pushnotification"){
|
||||||
|
|
||||||
var notify = new Notification('Digitale Agentur', {
|
/*
|
||||||
body: e["data"].split("__")[1]
|
Check for Chat-Message in CHatview or invisible-Browser
|
||||||
});
|
*/
|
||||||
|
tempsplit = e["data"].split("__");
|
||||||
|
finalsplit = tempsplit[1].split(" ");
|
||||||
|
|
||||||
|
if(finalsplit[0] != "Chat"){
|
||||||
|
var notify = new Notification('Digitale Agentur', {
|
||||||
|
body: e["data"].split("__")[1]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
{% if active_link == "chat" %}
|
||||||
|
chatopen= true;
|
||||||
|
{% else %}
|
||||||
|
chatopen= false;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
windowvisible = false;
|
||||||
|
//Get Minimized-Window-Status to show up chat message, when window is in chat, but not focused by user
|
||||||
|
|
||||||
|
if(!document.hasFocus()){
|
||||||
|
var notify = new Notification('Digitale Agentur', {
|
||||||
|
body: e["data"].split("__")[1]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if(chatopen == false){
|
||||||
|
if($("#dynamicchatwindow").is(":visible")){
|
||||||
|
console.log("user in chat...")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var notify = new Notification('Digitale Agentur', {
|
||||||
|
body: e["data"].split("__")[1]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
loadUnsendNotifications();
|
loadUnsendNotifications();
|
||||||
loadUnviewnNotifications();
|
loadUnviewnNotifications();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue