@@ -11,16 +11,21 @@ import (
1111 "github.com/sirupsen/logrus"
1212 "google.golang.org/grpc/codes"
1313 "google.golang.org/grpc/status"
14+ "google.golang.org/protobuf/proto"
1415
16+ chatpb "github.com/code-payments/code-protobuf-api/generated/go/chat/v1"
1517 commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
1618 transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2"
1719
1820 "github.com/code-payments/code-server/pkg/code/balance"
1921 chat_util "github.com/code-payments/code-server/pkg/code/chat"
2022 "github.com/code-payments/code-server/pkg/code/common"
2123 "github.com/code-payments/code-server/pkg/code/data/account"
24+ "github.com/code-payments/code-server/pkg/code/data/chat"
25+ "github.com/code-payments/code-server/pkg/code/localization"
2226 push_util "github.com/code-payments/code-server/pkg/code/push"
2327 currency_lib "github.com/code-payments/code-server/pkg/currency"
28+ "github.com/code-payments/code-server/pkg/database/query"
2429 "github.com/code-payments/code-server/pkg/grpc/client"
2530 "github.com/code-payments/code-server/pkg/jupiter"
2631 "github.com/code-payments/code-server/pkg/kin"
@@ -493,6 +498,31 @@ func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Con
493498 }
494499 swapNotificationTimeByOwner [owner .PublicKey ().ToBase58 ()] = time .Now ()
495500
501+ chatId := chat_util .GetKinPurchasesChatId (owner )
502+
503+ // Inspect the chat history for a USDC deposited message. If that message
504+ // doesn't exist, then avoid sending the swap in progress chat message, since
505+ // it can lead to user confusion.
506+ chatMessageRecords , err := s .data .GetAllChatMessages (ctx , chatId , query .WithDirection (query .Descending ), query .WithLimit (1 ))
507+ switch err {
508+ case nil :
509+ var protoChatMessage chatpb.ChatMessage
510+ err := proto .Unmarshal (chatMessageRecords [0 ].Data , & protoChatMessage )
511+ if err != nil {
512+ return
513+ }
514+
515+ switch typed := protoChatMessage .Content [0 ].Type .(type ) {
516+ case * chatpb.Content_Localized :
517+ if typed .Localized .KeyOrText != localization .ChatMessageUsdcDeposited {
518+ return
519+ }
520+ }
521+ case chat .ErrMessageNotFound :
522+ default :
523+ return
524+ }
525+
496526 chatMessage , err := chat_util .NewUsdcBeingConvertedMessage ()
497527 if err != nil {
498528 return
0 commit comments