Skip to content

Commit f2b2c72

Browse files
author
Jeff Yanta
committed
all: send certain activity feed notifications outside the RPC call
1 parent 65c2420 commit f2b2c72

File tree

2 files changed

+63
-58
lines changed

2 files changed

+63
-58
lines changed

chat/server.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,22 +552,24 @@ func (s *Server) StartChat(ctx context.Context, req *chatpb.StartChatRequest) (*
552552
}
553553

554554
if md.Type == chatpb.Metadata_GROUP {
555-
_, err = activity.SendNotification(
556-
ctx,
557-
s.activityFeeds,
558-
activitypb.ActivityFeedType_TRANSACTION_HISTORY,
559-
userID,
560-
activity.NewCreateGroupNotificationBuilder(
555+
go func() {
556+
_, err = activity.SendNotification(
561557
ctx,
558+
s.activityFeeds,
559+
activitypb.ActivityFeedType_TRANSACTION_HISTORY,
562560
userID,
563-
md.ChatId,
564-
flags.StartGroupFee,
565-
time.Now(),
566-
),
567-
)
568-
if err != nil {
569-
s.log.Warn("Failed to send activity feed notification", zap.Error(err))
570-
}
561+
activity.NewCreateGroupNotificationBuilder(
562+
ctx,
563+
userID,
564+
md.ChatId,
565+
flags.StartGroupFee,
566+
time.Now(),
567+
),
568+
)
569+
if err != nil {
570+
s.log.Warn("Failed to send activity feed notification", zap.Error(err))
571+
}
572+
}()
571573
}
572574
}
573575

messaging/server.go

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)