feat(notifications): honor chat mute in web realtime alerts
Some checks failed
CI / test (push) Failing after 1m30s
Some checks failed
CI / test (push) Failing after 1m30s
This commit is contained in:
@@ -21,6 +21,7 @@ class ChatRead(BaseModel):
|
|||||||
is_saved: bool = False
|
is_saved: bool = False
|
||||||
archived: bool = False
|
archived: bool = False
|
||||||
pinned: bool = False
|
pinned: bool = False
|
||||||
|
muted: bool = False
|
||||||
unread_count: int = 0
|
unread_count: int = 0
|
||||||
unread_mentions_count: int = 0
|
unread_mentions_count: int = 0
|
||||||
pinned_message_id: int | None = None
|
pinned_message_id: int | None = None
|
||||||
|
|||||||
@@ -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)
|
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)
|
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)
|
archived = bool(user_setting and user_setting.archived)
|
||||||
pinned = bool(user_setting and user_setting.pinned)
|
pinned = bool(user_setting and user_setting.pinned)
|
||||||
|
muted = bool(notification_setting and notification_setting.muted)
|
||||||
|
|
||||||
return ChatRead.model_validate(
|
return ChatRead.model_validate(
|
||||||
{
|
{
|
||||||
@@ -137,6 +139,7 @@ async def serialize_chat_for_user(
|
|||||||
"is_saved": chat.is_saved,
|
"is_saved": chat.is_saved,
|
||||||
"archived": archived,
|
"archived": archived,
|
||||||
"pinned": pinned,
|
"pinned": pinned,
|
||||||
|
"muted": muted,
|
||||||
"unread_count": unread_count,
|
"unread_count": unread_count,
|
||||||
"unread_mentions_count": unread_mentions_count,
|
"unread_mentions_count": unread_mentions_count,
|
||||||
"pinned_message_id": chat.pinned_message_id,
|
"pinned_message_id": chat.pinned_message_id,
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ All fields are optional.
|
|||||||
"is_saved": false,
|
"is_saved": false,
|
||||||
"archived": false,
|
"archived": false,
|
||||||
"pinned": false,
|
"pinned": false,
|
||||||
|
"muted": false,
|
||||||
"unread_count": 3,
|
"unread_count": 3,
|
||||||
"unread_mentions_count": 1,
|
"unread_mentions_count": 1,
|
||||||
"pinned_message_id": null,
|
"pinned_message_id": null,
|
||||||
|
|||||||
@@ -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)
|
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)
|
26. Channels - `PARTIAL` (create/post/edit/delete/subscribe/unsubscribe; UX edge-cases still polishing)
|
||||||
27. Channel Types - `DONE` (public/private)
|
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`
|
29. Archive - `DONE`
|
||||||
30. Blacklist - `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)
|
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)
|
||||||
|
|||||||
@@ -135,6 +135,37 @@ async def test_delete_saved_messages_chat_clears_messages_but_keeps_chat(client,
|
|||||||
assert messages_after_delete.json() == []
|
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):
|
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")
|
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")
|
u2 = await _create_verified_user(client, db_session, "pm_u2@example.com", "pm_user_two", "strongpass123")
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export interface Chat {
|
|||||||
is_saved?: boolean;
|
is_saved?: boolean;
|
||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
pinned?: boolean;
|
pinned?: boolean;
|
||||||
|
muted?: boolean;
|
||||||
unread_count?: number;
|
unread_count?: number;
|
||||||
unread_mentions_count?: number;
|
unread_mentions_count?: number;
|
||||||
pinned_message_id?: number | null;
|
pinned_message_id?: number | null;
|
||||||
|
|||||||
@@ -433,6 +433,9 @@ function maybeShowBrowserNotification(
|
|||||||
}
|
}
|
||||||
const chat = useChatStore.getState().chats.find((item) => item.id === chatId);
|
const chat = useChatStore.getState().chats.find((item) => item.id === chatId);
|
||||||
const isMention = hasMentionForUser(message.text, currentUsername);
|
const isMention = hasMentionForUser(message.text, currentUsername);
|
||||||
|
if (!isMention && chat?.muted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!isMention && chat?.type === "private" && !prefs.privateNotifications) {
|
if (!isMention && chat?.type === "private" && !prefs.privateNotifications) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user