From ae775d012017f29f1f1c235ef1e8748af179051c Mon Sep 17 00:00:00 2001 From: dgsasha Date: Mon, 3 Apr 2023 11:57:42 -0400 Subject: [PATCH] Fix issues with notifications on ms reminders --- meson.build | 2 +- po/remembrance.pot | 14 +++++++------- src/browser/application.py | 2 +- src/browser/preferences.py | 1 - src/service/backend.py | 29 +++++++++++++---------------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/meson.build b/meson.build index df9dc23..ec994d9 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,7 @@ dependency('gsound') release_type = get_option('release-type') -service_version = '2.2' +service_version = '2.3' app_executable = 'remembrance' diff --git a/po/remembrance.pot b/po/remembrance.pot index 6fc2d52..3c4820d 100644 --- a/po/remembrance.pot +++ b/po/remembrance.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: remembrance\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-04-03 10:32-0400\n" +"POT-Creation-Date: 2023-04-03 11:58-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -290,7 +290,7 @@ msgstr "" msgid "All" msgstr "" -#: src/browser/resources/ui/ms_user_row.ui:42 src/browser/preferences.py:223 +#: src/browser/resources/ui/ms_user_row.ui:42 src/browser/preferences.py:222 msgid "Sign Out" msgstr "" @@ -466,7 +466,7 @@ msgstr "" #: src/browser/resources/ui/reminder_edit_window.ui:419 #: src/browser/edit_lists_window.py:78 src/browser/edit_lists_window.py:187 -#: src/browser/main_window.py:162 src/browser/preferences.py:222 +#: src/browser/main_window.py:162 src/browser/preferences.py:221 #: src/browser/reminder.py:251 msgid "Cancel" msgstr "" @@ -699,11 +699,11 @@ msgstr "" msgid "Start typing to search" msgstr "" -#: src/browser/preferences.py:218 +#: src/browser/preferences.py:217 msgid "Are you sure you want to sign out?" msgstr "" -#: src/browser/preferences.py:219 +#: src/browser/preferences.py:218 #, python-brace-format msgid "This will sign out {self.email}" msgstr "" @@ -747,10 +747,10 @@ msgstr "" msgid "Microsoft reminders currently don't support recurrence" msgstr "" -#: src/service/backend.py:545 +#: src/service/backend.py:542 msgid "Mark as completed" msgstr "" -#: src/service/backend.py:838 +#: src/service/backend.py:835 msgid "Local Reminders" msgstr "" diff --git a/src/browser/application.py b/src/browser/application.py index 1555a53..39ea7a9 100644 --- a/src/browser/application.py +++ b/src/browser/application.py @@ -31,7 +31,7 @@ from remembrance.browser.preferences import PreferencesWindow # Always update this when new features are added that require the service to restart -MIN_SERVICE_VERSION = 2.2 +MIN_SERVICE_VERSION = 2.3 class Remembrance(Adw.Application): '''Application for the frontend''' diff --git a/src/browser/preferences.py b/src/browser/preferences.py index d25653b..a277f1a 100644 --- a/src/browser/preferences.py +++ b/src/browser/preferences.py @@ -83,7 +83,6 @@ def on_close(self, window, data = None): if self.synced != synced: self.synced = synced self.settings.set_value('synced-task-lists', GLib.Variant('a{sas}', self.synced)) - self.app.refresh_reminders() self.set_visible(False) return True diff --git a/src/service/backend.py b/src/service/backend.py index c8f821e..abbb194 100644 --- a/src/service/backend.py +++ b/src/service/backend.py @@ -257,7 +257,7 @@ def emit_login(self, user_id): self.synced_ids[user_id] = ['all'] self.set_enabled_lists(self.synced_ids) self.do_emit('MSSignedIn', GLib.Variant('(ss)', (user_id, email))) - self.refresh() + self.refresh(False) logger.info('Logged into Microsoft account') def start_countdowns(self): @@ -290,6 +290,7 @@ def _refresh_time_changed(self): def _synced_task_list_changed(self): self.synced_ids = self.app.settings.get_value('synced-task-lists').unpack() self.do_emit('MSSyncedListsChanged', self.get_enabled_lists()) + self.refresh(False) def _rfc_to_timestamp(self, rfc): return GLib.DateTime.new_from_iso8601(rfc, GLib.TimeZone.new_utc()).to_unix() @@ -313,7 +314,7 @@ def _reminder_updated(self, app_id, reminder_id, reminder): } self.do_emit('ReminderUpdated', GLib.Variant('(sa{sv})', (app_id, variant))) - def _sync_ms(self, old_ms, old_lists, old_list_ids): + def _sync_ms(self, old_ms, old_lists, old_list_ids, notify_past): try: lists = self.to_do.get_lists() except: @@ -354,7 +355,7 @@ def _sync_ms(self, old_ms, old_lists, old_list_ids): for task in task_list['tasks']: task_id = task['id'] reminder_id = None - for old_reminder_id, old_reminder in self.ms.items(): + for old_reminder_id, old_reminder in old_ms.items(): if old_reminder['ms-id'] == task_id: reminder_id = old_reminder_id break @@ -363,18 +364,14 @@ def _sync_ms(self, old_ms, old_lists, old_list_ids): reminder_id = self._do_generate_id() timestamp = self._rfc_to_timestamp(task['reminderDateTime']['dateTime']) if 'reminderDateTime' in task else 0 + is_future = timestamp > floor(time.time()) - if reminder_id in self.ms: + if reminder_id in old_ms: reminder = old_ms[reminder_id].copy() else: - is_future = timestamp > floor(time.time()) reminder = {} - if old_ms == {}: - reminder['repeat-times'] = 0 - else: - reminder['repeat-times'] = 1 if is_future else 0 - - reminder['old-timestamp'] = 0 if is_future else timestamp + reminder['repeat-times'] = 1 if is_future or notify_past else 0 + reminder['old-timestamp'] = 0 reminder['ms-id'] = task_id reminder['title'] = task['title'].strip() @@ -385,7 +382,7 @@ def _sync_ms(self, old_ms, old_lists, old_list_ids): reminder['repeat-frequency'] = 1 reminder['repeat-days'] = 0 reminder['repeat-until'] = 0 - if timestamp < floor(time.time()): + if not is_future: reminder['old-timestamp'] = timestamp reminder['list'] = list_id reminder['user-id'] = user_id @@ -783,7 +780,7 @@ def _get_saved_ms_reminders(self): return old_ms - def _get_reminders(self): + def _get_reminders(self, notify_past = True): local = {} ms = {} list_ids = {} @@ -838,7 +835,7 @@ def _get_reminders(self): list_names['local']['local'] = _('Local Reminders') old_ms = self._get_saved_ms_reminders() - ms, ms_list_names, list_ids = self._sync_ms(old_ms, ms_list_names, list_ids) + ms, ms_list_names, list_ids = self._sync_ms(old_ms, ms_list_names, list_ids, notify_past) list_names.update(ms_list_names) return local, ms, list_names, list_ids @@ -1056,11 +1053,11 @@ def logout_todo(self, user_id: str): self.refresh() logger.info('Logged out of Microsoft account') - def refresh(self): + def refresh(self, notify_past = True): try: self.countdowns.add_timeout(self.refresh_time, self.refresh, -1) - local, ms, list_names, list_ids = self._get_reminders() + local, ms, list_names, list_ids = self._get_reminders(notify_past) new_ids = [] removed_ids = []