get_active_presence_idle_user_ids: Check notifiability more thoroughly.

* Have the `get_active_presence_idle_user_ids` function look at all the
user data, not just `private_message` and `mentioned`.
* Fix a couple of incorrect `missedmessage_hook` tests, which did not
catch the earlier behaviour.
* Add some comments to the tests for this function for clarity.
* Add a helper to create `UserMessageNotificationsData` objects from the
user ID lists. This will later help us deduplicate code in the event_queue
logic.

This fixes a bug which earlier existed, that if a user turned on stream
notifications, and received a message in that stream which did not mention
them, they wouldn't be in the `presence_idle_users` list, and hence would
never get notifications for that message.

Note that, after this commit, users might still not get notifications in
the above scenarios in some cases, because the downstream logic in the
notification queue consumers sometimes erroneously skips sending
notifications for stream messages.
This commit is contained in:
Abhijeet Prasad Bodas
2021-06-18 17:46:16 +05:30
committed by Tim Abbott
parent aeb2ad5f46
commit 5c483e3b58
4 changed files with 79 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Collection
from typing import Collection, Set
@dataclass
@@ -19,6 +19,31 @@ class UserMessageNotificationsData:
if self.wildcard_mention_notify:
assert "wildcard_mentioned" in self.flags
@classmethod
def from_user_id_sets(
cls,
user_id: int,
flags: Collection[str],
online_push_user_ids: Set[int],
stream_push_user_ids: Set[int],
stream_email_user_ids: Set[int],
wildcard_mention_user_ids: Set[int],
muted_sender_user_ids: Set[int],
) -> "UserMessageNotificationsData":
wildcard_mention_notify = (
user_id in wildcard_mention_user_ids and "wildcard_mentioned" in flags
)
return cls(
id=user_id,
flags=flags,
mentioned=("mentioned" in flags),
online_push_enabled=(user_id in online_push_user_ids),
stream_push_notify=(user_id in stream_push_user_ids),
stream_email_notify=(user_id in stream_email_user_ids),
wildcard_mention_notify=wildcard_mention_notify,
sender_is_muted=(user_id in muted_sender_user_ids),
)
# TODO: The following functions should also look at the `enable_offline_push_notifications` and
# `enable_offline_email_notifications` settings (for PMs and mentions), but currently they
# don't.