Compare commits
10 Commits
b13cd05b45
...
a2e74105c5
Author | SHA1 | Date | |
---|---|---|---|
a2e74105c5 | |||
49cfb9c649 | |||
22fac48796 | |||
4fdc64c03b | |||
b4ee5f77b8 | |||
3b6c3e28f3 | |||
1a28ab584a | |||
68f2975201 | |||
77eaceb152 | |||
37b638712c |
@ -82,7 +82,3 @@ func (s State) LogError(err error) {
|
||||
func (s State) Move(mc fsm.MachineControls[Wizard], stateID fsm.StateID, pl *Wizard) {
|
||||
s.LogError(mc.Move(stateID, pl))
|
||||
}
|
||||
|
||||
func (s State) MoveForHandle(mc fsm.MachineControls[Wizard], stateID fsm.StateID, pl *Wizard) {
|
||||
s.LogError(mc.MoveForHandle(stateID, pl))
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ func (s *WaitingForMemberWebhookState) Enter(pl *Wizard, mc fsm.MachineControls[
|
||||
}
|
||||
if !cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
|
||||
cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
|
||||
s.MoveForHandle(mc, AddChatMemberStateID, pl)
|
||||
s.Move(mc, AddChatMemberStateID, pl)
|
||||
return nil
|
||||
}
|
||||
if cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
|
||||
!cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
|
||||
s.MoveForHandle(mc, RemoveChatMemberStateID, pl)
|
||||
s.Move(mc, RemoveChatMemberStateID, pl)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ type Machine[T any] struct {
|
||||
initialState StateID
|
||||
states *types.Map[StateID, IState[T]]
|
||||
errHandler ErrorState[T]
|
||||
handleNow bool
|
||||
}
|
||||
|
||||
// New machine.
|
||||
@ -90,11 +89,6 @@ func (m *Machine[T]) Move(id StateID, payload *T) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Machine[T]) MoveForHandle(id StateID, payload *T) error {
|
||||
m.handleNow = true
|
||||
return m.Move(id, payload)
|
||||
}
|
||||
|
||||
// Handle the input.
|
||||
func (m *Machine[T]) Handle(provider MachineStateProvider[T]) error {
|
||||
if provider != nil {
|
||||
@ -107,14 +101,8 @@ func (m *Machine[T]) Handle(provider MachineStateProvider[T]) error {
|
||||
if st == nil || err != nil {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
st.Handle(m.payload, m)
|
||||
if m.handleNow { // MoveForHandle was called, trying to handle again.
|
||||
m.handleNow = false
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// State of the Machine.
|
||||
|
@ -10,8 +10,6 @@ const NilStateID = StateID("")
|
||||
// It may fail with an error which should be handled by the IState implementation.
|
||||
type MachineControls[T any] interface {
|
||||
Move(StateID, *T) error
|
||||
// MoveForHandle is the same as Move but it also triggers Handle immediately for the next state.
|
||||
MoveForHandle(StateID, *T) error
|
||||
Reset()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user