Files
ds-chat/backend/app/schemas/room.py
T
ksmithandClaude Sonnet 5 4bac502b2c Add @-mention highlighting, sidebar badge, and push customization (#39)
@username tokens in a sent message are parsed against the room's actual
members (skipping fenced/inline code, so pasted code isn't misread) and
recorded as MessageMention rows, reusing #38's read-tracking and
offline-member broadcast infrastructure rather than building a parallel
notification path:

- Sidebar: a mentioned-and-unread room shows a distinct highlight-
  colored badge instead of (not alongside) the plain unread dot --
  computed the same way as has_unread, just scoped to messages that
  mention the caller, and cleared by the same last_read_at mark-read
  flow.
- Push notifications: a mentioned offline recipient gets "X mentioned
  you: ..." instead of the generic "X: ...", still per-recipient since
  the same message can page some room members and not others.
- Message rendering: a validated @username is highlighted inline,
  implemented by turning it into a `[@username](mention:username)` link
  before markdown parsing and overriding link rendering to style
  `mention:`-scheme links as a span instead of an anchor -- reuses
  markdown-to-jsx's existing parser rather than hand-rolling text-node
  splitting.
- Composer: typing @ opens an autocomplete dropdown of matching room
  members (arrow keys to navigate, Enter/Tab/click to insert, Escape or
  moving the cursor away to dismiss).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 08:56:40 -06:00

84 lines
2.2 KiB
Python

import uuid
from datetime import datetime
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
from app.models import RoomRole
class RoomCreate(BaseModel):
name: str = Field(min_length=1, max_length=100)
description: str | None = Field(default=None, max_length=2000)
is_private: bool = False
class RoomUpdate(BaseModel):
name: str | None = Field(default=None, min_length=1, max_length=100)
description: str | None = Field(default=None, max_length=2000)
class RoomRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
name: str
description: str | None
is_private: bool
owner_id: uuid.UUID
created_at: datetime
class RoomListItem(RoomRead):
is_member: bool
class MyRoomItem(RoomRead):
role: RoomRole
# Whether this room has a message newer than the caller's last_read_at --
# computed by the router/service, not a stored column on Room itself
# (it's inherently per-viewer, unlike everything else on RoomRead).
has_unread: bool
# Unread AND mentions this user specifically -- takes visual priority
# over has_unread in the sidebar (see RoomRow.tsx), not shown alongside
# it.
has_mention: bool
class RoomMemberRead(BaseModel):
user_id: uuid.UUID
username: str
display_name: str | None
avatar_filename: str | None
role: RoomRole
joined_at: datetime
# "offline" whenever the user has set appear_offline, regardless of
# actual connection -- computed by the router (needs GlobalPresence),
# not derivable from the model alone.
status: Literal["online", "offline"]
class RoomMemberAdd(BaseModel):
user_id: uuid.UUID
class RoomMemberRoleUpdate(BaseModel):
role: RoomRole
class TransferOwnershipRequest(BaseModel):
new_owner_user_id: uuid.UUID
class RoomAttachmentRead(BaseModel):
id: uuid.UUID
kind: Literal["file", "image"]
# None for images -- MessageImage has no stored original filename,
# unlike MessageFile (see backend/app/models/message_image.py).
filename: str | None
content_type: str
size_bytes: int
uploaded_by: str
message_id: uuid.UUID
created_at: datetime