/
kbfs_favorites_handler.go
75 lines (58 loc) · 2.03 KB
/
kbfs_favorites_handler.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// Handlers for KBFS-favorites-related gregor messages
package service
import (
"fmt"
"strings"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
"github.com/keybase/client/go/gregor"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/gregor1"
)
const kbfsFavoritesHandlerName = "kbfsFavoritesHandler"
type kbfsFavoritesHandler struct {
libkb.Contextified
}
var _ libkb.GregorInBandMessageHandler = (*kbfsFavoritesHandler)(nil)
func newKBFSFavoritesHandler(g *libkb.GlobalContext) *kbfsFavoritesHandler {
return &kbfsFavoritesHandler{
Contextified: libkb.NewContextified(g),
}
}
func (r *kbfsFavoritesHandler) Create(ctx context.Context, cli gregor1.IncomingInterface,
category string, item gregor.Item) (bool, error) {
switch category {
case "kbfs.favorites":
return true, r.favoritesChanged(ctx, cli, item)
default:
if strings.HasPrefix(category, "kbfs.") {
return false, fmt.Errorf("unknown KBFS category: %q", category)
}
return false, nil
}
}
func (r *kbfsFavoritesHandler) Dismiss(ctx context.Context, cli gregor1.IncomingInterface, category string, item gregor.Item) (bool, error) {
return false, nil
}
func (r *kbfsFavoritesHandler) IsAlive() bool {
return true
}
func (r *kbfsFavoritesHandler) Name() string {
return kbfsFavoritesHandlerName
}
func (r *kbfsFavoritesHandler) favoritesChanged(ctx context.Context,
cli gregor1.IncomingInterface,
item gregor.Item) error {
r.G().Log.CDebugf(ctx, "kbfsFavoritesHandler: kbfs."+
"favorites received")
// We will locally dismiss for now so that each client only plays them once:
if err := r.G().GregorState.LocalDismissItem(ctx, item.Metadata().MsgID()); err != nil {
r.G().Log.CDebugf(ctx,
"failed to locally dismiss favoritesChanged notification: %s", err)
}
kbUID := keybase1.UID(item.Metadata().UID().String())
r.Contextified.G().NotifyRouter.HandleFavoritesChanged(kbUID)
return nil
}