Skip to content

Commit c77e5ab

Browse files
ErenratZengQiutong Zeng
and
Qiutong Zeng
authored
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 <Qiutong.zeng@anu.edu.au>
1 parent 817e07b commit c77e5ab

File tree

9 files changed

+32
-10
lines changed

9 files changed

+32
-10
lines changed

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import fr.free.nrw.commons.auth.SessionManager;
2020
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
2121
import fr.free.nrw.commons.notification.models.Notification;
22+
import fr.free.nrw.commons.notification.models.NotificationType;
2223
import fr.free.nrw.commons.theme.BaseActivity;
2324
import fr.free.nrw.commons.utils.NetworkUtils;
2425
import fr.free.nrw.commons.utils.ViewUtil;
@@ -148,7 +149,11 @@ private void initListView() {
148149
}
149150
adapter = new NotificatinAdapter(item -> {
150151
Timber.d("Notification clicked %s", item.getLink());
151-
handleUrl(item.getLink());
152+
if (item.getNotificationType() == NotificationType.EMAIL){
153+
ViewUtil.showLongSnackbar(binding.container,getString(R.string.check_your_email_inbox));
154+
} else {
155+
handleUrl(item.getLink());
156+
}
152157
removeNotification(item);
153158
return Unit.INSTANCE;
154159
});

app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.kt

+19-9
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,23 @@ class NotificationClient
5151
}
5252
}
5353

54-
private fun WikimediaNotification.toCommonsNotification() =
55-
Notification(
56-
notificationType = NotificationType.UNKNOWN,
57-
notificationText = contents?.compactHeader ?: "",
58-
date = DateUtil.getMonthOnlyDateString(timestamp),
59-
link = contents?.links?.primary?.url ?: "",
60-
iconUrl = "",
61-
notificationId = id().toString(),
62-
)
54+
private fun WikimediaNotification.toCommonsNotification() :
55+
Notification {
56+
val notificationText = contents?.compactHeader ?: ""
57+
val notificationType =
58+
if (notificationText.contains("Sent you an email", ignoreCase = true)) {
59+
NotificationType.EMAIL
60+
} else {
61+
NotificationType.UNKNOWN
62+
}
63+
64+
return Notification(
65+
notificationType = notificationType,
66+
notificationText = notificationText,
67+
date = DateUtil.getMonthOnlyDateString(timestamp),
68+
link = contents?.links?.primary?.url ?: "",
69+
iconUrl = "",
70+
notificationId = id().toString(),
71+
)
72+
}
6373
}

app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public enum NotificationType {
44
THANK_YOU_EDIT("thank-you-edit"),
55
EDIT_USER_TALK("edit-user-talk"),
66
MENTION("mention"),
7+
EMAIL("email"),
78
WELCOME("welcome"),
89
UNKNOWN("unknown");
910
private String type;

app/src/main/res/values-ja/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@
679679
<string name="error_sending_thanks">作者への感謝の送信エラー。</string>
680680
<string name="invalid_login_message">ログインが期限切れになりました。もう一度ログインしてください。</string>
681681
<string name="no_application_available_to_open_gpx_files">GPXファイルを開くことができるアプリケーションがありません</string>
682+
<string name="check_your_email_inbox">メールをご確認ください</string>
682683
<plurals name="custom_picker_images_selected_title_appendix">
683684
<item quantity="other">%d件の画像が選択されました</item>
684685
</plurals>

app/src/main/res/values-zh-rCN/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@
111111
<string name="detail_description_empty">没有说明</string>
112112
<string name="detail_license_empty">未知授权协议</string>
113113
<string name="menu_refresh">刷新</string>
114+
<string name="check_your_email_inbox">请查看你的电子邮箱</string>
114115
</resources>

app/src/main/res/values-zh-rHK/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,5 @@
215215
<string name="description_info">請盡可能描述媒體內容:拍攝於何處?是顯示什麼事物?有什麼脈絡?請描述對象或人物。透露出一些較不易猜測的訊息,例如是風景的話,可以是一天裡的時間。如果媒體顯示出了一些不尋常的事物,請說明不尋常原因。</string>
216216
<string name="learn_how_to_write_a_useful_description">學習如何編寫有用的描述</string>
217217
<string name="learn_how_to_write_a_useful_caption">學習如何編寫有用的標題</string>
218+
<string name="check_your_email_inbox">請查看你的電子郵件信箱</string>
218219
</resources>

app/src/main/res/values-zh-rTW/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,5 @@
805805
<string name="pending">待處理</string>
806806
<string name="failed">失敗</string>
807807
<string name="could_not_load_place_data">無法載入地點資料</string>
808+
<string name="check_your_email_inbox">請查看你的電子郵件信箱</string>
808809
</resources>

app/src/main/res/values-zh/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -834,4 +834,5 @@
834834
<string name="pending">待处理</string>
835835
<string name="failed">失败</string>
836836
<string name="could_not_load_place_data">无法加载地点数据</string>
837+
<string name="check_your_email_inbox">请查看你的电子邮箱</string>
837838
</resources>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ Upload your first media by tapping on the add button.</string>
504504
<string name="no_notification">You have no unread notifications</string>
505505
<string name="no_read_notification">You have no read notifications</string>
506506
<string name="share_logs_using">Share logs using</string>
507+
<string name="check_your_email_inbox">Check your email inbox</string>
507508
<string name="menu_option_read">View read</string>
508509
<string name="menu_option_unread">View unread</string>
509510

0 commit comments

Comments
 (0)