From c77e5abba7068a99b64631b5d83fccb16e3d7a5d Mon Sep 17 00:00:00 2001 From: ErenratZeng <149918708+ErenratZeng@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:31:54 +1100 Subject: [PATCH] notification: classify email messages and add mail check prompt (#5865) This commit adds logic to classify notifications as "email" type when the notification text contains "sent you an email". It also updates the email notification prompt to support localization, ensuring a better user experience across different regions. ### Problem: 1. Previously, email-related notifications from the backend were missing a URL. As a result, when users clicked on these notifications, there was no link to open, and the notifications were categorized as UNKNOWN. This led to a poor user experience since there was no feedback provided when the user clicked on an email notification. 2. Additionally, the existing code used hardcoded English text for the email notification prompt, which did not provide a localized experience for users in different regions. ### Solution: 1. Added logic to categorize email-related notifications as `EMAIL` when the notification text contains "sent you an email". 2. Replaced the hardcoded "Check your email inbox" string with a localized string and added translations for multiple languages, including zh, zh-rhk, zh-rcn, zh-rtw, and ja. ### Changes: - **NotificationClient**: - Modified `WikimediaNotification.toCommonsNotification()` to check if the notification text contains "sent you an email". If it does, the notification is classified as `EMAIL_MESSAGE` instead of the default `UNKNOWN`. - **NotificationActivity**: - In the `NotificatinAdapter` click handler, added a check for `EMAIL_MESSAGE` type. When an email-type notification is clicked, a localized "Check your mail box" prompt is shown using `Snackbar`, instead of attempting to open a URL (which is typically missing for such notifications). - Modified to fetch the string using `getString(R.string.check_your_mail_box)` to support localization. - **NotificationType**: - Added a new `EMAIL` type to categorize email-related notifications. - **Localization**: - Added localized translations for "Check your mail box" in zh, zh-rhk, zh-rcn, zh-rtw, and ja. Co-authored-by: Qiutong Zeng --- .../notification/NotificationActivity.java | 7 ++++- .../notification/NotificationClient.kt | 28 +++++++++++++------ .../notification/models/NotificationType.java | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java index 75a010ea7..572dd0317 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java @@ -19,6 +19,7 @@ import fr.free.nrw.commons.databinding.ActivityNotificationBinding; import fr.free.nrw.commons.auth.SessionManager; import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException; import fr.free.nrw.commons.notification.models.Notification; +import fr.free.nrw.commons.notification.models.NotificationType; import fr.free.nrw.commons.theme.BaseActivity; import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.utils.ViewUtil; @@ -148,7 +149,11 @@ public class NotificationActivity extends BaseActivity { } adapter = new NotificatinAdapter(item -> { Timber.d("Notification clicked %s", item.getLink()); - handleUrl(item.getLink()); + if (item.getNotificationType() == NotificationType.EMAIL){ + ViewUtil.showLongSnackbar(binding.container,getString(R.string.check_your_email_inbox)); + } else { + handleUrl(item.getLink()); + } removeNotification(item); return Unit.INSTANCE; }); diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.kt b/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.kt index aa998ffb5..a0bf1176a 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.kt +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.kt @@ -51,13 +51,23 @@ class NotificationClient } } - private fun WikimediaNotification.toCommonsNotification() = - Notification( - notificationType = NotificationType.UNKNOWN, - notificationText = contents?.compactHeader ?: "", - date = DateUtil.getMonthOnlyDateString(timestamp), - link = contents?.links?.primary?.url ?: "", - iconUrl = "", - notificationId = id().toString(), - ) + private fun WikimediaNotification.toCommonsNotification() : + Notification { + val notificationText = contents?.compactHeader ?: "" + val notificationType = + if (notificationText.contains("Sent you an email", ignoreCase = true)) { + NotificationType.EMAIL + } else { + NotificationType.UNKNOWN + } + + return Notification( + notificationType = notificationType, + notificationText = notificationText, + date = DateUtil.getMonthOnlyDateString(timestamp), + link = contents?.links?.primary?.url ?: "", + iconUrl = "", + notificationId = id().toString(), + ) + } } diff --git a/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java b/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java index 1b825f071..fb9ae7e99 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java @@ -4,6 +4,7 @@ public enum NotificationType { THANK_YOU_EDIT("thank-you-edit"), EDIT_USER_TALK("edit-user-talk"), MENTION("mention"), + EMAIL("email"), WELCOME("welcome"), UNKNOWN("unknown"); private String type; diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 6fb40d2ff..1a50e9799 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -679,6 +679,7 @@ 作者への感謝の送信エラー。 ログインが期限切れになりました。もう一度ログインしてください。 GPXファイルを開くことができるアプリケーションがありません + メールをご確認ください %d件の画像が選択されました diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 379cc42ae..3e2969df4 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -111,4 +111,5 @@ 没有说明 未知授权协议 刷新 + 请查看你的电子邮箱 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 23da2c286..ab203b841 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -215,4 +215,5 @@ 請盡可能描述媒體內容:拍攝於何處?是顯示什麼事物?有什麼脈絡?請描述對象或人物。透露出一些較不易猜測的訊息,例如是風景的話,可以是一天裡的時間。如果媒體顯示出了一些不尋常的事物,請說明不尋常原因。 學習如何編寫有用的描述 學習如何編寫有用的標題 + 請查看你的電子郵件信箱 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0c09d229a..59dfdd57f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -805,4 +805,5 @@ 待處理 失敗 無法載入地點資料 + 請查看你的電子郵件信箱 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 7654cee2c..e66f40879 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -834,4 +834,5 @@ 待处理 失败 无法加载地点数据 + 请查看你的电子邮箱 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c6be3129..b5c2dc529 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -504,6 +504,7 @@ Upload your first media by tapping on the add button. You have no unread notifications You have no read notifications Share logs using + Check your email inbox View read View unread