Skip to content

Django Channels consumer: websocket connection, auth, message events #115

Description

@mehalyna

Task 4 — Django Channels consumer: websocket connection, auth, message events

Title: realtime: implement WebSocket consumer(s) for messaging using Django Channels

API / behavior

  • WebSocket endpoint: ws://<host>/ws/chat/

  • Authentication: accept JWT in Sec-WebSocket-Protocol or use session cookie (documented).

  • On connect: authenticate user, subscribe to channels for user (user.<userid>) and to conversation groups when requested.

  • Events:

    • join_conversation { "conversation_id": "uuid" } → subscribe group conversation.<id>.
    • leave_conversation
    • send_message { "conversation_id","body","attachments":[upload_ids] } → validate, call service.create_message, publish message_received.
    • typing and presence signals forwarded to other participants.
    • mark_read { "conversation_id" } → call service.mark_messages_read and emit read_receipt.
  • Outgoing events:

    • message_received (to conversation group) with message payload.
    • read_receipt, typing, presence events.

Acceptance

  • Consumer unit tests (channels testing) that:

    • Auth works,
    • send_message persists the message and broadcasts to conversation participants,
    • join/leave subscription works,
    • read receipts emitted correctly.

Dependencies

  • Redis channel layer (Channels).
  • Messaging service (Task 3).
  • Auth middleware for Channels.

Notes

  • Keep consumer logic thin: validate + call service + publish event.
  • Ensure proper exception handling to avoid leaking info.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions