github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/favorite.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package service
     5  
     6  import (
     7  	"github.com/keybase/client/go/engine"
     8  	"github.com/keybase/client/go/libkb"
     9  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    10  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    11  	"golang.org/x/net/context"
    12  )
    13  
    14  // FavoriteHandler implements the keybase1.Favorite protocol
    15  type FavoriteHandler struct {
    16  	*BaseHandler
    17  	libkb.Contextified
    18  }
    19  
    20  // NewFavoriteHandler creates a FavoriteHandler with the xp
    21  // protocol.
    22  func NewFavoriteHandler(xp rpc.Transporter, g *libkb.GlobalContext) *FavoriteHandler {
    23  	return &FavoriteHandler{
    24  		BaseHandler:  NewBaseHandler(g, xp),
    25  		Contextified: libkb.NewContextified(g),
    26  	}
    27  }
    28  
    29  // FavoriteAdd handles the favoriteAdd RPC.
    30  func (h *FavoriteHandler) FavoriteAdd(ctx context.Context, arg keybase1.FavoriteAddArg) error {
    31  	eng := engine.NewFavoriteAdd(h.G(), &arg)
    32  	uis := libkb.UIs{
    33  		IdentifyUI: h.NewRemoteIdentifyUI(arg.SessionID, h.G()),
    34  	}
    35  	m := libkb.NewMetaContext(ctx, h.G()).WithUIs(uis)
    36  	return engine.RunEngine2(m, eng)
    37  }
    38  
    39  // FavoriteIgnore handles the favoriteIgnore RPC.
    40  func (h *FavoriteHandler) FavoriteIgnore(ctx context.Context, arg keybase1.FavoriteIgnoreArg) error {
    41  	eng := engine.NewFavoriteIgnore(h.G(), &arg)
    42  	m := libkb.NewMetaContext(ctx, h.G())
    43  	return engine.RunEngine2(m, eng)
    44  }
    45  
    46  // FavoriteList handles the favoriteList RPC.
    47  func (h *FavoriteHandler) GetFavorites(ctx context.Context, sessionID int) (keybase1.FavoritesResult, error) {
    48  	eng := engine.NewFavoriteList(h.G())
    49  	m := libkb.NewMetaContext(ctx, h.G())
    50  	if err := engine.RunEngine2(m, eng); err != nil {
    51  		return keybase1.FavoritesResult{}, err
    52  	}
    53  	return eng.Result(), nil
    54  }