@@ -13,8 +13,6 @@ import android.graphics.Color
1313import android.net.Uri
1414import android.os.Build
1515import android.os.Bundle
16- import android.provider.Settings
17- import android.text.TextUtils
1816import android.util.Log
1917import androidx.core.app.NotificationManagerCompat
2018import androidx.core.app.NotificationCompat
@@ -56,7 +54,7 @@ private fun logNotificationData(msg: String, data: Bundle) {
5654 Log .v(TAG , " $msg : $data " )
5755}
5856
59- internal fun onReceived (context : Context , conversations : ConversationMap , mapData : Map <String , String >) {
57+ internal fun onReceived (context : Context , mapData : Map <String , String >) {
6058 // TODO refactor to not need this; reflects a juxtaposition of FCM with old GCM interfaces.
6159 val data = Bundle ()
6260 for ((key, value) in mapData) {
@@ -73,14 +71,8 @@ internal fun onReceived(context: Context, conversations: ConversationMap, mapDat
7371 }
7472
7573 if (fcmMessage is MessageFcmMessage ) {
76- addConversationToMap(fcmMessage, conversations)
77- updateNotification(context, conversations, fcmMessage)
78- } else if (fcmMessage is RemoveFcmMessage ) {
79- removeMessagesFromMap(conversations, fcmMessage)
80- if (conversations.isEmpty()) {
81- NotificationManagerCompat .from(context).cancelAll()
82- }
83- }
74+ updateNotification(context, fcmMessage)
75+ } // TODO handle case for RemoveFcmMessage
8476}
8577
8678private fun createViewPendingIntent (fcmMessage : MessageFcmMessage , context : Context ): PendingIntent {
@@ -157,7 +149,7 @@ private fun createSummaryNotification(
157149}
158150
159151private fun updateNotification (
160- context : Context , conversations : ConversationMap , fcmMessage : MessageFcmMessage ) {
152+ context : Context , fcmMessage : MessageFcmMessage ) {
161153 val user = Person .Builder ().setName(" You" ).build()
162154 val sender = Person .Builder ()
163155 .setName(fcmMessage.sender.fullName)
@@ -222,95 +214,13 @@ private fun updateNotification(
222214 }
223215}
224216
225- private fun getNotificationSoundUri (context : Context ): Uri {
226- // Note: Provide default notification sound until we found a good sound
227- // return Uri.parse("${ContentResolver.SCHEME_ANDROID_RESOURCE}://${context.packageName}/${R.raw.zulip}")
228- return Settings .System .DEFAULT_NOTIFICATION_URI
229- }
230-
231- private fun getNotificationBuilder (
232- context : Context , conversations : ConversationMap , fcmMessage : MessageFcmMessage ): NotificationCompat .Builder {
233- val builder = NotificationCompat .Builder (context, CHANNEL_ID )
234-
235- val viewPendingIntent = createViewPendingIntent(fcmMessage, context)
236- builder.setContentIntent(viewPendingIntent)
237- builder.setAutoCancel(true )
238-
239- val totalMessagesCount = extractTotalMessagesCount(conversations)
240-
241- if (BuildConfig .DEBUG ) {
242- builder.setSmallIcon(R .mipmap.ic_launcher)
243- } else {
244- builder.setSmallIcon(R .drawable.zulip_notification)
245- }
246-
247- // This should agree with `BRAND_COLOR` in the JS code.
248- builder.setColor(Color .rgb(100 , 146 , 254 ))
249-
250- val nameList = extractNames(conversations)
251-
252- if (conversations.size == 1 && nameList.size == 1 ) {
253- // Only one 1 notification therefore no using of big view styles
254- if (totalMessagesCount > 1 ) {
255- builder.setContentTitle(" ${fcmMessage.sender.fullName} ($totalMessagesCount )" )
256- } else {
257- builder.setContentTitle(fcmMessage.sender.fullName)
258- }
259- builder.setContentText(fcmMessage.content)
260- if (fcmMessage.recipient is Recipient .Stream ) {
261- val (stream, topic) = fcmMessage.recipient
262- val displayTopic = " $stream > $topic "
263- builder.setSubText(" Message on $displayTopic " )
264- }
265- fetchBitmap(sizedURL(context, fcmMessage.sender.avatarURL, 64f ))
266- ?.let { builder.setLargeIcon(it) }
267- builder.setStyle(NotificationCompat .BigTextStyle ().bigText(fcmMessage.content))
268- } else {
269- val numConversations = context.resources.getQuantityString(
270- R .plurals.numConversations, conversations.size, conversations.size)
271- builder.setContentTitle(" $totalMessagesCount messages in $numConversations " )
272- builder.setContentText(" Messages from ${TextUtils .join(" ," , nameList)} " )
273- val inboxStyle = NotificationCompat .InboxStyle (builder)
274- inboxStyle.setSummaryText(numConversations)
275- buildNotificationContent(conversations, inboxStyle)
276- builder.setStyle(inboxStyle)
277- }
278-
279- try {
280- ShortcutBadger .applyCount(context, totalMessagesCount)
281- } catch (e: Exception ) {
282- Log .e(TAG , " BADGE ERROR: $e " )
283- }
284-
285- builder.setWhen(fcmMessage.timeMs)
286- builder.setShowWhen(true )
287-
288- val vPattern = longArrayOf(0 , 100 , 200 , 100 )
289- // NB the DEFAULT_VIBRATE flag below causes this to have no effect.
290- // TODO: choose a vibration pattern we like, and unset DEFAULT_VIBRATE.
291- builder.setVibrate(vPattern)
292-
293- builder.setDefaults(NotificationCompat .DEFAULT_VIBRATE or NotificationCompat .DEFAULT_LIGHTS )
294-
295- builder.addAction(createDismissAction(context))
296-
297- val soundUri = getNotificationSoundUri(context)
298- builder.setSound(soundUri)
299- return builder
300- }
301-
302- internal fun onOpened (application : ReactApplication , conversations : ConversationMap , data : Bundle ) {
217+ internal fun onOpened (application : ReactApplication , data : Bundle ) {
303218 logNotificationData(" notif opened" , data)
304219 notifyReact(application, data)
305- clearConversations(conversations)
306220 try {
307221 ShortcutBadger .removeCount(application as Context )
308222 } catch (e: Exception ) {
309223 Log .e(TAG , " BADGE ERROR: $e " )
310224 }
311225
312226}
313-
314- internal fun onClear (context : Context , conversations : ConversationMap ) {
315- clearConversations(conversations)
316- }
0 commit comments