Skip to content

Commit

Permalink
fix: Delete conversation Crash
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow committed Jan 29, 2025
1 parent f4566e5 commit 4e3f805
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ enum class NotificationIds {
MIGRATION_NOTIFICATION_ID,
SINGLE_USER_MIGRATION_NOTIFICATION_ID,
MIGRATION_ERROR_NOTIFICATION_ID,
DELETING_CONVERSATION_NOTIFICATION_ID,
PLAYING_AUDIO_MESSAGE_ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WireWorkerFactory @Inject constructor(
PersistentWebsocketCheckWorker(appContext, workerParameters, startPersistentWebsocketIfNecessary)

DeleteConversationLocallyWorker::class.java.canonicalName ->
DeleteConversationLocallyWorker(appContext, workerParameters, coreLogic)
DeleteConversationLocallyWorker(appContext, workerParameters, coreLogic, notificationChannelsManager)

else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
package com.wire.android.workmanager.worker

import android.content.Context
import androidx.core.app.NotificationCompat
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.ExistingWorkPolicy
import androidx.work.ForegroundInfo
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.wire.android.R
import com.wire.android.notification.NotificationChannelsManager
import com.wire.android.notification.NotificationConstants
import com.wire.android.notification.NotificationIds
import com.wire.android.notification.openAppPendingIntent
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedIdMapperImpl
Expand Down Expand Up @@ -54,7 +61,8 @@ import kotlinx.coroutines.flow.mapNotNull
class DeleteConversationLocallyWorker @AssistedInject constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val coreLogic: CoreLogic
private val coreLogic: CoreLogic,
private val notificationChannelsManager: NotificationChannelsManager
) : CoroutineWorker(appContext, workerParams) {
override suspend fun doWork(): Result = coroutineScope {
inputData.getString(CONVERSATION_ID)?.let { id ->
Expand All @@ -71,6 +79,26 @@ class DeleteConversationLocallyWorker @AssistedInject constructor(
} ?: Result.failure()
}

override suspend fun getForegroundInfo(): ForegroundInfo {
notificationChannelsManager.createRegularChannel(
NotificationConstants.OTHER_CHANNEL_ID,
NotificationConstants.OTHER_CHANNEL_NAME
)

val notification = NotificationCompat.Builder(applicationContext, NotificationConstants.OTHER_CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon_small)
.setAutoCancel(true)
.setSilent(true)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setProgress(0, 0, true)
.setContentTitle(applicationContext.getString(R.string.notification_deleting_conversation))
.setPriority(NotificationCompat.PRIORITY_MIN)
.setContentIntent(openAppPendingIntent(applicationContext))
.build()

return ForegroundInfo(NotificationIds.DELETING_CONVERSATION_NOTIFICATION_ID.ordinal, notification)
}

companion object {
private const val NAME = "delete_conversation_locally_"
const val CONVERSATION_ID = "delete_conversation_locally_conversation_id"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
<string name="notification_call_default_group_name">Incoming group call</string>
<string name="notification_outgoing_call_tap_to_return">Tap to return to call - Calling...</string>
<string name="notification_audio_message_body">Audio message</string>
<string name="notification_deleting_conversation">Deleting conversation…</string>
<!-- Calling-->
<string name="calling_constant_bit_rate_indication">Constant Bit Rate</string>
<string name="calling_button_label_microphone">Microphone</string>
Expand Down

0 comments on commit 4e3f805

Please sign in to comment.