16
16
import fr .free .nrw .commons .BuildConfig ;
17
17
import fr .free .nrw .commons .R ;
18
18
19
- import static fr .free .nrw .commons .notification .NotificationType .THANK_YOU_EDIT ;
20
19
import static fr .free .nrw .commons .notification .NotificationType .UNKNOWN ;
21
20
22
21
public class NotificationUtils {
23
22
24
23
private static final String COMMONS_WIKI = "commonswiki" ;
24
+ private static final String WIKIDATA_WIKI = "wikidatawiki" ;
25
+ private static final String WIKIPEDIA_WIKI = "enwiki" ;
25
26
26
27
public static boolean isCommonsNotification (Node document ) {
27
28
if (document == null || !document .hasAttributes ()) {
@@ -31,6 +32,32 @@ public static boolean isCommonsNotification(Node document) {
31
32
return COMMONS_WIKI .equals (element .getAttribute ("wiki" ));
32
33
}
33
34
35
+ /**
36
+ * Returns true if the wiki attribute corresponds to wikidatawiki
37
+ * @param document
38
+ * @return
39
+ */
40
+ public static boolean isWikidataNotification (Node document ) {
41
+ if (document == null || !document .hasAttributes ()) {
42
+ return false ;
43
+ }
44
+ Element element = (Element ) document ;
45
+ return WIKIDATA_WIKI .equals (element .getAttribute ("wiki" ));
46
+ }
47
+
48
+ /**
49
+ * Returns true if the wiki attribute corresponds to enwiki
50
+ * @param document
51
+ * @return
52
+ */
53
+ public static boolean isWikipediaNotification (Node document ) {
54
+ if (document == null || !document .hasAttributes ()) {
55
+ return false ;
56
+ }
57
+ Element element = (Element ) document ;
58
+ return WIKIPEDIA_WIKI .equals (element .getAttribute ("wiki" ));
59
+ }
60
+
34
61
public static NotificationType getNotificationType (Node document ) {
35
62
Element element = (Element ) document ;
36
63
String type = element .getAttribute ("type" );
@@ -68,10 +95,17 @@ public static List<Notification> getNotificationsFromList(Context context, NodeL
68
95
return notifications ;
69
96
}
70
97
98
+ /**
99
+ * Currently the app is interested in showing notifications just from the following three wikis: commons, wikidata, wikipedia
100
+ * This function returns true only if the notification belongs to any of the above wikis and is of a known notification type
101
+ * @param node
102
+ * @return
103
+ */
71
104
private static boolean isUsefulNotification (Node node ) {
72
- return isCommonsNotification (node )
73
- && !getNotificationType (node ).equals (UNKNOWN )
74
- && !getNotificationType (node ).equals (THANK_YOU_EDIT );
105
+ return (isCommonsNotification (node )
106
+ || isWikidataNotification (node )
107
+ || isWikipediaNotification (node ))
108
+ && !getNotificationType (node ).equals (UNKNOWN );
75
109
}
76
110
77
111
public static boolean isBundledNotification (Node document ) {
@@ -97,7 +131,7 @@ public static Notification getNotificationFromApiResult(Context context, Node do
97
131
98
132
switch (type ) {
99
133
case THANK_YOU_EDIT :
100
- notificationText = context . getString ( R . string . notifications_thank_you_edit );
134
+ notificationText = getThankYouEditDescription ( document );
101
135
break ;
102
136
case EDIT_USER_TALK :
103
137
notificationText = getNotificationText (document );
@@ -146,6 +180,16 @@ private static String getMentionDescription(Node document) {
146
180
return body != null ? body .getTextContent () : "" ;
147
181
}
148
182
183
+ /**
184
+ * Gets the header node returned in the XML document to form the description for thank you edits
185
+ * @param document
186
+ * @return
187
+ */
188
+ private static String getThankYouEditDescription (Node document ) {
189
+ Node body = getNode (getModel (document ), "header" );
190
+ return body != null ? body .getTextContent () : "" ;
191
+ }
192
+
149
193
private static String getNotificationIconUrl (Node document ) {
150
194
String format = "%s%s" ;
151
195
Node iconUrl = getNode (getModel (document ), "iconUrl" );
0 commit comments