github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/storage/pinignore.go (about) 1 package storage 2 3 import ( 4 "fmt" 5 6 "github.com/keybase/client/go/chat/globals" 7 "github.com/keybase/client/go/chat/utils" 8 "github.com/keybase/client/go/libkb" 9 "github.com/keybase/client/go/protocol/chat1" 10 "github.com/keybase/client/go/protocol/gregor1" 11 "golang.org/x/net/context" 12 ) 13 14 type PinIgnore struct { 15 globals.Contextified 16 utils.DebugLabeler 17 18 uid gregor1.UID 19 } 20 21 func NewPinIgnore(g *globals.Context, uid gregor1.UID) *PinIgnore { 22 return &PinIgnore{ 23 Contextified: globals.NewContextified(g), 24 DebugLabeler: utils.NewDebugLabeler(g.ExternalG(), "PinIgnore", false), 25 uid: uid, 26 } 27 } 28 29 func (p *PinIgnore) dbKey(convID chat1.ConversationID) libkb.DbKey { 30 return libkb.DbKey{ 31 Typ: libkb.DBChatPinIgnore, 32 Key: fmt.Sprintf("%s:%s", p.uid, convID), 33 } 34 } 35 36 func (p *PinIgnore) IsIgnored(ctx context.Context, convID chat1.ConversationID, msgID chat1.MessageID) bool { 37 var ignoredMsgID chat1.MessageID 38 found, err := p.G().GetKVStore().GetInto(&ignoredMsgID, p.dbKey(convID)) 39 if err != nil { 40 p.Debug(ctx, "IsIgnored: failed to read from storage: %s", err) 41 return false 42 } 43 if !found { 44 return false 45 } 46 return msgID == ignoredMsgID 47 } 48 49 func (p *PinIgnore) Ignore(ctx context.Context, convID chat1.ConversationID, msgID chat1.MessageID) error { 50 return p.G().GetKVStore().PutObj(p.dbKey(convID), nil, msgID) 51 }