Files
ds-chat/backend/app/schemas/message.py
T
ksmithandClaude Sonnet 5 ef615e1ef4 Add the ability to delete a message (#53)
Message.deleted_at has existed since the initial schema but was never
wired up -- no WS envelope, no permission check, no frontend concept of
it at all. Soft delete, author-only (mirrors the existing edit
permission exactly): content and any attached image/file are cleared
and the underlying MessageImage/MessageFile row and stored file are
actually removed, not just detached, so the message becomes a "This
message was deleted" tombstone with nothing left to recover through a
stale attachment URL. A deleted message can no longer be edited or
reacted to.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-28 16:35:00 -06:00

53 lines
1.3 KiB
Python

import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict
class ReactionSummary(BaseModel):
emoji: str
count: int
user_ids: list[str]
class MessageFileInfo(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
filename: str
size_bytes: int
content_type: str
class LinkPreviewInfo(BaseModel):
model_config = ConfigDict(from_attributes=True)
url: str
title: str | None
description: str | None
image_url: str | None
site_name: str | None
is_image: bool
class MessageRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
room_id: uuid.UUID
user_id: uuid.UUID
username: str
content: str | None
image_id: uuid.UUID | None
file: MessageFileInfo | None
link_preview: LinkPreviewInfo | None
reactions: list[ReactionSummary]
created_at: datetime
edited_at: datetime | None
# #53: null for a live message; set once deleted, at which point
# content/image_id/file/link_preview are all already cleared
# server-side (see message_service.delete_message). `reactions` isn't
# cleared server-side -- the frontend just doesn't render them once
# deleted_at is set, same as it doesn't render the rest of a tombstone.
deleted_at: datetime | None