'Encode the invited rooms in a sync result
Args:
rooms(list[synapse.handlers.sync.InvitedSyncResult]): list of
sync results for rooms this user is joined to
time_now(int): current time - used as a baseline for age
calculations
token_id(int): ID of the user\'s auth token - used for namespacing
of transaction IDs
Returns:
dict[str, dict[str, object]]: the invited rooms list, in our
response format'

def encode_invited(self, rooms, time_now, token_id):

    invited = {}
    for room in rooms:
        invite = serialize_event(room.invite, time_now, token_id=token_id, event_format=format_event_for_client_v2_without_room_id, is_invite=True)
        unsigned = dict(invite.get('unsigned', {}))
        invite['unsigned'] = unsigned
        invited_state = list(unsigned.pop('invite_room_state', []))
        invited_state.append(invite)
        invited[room.room_id] = {'invite_state': {'events': invited_state}}
    return invited
