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

New feature: dismiss event from notification #781

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

For next releases info look here: <https://github.com/leits/MeetingBar/releases>

## Version 4.11.0

> (released)

* Added action to dismiss the event from the notification

## Version 4.0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I added to the changelogs as requested but they both seem out of date. Are they deprecated? Should I updated the PR template?


> (released)
Expand Down
45 changes: 20 additions & 25 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,40 +223,35 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
}

func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

defer {
completionHandler()
}

guard ["EVENT", "SNOOZE_EVENT"].contains(response.notification.request.content.categoryIdentifier),
let eventID = response.notification.request.content.userInfo["eventID"] as? String,
let event = statusBarItem.events.first(where: { $0.ID == eventID }) else {
return
}
switch response.actionIdentifier {
case "JOIN_ACTION", UNNotificationDefaultActionIdentifier:
if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" {
if let eventID = response.notification.request.content.userInfo["eventID"] as? String {
if let event = statusBarItem.events.first(where: { $0.ID == eventID }) {
event.openMeeting()
}
}
}
event.openMeeting()
case "DISMISS_ACTION":
statusBarItem.dismiss(event: event)
case NotificationEventTimeAction.untilStart.rawValue:
handleSnoozeEvent(response, NotificationEventTimeAction.untilStart)
snoozeEventNotification(event, NotificationEventTimeAction.untilStart)
case NotificationEventTimeAction.fiveMinuteLater.rawValue:
handleSnoozeEvent(response, NotificationEventTimeAction.fiveMinuteLater)
snoozeEventNotification(event, NotificationEventTimeAction.fiveMinuteLater)
case NotificationEventTimeAction.tenMinuteLater.rawValue:
handleSnoozeEvent(response, NotificationEventTimeAction.tenMinuteLater)
snoozeEventNotification(event, NotificationEventTimeAction.tenMinuteLater)
case NotificationEventTimeAction.fifteenMinuteLater.rawValue:
handleSnoozeEvent(response, NotificationEventTimeAction.fifteenMinuteLater)
snoozeEventNotification(event, NotificationEventTimeAction.fifteenMinuteLater)
case NotificationEventTimeAction.thirtyMinuteLater.rawValue:
handleSnoozeEvent(response, NotificationEventTimeAction.thirtyMinuteLater)
snoozeEventNotification(event, NotificationEventTimeAction.thirtyMinuteLater)
default:
break
}

completionHandler()
}

func handleSnoozeEvent(_ response: UNNotificationResponse, _ action: NotificationEventTimeAction) {
if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" {
if let eventID = response.notification.request.content.userInfo["eventID"] as? String {
if let event = statusBarItem.events.first(where: { $0.ID == eventID }) {
snoozeEventNotification(event, action)
}
}
}
}

