def get_active_presence_idle_user_ids(realm: Realm, sender_id: int, message_type: str, active_user_ids: Set[int], user_flags: Dict[(int, List[str])]) -> List[int]:
    '\n    Given a list of active_user_ids, we build up a subset\n    of those users who fit these criteria:\n\n        * They are likely to need notifications (either due\n          to mentions, alert words, or being PM\'ed).\n        * They are no longer "present" according to the\n          UserPresence table.\n    '
    if realm.presence_disabled:
        return []
    is_pm = (message_type == 'private')
    user_ids = set()
    for user_id in active_user_ids:
        flags: Iterable[str] = user_flags.get(user_id, [])
        mentioned = (('mentioned' in flags) or ('wildcard_mentioned' in flags))
        private_message = (is_pm and (user_id != sender_id))
        alerted = ('has_alert_word' in flags)
        if (mentioned or private_message or alerted):
            user_ids.add(user_id)
    return filter_presence_idle_user_ids(user_ids)
Given a list of active_user_ids, we build up a subset
of those users who fit these criteria:

    * They are likely to need notifications (either due
      to mentions, alert words, or being PM'ed).
    * They are no longer "present" according to the
      UserPresence table.
def get_active_presence_idle_user_ids(realm: Realm, sender_id: int, message_type: str, active_user_ids: Set[int], user_flags: Dict[(int, List[str])]) -> List[int]:
    '\n    Given a list of active_user_ids, we build up a subset\n    of those users who fit these criteria:\n\n        * They are likely to need notifications (either due\n          to mentions, alert words, or being PM\'ed).\n        * They are no longer "present" according to the\n          UserPresence table.\n    '
    if realm.presence_disabled:
        return []
    is_pm = (message_type == 'private')
    user_ids = set()
    for user_id in active_user_ids:
        flags: Iterable[str] = user_flags.get(user_id, [])
        mentioned = (('mentioned' in flags) or ('wildcard_mentioned' in flags))
        private_message = (is_pm and (user_id != sender_id))
        alerted = ('has_alert_word' in flags)
        if (mentioned or private_message or alerted):
            user_ids.add(user_id)
    return filter_presence_idle_user_ids(user_ids)