Task #35
openChat System
0%
Description
*Buyer–Seller Chat
Enable real-time or near real-time communication between buyers and sellers for a specific ad.
*Message Delivery
Ensure that messages (text or image) are correctly sent, stored, and displayed in the correct order.
*Read / Unread Status
Track whether a message has been read by the receiver to improve communication clarity.
***Table: chats
id-INT (PK)-Unique chat ID
ad_id-INT (FK)-Ad related to the chat
buyer_id-INT (FK)-User interested in the ad
seller_id-INT (FK)-Owner of the ad
last_message_at-DATETIME-Timestamp of last message
*Each record represents one conversation for a specific ad.
*Prevents multiple chat threads for the same buyer and seller.
*last_message_at helps in sorting recent chats.
***Table: chat_messages
*id-INT (PK)-Unique message ID
*chat_id-INT (FK)-Related chat
*sender_id-INT (FK)-Message sender
*message_type-ENUM-text / image
*message_text-TEXT-Message content
*created_at-DATETIME-Message sent time
*Stores individual messages in a chat.
*message_type differentiates between text and image messages.
*Messages are always linked to a valid chat using chat_id.
****Validations
*A chat can be initiated only after an ad is published.
*A chat is allowed only between the ad owner (seller) and an interested user (buyer).
*A unique chat must exist for each ad–buyer–seller combination.
*Only the sender or receiver can view messages in a chat.
*Messages must be displayed in chronological order.
*Empty messages are not allowed.
*Only valid file types (e.g., JPG, PNG) are allowed for image messages.
*Deleted or blocked users cannot send messages.