From b75bf5c3b7966a2eb72be3c28bb5932892712462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Sat, 28 Dec 2024 21:19:06 +0700 Subject: [PATCH 1/2] Fix daily noti failed cause the bad user structure - missing fcm_token --- backend/database/notifications.py | 7 +++++-- backend/utils/other/notifications.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/database/notifications.py b/backend/database/notifications.py index 98f5b09fd8..dd105c6e99 100644 --- a/backend/database/notifications.py +++ b/backend/database/notifications.py @@ -62,8 +62,11 @@ def sync_query(): chunk_users = [] try: query = users_ref.where(filter=FieldFilter('time_zone', 'in', chunk)) - for doc in query.stream(): - if (filter == 'fcm_token'): + for result in query.stream(): + doc = result.to_dict() + if 'fcm_token' not in doc: + continue + if filter == 'fcm_token': token = doc.get('fcm_token') else: token = doc.id, doc.get('fcm_token') diff --git a/backend/utils/other/notifications.py b/backend/utils/other/notifications.py index c6bbf6f956..3e8a883f3f 100644 --- a/backend/utils/other/notifications.py +++ b/backend/utils/other/notifications.py @@ -85,7 +85,7 @@ async def _send_bulk_summary_notification(users: list): async def send_daily_notification(): try: - morning_alert_title = "Don\'t forget to wear Friend today" + morning_alert_title = "Don\'t forget to wear Omi today" morning_alert_body = "Wear your friend and capture your memories today." morning_target_time = "08:00" From 8f6d5b5c26feea511d2128a2d1feff4ffcc80c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Sun, 29 Dec 2024 08:16:07 +0700 Subject: [PATCH 2/2] Keep the doc id, use send_each --- backend/database/notifications.py | 5 ++--- backend/utils/notifications.py | 2 +- backend/utils/other/notifications.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/database/notifications.py b/backend/database/notifications.py index dd105c6e99..b283bdc445 100644 --- a/backend/database/notifications.py +++ b/backend/database/notifications.py @@ -62,9 +62,8 @@ def sync_query(): chunk_users = [] try: query = users_ref.where(filter=FieldFilter('time_zone', 'in', chunk)) - for result in query.stream(): - doc = result.to_dict() - if 'fcm_token' not in doc: + for doc in query.stream(): + if 'fcm_token' not in doc.to_dict(): continue if filter == 'fcm_token': token = doc.get('fcm_token') diff --git a/backend/utils/notifications.py b/backend/utils/notifications.py index ede5af116f..f83be08963 100644 --- a/backend/utils/notifications.py +++ b/backend/utils/notifications.py @@ -36,7 +36,7 @@ def send_batch(batch_users): token=token ) for token in batch_users ] - return messaging.send_all(messages) + return messaging.send_each(messages) tasks = [] for i in range(num_batches): diff --git a/backend/utils/other/notifications.py b/backend/utils/other/notifications.py index 3e8a883f3f..4f4fd21248 100644 --- a/backend/utils/other/notifications.py +++ b/backend/utils/other/notifications.py @@ -86,7 +86,7 @@ async def _send_bulk_summary_notification(users: list): async def send_daily_notification(): try: morning_alert_title = "Don\'t forget to wear Omi today" - morning_alert_body = "Wear your friend and capture your memories today." + morning_alert_body = "Wear your omi and capture your memories today." morning_target_time = "08:00" await _send_notification_for_time(morning_target_time, morning_alert_title, morning_alert_body)