forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorite.go
51 lines (44 loc) · 1.54 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
// 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"
rpc "github.com/keybase/go-framed-msgpack-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(xp),
Contextified: libkb.NewContextified(g),
}
}
// FavoriteAdd handles the favoriteAdd RPC.
func (h *FavoriteHandler) FavoriteAdd(_ context.Context, arg keybase1.FavoriteAddArg) error {
eng := engine.NewFavoriteAdd(&arg, h.G())
ctx := &engine.Context{}
return engine.RunEngine(eng, ctx)
}
// FavoriteDelete handles the favoriteDelete RPC.
func (h *FavoriteHandler) FavoriteDelete(_ context.Context, arg keybase1.FavoriteDeleteArg) error {
eng := engine.NewFavoriteDelete(&arg, h.G())
ctx := &engine.Context{}
return engine.RunEngine(eng, ctx)
}
// FavoriteList handles the favoriteList RPC.
func (h *FavoriteHandler) FavoriteList(_ context.Context, sessionID int) ([]keybase1.Folder, error) {
eng := engine.NewFavoriteList(h.G())
ctx := &engine.Context{}
if err := engine.RunEngine(eng, ctx); err != nil {
return nil, err
}
return eng.Favorites(), nil
}