diff --git a/app/chats/schemas.py b/app/chats/schemas.py index 41abebf..afd0e0e 100644 --- a/app/chats/schemas.py +++ b/app/chats/schemas.py @@ -21,6 +21,7 @@ class ChatRead(BaseModel): is_saved: bool = False archived: bool = False pinned: bool = False + muted: bool = False unread_count: int = 0 unread_mentions_count: int = 0 pinned_message_id: int | None = None diff --git a/app/chats/service.py b/app/chats/service.py index 00d5cda..84d3d9f 100644 --- a/app/chats/service.py +++ b/app/chats/service.py @@ -120,8 +120,10 @@ async def serialize_chat_for_user( ) last_message = await repository.get_last_visible_message_for_user(db, chat_id=chat.id, user_id=user_id) user_setting = await repository.get_chat_user_setting(db, chat_id=chat.id, user_id=user_id) + notification_setting = await repository.get_chat_notification_setting(db, chat_id=chat.id, user_id=user_id) archived = bool(user_setting and user_setting.archived) pinned = bool(user_setting and user_setting.pinned) + muted = bool(notification_setting and notification_setting.muted) return ChatRead.model_validate( { @@ -137,6 +139,7 @@ async def serialize_chat_for_user( "is_saved": chat.is_saved, "archived": archived, "pinned": pinned, + "muted": muted, "unread_count": unread_count, "unread_mentions_count": unread_mentions_count, "pinned_message_id": chat.pinned_message_id, diff --git a/docs/api-reference.md b/docs/api-reference.md index 960e54e..e490f8c 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -231,6 +231,7 @@ All fields are optional. "is_saved": false, "archived": false, "pinned": false, + "muted": false, "unread_count": 3, "unread_mentions_count": 1, "pinned_message_id": null, diff --git a/docs/core-checklist-status.md b/docs/core-checklist-status.md index 68fdaa0..bf30abd 100644 --- a/docs/core-checklist-status.md +++ b/docs/core-checklist-status.md @@ -34,7 +34,7 @@ Legend: 25. Admin Rights - `PARTIAL` (delete/pin/edit info + explicit ban API for groups/channels; integration tests cover channel member read-only, channel admin full-delete, channel message delete-for-all permissions, group profile edit permissions, and owner-only role management rules; remaining UX moderation tools limited) 26. Channels - `PARTIAL` (create/post/edit/delete/subscribe/unsubscribe; UX edge-cases still polishing) 27. Channel Types - `DONE` (public/private) -28. Notifications - `PARTIAL` (browser notifications + mute/settings; no mobile push infra) +28. Notifications - `PARTIAL` (browser notifications + mute/settings; chat mute is now propagated in chat list payload and honored by web realtime notifications with mention override; no mobile push infra) 29. Archive - `DONE` 30. Blacklist - `DONE` 31. Privacy - `PARTIAL` (avatar/last-seen/group-invites + PM policy `everyone|contacts|nobody`; group-invite `nobody` is available in API and web settings; integration tests cover PM policy matrix (`everyone/contacts/nobody`), group-invite policy matrix (`everyone/contacts/nobody`), and private chat counterpart visibility for `nobody/contacts`, remaining UX/matrix hardening) diff --git a/tests/test_chat_message_flow.py b/tests/test_chat_message_flow.py index d080d36..39cbeb0 100644 --- a/tests/test_chat_message_flow.py +++ b/tests/test_chat_message_flow.py @@ -135,6 +135,37 @@ async def test_delete_saved_messages_chat_clears_messages_but_keeps_chat(client, assert messages_after_delete.json() == [] +async def test_chat_list_includes_notification_muted_flag(client, db_session): + u1 = await _create_verified_user(client, db_session, "muted_flag_u1@example.com", "muted_flag_u1", "strongpass123") + u2 = await _create_verified_user(client, db_session, "muted_flag_u2@example.com", "muted_flag_u2", "strongpass123") + + me_u2 = await client.get("/api/v1/auth/me", headers={"Authorization": f"Bearer {u2['access_token']}"}) + u2_id = me_u2.json()["id"] + + create_chat_response = await client.post( + "/api/v1/chats", + headers={"Authorization": f"Bearer {u1['access_token']}"}, + json={"type": ChatType.PRIVATE.value, "title": None, "member_ids": [u2_id]}, + ) + assert create_chat_response.status_code == 200 + chat_id = create_chat_response.json()["id"] + + mute_response = await client.put( + f"/api/v1/chats/{chat_id}/notifications", + headers={"Authorization": f"Bearer {u1['access_token']}"}, + json={"muted": True}, + ) + assert mute_response.status_code == 200 + assert mute_response.json()["muted"] is True + + chats_response = await client.get("/api/v1/chats", headers={"Authorization": f"Bearer {u1['access_token']}"}) + assert chats_response.status_code == 200 + rows = chats_response.json() + row = next((item for item in rows if item["id"] == chat_id), None) + assert row is not None + assert row["muted"] is True + + async def test_private_chat_respects_contacts_only_policy(client, db_session): u1 = await _create_verified_user(client, db_session, "pm_u1@example.com", "pm_user_one", "strongpass123") u2 = await _create_verified_user(client, db_session, "pm_u2@example.com", "pm_user_two", "strongpass123") diff --git a/web/src/chat/types.ts b/web/src/chat/types.ts index 0a87811..415d6be 100644 --- a/web/src/chat/types.ts +++ b/web/src/chat/types.ts @@ -15,6 +15,7 @@ export interface Chat { is_saved?: boolean; archived?: boolean; pinned?: boolean; + muted?: boolean; unread_count?: number; unread_mentions_count?: number; pinned_message_id?: number | null; diff --git a/web/src/hooks/useRealtime.ts b/web/src/hooks/useRealtime.ts index 3e6d1bd..c56297b 100644 --- a/web/src/hooks/useRealtime.ts +++ b/web/src/hooks/useRealtime.ts @@ -433,6 +433,9 @@ function maybeShowBrowserNotification( } const chat = useChatStore.getState().chats.find((item) => item.id === chatId); const isMention = hasMentionForUser(message.text, currentUsername); + if (!isMention && chat?.muted) { + return; + } if (!isMention && chat?.type === "private" && !prefs.privateNotifications) { return; }