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
|
||||
|
||||
'''
|
||||
|
||||
MODEL ChatMessage
|
||||
|
||||
|
||||
'''
|
||||
class ChatMessage(models.Model):
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
content = encrypt(models.CharField(max_length=5000, blank=False, default=""))
|
||||
sendtime = models.DateTimeField(default=timezone.now, blank=True)
|
||||
room = models.ForeignKey("ChatRoom", on_delete=models.CASCADE)
|
||||
'''
|
||||
|
||||
'''
|
||||
Model ChatRoom
|
||||
|
||||
'''
|
||||
|
||||
class ChatRoom(models.Model):
|
||||
|
||||
creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ $(document).ready(function(){
|
|||
|
||||
chatwebsocket.onmessage = function(e) {
|
||||
|
||||
|
||||
|
||||
datainfo = e["data"].split("__");
|
||||
|
||||
|
|
@ -114,7 +115,7 @@ $(document).ready(function(){
|
|||
}
|
||||
}
|
||||
|
||||
if(datainfo[0] == "stoptyping")
|
||||
if(datainfo[0] == "stoptyping")
|
||||
{
|
||||
$("#is_typing_name").html(" ");
|
||||
$("#typingspinner").hide();
|
||||
|
|
@ -133,11 +134,10 @@ $(document).ready(function(){
|
|||
success: function( data )
|
||||
{
|
||||
$("#chatmessages").append(data);
|
||||
$('#chatcontentcomplete').scrollTop( $('#chatcontentcomplete').height()*200 );
|
||||
$('#chatcontentcomplete').scrollTop( $('#chatcontentcomplete').height()*200 );
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log(datainfo)
|
||||
}
|
||||
if(datainfo[0] == "delete_message"){
|
||||
$("#usermessage_" + datainfo[1]).remove();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,6 @@ $(document).ready(function(){
|
|||
|
||||
chatwebsocket.onmessage = function(e) {
|
||||
|
||||
|
||||
datainfo = e["data"].split("__");
|
||||
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.signals import presence_changed
|
||||
from organizer.models import *
|
||||
from chat.models import ChatMessage
|
||||
|
||||
def loadingFreeDays(plz, year):
|
||||
# Getting land
|
||||
|
|
@ -674,7 +675,39 @@ def save_newabsence(sender, instance, **kwargs):
|
|||
print("Absence-Object is no holiday...")
|
||||
|
||||
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)
|
||||
def delete_absence(sender, instance, **kwargs):
|
||||
|
|
|
|||
|
|
@ -615,9 +615,6 @@ $( window ).resize(function() {
|
|||
|
||||
*/
|
||||
newunknownotificationscounter = 0;
|
||||
|
||||
|
||||
|
||||
function loadUnsendNotifications(){
|
||||
$.ajax(
|
||||
{
|
||||
|
|
@ -718,11 +715,46 @@ $(document).ready(function(){
|
|||
if(e["data"] != "presence_update")
|
||||
{
|
||||
//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();
|
||||
loadUnviewnNotifications();
|
||||
|
|
|
|||
Loading…
Reference in New Issue