Skip to content

Commit b83bfec

Browse files
authored
Include convID with SendMiniChatPayments (keybase#15089)
* Add chatConversationID to PaymentDirectPost * Include ChatConversationID when sending MiniChatPayment * Fix tests * Rebuild * Add chatConversationID to PaymentDirectPost * Fix mock * Who knows
1 parent 3d187d7 commit b83bfec

17 files changed

Lines changed: 76 additions & 25 deletions

File tree

‎go/chat/server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ func (h *Server) runStellarSendUI(ctx context.Context, sessionID int, uid gregor
12331233
return res, errors.New("Payment message declined")
12341234
}
12351235
h.Debug(ctx, "runStellarSendUI: message confirmed, sending payments")
1236-
payments, err := h.G().StellarSender.SendPayments(ctx, toSend)
1236+
payments, err := h.G().StellarSender.SendPayments(ctx, convID, toSend)
12371237
if err != nil {
12381238
// Send regardless here
12391239
h.Debug(ctx, "runStellarSendUI: failed to send payments, but continuing on: %s", err)

‎go/chat/server_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5348,7 +5348,7 @@ type mockStellar struct {
53485348
specFn func([]libkb.MiniChatPayment) (*libkb.MiniChatPaymentSummary, error)
53495349
}
53505350

5351-
func (m *mockStellar) SendMiniChatPayments(mctx libkb.MetaContext, payments []libkb.MiniChatPayment) (res []libkb.MiniChatPaymentResult, err error) {
5351+
func (m *mockStellar) SendMiniChatPayments(mctx libkb.MetaContext, convID chat1.ConversationID, payments []libkb.MiniChatPayment) (res []libkb.MiniChatPaymentResult, err error) {
53525352
for _, p := range payments {
53535353
res = append(res, libkb.MiniChatPaymentResult{
53545354
Username: p.Username,

‎go/chat/types/interfaces.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ type StellarSender interface {
367367
body string) []ParsedStellarPayment
368368
DescribePayments(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
369369
payments []ParsedStellarPayment) (chat1.UIChatPaymentSummary, []ParsedStellarPayment, error)
370-
SendPayments(ctx context.Context, payments []ParsedStellarPayment) ([]chat1.TextPayment, error)
371370
DecorateWithPayments(ctx context.Context, body string, payments []chat1.TextPayment) string
371+
SendPayments(ctx context.Context, convID chat1.ConversationID, payments []ParsedStellarPayment) ([]chat1.TextPayment, error)
372372
}
373373

374374
type ConversationBackedStorage interface {

‎go/chat/types/types.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (d DummyStellarSender) DescribePayments(ctx context.Context, uid gregor1.UI
372372
return res, toSend, nil
373373
}
374374

375-
func (d DummyStellarSender) SendPayments(ctx context.Context, payments []ParsedStellarPayment) ([]chat1.TextPayment, error) {
375+
func (d DummyStellarSender) SendPayments(ctx context.Context, convID chat1.ConversationID, payments []ParsedStellarPayment) ([]chat1.TextPayment, error) {
376376
return nil, nil
377377
}
378378

‎go/chat/wallet/sender.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ func (s *Sender) DescribePayments(ctx context.Context, uid gregor1.UID, convID c
181181
return res, toSend, nil
182182
}
183183

184-
func (s *Sender) SendPayments(ctx context.Context, payments []types.ParsedStellarPayment) (res []chat1.TextPayment, err error) {
184+
func (s *Sender) SendPayments(ctx context.Context, convID chat1.ConversationID, payments []types.ParsedStellarPayment) (res []chat1.TextPayment, err error) {
185185
defer s.Trace(ctx, func() error { return err }, "SendPayments")()
186186
usernameToFull := make(map[string]string)
187187
var minis []libkb.MiniChatPayment
188188
for _, p := range payments {
189189
minis = append(minis, p.ToMini())
190190
usernameToFull[p.Username.String()] = p.Full
191191
}
192-
paymentRes, err := s.G().GetStellar().SendMiniChatPayments(s.G().MetaContext(ctx), minis)
192+
paymentRes, err := s.G().GetStellar().SendMiniChatPayments(s.G().MetaContext(ctx), convID, minis)
193193
if err != nil {
194194
return res, err
195195
}

‎go/chat/wallet/sender_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type mockStellar struct {
4848
miniFn func([]libkb.MiniChatPayment) ([]libkb.MiniChatPaymentResult, error)
4949
}
5050

51-
func (m *mockStellar) SendMiniChatPayments(mctx libkb.MetaContext, payments []libkb.MiniChatPayment) (res []libkb.MiniChatPaymentResult, err error) {
51+
func (m *mockStellar) SendMiniChatPayments(mctx libkb.MetaContext, convID chat1.ConversationID, payments []libkb.MiniChatPayment) (res []libkb.MiniChatPaymentResult, err error) {
5252
return m.miniFn(payments)
5353
}
5454

@@ -130,7 +130,7 @@ func TestStellarSender(t *testing.T) {
130130
mi.partsFn = partsFn
131131
ms.miniFn = miniFn
132132
parsedPayments := sender.ParsePayments(context.TODO(), senderUID, convID, body)
133-
res, err := sender.SendPayments(context.TODO(), parsedPayments)
133+
res, err := sender.SendPayments(context.TODO(), convID, parsedPayments)
134134
require.NoError(t, err)
135135
require.Equal(t, len(expected), len(res))
136136
for index, r := range expected {

‎go/libkb/interfaces.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ type Stellar interface {
700700
UpdateUnreadCount(ctx context.Context, accountID stellar1.AccountID, unread int) error
701701
GetMigrationLock() *sync.Mutex
702702
SpecMiniChatPayments(mctx MetaContext, payments []MiniChatPayment) (*MiniChatPaymentSummary, error)
703-
SendMiniChatPayments(mctx MetaContext, payments []MiniChatPayment) ([]MiniChatPaymentResult, error)
703+
SendMiniChatPayments(mctx MetaContext, convID chat1.ConversationID, payments []MiniChatPayment) ([]MiniChatPaymentResult, error)
704704
HandleOobm(context.Context, gregor.OutOfBandMessage) (bool, error)
705705
}
706706

‎go/libkb/stellar_stub.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync"
88

99
"github.com/keybase/client/go/gregor"
10+
"github.com/keybase/client/go/protocol/chat1"
1011
stellar1 "github.com/keybase/client/go/protocol/stellar1"
1112
)
1213

@@ -42,7 +43,7 @@ func (n *nullStellar) UpdateUnreadCount(context.Context, stellar1.AccountID, int
4243

4344
func (n *nullStellar) GetMigrationLock() *sync.Mutex { return new(sync.Mutex) }
4445

45-
func (n *nullStellar) SendMiniChatPayments(mctx MetaContext, payments []MiniChatPayment) ([]MiniChatPaymentResult, error) {
46+
func (n *nullStellar) SendMiniChatPayments(mctx MetaContext, convID chat1.ConversationID, payments []MiniChatPayment) ([]MiniChatPaymentResult, error) {
4647
return nil, errors.New("nullStellar SendMiniChatPayments")
4748
}
4849

‎go/protocol/chat1/notify.go‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/protocol/stellar1/extras.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,10 @@ func (b BuildPaymentID) IsNil() bool {
381381
func (b BuildPaymentID) Eq(other BuildPaymentID) bool {
382382
return b == other
383383
}
384+
385+
func NewChatConversationID(b []byte) *ChatConversationID {
386+
c := make([]byte, len(b))
387+
copy(c, b)
388+
cid := ChatConversationID(c)
389+
return &cid
390+
}

0 commit comments

Comments
 (0)