Private
Public Access
Rebuild frontend from the Claude Design handoff, DarkSingularity brand
Replaces the Phase 1 placeholder UI with a single persistent app shell (top bar + sidebar + chat pane, 860px responsive breakpoint) matching the "PWA chat system UI" design handoff: message bubbles with consecutive-run avatar/name grouping, auto-growing composer, room search, and the real DarkSingularity logo (also used to regenerate the PWA icons). The handoff didn't cover Phase 2 (private rooms, roles, invites) or browsing/joining open rooms, so those are added using the same visual language: a room info panel with role badges, invite-by-username with a pending-invites list, member management (remove/promote/demote/transfer ownership), room settings (rename/describe/delete), and separate browse-rooms/invites-inbox modals. Unread badges, last-message preview, and the typing indicator are deliberately deferred -- both need new backend features (read-tracking, a WS typing event) that weren't in scope this pass. Two small backend additions round out data the new UI needs but the API didn't expose: MessageRead.username (historic messages had no sender name) and InviteRead.target_username / MyInviteRead.room_name+invited_by_username (a recipient's invite list can't otherwise resolve a room they're not in). Both are additive; 35 backend tests still pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.database import get_db
|
||||
from app.dependencies import get_current_user
|
||||
from app.models import User
|
||||
from app.schemas.invite import InviteRead
|
||||
from app.schemas.invite import InviteRead, MyInviteRead
|
||||
from app.schemas.room import RoomMemberRead
|
||||
from app.services.invite_service import (
|
||||
InviteExpiredError,
|
||||
@@ -21,12 +21,26 @@ from app.services.invite_service import (
|
||||
router = APIRouter(prefix="/api/invites", tags=["invites"])
|
||||
|
||||
|
||||
@router.get("/mine", response_model=list[InviteRead])
|
||||
@router.get("/mine", response_model=list[MyInviteRead])
|
||||
async def list_my_invites_endpoint(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await list_my_invites(db, current_user.id)
|
||||
invites = await list_my_invites(db, current_user.id)
|
||||
return [
|
||||
MyInviteRead(
|
||||
id=i.id,
|
||||
room_id=i.room_id,
|
||||
invited_by=i.invited_by,
|
||||
target_user_id=i.target_user_id,
|
||||
status=i.status,
|
||||
expires_at=i.expires_at,
|
||||
created_at=i.created_at,
|
||||
room_name=i.room.name,
|
||||
invited_by_username=i.inviter.username,
|
||||
)
|
||||
for i in invites
|
||||
]
|
||||
|
||||
|
||||
@router.post("/{invite_id}/accept", response_model=RoomMemberRead)
|
||||
|
||||
@@ -257,7 +257,31 @@ async def get_room_messages_endpoint(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
await require_room_member(room_id, current_user, db)
|
||||
return await list_recent_messages(db, room_id, limit)
|
||||
messages = await list_recent_messages(db, room_id, limit)
|
||||
return [
|
||||
MessageRead(
|
||||
id=m.id,
|
||||
room_id=m.room_id,
|
||||
user_id=m.user_id,
|
||||
username=m.user.username,
|
||||
content=m.content,
|
||||
created_at=m.created_at,
|
||||
)
|
||||
for m in messages
|
||||
]
|
||||
|
||||
|
||||
def _to_invite_read(invite) -> InviteRead:
|
||||
return InviteRead(
|
||||
id=invite.id,
|
||||
room_id=invite.room_id,
|
||||
invited_by=invite.invited_by,
|
||||
target_user_id=invite.target_user_id,
|
||||
target_username=invite.target_user.username if invite.target_user else None,
|
||||
status=invite.status,
|
||||
expires_at=invite.expires_at,
|
||||
created_at=invite.created_at,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/{room_id}/invites", response_model=InviteRead, status_code=201)
|
||||
@@ -269,13 +293,14 @@ async def create_invite_endpoint(
|
||||
):
|
||||
await require_room_role(room_id, current_user, db, RoomRole.admin)
|
||||
try:
|
||||
return await create_invite(db, room_id, current_user.id, data.target_username)
|
||||
invite = await create_invite(db, room_id, current_user.id, data.target_username)
|
||||
except TargetUserNotFoundError:
|
||||
raise HTTPException(status_code=404, detail="No user with that username")
|
||||
except AlreadyMemberError:
|
||||
raise HTTPException(status_code=409, detail="That user is already a member")
|
||||
except DuplicateInviteError:
|
||||
raise HTTPException(status_code=409, detail="That user already has a pending invite")
|
||||
return _to_invite_read(invite)
|
||||
|
||||
|
||||
@router.get("/{room_id}/invites", response_model=list[InviteRead])
|
||||
@@ -285,7 +310,8 @@ async def list_room_invites_endpoint(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
await require_room_role(room_id, current_user, db, RoomRole.admin)
|
||||
return await list_room_invites(db, room_id)
|
||||
invites = await list_room_invites(db, room_id)
|
||||
return [_to_invite_read(i) for i in invites]
|
||||
|
||||
|
||||
@router.delete("/{room_id}/invites/{invite_id}", status_code=204)
|
||||
|
||||
@@ -17,6 +17,15 @@ class InviteRead(BaseModel):
|
||||
room_id: uuid.UUID
|
||||
invited_by: uuid.UUID
|
||||
target_user_id: uuid.UUID | None
|
||||
target_username: str | None = None
|
||||
status: InviteStatus
|
||||
expires_at: datetime
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class MyInviteRead(InviteRead):
|
||||
"""InviteRead plus context the recipient can't otherwise resolve client-side --
|
||||
GET /api/invites/mine is for rooms the user isn't a member of yet."""
|
||||
|
||||
room_name: str
|
||||
invited_by_username: str
|
||||
|
||||
@@ -10,5 +10,6 @@ class MessageRead(BaseModel):
|
||||
id: uuid.UUID
|
||||
room_id: uuid.UUID
|
||||
user_id: uuid.UUID
|
||||
username: str
|
||||
content: str
|
||||
created_at: datetime
|
||||
|
||||
@@ -72,14 +72,15 @@ async def create_invite(
|
||||
db.add(invite)
|
||||
await db.commit()
|
||||
await db.refresh(invite)
|
||||
invite.target_user = target
|
||||
return invite
|
||||
|
||||
|
||||
async def list_room_invites(db: AsyncSession, room_id: uuid.UUID) -> list[RoomInvite]:
|
||||
result = await db.execute(
|
||||
select(RoomInvite).where(
|
||||
RoomInvite.room_id == room_id, RoomInvite.status == InviteStatus.pending
|
||||
)
|
||||
select(RoomInvite)
|
||||
.where(RoomInvite.room_id == room_id, RoomInvite.status == InviteStatus.pending)
|
||||
.options(selectinload(RoomInvite.target_user))
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
@@ -92,7 +93,7 @@ async def list_my_invites(db: AsyncSession, user_id: uuid.UUID) -> list[RoomInvi
|
||||
RoomInvite.status == InviteStatus.pending,
|
||||
RoomInvite.expires_at > datetime.now(timezone.utc),
|
||||
)
|
||||
.options(selectinload(RoomInvite.room))
|
||||
.options(selectinload(RoomInvite.room), selectinload(RoomInvite.inviter))
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.models import Message
|
||||
|
||||
@@ -22,6 +23,7 @@ async def list_recent_messages(
|
||||
result = await db.execute(
|
||||
select(Message)
|
||||
.where(Message.room_id == room_id)
|
||||
.options(selectinload(Message.user))
|
||||
.order_by(Message.created_at.desc())
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
@@ -49,6 +49,11 @@ async def test_invite_accept_flow(client, db_session):
|
||||
assert resp.status_code == 201
|
||||
invite = resp.json()
|
||||
assert invite["status"] == "pending"
|
||||
assert invite["target_username"] == "bob"
|
||||
|
||||
resp = await client.get(f"/api/rooms/{room['id']}/invites")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()[0]["target_username"] == "bob"
|
||||
|
||||
await client.post("/api/auth/logout")
|
||||
await login_as(client, "bob")
|
||||
@@ -58,6 +63,8 @@ async def test_invite_accept_flow(client, db_session):
|
||||
mine = resp.json()
|
||||
assert len(mine) == 1
|
||||
assert mine[0]["id"] == invite["id"]
|
||||
assert mine[0]["room_name"] == room["name"]
|
||||
assert mine[0]["invited_by_username"] == "alice"
|
||||
|
||||
resp = await client.post(f"/api/invites/{invite['id']}/accept")
|
||||
assert resp.status_code == 200
|
||||
|
||||
@@ -60,8 +60,8 @@ def test_ws_join_and_message_roundtrip(ws_client):
|
||||
|
||||
resp = ws_client.get(f"/api/rooms/{room['id']}/messages")
|
||||
assert resp.status_code == 200
|
||||
contents = [m["content"] for m in resp.json()]
|
||||
assert "hello" in contents
|
||||
history = resp.json()
|
||||
assert any(m["content"] == "hello" and m["username"] == username for m in history)
|
||||
|
||||
|
||||
def test_ws_message_without_join_errors(ws_client):
|
||||
|
||||
Reference in New Issue
Block a user