Skip to content

Fix notification spam bug by persisting notification state across module reloads#130

Merged
maorun merged 3 commits intomasterfrom
copilot/fix-cfe2423d-32fa-47c5-ba2b-3d41d88fdfe2
Oct 1, 2025
Merged

Fix notification spam bug by persisting notification state across module reloads#130
maorun merged 3 commits intomasterfrom
copilot/fix-cfe2423d-32fa-47c5-ba2b-3d41d88fdfe2

Conversation

Copy link
Contributor

Copilot AI commented Oct 1, 2025

Problem

Users were experiencing constant "Daily goal exceeded!" notifications since the last feature commit. The notifications would appear repeatedly whenever performing common operations like viewing the weekly overview or adding time entries, even when the daily goal notification was configured for oncePerDay = true.

Root Cause

The notification state tracking was stored in a module-local variable that gets reset every time the Lua module is reloaded:

-- This state was lost on module reload
local notification_state = {
    dailyGoal = {
        lastNotification = {}, -- Lost on reload!
        lastRecurringNotification = {},
    },
    coreHours = {
        lastNotification = {},
    },
}

Since checkDailyGoalNotification() is called from within the calculate() function, and calculate() is invoked frequently (weekly overview, adding time, etc.), users would see repeated notifications whenever these operations reset the notification tracking state.

Solution

This PR implements persistent notification state by:

  1. Adding state persistence functions:

    • loadNotificationState() - Loads notification state from the JSON data file
    • saveNotificationState() - Saves notification state to the JSON data file
  2. Integrating with existing data storage:

    • Notification state is now stored in config_module.obj.content.notificationState
    • State is loaded during plugin initialization after JSON data is read
    • State is automatically saved whenever notifications are triggered or modified
  3. Maintaining all existing functionality:

    • Once-per-day notifications continue to work correctly
    • Recurring notifications with configurable intervals still work
    • Mode switching between notification types is preserved
    • Cleanup of old notification entries still functions

Changes Made

  • Modified M.init() to load notification state after JSON data is loaded
  • Updated notification functions to save state when modified:
    • checkDailyGoalNotification()
    • checkCoreHoursCompliance()
    • _handleModeSwitch()
  • Fixed function name typo in cleanup call
  • Applied code formatting with stylua

Testing

All existing tests continue to pass (169/169), ensuring no regressions were introduced. The fix specifically addresses the notification spam issue while preserving all existing notification functionality.

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>mit letzten commit ein bug</issue_title>
<issue_description>ich bekomme ständig "Daily goal exceeded! ..." seit dem letzten feature-commit.

Berücksichtige die komplette copilot-instructions.md</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #129

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 1, 2025 07:26
Co-authored-by: maorun <2291503+maorun@users.noreply.github.com>
Co-authored-by: maorun <2291503+maorun@users.noreply.github.com>
Copilot AI changed the title [WIP] mit letzten commit ein bug Fix notification spam bug by persisting notification state across module reloads Oct 1, 2025
Copilot AI requested a review from maorun October 1, 2025 07:28
@maorun maorun marked this pull request as ready for review October 1, 2025 07:47
@maorun maorun merged commit c0df5f5 into master Oct 1, 2025
5 of 6 checks passed
@maorun maorun deleted the copilot/fix-cfe2423d-32fa-47c5-ba2b-3d41d88fdfe2 branch October 1, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mit letzten commit ein bug

2 participants