revert calculation of delayed delivery time

this didn't make sense because time between firebase and devices is not synchronized, so the results were useless.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-11-10 13:38:49 +01:00
parent 3a517f5760
commit ca145d170c
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 5 additions and 33 deletions

View File

@ -65,7 +65,6 @@ class NCFirebaseMessagingService : FirebaseMessagingService() {
val messageData = Data.Builder()
.putString(BundleKeys.KEY_NOTIFICATION_SUBJECT, subject)
.putString(BundleKeys.KEY_NOTIFICATION_SIGNATURE, signature)
.putLong(BundleKeys.KEY_NOTIFICATION_SENT_TIME, remoteMessage.sentTime)
.build()
val notificationWork =
OneTimeWorkRequest.Builder(NotificationWorker::class.java).setInputData(messageData)

View File

@ -53,7 +53,6 @@ import androidx.work.Worker
import androidx.work.WorkerParameters
import autodagger.AutoInjector
import com.bluelinelabs.logansquare.LoganSquare
import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.CallNotificationActivity
import com.nextcloud.talk.activities.MainActivity
@ -136,14 +135,12 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
private var conversationType: String? = "one2one"
private var muteCall = false
private var importantConversation = false
private var deliveryDelayTime: Long = 0
private lateinit var notificationManager: NotificationManagerCompat
override fun doWork(): Result {
sharedApplication!!.componentApplication.inject(this)
context = applicationContext
calculateDeliveryDelayTime(inputData)
initDecryptedData(inputData)
initNcApiAndCredentials()
@ -247,9 +244,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
.setSubText(baseUrl)
.setShowWhen(true)
.setWhen(pushMessage.timestamp)
.setContentTitle(
EmojiCompat.get().process(pushMessage.subject + getDeliveryDelayTimeForDebug())
)
.setContentTitle(EmojiCompat.get().process(pushMessage.subject))
.setAutoCancel(true)
.setOngoing(true)
.setContentIntent(fullScreenPendingIntent)
@ -263,20 +258,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
checkIfCallIsActive(signatureVerification, pushMessage)
}
/**
* Calculates the time between the sent time (from firebase) and the received time on the device.
* 'deliveryDelayTime' is displayed in debug mode right after the notification message.
* A huge delay means that there might be something wrong on device side.
*/
private fun calculateDeliveryDelayTime(inputData: Data) {
val messageSentTime = inputData.getLong(BundleKeys.KEY_NOTIFICATION_SENT_TIME, 0)
deliveryDelayTime = if (messageSentTime == 0L) {
0
} else {
System.currentTimeMillis() - messageSentTime
}
}
private fun initNcApiAndCredentials() {
credentials = ApiUtils.getCredentials(
signatureVerification.user!!.username,
@ -456,12 +437,12 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
.setAutoCancel(true)
if (!TextUtils.isEmpty(pushMessage.subject)) {
notificationBuilder.setContentTitle(
EmojiCompat.get().process(pushMessage.subject + getDeliveryDelayTimeForDebug())
EmojiCompat.get().process(pushMessage.subject)
)
}
if (!TextUtils.isEmpty(pushMessage.text)) {
notificationBuilder.setContentText(
EmojiCompat.get().process(pushMessage.text!! + getDeliveryDelayTimeForDebug())
EmojiCompat.get().process(pushMessage.text!!)
)
}
if (Build.VERSION.SDK_INT >= 23) {
@ -625,17 +606,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
)
}
)
newStyle.addMessage(pushMessage.text + getDeliveryDelayTimeForDebug(), pushMessage.timestamp, person)
newStyle.addMessage(pushMessage.text, pushMessage.timestamp, person)
return newStyle
}
private fun getDeliveryDelayTimeForDebug(): String {
if (BuildConfig.DEBUG) {
return " ($deliveryDelayTime ms delay)"
}
return ""
}
@Throws(NumberFormatException::class)
private fun parseMessageId(objectId: String): Int {
val objectIdParts = objectId.split("/".toRegex()).toTypedArray()
@ -801,7 +775,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
String.format(
context!!.resources.getString(R.string.nc_missed_call),
currentConversation!!.displayName
) + getDeliveryDelayTimeForDebug()
)
)
.setSmallIcon(R.drawable.ic_baseline_phone_missed_24)
.setOngoing(false)

View File

@ -48,7 +48,6 @@ object BundleKeys {
const val KEY_MODIFIED_BASE_URL = "KEY_MODIFIED_BASE_URL"
const val KEY_NOTIFICATION_SUBJECT = "KEY_NOTIFICATION_SUBJECT"
const val KEY_NOTIFICATION_SIGNATURE = "KEY_NOTIFICATION_SIGNATURE"
const val KEY_NOTIFICATION_SENT_TIME = "KEY_NOTIFICATION_SENT_TIME"
const val KEY_INTERNAL_USER_ID = "KEY_INTERNAL_USER_ID"
const val KEY_CONVERSATION_TYPE = "KEY_CONVERSATION_TYPE"
const val KEY_INVITED_PARTICIPANTS = "KEY_INVITED_PARTICIPANTS"