@@ -452,62 +452,65 @@ func (s *Server) SendMessage(ctx context.Context, req *messagingpb.SendMessageRe
452452 return nil , status .Errorf (codes .Internal , "failed to mark intent as fulfilled" )
453453 }
454454
455- paymentAmount , err := intent .GetPaymentAmount (ctx , s .codeData , req .PaymentIntent )
456- if err != nil {
457- log .Warn ("Failed to get payment amount" , zap .Error (err ))
458- return nil , status .Errorf (codes .Internal , "failed to get payment amount" )
459- }
455+ go func () {
456+ ctx := context .Background ()
460457
461- var notificationBuilders []activity.NotificationBuilder
462- switch typed := req .Content [0 ].Type .(type ) {
463- case * messagingpb.Content_Text , * messagingpb.Content_Reply :
464- notificationBuilders = []activity.NotificationBuilder {
465- activity .NewSendListenerMessageNotificationBuilder (
466- ctx ,
467- userID ,
468- req .ChatId ,
469- sent .MessageId ,
470- paymentAmount ,
471- sent .Ts .AsTime (),
472- ),
473- }
474- case * messagingpb.Content_Tip :
475- referenceMessage , err := s .messages .GetMessage (ctx , req .ChatId , typed .Tip .OriginalMessageId )
458+ paymentAmount , err := intent .GetPaymentAmount (ctx , s .codeData , req .PaymentIntent )
476459 if err != nil {
477- log .Warn ("Failed to get reference message" , zap .Error (err ))
478- } else {
460+ log .Warn ("Failed to get payment amount for activity feed notification" , zap .Error (err ))
461+ }
462+
463+ var notificationBuilders []activity.NotificationBuilder
464+ switch typed := req .Content [0 ].Type .(type ) {
465+ case * messagingpb.Content_Text , * messagingpb.Content_Reply :
479466 notificationBuilders = []activity.NotificationBuilder {
480- activity .NewSendTipNotificationBuilder (
467+ activity .NewSendListenerMessageNotificationBuilder (
481468 ctx ,
482469 userID ,
483470 req .ChatId ,
484- referenceMessage .MessageId ,
485- paymentAmount ,
486- sent .Ts .AsTime (),
487- ),
488- activity .NewReceivedTipNotificationBuilder (
489- ctx ,
490- referenceMessage .SenderId ,
491- req .ChatId ,
492- referenceMessage .MessageId ,
471+ sent .MessageId ,
493472 paymentAmount ,
494473 sent .Ts .AsTime (),
495474 ),
496475 }
476+ case * messagingpb.Content_Tip :
477+ referenceMessage , err := s .messages .GetMessage (ctx , req .ChatId , typed .Tip .OriginalMessageId )
478+ if err != nil {
479+ log .Warn ("Failed to get reference message" , zap .Error (err ))
480+ } else {
481+ notificationBuilders = []activity.NotificationBuilder {
482+ activity .NewSendTipNotificationBuilder (
483+ ctx ,
484+ userID ,
485+ req .ChatId ,
486+ referenceMessage .MessageId ,
487+ paymentAmount ,
488+ sent .Ts .AsTime (),
489+ ),
490+ activity .NewReceivedTipNotificationBuilder (
491+ ctx ,
492+ referenceMessage .SenderId ,
493+ req .ChatId ,
494+ referenceMessage .MessageId ,
495+ paymentAmount ,
496+ sent .Ts .AsTime (),
497+ ),
498+ }
499+ }
497500 }
498- }
499- for _ , notificationBuilder := range notificationBuilders {
500- _ , err = activity . SendNotification (
501- ctx ,
502- s . activityFeeds ,
503- activitypb . ActivityFeedType_TRANSACTION_HISTORY ,
504- userID ,
505- notificationBuilder ,
506- )
507- if err != nil {
508- log . Warn ( "Failed to send activity feed notification" , zap . Error ( err ))
501+ for _ , notificationBuilder := range notificationBuilders {
502+ _ , err = activity . SendNotification (
503+ ctx ,
504+ s . activityFeeds ,
505+ activitypb . ActivityFeedType_TRANSACTION_HISTORY ,
506+ userID ,
507+ notificationBuilder ,
508+ )
509+ if err != nil {
510+ log . Warn ( "Failed to send activity feed notification" , zap . Error ( err ))
511+ }
509512 }
510- }
513+ }()
511514 }
512515
513516 return & messagingpb.SendMessageResponse {
0 commit comments