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

     1  package commands
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/keybase/client/go/chat/globals"
     7  	"github.com/keybase/client/go/chat/types"
     8  	"github.com/keybase/client/go/chat/utils"
     9  	"github.com/keybase/client/go/protocol/chat1"
    10  	"github.com/keybase/client/go/protocol/gregor1"
    11  )
    12  
    13  type Headline struct {
    14  	*baseCommand
    15  }
    16  
    17  func NewHeadline(g *globals.Context) *Headline {
    18  	return &Headline{
    19  		baseCommand: newBaseCommand(g, "headline", "<description>",
    20  			"Set the team channel topic", false, "topic"),
    21  	}
    22  }
    23  
    24  func (s *Headline) Execute(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
    25  	tlfName, text string, replyTo *chat1.MessageID) (err error) {
    26  	defer s.Trace(ctx, &err, "Execute")()
    27  	if !s.Match(ctx, text) {
    28  		return ErrInvalidCommand
    29  	}
    30  	defer func() {
    31  		if err != nil {
    32  			_ = s.getChatUI().ChatCommandStatus(ctx, convID, "Failed to set channel headline",
    33  				chat1.UICommandStatusDisplayTyp_ERROR, nil)
    34  		}
    35  	}()
    36  	_, msg, err := s.commandAndMessage(text)
    37  	if err != nil {
    38  		return err
    39  	}
    40  	conv, err := utils.GetVerifiedConv(ctx, s.G(), uid, convID, types.InboxSourceDataSourceAll)
    41  	if err != nil {
    42  		return err
    43  	}
    44  	return s.G().ChatHelper.SendMsgByID(ctx, convID, tlfName,
    45  		chat1.NewMessageBodyWithHeadline(chat1.MessageHeadline{
    46  			Headline: msg,
    47  		}), chat1.MessageType_HEADLINE, conv.Info.Visibility)
    48  }