Skip to content

Commit ebe902b

Browse files
author
Jeff Yanta
committed
messaging: fix listener message activity notifications and integrate tips
1 parent a766c0d commit ebe902b

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

intent/payment_metadata.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ var (
2020
ErrInvalidPaymentMetadata = errors.New("invalid payment metadata")
2121
)
2222

23+
func GetPaymentAmount(ctx context.Context, codeData codedata.Provider, intentID *commonpb.IntentId) (uint64, error) {
24+
intentRecord, err := codeData.GetIntent(ctx, model.IntentIDString(intentID))
25+
if err == codeintent.ErrIntentNotFound {
26+
return 0, ErrNoPaymentMetadata
27+
} else if err != nil {
28+
return 0, err
29+
}
30+
return intentRecord.SendPublicPaymentMetadata.Quantity, nil
31+
}
32+
2333
func LoadPaymentMetadata(ctx context.Context, codeData codedata.Provider, intentID *commonpb.IntentId, dst proto.Message) (*codeintent.Record, error) {
2434
intentRecord, err := codeData.GetIntent(ctx, model.IntentIDString(intentID))
2535
if err == codeintent.ErrIntentNotFound {

messaging/server.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,44 @@ 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-
_, err = activity.SendNotification(
456-
ctx,
457-
s.activityFeeds,
458-
activitypb.ActivityFeedType_TRANSACTION_HISTORY,
459-
userID,
460-
activity.NewSendListenerMessageNotificationBuilder(
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+
}
460+
461+
var notificationBuilder activity.NotificationBuilder
462+
switch req.Content[0].Type.(type) {
463+
case *messagingpb.Content_Text, *messagingpb.Content_Reply:
464+
notificationBuilder = activity.NewSendListenerMessageNotificationBuilder(
461465
ctx,
462466
userID,
463467
req.ChatId,
464468
sent.MessageId,
465-
flags.StartGroupFee,
469+
paymentAmount,
466470
sent.Ts.AsTime(),
467-
),
468-
)
469-
if err != nil {
470-
log.Warn("Failed to send activity feed notification", zap.Error(err))
471+
)
472+
case *messagingpb.Content_Tip:
473+
notificationBuilder = activity.NewSendTipNotificationBuilder(
474+
ctx,
475+
userID,
476+
req.ChatId,
477+
sent.MessageId,
478+
paymentAmount,
479+
sent.Ts.AsTime(),
480+
)
481+
}
482+
if notificationBuilder != nil {
483+
_, err = activity.SendNotification(
484+
ctx,
485+
s.activityFeeds,
486+
activitypb.ActivityFeedType_TRANSACTION_HISTORY,
487+
userID,
488+
notificationBuilder,
489+
)
490+
if err != nil {
491+
log.Warn("Failed to send activity feed notification", zap.Error(err))
492+
}
471493
}
472494
}
473495

0 commit comments

Comments
 (0)