feat(notifications): per-chat mute settings
Some checks failed
CI / test (push) Failing after 18s

- add chat_notification_settings table and migration
- add chat notifications API (get/update muted)
- skip message notifications for muted recipients
- add mute/unmute control in chat info panel
This commit is contained in:
2026-03-08 02:17:09 +03:00
parent eddd4bda0b
commit ea8a50ee05
9 changed files with 238 additions and 3 deletions

View File

@@ -4,7 +4,16 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.chats import repository
from app.chats.models import Chat, ChatMember, ChatMemberRole, ChatType
from app.chats.schemas import ChatCreateRequest, ChatDeleteRequest, ChatDiscoverRead, ChatPinMessageRequest, ChatRead, ChatTitleUpdateRequest
from app.chats.schemas import (
ChatCreateRequest,
ChatDeleteRequest,
ChatDiscoverRead,
ChatNotificationSettingsRead,
ChatNotificationSettingsUpdate,
ChatPinMessageRequest,
ChatRead,
ChatTitleUpdateRequest,
)
from app.messages.repository import (
delete_messages_in_chat,
get_hidden_message,
@@ -420,3 +429,41 @@ async def clear_chat_for_user(db: AsyncSession, *, chat_id: int, user_id: int) -
continue
await hide_message_for_user(db, message_id=message_id, user_id=user_id)
await db.commit()
async def get_chat_notification_settings_for_user(
db: AsyncSession,
*,
chat_id: int,
user_id: int,
) -> ChatNotificationSettingsRead:
await ensure_chat_membership(db, chat_id=chat_id, user_id=user_id)
setting = await repository.get_chat_notification_setting(db, chat_id=chat_id, user_id=user_id)
return ChatNotificationSettingsRead(
chat_id=chat_id,
user_id=user_id,
muted=bool(setting and setting.muted),
)
async def update_chat_notification_settings_for_user(
db: AsyncSession,
*,
chat_id: int,
user_id: int,
payload: ChatNotificationSettingsUpdate,
) -> ChatNotificationSettingsRead:
await ensure_chat_membership(db, chat_id=chat_id, user_id=user_id)
setting = await repository.upsert_chat_notification_setting(
db,
chat_id=chat_id,
user_id=user_id,
muted=payload.muted,
)
await db.commit()
await db.refresh(setting)
return ChatNotificationSettingsRead(
chat_id=chat_id,
user_id=user_id,
muted=setting.muted,
)