Skip to content

Commit 448bcd2

Browse files
committed
Fix useLatestUpdateInJobs to support actions issued in jobs
1 parent 98c869a commit 448bcd2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/Telegram/Bot/Simple/Conversation.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,25 @@ conversationBot toConversation BotApp{..} = BotApp
5757
-- This enables jobs to easily send notifications.
5858
useLatestUpdateInJobs
5959
:: BotApp model action
60-
-> BotApp (Maybe Telegram.Update, model) (Either Telegram.Update action)
60+
-> BotApp (Maybe Telegram.Update, model) (Maybe Telegram.Update, action)
6161
useLatestUpdateInJobs BotApp{..} = BotApp
6262
{ botInitialModel = (Nothing, botInitialModel)
6363
, botAction = newAction
6464
, botHandler = newHandler
6565
, botJobs = newJobs
6666
}
6767
where
68-
newAction update _ = Just (Left update)
69-
newHandler (Left update) (_, model) = do
70-
case botAction update model of
71-
Nothing -> pure ()
72-
Just action -> eff (pure (Right action))
73-
pure (Just update, model)
74-
newHandler (Right action) (update, model) =
75-
bimap Right (update,) (botHandler action model)
68+
newAction update (_, model) = (Just update,) <$> botAction update model
69+
70+
newHandler (update, action) (_update, model) =
71+
bimap (update,) (update,) $
72+
-- re-enforcing update here is needed for actions issued in jobs
73+
setEffUpdate update (botHandler action model)
7674

7775
newJobs = map addUpdateToJob botJobs
7876

7977
addUpdateToJob BotJob{..} = BotJob
8078
{ botJobSchedule = botJobSchedule
8179
, botJobTask = \(update, model) ->
82-
bimap Right (update,) (setEffUpdate update (botJobTask model))
80+
bimap (update,) (update,) (setEffUpdate update (botJobTask model))
8381
}

0 commit comments

Comments
 (0)