Fixed Multiple-Nag Bug by Refactoring in-app New Campaign Handling #5357
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For a good long while there has been a weird bug where sometimes advancing day would cause nag dialogs to trigger multiple times. This became more noticeable with the introduction of the Turnover module, as that nags users on a monthly basis increasing the likelihood users will interact with this bug.
It's taken me literal months to track down and identify the cause of this bug. It turns out that when a user creates a new campaign, from within an existing campaign, event listeners are not unregistered causing all events to be triggered multiple times. For example, it would mean that any New Day event would be triggered twice. Technically, it would trigger once for each new in-app campaign created. Create 20 new campaigns, one after the other, without exiting mhq? Your new day events would trigger 20 times.
However, if we unregister these event listeners and the user happened to cancel out of the in-app new campaign dialog then no events would trigger until the campaign was reloaded or mhq exited.
Previously we've papered over in-app new campaign issues by having a dialog pop-up advising the user not to cancel once they pass a certain point. That worked well enough for the old 'preset' bug, but that wouldn't work here. At least, not without a really poor play experience.
Instead, what I've done is passed some logic down the chain so that a few things happen when a player triggers an in-app new campaign: