'Returns the entry for a room'

@cachedInlineCallbacks(num_args=1, cache_context=True)
def _generate_room_entry(self, room_id, num_joined_users, cache_context):

    result = {'room_id': room_id, 'num_joined_members': num_joined_users}
    current_state_ids = (yield self.store.get_current_state_ids(room_id, on_invalidate=cache_context.invalidate))
    event_map = (yield self.store.get_events([event_id for (key, event_id) in current_state_ids.iteritems() if (key[0] in (EventTypes.JoinRules, EventTypes.Name, EventTypes.Topic, EventTypes.CanonicalAlias, EventTypes.RoomHistoryVisibility, EventTypes.GuestAccess, 'm.room.avatar'))]))
    current_state = {(ev.type, ev.state_key): ev for ev in event_map.values()}
    join_rules_event = current_state.get((EventTypes.JoinRules, ''))
    if join_rules_event:
        join_rule = join_rules_event.content.get('join_rule', None)
        if (join_rule and (join_rule != JoinRules.PUBLIC)):
            defer.returnValue(None)
    aliases = (yield self.store.get_aliases_for_room(room_id, on_invalidate=cache_context.invalidate))
    if aliases:
        result['aliases'] = aliases
    name_event = (yield current_state.get((EventTypes.Name, '')))
    if name_event:
        name = name_event.content.get('name', None)
        if name:
            result['name'] = name
    topic_event = current_state.get((EventTypes.Topic, ''))
    if topic_event:
        topic = topic_event.content.get('topic', None)
        if topic:
            result['topic'] = topic
    canonical_event = current_state.get((EventTypes.CanonicalAlias, ''))
    if canonical_event:
        canonical_alias = canonical_event.content.get('alias', None)
        if canonical_alias:
            result['canonical_alias'] = canonical_alias
    visibility_event = current_state.get((EventTypes.RoomHistoryVisibility, ''))
    visibility = None
    if visibility_event:
        visibility = visibility_event.content.get('history_visibility', None)
    result['world_readable'] = (visibility == 'world_readable')
    guest_event = current_state.get((EventTypes.GuestAccess, ''))
    guest = None
    if guest_event:
        guest = guest_event.content.get('guest_access', None)
    result['guest_can_join'] = (guest == 'can_join')
    avatar_event = current_state.get(('m.room.avatar', ''))
    if avatar_event:
        avatar_url = avatar_event.content.get('url', None)
        if avatar_url:
            result['avatar_url'] = avatar_url
    defer.returnValue(result)
