Restore reactions, add constraint, handle errors
Restore soft-deleted message reactions and enforce uniqueness only for active reactions; add WebSocket error handling and minor UI/Docker tweaks. - backend/social/chat/models.py: Toggle reaction now restores a stale soft-deleted MessageReaction (avoids unique conflicts) and creates new reactions as needed. Replaced unique_together with a conditional UniqueConstraint that applies only to non-deleted records. - backend/social/chat/consumers.py: Wrap reaction toggle in try/except to return a WS error message on failure instead of allowing exceptions to bubble up. - frontend/src/components/social/chat/Message.tsx: Adjusted Tailwind max-width class for the reaction menu (max-w-32). - docker-compose.yml: Added commented example configuration for an optional Janus media server (documentational/commented service). These changes prevent unique constraint errors when restoring reactions, improve robustness of the WebSocket reaction flow, and include small UI and deployment notes.
This commit is contained in:
@@ -74,11 +74,16 @@ class ChatConsumer(AsyncWebsocketConsumer):
|
||||
})
|
||||
|
||||
elif msg_type == "reaction":
|
||||
action, reaction = await _toggle_reaction(
|
||||
message_id=data["message_id"],
|
||||
user=user,
|
||||
emoji=data["emoji"],
|
||||
)
|
||||
try:
|
||||
action, _reaction = await _toggle_reaction(
|
||||
message_id=data["message_id"],
|
||||
user=user,
|
||||
emoji=data["emoji"],
|
||||
)
|
||||
except Exception:
|
||||
await self.send(text_data=json.dumps({"error": "Reaction failed."}))
|
||||
return
|
||||
|
||||
await self.channel_layer.group_send(self.chat_name, {
|
||||
"type": "message.reaction",
|
||||
"message_id": data["message_id"],
|
||||
|
||||
Reference in New Issue
Block a user