'Returns:
a Deferred TimelineBatch'

@defer.inlineCallbacks
def _load_filtered_recents(self, room_id, sync_config, now_token, since_token=None, recents=None, newly_joined_room=False):

    with Measure(self.clock, 'load_filtered_recents'):
        timeline_limit = sync_config.filter_collection.timeline_limit()
        block_all_timeline = sync_config.filter_collection.blocks_all_room_timeline()
        if ((recents is None) or newly_joined_room or (timeline_limit < len(recents))):
            limited = True
        else:
            limited = False
        if recents:
            recents = sync_config.filter_collection.filter_room_timeline(recents)
            recents = (yield filter_events_for_client(self.store, sync_config.user.to_string(), recents))
        else:
            recents = []
        if ((not limited) or block_all_timeline):
            defer.returnValue(TimelineBatch(events=recents, prev_batch=now_token, limited=False))
        filtering_factor = 2
        load_limit = max((timeline_limit * filtering_factor), 10)
        max_repeat = 5
        room_key = now_token.room_key
        end_key = room_key
        since_key = None
        if (since_token and (not newly_joined_room)):
            since_key = since_token.room_key
        while (limited and (len(recents) < timeline_limit) and max_repeat):
            (events, end_key) = (yield self.store.get_room_events_stream_for_room(room_id, limit=(load_limit + 1), from_key=since_key, to_key=end_key))
            loaded_recents = sync_config.filter_collection.filter_room_timeline(events)
            loaded_recents = (yield filter_events_for_client(self.store, sync_config.user.to_string(), loaded_recents))
            loaded_recents.extend(recents)
            recents = loaded_recents
            if (len(events) <= load_limit):
                limited = False
                break
            max_repeat -= 1
        if (len(recents) > timeline_limit):
            limited = True
            recents = recents[(- timeline_limit):]
            room_key = recents[0].internal_metadata.before
        prev_batch_token = now_token.copy_and_replace('room_key', room_key)
    defer.returnValue(TimelineBatch(events=recents, prev_batch=prev_batch_token, limited=(limited or newly_joined_room)))
