def append_unread_msg_if_not_connected(room, user, connected_users, message): if not user in connected_users: try: unread_msgs = UnreadChatRoomMessages.objects.get(room=room, user=user) unread_msgs.most_recent_message = message unread_msgs.count += 1 unread_msgs.save() except UnreadChatRoomMessages.DoesNotExist: UnreadChatRoomMessages(room=room, user=user, count=1).save() pass return
def on_user_connected(room, user): connected_users = room.connected_users.all() if user in connected_users: try: unread_msgs = UnreadChatRoomMessages.objects.get(room=room, user=user) unread_msgs.count = 0 unread_msgs.save() except UnreadChatRoomMessages.DoesNotExist: UnreadChatRoomMessages(room=room, user=user, count=0).save() pass return
def on_user_connected(room, user): # confirm they are in the connected users list connected_users = room.connected_users.all() if user in connected_users: try: # reset count unread_msgs = UnreadChatRoomMessages.objects.get(room=room, user=user) unread_msgs.count = 0 unread_msgs.save() except UnreadChatRoomMessages.DoesNotExist: UnreadChatRoomMessages(room=room, user=user).save() pass return