/
ephemeral_handler.go
72 lines (57 loc) · 1.96 KB
/
ephemeral_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
// Handlers for ephemeral-related gregor messages
package service
import (
"encoding/json"
"fmt"
"strings"
"golang.org/x/net/context"
"github.com/keybase/client/go/ephemeral"
"github.com/keybase/client/go/gregor"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/gregor1"
"github.com/keybase/client/go/protocol/keybase1"
)
const ekHandlerName = "ephemeralHandler"
type ekHandler struct {
libkb.Contextified
}
var _ libkb.GregorInBandMessageHandler = (*ekHandler)(nil)
func newEKHandler(g *libkb.GlobalContext) *ekHandler {
return &ekHandler{
Contextified: libkb.NewContextified(g),
}
}
func (r *ekHandler) Create(ctx context.Context, cli gregor1.IncomingInterface, category string, item gregor.Item) (bool, error) {
switch category {
case "ephemeral.new_team_ek":
return true, r.newTeamEK(ctx, cli, item)
default:
if strings.HasPrefix(category, "ephemeral.") {
return false, fmt.Errorf("unknown ekHandler category: %q", category)
}
return false, nil
}
}
func (r *ekHandler) Dismiss(ctx context.Context, cli gregor1.IncomingInterface, category string, item gregor.Item) (bool, error) {
return false, nil
}
func (r *ekHandler) IsAlive() bool {
return true
}
func (r *ekHandler) Name() string {
return ekHandlerName
}
func (r *ekHandler) newTeamEK(ctx context.Context, cli gregor1.IncomingInterface, item gregor.Item) error {
r.G().Log.CDebugf(ctx, "ekHandler: ephemeral.new_team_ek received")
var msg keybase1.NewTeamEkArg
if err := json.Unmarshal(item.Body().Bytes(), &msg); err != nil {
r.G().Log.CDebugf(ctx, "error unmarshaling ephemeral.new_team_ek item: %s", err)
return err
}
r.G().Log.CDebugf(ctx, "ephemeral.new_team_ek unmarshaled: %+v", msg)
if err := ephemeral.HandleNewTeamEK(ctx, r.G(), msg.Id, msg.Generation); err != nil {
return err
}
r.G().Log.CDebugf(ctx, "dismissing ephemeral.new_team_ek item since action succeeded")
return r.G().GregorDismisser.DismissItem(ctx, cli, item.Metadata().MsgID())
}