Skip to content

Commit e4c7860

Browse files
committed
chat,user: pipe back FriendChatId in user, debug checks on StartChat
1 parent 0dd205a commit e4c7860

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ require (
131131
gopkg.in/yaml.v2 v2.4.0 // indirect
132132
gopkg.in/yaml.v3 v3.0.1 // indirect
133133
)
134+
135+
replace github.com/code-payments/code-protobuf-api => github.com/mfycheng/code-protobuf-api v0.0.0-20240917192150-82a26e4a0108

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
121121
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
122122
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
123123
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
124-
github.com/code-payments/code-protobuf-api v1.19.0 h1:md/eJhqltz8dDY0U8hwT/42C3h+kP+W/68D7RMSjqPo=
125-
github.com/code-payments/code-protobuf-api v1.19.0/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
126124
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
127125
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
128126
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
@@ -425,6 +423,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
425423
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
426424
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
427425
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
426+
github.com/mfycheng/code-protobuf-api v0.0.0-20240917192150-82a26e4a0108 h1:pFXpZNkx7E1MfUyf3G6kD95L0aPry98WunNH6nszHWY=
427+
github.com/mfycheng/code-protobuf-api v0.0.0-20240917192150-82a26e4a0108/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
428428
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
429429
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
430430
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=

pkg/code/server/grpc/chat/v2/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package chat_v2
33
import (
44
"context"
55
"database/sql"
6+
"encoding/base64"
67
"fmt"
78
"math"
89
"sync"
@@ -603,7 +604,15 @@ func (s *Server) StartChat(ctx context.Context, req *chatpb.StartChatRequest) (*
603604
return &chatpb.StartChatResponse{Result: chatpb.StartChatResponse_DENIED}, nil
604605
}
605606

606-
// TODO: Further verification
607+
// TODO: Further verification + Enforcement
608+
if !intentRecord.SendPrivatePaymentMetadata.IsChat {
609+
log.Warn("intent is not for chat")
610+
}
611+
612+
expectedChatId := base64.StdEncoding.EncodeToString(chatId[:])
613+
if intentRecord.SendPrivatePaymentMetadata.ChatId != expectedChatId {
614+
log.WithField("expected", expectedChatId).WithField("actual", intentRecord.SendPrivatePaymentMetadata.ChatId).Warn("chat id mismatch")
615+
}
607616
}
608617

609618
// At this point, we assume the relationship is valid, and can proceed to recover or create
@@ -639,7 +648,7 @@ func (s *Server) StartChat(ctx context.Context, req *chatpb.StartChatRequest) (*
639648

640649
err = s.data.ExecuteInTx(ctx, sql.LevelDefault, func(ctx context.Context) error {
641650
chatRecord, err = s.data.GetChatByIdV2(ctx, chatId)
642-
if err != nil && errors.Is(err, chat.ErrChatNotFound) {
651+
if err != nil && !errors.Is(err, chat.ErrChatNotFound) {
643652
return fmt.Errorf("failed to check existing chat: %w", err)
644653
}
645654

pkg/code/server/grpc/user/server.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/code-payments/code-server/pkg/code/common"
2323
code_data "github.com/code-payments/code-server/pkg/code/data"
2424
"github.com/code-payments/code-server/pkg/code/data/account"
25+
chat "github.com/code-payments/code-server/pkg/code/data/chat/v2"
2526
"github.com/code-payments/code-server/pkg/code/data/intent"
2627
"github.com/code-payments/code-server/pkg/code/data/paymentrequest"
2728
"github.com/code-payments/code-server/pkg/code/data/phone"
@@ -701,6 +702,12 @@ func (s *identityServer) GetTwitterUser(ctx context.Context, req *userpb.GetTwit
701702
return nil, status.Error(codes.Internal, "")
702703
}
703704

705+
var friendChatId *commonpb.ChatId
706+
if req.Requestor != nil {
707+
// TODO: Validate the requestor
708+
friendChatId = chat.GetChatId(base58.Encode(req.Requestor.Value), tipAddress.PublicKey().ToBase58(), true).ToProto()
709+
}
710+
704711
return &userpb.GetTwitterUserResponse{
705712
Result: userpb.GetTwitterUserResponse_OK,
706713
TwitterUser: &userpb.TwitterUser{
@@ -710,6 +717,11 @@ func (s *identityServer) GetTwitterUser(ctx context.Context, req *userpb.GetTwit
710717
ProfilePicUrl: record.ProfilePicUrl,
711718
VerifiedType: record.VerifiedType,
712719
FollowerCount: record.FollowerCount,
720+
FriendshipCost: &transactionpb.ExchangeDataWithoutRate{
721+
Currency: "usd",
722+
NativeAmount: 1.0,
723+
},
724+
FriendChatId: friendChatId,
713725
},
714726
}, nil
715727
case twitter.ErrUserNotFound:
@@ -720,7 +732,6 @@ func (s *identityServer) GetTwitterUser(ctx context.Context, req *userpb.GetTwit
720732
log.WithError(err).Warn("failure getting twitter user info")
721733
return nil, status.Error(codes.Internal, "")
722734
}
723-
724735
}
725736

726737
func (s *identityServer) markWebhookAsPending(ctx context.Context, id string) error {

0 commit comments

Comments
 (0)