Skip to content

Commit 5dc21f0

Browse files
Revert "Do not notify if decryption fails (#2079)" (#2085)
This reverts commit 070142f.
1 parent c08f7e9 commit 5dc21f0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationId.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ object NotificationId {
77
const val KEY_CACHING_SERVICE = 4141
88
const val WEBRTC_CALL = 313388
99
const val TOKEN_DROP = 777
10+
const val LEGACY_PUSH = 11111
1011

1112
/**
1213
* ID for thread based notification. Each thread will be tagged differently.

app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package org.thoughtcrime.securesms.notifications
22

3+
import android.Manifest
4+
import android.app.PendingIntent
35
import android.content.Context
6+
import android.content.Intent
7+
import android.content.pm.PackageManager
8+
import androidx.core.app.ActivityCompat
9+
import androidx.core.app.NotificationCompat
10+
import androidx.core.app.NotificationManagerCompat
11+
import androidx.core.content.ContextCompat.getString
412
import dagger.hilt.android.qualifiers.ApplicationContext
513
import kotlinx.coroutines.CoroutineScope
614
import kotlinx.coroutines.launch
715
import kotlinx.serialization.json.Json
16+
import network.loki.messenger.R
817
import network.loki.messenger.libsession_util.Namespace
918
import network.loki.messenger.libsession_util.SessionEncrypt
1019
import org.session.libsession.messaging.messages.Message.Companion.senderOrSync
@@ -26,6 +35,7 @@ import org.thoughtcrime.securesms.database.ReceivedMessageHashDatabase
2635
import org.thoughtcrime.securesms.dependencies.ConfigFactory
2736
import org.thoughtcrime.securesms.dependencies.ManagerScope
2837
import org.thoughtcrime.securesms.groups.GroupRevokedMessageHandler
38+
import org.thoughtcrime.securesms.home.HomeActivity
2939
import javax.inject.Inject
3040

3141
private const val TAG = "PushHandler"
@@ -40,6 +50,8 @@ class PushReceiver @Inject constructor(
4050
private val receivedMessageHashDatabase: ReceivedMessageHashDatabase,
4151
@param:ManagerScope private val scope: CoroutineScope,
4252
private val loginStateRepository: LoginStateRepository,
53+
private val notificationChannelManager: NotificationChannelManager,
54+
private val notificationManagerCompat: NotificationManagerCompat,
4355
) {
4456

4557
/**
@@ -79,6 +91,7 @@ class PushReceiver @Inject constructor(
7991

8092
// send a generic notification if we have no data
8193
if (pushData.data == null) {
94+
sendGenericNotification()
8295
return
8396
}
8497

@@ -146,6 +159,10 @@ class PushReceiver @Inject constructor(
146159
namespace == Namespace.DEFAULT() || pushData?.metadata == null -> {
147160
if (pushData?.data == null) {
148161
Log.d(TAG, "Push data is null")
162+
if(pushData?.metadata?.data_too_long != true) {
163+
Log.d(TAG, "Sending a generic notification (data_too_long was false)")
164+
sendGenericNotification()
165+
}
149166
return
150167
}
151168

@@ -187,6 +204,33 @@ class PushReceiver @Inject constructor(
187204

188205
}
189206

207+
208+
private fun sendGenericNotification() {
209+
// no need to do anything if notification permissions are not granted
210+
if (ActivityCompat.checkSelfPermission(
211+
context,
212+
Manifest.permission.POST_NOTIFICATIONS
213+
) != PackageManager.PERMISSION_GRANTED
214+
) {
215+
return
216+
}
217+
218+
val builder = NotificationCompat.Builder(context,
219+
notificationChannelManager.getNotificationChannelId(NotificationChannelManager.ChannelDescription.ONE_TO_ONE_MESSAGES))
220+
.setSmallIcon(R.drawable.ic_notification)
221+
.setColor(context.getColor(R.color.textsecure_primary))
222+
.setContentTitle(getString(context, R.string.app_name))
223+
224+
// Note: We set the count to 1 in the below plurals string so it says "You've got a new message" (singular)
225+
.setContentText(context.resources.getQuantityString(R.plurals.messageNewYouveGot, 1, 1))
226+
227+
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
228+
.setAutoCancel(true)
229+
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, HomeActivity::class.java), PendingIntent.FLAG_IMMUTABLE))
230+
231+
notificationManagerCompat.notify(NotificationId.LEGACY_PUSH, builder.build())
232+
}
233+
190234
private fun Map<String, String>.asPushData(): PushData =
191235
when {
192236
// this is a v2 push notification

0 commit comments

Comments
 (0)