You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: join.go
    path of file: ./repos/td/telegram/message
    
    the code of the file until where you have to start completion: package message

import (
	"context"

	"github.com/go-faster/errors"

	"github.com/gotd/td/telegram/internal/deeplink"
	"github.com/gotd/td/telegram/message/peer"
	"github.com/gotd/td/tg"
	"github.com/gotd/td/tgerr"
)

// JoinLink joins to private chat using given link or hash.
// Input examples:
//
//	t.me/+AAAAAAAAAAAAAAAA
//	https://t.me/+AAAAAAAAAAAAAAAA
//	t.me/joinchat/AAAAAAAAAAAAAAA
    
func (b *RequestBuilder) leave(ctx context.Context, revoke bool) (tg.UpdatesClass, error) {
	p, err := b.peer(ctx)
	if err != nil {
		return nil, errors.Wrap(err, "peer")
	}

	input, ok := peer.ToInputChannel(p)
	if ok {
		r, err := b.sender.leaveChannel(ctx, input)
		if err != nil {
			return nil, errors.Wrap(err, "leave channel")
		}
		return r, nil
	}

	chat, ok := p.(*tg.InputPeerChat)
	if !ok {
		return &tg.Updates{}, nil
	}

	r, err := b.sender.deleteChatUser(ctx, &tg.MessagesDeleteChatUserRequest{
		RevokeHistory: revoke,
		ChatID:        chat.ChatID,
		UserID:        &tg.InputUserSelf{},
	})
	if err != nil {
		// Happens if chat was deactivated.
		if tgerr.Is(err, tg.ErrPeerIDInvalid) {
			return &tg.Updates{}, nil
		}
		return nil, errors.Wrap(err, "leave chat")
	}
	return r, nil
}