Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Regex doesn't filter multiple entries #787

Open
seahindeniz opened this issue Dec 18, 2024 · 1 comment
Open

Bug: Regex doesn't filter multiple entries #787

seahindeniz opened this issue Dec 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@seahindeniz
Copy link

macOS version

15.1

MeetingBar version

4.10.0

Installation source

manually

Calendars provider

Google Calendar

Bug description

I have multiple slots with the same name in my calendar. I sed the regex filter but it only filters out the first match.

Reproduction steps

  1. Create multiple entries on your calendar with the same name
  2. Integrate with the MeetingBar
  3. Use regex filter
  4. Restart the app
  5. Expect the first match in the list gets filtered but not the rest

Expected behavior

The filter should be used for all entries expect the first match

Screenshots/screen recordings

Before the filter:
image

After:
image

Additional context

I believe this is related to this line, but I'm not sure

let hasMatch = regex.firstMatch(in: calendarEvent.title, range: NSRange(calendarEvent.title.startIndex..., in: calendarEvent.title)) != nil
if hasMatch {

@seahindeniz seahindeniz added the bug Something isn't working label Dec 18, 2024
Copy link

dosubot bot commented Dec 18, 2024

Hey @seahindeniz 👋, I'm here to help you with your MeetingBar issue. Let's get this sorted out together!

To address the issue where the regex filter only filters out the first matching event in MeetingBar, you need to modify the filtering logic in the Event.swift file. Specifically, you should ensure that the loop continues to check all regex patterns for each event, rather than stopping after the first match. Here's how you can adjust the code:

In the filterEvents function, replace the logic that breaks out of the loop after finding the first match. Instead of using continue outerloop, allow the loop to continue checking all patterns for each event. Here's the modified code snippet:

func filterEvents(_ events: [MBEvent]) -> [MBEvent] {
    var filteredCalendarEvents: [MBEvent] = []

    for calendarEvent in events {
        var isFiltered = false
        // Filter events based on custom user regexes
        for pattern in Defaults[.filterEventRegexes] {
            if let regex = try? NSRegularExpression(pattern: pattern) {
                let hasMatch = regex.firstMatch(in: calendarEvent.title, range: NSRange(calendarEvent.title.startIndex..., in: calendarEvent.title)) != nil
                if hasMatch {
                    isFiltered = true
                    break // Exit the inner loop if a match is found
                }
            }
        }
        
        if isFiltered {
            continue // Skip this event if it matches any regex
        }

        // The rest of the filtering logic remains unchanged
        if calendarEvent.isAllDay {
            // Filter all day events
            switch Defaults[.allDayEvents] {
            case .show:
                break
            case .show_with_meeting_link_only:
                if calendarEvent.meetingLink?.url == nil {
                    continue // Skip this event
                }
            case .hide:
                continue // Skip this event
            }
        } else {
            // Filter not for all day events
            switch Defaults[.nonAllDayEvents] {
            case .show, .show_inactive_without_meeting_link:
                break
            case .hide_without_meeting_link:
                if calendarEvent.meetingLink?.url == nil {
                    continue // Skip this event
                }
            }
        }

        // Filter pending events
        switch Defaults[.showPendingEvents] {
        case .show, .show_inactive, .show_underlined:
            break
        case .hide:
            if calendarEvent.participationStatus == .pending {
                continue // Skip this event
            }
        }

        // Filter tentative events
        switch Defaults[.showTentativeEvents] {
        case .show, .show_inactive, .show_underlined:
            break
        case .hide:
            if calendarEvent.participationStatus == .tentative {
                continue // Skip this event
            }
        }

        filteredCalendarEvents.append(calendarEvent)
    }
    return filteredCalendarEvents
}

This change ensures that all events matching any of the regex patterns are filtered, not just the first one [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants