Skip to content

Commit

Permalink
Fix issues with notifications on ms reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsasha committed Apr 3, 2023
1 parent b544576 commit ae775d0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependency('gsound')

release_type = get_option('release-type')

service_version = '2.2'
service_version = '2.3'

app_executable = 'remembrance'

Expand Down
14 changes: 7 additions & 7 deletions po/remembrance.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 <b>{self.email}</b>"
msgstr ""
Expand Down Expand Up @@ -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 ""
2 changes: 1 addition & 1 deletion src/browser/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down
1 change: 0 additions & 1 deletion src/browser/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 13 additions & 16 deletions src/service/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit ae775d0

Please sign in to comment.