/*
Expand Down Expand Up @@ -335,7 +330,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
}

@objc
func openPrefecencesWindow(_: NSStatusBarButton?) {
func openPreferencesWindow(_: NSStatusBarButton?) {
let contentView = PreferencesView()

if let preferencesWindow {
Expand Down Expand Up @@ -402,7 +397,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
if let string = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue,
let url = URL(string: string) {
if url == URL(string: "meetingbar://preferences") {
openPrefecencesWindow(nil)
openPreferencesWindow(nil)
} else {
GCEventStore.shared
.currentAuthorizationFlow?.resumeExternalUserAgentFlow(with: url)
Expand Down
4 changes: 2 additions & 2 deletions MeetingBar/I18N.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class I18N {
if appLanguage == .system {
resetToDefault()
return true
} else if let newBunlde = checkLanguageAvailability(appLanguage.rawValue) {
bundle = newBunlde
} else if let newBundle = checkLanguageAvailability(appLanguage.rawValue) {
bundle = newBundle
locale = Locale(identifier: appLanguage.rawValue)
return true
}
Expand Down
8 changes: 6 additions & 2 deletions MeetingBar/Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func registerNotificationCategories() {
title: "notifications_meetingbar_join_event_action".loco(),
options: .foreground)

let dismissAction = UNNotificationAction(identifier: "DISMISS_ACTION",
title: "notifications_meetingbar_dismiss_event_action".loco(),
options: .foreground)

let snoozeUntilStartTime = UNNotificationAction(identifier: NotificationEventTimeAction.untilStart.rawValue,
title: "notifications_snooze_until_start".loco(),
options: .foreground)
Expand All @@ -42,13 +46,13 @@ func registerNotificationCategories() {
options: .foreground)

let eventCategory = UNNotificationCategory(identifier: "EVENT",
actions: [acceptAction, snoozeUntilStartTime, snooze5Min, snooze10Min, snooze15Min, snooze30Min],
actions: [acceptAction, dismissAction, snoozeUntilStartTime, snooze5Min, snooze10Min, snooze15Min, snooze30Min],
intentIdentifiers: [],
hiddenPreviewsBodyPlaceholder: "",
options: [.customDismissAction, .hiddenPreviewsShowTitle])

let snoozeEventCategory = UNNotificationCategory(identifier: "SNOOZE_EVENT",
actions: [acceptAction, snooze5Min, snooze10Min, snooze15Min, snooze30Min],
actions: [acceptAction, dismissAction, snooze5Min, snooze10Min, snooze15Min, snooze30Min],
intentIdentifiers: [],
hiddenPreviewsBodyPlaceholder: "",
options: [.customDismissAction, .hiddenPreviewsShowTitle])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
"notifications_event_ends_one_minute_body" = "The event ends in one minute";
"notifications_event_ends_three_minutes_body" = "The event ends in three minutes";
"notifications_event_ends_five_minutes_body" = "The event ends in five minutes";
"notifications_meetingbar_dismiss_event_action" = "Dismiss";

// MARK: - Link open

Expand Down
18 changes: 11 additions & 7 deletions MeetingBar/StatusBarItemController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ class StatusBarItemController {
quickActionsItem.submenu!.addItem(toggleMeetingTitleVisibilityItem)
}

// MENU ITEM: QUICK ACTIONS: Refresh soruces
// MENU ITEM: QUICK ACTIONS: Refresh sources
let refreshSourcesItem = NSMenuItem()
refreshSourcesItem.title = "status_bar_section_refresh_sources".loco()
refreshSourcesItem.action = #selector(refreshSources)
Expand Down Expand Up @@ -842,7 +842,7 @@ class StatusBarItemController {

statusItemMenu.addItem(
withTitle: "\("status_bar_preferences".loco())…",
action: #selector(AppDelegate.openPrefecencesWindow),
action: #selector(AppDelegate.openPreferencesWindow),
keyEquivalent: ","
)

Expand Down Expand Up @@ -940,14 +940,18 @@ class StatusBarItemController {
@objc
func dismissEvent(sender: NSMenuItem) {
if let event: MBEvent = sender.representedObject as? MBEvent {
let dismissedEvent = ProcessedEvent(id: event.ID, lastModifiedDate: event.lastModifiedDate, eventEndDate: event.endDate)
Defaults[.dismissedEvents].append(dismissedEvent)

updateTitle()
updateMenu()
dismiss(event: event)
}
}

func dismiss(event: MBEvent) {
let dismissedEvent = ProcessedEvent(id: event.ID, lastModifiedDate: event.lastModifiedDate, eventEndDate: event.endDate)
Defaults[.dismissedEvents].append(dismissedEvent)

updateTitle()
updateMenu()
}

@objc
func undismissEvent(sender: NSMenuItem) {
if let event: MBEvent = sender.representedObject as? MBEvent {
Expand Down
5 changes: 5 additions & 0 deletions MeetingBar/Views/Changelog/Changelog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ struct ChangelogView: View {
Text("🌍 Translation into Slovak and Dutch")
}
}
if compareVersions("4.11.0", lastRevisedVersionInChangelog) {
Section(header: Text("Version 4.11")) {
Text("Added action to dismiss the event from the notification")
}
}
}
}.listStyle(SidebarListStyle())
Button("general_close".loco(), action: close)
Expand Down
Loading