Add username search and improve chat creation UX
All checks were successful
CI / test (push) Successful in 23s
All checks were successful
CI / test (push) Successful in 23s
Backend user search: - Added users search endpoint for @username lookup. - Implemented repository/service/router support with bounded result limits. Web chat creation: - Added API client for /users/search. - Added NewChatPanel for creating private chats via @username search. - Added group/channel creation flow from sidebar. UX refinement: - Hide message composer when no chat is selected. - Show explicit placeholder: 'Выберите чат, чтобы начать переписку'. - Added tsbuildinfo ignore rule.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.users.models import User
|
||||
@@ -31,3 +31,19 @@ async def list_users_by_ids(db: AsyncSession, user_ids: list[int]) -> list[User]
|
||||
return []
|
||||
result = await db.execute(select(User).where(User.id.in_(user_ids)))
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def search_users_by_username(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
query: str,
|
||||
limit: int = 20,
|
||||
exclude_user_id: int | None = None,
|
||||
) -> list[User]:
|
||||
normalized = query.lower().strip().lstrip("@")
|
||||
stmt = select(User).where(func.lower(User.username).like(f"%{normalized}%"))
|
||||
if exclude_user_id is not None:
|
||||
stmt = stmt.where(User.id != exclude_user_id)
|
||||
stmt = stmt.order_by(User.username.asc()).limit(limit)
|
||||
result = await db.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
Reference in New Issue
Block a user