|
|
|
@ -19,20 +19,6 @@ class TicketRoomConsumer(WebsocketConsumer):
|
|
|
|
|
self.ticket = get_object_or_404(Ticket, id=self.ticket_id)
|
|
|
|
|
self.ticket_number = self.ticket.ticket_number
|
|
|
|
|
|
|
|
|
|
existing_connection = TicketConnection.objects.filter(ticket=self.ticket, user=self.user, terminated_at__isnull=True).delete()
|
|
|
|
|
TicketConnection.objects.create(
|
|
|
|
|
ticket=self.ticket,
|
|
|
|
|
user=self.user,
|
|
|
|
|
date=datetime.now()
|
|
|
|
|
)
|
|
|
|
|
staff_profile = StaffProfile.objects.filter(user=self.user).first()
|
|
|
|
|
if staff_profile:
|
|
|
|
|
if not TicketStaff.objects.filter(staff=staff_profile, ticket=self.ticket).exists():
|
|
|
|
|
TicketStaff.objects.create(
|
|
|
|
|
staff=staff_profile,
|
|
|
|
|
ticket=self.ticket,
|
|
|
|
|
date_added=datetime.now()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
async_to_sync(self.channel_layer.group_add)(
|
|
|
|
|
self.ticket_number, self.channel_name
|
|
|
|
@ -51,6 +37,60 @@ class TicketRoomConsumer(WebsocketConsumer):
|
|
|
|
|
)
|
|
|
|
|
self.modify_online_user()
|
|
|
|
|
|
|
|
|
|
def receive(self, text_data):
|
|
|
|
|
text_data_json = json.loads(text_data)
|
|
|
|
|
event_type = text_data_json.get('event_type')
|
|
|
|
|
|
|
|
|
|
if event_type == 'typing':
|
|
|
|
|
event = {
|
|
|
|
|
'type': 'typing_handler',
|
|
|
|
|
'user': self.scope['user']
|
|
|
|
|
}
|
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
|
self.ticket_number, event
|
|
|
|
|
)
|
|
|
|
|
elif event_type == 'stop_typing':
|
|
|
|
|
event = {
|
|
|
|
|
'type': 'stop_typing_handler',
|
|
|
|
|
}
|
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
|
self.ticket_number, event
|
|
|
|
|
)
|
|
|
|
|
elif event_type == 'update_reaction':
|
|
|
|
|
reaction = text_data_json['reaction']
|
|
|
|
|
update_id = text_data_json['update_id']
|
|
|
|
|
event = {
|
|
|
|
|
'type': 'reaction_handler',
|
|
|
|
|
'update_id': update_id,
|
|
|
|
|
'reaction': reaction,
|
|
|
|
|
'user': self.scope['user']
|
|
|
|
|
}
|
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
|
self.ticket_number, event
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
body = text_data_json['description']
|
|
|
|
|
file_paths = text_data_json['filePath']
|
|
|
|
|
ticketupdate = TicketUpdate.objects.create(
|
|
|
|
|
added_by=self.user,
|
|
|
|
|
description=body,
|
|
|
|
|
ticket=self.ticket,
|
|
|
|
|
date_added=datetime.now()
|
|
|
|
|
)
|
|
|
|
|
for file_path in file_paths:
|
|
|
|
|
ticket_attachment = TicketAttachment(
|
|
|
|
|
ticket_update=ticketupdate,
|
|
|
|
|
file_path=file_path
|
|
|
|
|
)
|
|
|
|
|
ticket_attachment.save()
|
|
|
|
|
event = {
|
|
|
|
|
'type': 'update_handler',
|
|
|
|
|
'update_id': ticketupdate.id
|
|
|
|
|
}
|
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
|
self.ticket_number, event
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def update_handler(self, event):
|
|
|
|
|
update_id = event['update_id']
|
|
|
|
|
update = TicketUpdate.objects.get(id=update_id)
|
|
|
|
|