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