Skip to content

Commit

Permalink
journeycard persistent storage (keybase#20754)
Browse files Browse the repository at this point in the history
* persistence

* lint

* pin db key to uid
  • Loading branch information
mlsteele authored Nov 5, 2019
1 parent 436ef7a commit c0afbee
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 60 deletions.
13 changes: 11 additions & 2 deletions go/chat/convsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"errors"
"fmt"
"sort"
"time"

"github.com/keybase/client/go/chat/attachments"
"github.com/keybase/client/go/chat/globals"
"github.com/keybase/client/go/chat/storage"
"github.com/keybase/client/go/chat/types"
"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/gregor1"
context "golang.org/x/net/context"
Expand Down Expand Up @@ -88,7 +90,10 @@ func (s *baseConversationSource) addPendingPreviews(ctx context.Context, thread

func (s *baseConversationSource) addConversationCards(ctx context.Context, uid gregor1.UID,
convID chat1.ConversationID, convOptional *chat1.ConversationLocal, thread *chat1.ThreadView) {
card, err := s.G().JourneyCardManager.PickCard(ctx, uid, convID, convOptional, thread)
ctxShort, ctxShortCancel := context.WithTimeout(ctx, 2*time.Second)
defer ctxShortCancel()
card, err := s.G().JourneyCardManager.PickCard(ctxShort, uid, convID, convOptional, thread)
ctxShortCancel()
if err != nil {
s.Debug(ctx, "addConversationCards: error getting next conversation card: %s", err)
return
Expand Down Expand Up @@ -222,6 +227,7 @@ func (s *baseConversationSource) patchPaginationLast(ctx context.Context, conv t

func (s *baseConversationSource) PullFull(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, reason chat1.GetThreadReason,
query *chat1.GetThreadQuery, maxPages *int) (res chat1.ThreadView, err error) {
ctx = libkb.WithLogTag(ctx, "PUL")
pagination := &chat1.Pagination{
Num: 300,
}
Expand Down Expand Up @@ -292,6 +298,7 @@ func (s *RemoteConversationSource) PushUnboxed(ctx context.Context, convID chat1

func (s *RemoteConversationSource) Pull(ctx context.Context, convID chat1.ConversationID,
uid gregor1.UID, reason chat1.GetThreadReason, query *chat1.GetThreadQuery, pagination *chat1.Pagination) (chat1.ThreadView, error) {
ctx = libkb.WithLogTag(ctx, "PUL")

if convID.IsNil() {
return chat1.ThreadView{}, errors.New("RemoteConversationSource.Pull called with empty convID")
Expand Down Expand Up @@ -489,7 +496,7 @@ func (s *HybridConversationSource) Push(ctx context.Context, convID chat1.Conver
return decmsg, continuousUpdate, err
}
if msg.ClientHeader.Sender.Eq(uid) {
go s.G().JourneyCardManager.SentMessage(globals.BackgroundChatCtx(ctx, s.G()), convID)
go s.G().JourneyCardManager.SentMessage(globals.BackgroundChatCtx(ctx, s.G()), uid, convID)
}
// Remove any pending previews from storage
s.completeAttachmentUpload(ctx, decmsg)
Expand Down Expand Up @@ -561,6 +568,7 @@ var maxHolesForPull = 50

func (s *HybridConversationSource) Pull(ctx context.Context, convID chat1.ConversationID,
uid gregor1.UID, reason chat1.GetThreadReason, query *chat1.GetThreadQuery, pagination *chat1.Pagination) (thread chat1.ThreadView, err error) {
ctx = libkb.WithLogTag(ctx, "PUL")
defer s.Trace(ctx, func() error { return err }, "Pull(%s)", convID)()
if convID.IsNil() {
return chat1.ThreadView{}, errors.New("HybridConversationSource.Pull called with empty convID")
Expand Down Expand Up @@ -697,6 +705,7 @@ func newPullLocalResultCollector(baseRC storage.ResultCollector) *pullLocalResul

func (s *HybridConversationSource) PullLocalOnly(ctx context.Context, convID chat1.ConversationID,
uid gregor1.UID, query *chat1.GetThreadQuery, pagination *chat1.Pagination, maxPlaceholders int) (tv chat1.ThreadView, err error) {
ctx = libkb.WithLogTag(ctx, "PUL")
defer s.Trace(ctx, func() error { return err }, "PullLocalOnly")()
if _, err = s.lockTab.Acquire(ctx, uid, convID); err != nil {
return tv, err
Expand Down
Loading

0 comments on commit c0afbee

Please sign in to comment.