'Given an event context return the rules for all users who are
currently in the room.'

@defer.inlineCallbacks
def get_rules(self, event, context):

    state_group = context.state_group
    with (yield self.linearizer.queue(())):
        if (state_group and (self.state_group == state_group)):
            logger.debug('Using    cached    rules    for    %r', self.room_id)
            defer.returnValue(self.rules_by_user)
        ret_rules_by_user = {}
        missing_member_event_ids = {}
        if (state_group and (self.state_group == context.prev_group)):
            ret_rules_by_user = self.rules_by_user
            current_state_ids = context.delta_ids
        else:
            current_state_ids = context.current_state_ids
        logger.debug('Looking    for    member    changes    in    %r    %r', state_group, current_state_ids)
        for key in current_state_ids:
            (typ, user_id) = key
            if (typ != EventTypes.Member):
                continue
            if (user_id in self.uninteresting_user_set):
                continue
            if (not self.is_mine_id(user_id)):
                self.uninteresting_user_set.add(user_id)
                continue
            if self.store.get_if_app_services_interested_in_user(user_id):
                self.uninteresting_user_set.add(user_id)
                continue
            event_id = current_state_ids[key]
            res = self.member_map.get(event_id, None)
            if res:
                (user_id, state) = res
                if (state == Membership.JOIN):
                    rules = self.rules_by_user.get(user_id, None)
                    if rules:
                        ret_rules_by_user[user_id] = rules
                continue
            ret_rules_by_user.pop(user_id, None)
            missing_member_event_ids[user_id] = event_id
        if missing_member_event_ids:
            logger.debug('Found    new    member    events    %r', missing_member_event_ids)
            (yield self._update_rules_with_member_event_ids(ret_rules_by_user, missing_member_event_ids, state_group, event))
    if logger.isEnabledFor(logging.DEBUG):
        logger.debug('Returning    push    rules    for    %r    %r', self.room_id, ret_rules_by_user.keys())
    defer.returnValue(ret_rules_by_user)
