Skip to content

Commit

Permalink
Merge pull request #1300 from zurichat/dev
Browse files Browse the repository at this point in the history
Merging to Main
  • Loading branch information
blacdev authored Oct 29, 2021
2 parents 65c8519 + 9af0754 commit b81a265
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 168 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ database.sqlite

*.idea

*Pipfile.lock
Pipfile.lock
Pipfile*
# *media
*.DS_Store
/.vscode
Expand Down
5 changes: 2 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ idna = "==3.2"
requests = "==2.26.0"
urllib3 = "==1.26.6"
drf-yasg = "==1.20.0"
django = "==3.2.6"
djangorestframework-simplejwt = "==4.8.0"
apscheduler = "==3.8.0"
coreapi = "==2.3.3"
coreschema = "==0.0.4"
coverage = "==6.0.1"
inflection = "==0.5.1"
itypes = "==1.2.0"
jinja2 = "==3.0.1"
pyparsing = "==2.4.7"
"ruamel.yaml" = "==0.17.16"
"ruamel.yaml.clib" = "==0.2.6"
Expand All @@ -36,6 +33,8 @@ tzlocal = "==2.1"
uritemplate = "==3.0.1"
MarkupSafe = "==2.0.1"
PyJWT = "==2.1.0"
APScheduler = "==3.8.0"
Jinja2 = "==3.0.1"

[dev-packages]
black = "*"
Expand Down
110 changes: 57 additions & 53 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions backend/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,55 @@ def edit_message(request, message_id, room_id):
@db_init_with_credentials
def delete_message(request, message_id, room_id):
"""
This function deletes message in rooms using message
organization id (org_id), room id (room_id) and the message id (message_id).
Deletes a message from a room.
It access room with the 'room_id' and the message in the room with 'message_id' and then deletes the message if it exists.
The id of the organization (org_id) where the room is located is also needed.
Parameters:
org_id (str) : This is the id of the organization th user belongs to.
room_id (str) : This is the unique id of the room the message to be deleted is in.
message_id (str) : This is the unique id of the message to be deleted from a given room.
Returns:
A dict object indicating the the message has been deleted. Example:
{
"status" : "success",
"event" : "message_delete",
"room_id" : "6169dbcef5998a09e3bbbcd3",
"message_id" : "616ad4f989454c2006018af2"
}
Raises:
Not Found: If there is no message with specified id in the specified room, it returns 'message not found' and a '404' error message.
IOError: An error occurred while deleteing the message.
"""

if request.method == "DELETE":
try:
message = DB.read("dm_messages", {"_id": message_id})
room = DB.read("dm_rooms", {"_id": room_id})
# Sends a get request to the database to fetch the message and the room of the message from.
message = DB.read("dm_messages", {"_id": message_id, "room_id": room_id})

if room and message:
# Checks if the room exists and if the message exists in the room.
# If this returns true, the message is deleted. Else an error message is returned.
if message:
response = DB.delete("dm_messages", message_id)
# if the delete operation was successful, it returns a success message.
if response.get("status") == 200:
response_output = {
"status": response["message"],
"event": "message_delete",
"room_id": room_id,
"message_id": message_id,
}
# This publishes the operation across all active devices in the room where the operation was performed.
centrifugo_data = centrifugo_client.publish(
room=room_id, data=response
)
# Checks if the publish was successful and returns a success message if True, else an error message is returned.
if centrifugo_data and centrifugo_data.get("status_code") == 200:
return Response(response_output, status=status.HTTP_200_OK)
return Response(
Expand All @@ -219,6 +247,7 @@ def delete_message(request, message_id, room_id):
)
return Response("message not found", status=status.HTTP_404_NOT_FOUND)
except Exception as e:
# All exeptions are caught are returned here...
return Response(str(e), status=status.HTTP_400_BAD_REQUEST)


Expand Down
Loading

0 comments on commit b81a265

Please sign in to comment.