github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/commands/join.go (about)

     1  package commands
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	"github.com/keybase/client/go/chat/globals"
     8  	"github.com/keybase/client/go/chat/types"
     9  	"github.com/keybase/client/go/protocol/chat1"
    10  	"github.com/keybase/client/go/protocol/gregor1"
    11  )
    12  
    13  type Join struct {
    14  	*baseCommand
    15  }
    16  
    17  func NewJoin(g *globals.Context) *Join {
    18  	return &Join{
    19  		baseCommand: newBaseCommand(g, "join", "", "Join a team channel", false),
    20  	}
    21  }
    22  
    23  func (h *Join) Execute(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
    24  	tlfName, text string, replyTo *chat1.MessageID) (err error) {
    25  	defer h.Trace(ctx, &err, "Join")()
    26  	if !h.Match(ctx, text) {
    27  		return ErrInvalidCommand
    28  	}
    29  	ui, err := h.G().UIRouter.GetChatUI()
    30  	if err != nil {
    31  		return err
    32  	}
    33  	ib, _, err := h.G().InboxSource.Read(ctx, uid, types.ConversationLocalizerBlocking,
    34  		types.InboxSourceDataSourceAll, nil,
    35  		&chat1.GetInboxLocalQuery{
    36  			ConvIDs: []chat1.ConversationID{convID},
    37  		})
    38  	if err != nil {
    39  		return err
    40  	}
    41  	if len(ib.Convs) == 0 {
    42  		return errors.New("conv not found")
    43  	}
    44  	err = ui.ChatShowManageChannels(ctx, ib.Convs[0].Info.TlfName)
    45  	if err != nil {
    46  		h.Debug(ctx, "Execute: error with managing channels: %+v", err)
    47  	}
    48  	return nil
    49  }