github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/commands/mute.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 Mute struct {
    14  	*baseCommand
    15  }
    16  
    17  func NewMute(g *globals.Context) *Mute {
    18  	return &Mute{
    19  		baseCommand: newBaseCommand(g, "mute", "", "Mute the current conversation", false, "shh"),
    20  	}
    21  }
    22  
    23  func (h *Mute) 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, "Mute")()
    26  	if !h.Match(ctx, text) {
    27  		return ErrInvalidCommand
    28  	}
    29  	ib, _, err := h.G().InboxSource.Read(ctx, uid, types.ConversationLocalizerBlocking,
    30  		types.InboxSourceDataSourceAll, nil,
    31  		&chat1.GetInboxLocalQuery{
    32  			ConvIDs: []chat1.ConversationID{convID},
    33  		})
    34  	if err != nil {
    35  		return err
    36  	}
    37  	if len(ib.Convs) == 0 {
    38  		return errors.New("no conversation found")
    39  	}
    40  	status := chat1.ConversationStatus_MUTED
    41  	if ib.Convs[0].Info.Status == chat1.ConversationStatus_MUTED {
    42  		status = chat1.ConversationStatus_UNFILED
    43  	}
    44  	return h.G().InboxSource.RemoteSetConversationStatus(ctx, uid, convID, status)
    45  }