human
Solve the following python programming problem given the following code:
@defer.inlineCallbacks
def filter_events_for_clients(store, user_tuples, events, event_id_to_state):
assistant
#Here is the Python code you requested.

    """Returns dict of user_id -> list of events that user is allowed to
    see.
    Args:
    user_tuples (str, bool): (user id, is_peeking) for each user to be
    checked. is_peeking should be true if:
    * the user is not currently a member of the room, and:
    * the user has not been a member of the room since the
    given events
    events ([synapse.events.EventBase]): list of events to filter
    """
    forgotten = (yield preserve_context_over_deferred(defer.gatherResults([defer.maybeDeferred(preserve_fn(store.who_forgot_in_room), room_id) for room_id in frozenset((e.room_id for e in events))], consumeErrors=True)))
    event_id_forgotten = frozenset((row['event_id'] for rows in forgotten for row in rows))
    ignore_dict_content = (yield store.get_global_account_data_by_type_for_users('m.ignored_user_list', user_ids=[user_id for (user_id, _) in user_tuples]))
    ignore_dict = {user_id: frozenset((content.get('ignored_users', {}).keys() if content else [])) for (user_id, content) in ignore_dict_content.items()}
    def allowed(event, user_id, is_peeking, ignore_list):
        '\n                                Args:\n                                                event    (synapse.events.EventBase):    event    to    check\n                                                user_id    (str)\n                                                is_peeking    (bool)\n                                                ignore_list    (list):    list    of    users    to    ignore\n                                '
        if ((not event.is_state()) and (event.sender in ignore_list)):
            return False
        state = event_id_to_state[event.event_id]
        visibility_event = state.get((EventTypes.RoomHistoryVisibility, ''), None)
        if visibility_event:
            visibility = visibility_event.content.get('history_visibility', 'shared')
        else:
            visibility = 'shared'
        if (visibility not in VISIBILITY_PRIORITY):
            visibility = 'shared'
        if (visibility == 'world_readable'):
            return True
        if (event.type == EventTypes.RoomHistoryVisibility):
            prev_content = event.unsigned.get('prev_content', {})
            prev_visibility = prev_content.get('history_visibility', None)
            if (prev_visibility not in VISIBILITY_PRIORITY):
                prev_visibility = 'shared'
            new_priority = VISIBILITY_PRIORITY.index(visibility)
  ...