44import io .github .opendonationassistant .commons .logging .ODALogger ;
55import io .github .opendonationassistant .events .CompletedPaymentNotification ;
66import io .github .opendonationassistant .events .widget .Widget ;
7+ import io .github .opendonationassistant .events .widget .WidgetCommandSender ;
8+ import io .github .opendonationassistant .events .widget .WidgetConfig ;
9+ import io .github .opendonationassistant .events .widget .WidgetProperty ;
10+ import io .github .opendonationassistant .events .widget .WidgetUpdateCommand ;
711import java .util .List ;
812import java .util .Map ;
913import java .util .Random ;
@@ -16,14 +20,17 @@ public class Reel {
1620 private final ReelCommandSender commandSender ;
1721 private final ReelDataRepository repository ;
1822 private final Random random ;
23+ private final WidgetCommandSender widgetSender ;
1924
2025 public Reel (
2126 ReelData data ,
2227 ReelCommandSender commandSender ,
23- ReelDataRepository repository
28+ ReelDataRepository repository ,
29+ WidgetCommandSender widgetSender
2430 ) {
2531 this .data = data ;
2632 this .commandSender = commandSender ;
33+ this .widgetSender = widgetSender ;
2734 this .repository = repository ;
2835 this .random = new Random ();
2936 }
@@ -35,7 +42,7 @@ public void handlePayment(CompletedPaymentNotification payment) {
3542 if (data .items () == null || data .items ().isEmpty ()) {
3643 return ;
3744 }
38- if (!data .enabled ()){
45+ if (!data .enabled ()) {
3946 return ;
4047 }
4148 log .info (
@@ -51,6 +58,27 @@ public void handlePayment(CompletedPaymentNotification payment) {
5158 command .setWidgetId (data .widgetConfigId ());
5259 command .setPaymentId (payment .id ());
5360 command .setRecipientId (payment .recipientId ());
61+ widgetSender .send (
62+ new WidgetUpdateCommand (
63+ data .widgetConfigId (),
64+ new WidgetConfig (
65+ List .of (
66+ new WidgetProperty (
67+ "requiredAmount" ,
68+ "widget-reel-required-amount" ,
69+ "number" ,
70+ data .requiredAmount ().getMajor () + data .stepAmount ().getMajor ()
71+ )
72+ )
73+ )
74+ )
75+ );
76+ try {
77+ Thread .sleep (30000 );
78+ } catch (InterruptedException e ) {
79+ // TODO Auto-generated catch block
80+ e .printStackTrace ();
81+ }
5482 log .info ("Send reel command" , Map .of ("command" , command ));
5583 commandSender .send ("reel" , command );
5684 }
@@ -72,6 +100,11 @@ public Reel update(Widget widget) {
72100 new Amount ((Integer ) property .value (), 0 , "RUB" )
73101 );
74102 }
103+ if ("stepAmount" .equals (property .name ())) {
104+ return data .withStepAmount (
105+ new Amount ((Integer ) property .value (), 0 , "RUB" )
106+ );
107+ }
75108 return data ;
76109 },
77110 (first , second ) -> {
@@ -80,6 +113,6 @@ public Reel update(Widget widget) {
80113 );
81114 log .info ("Update reel" , Map .of ("data" , updatedData ));
82115 repository .update (updatedData );
83- return new Reel (updatedData , commandSender , repository );
116+ return new Reel (updatedData , commandSender , repository , widgetSender );
84117 }
85118}
0 commit comments