srctree

Roee Hershberg parent 5ea74db9 00dea0c3
Fix a crash when messing with message notification of deleted contact

Also dismiss the message notifications of the associated contact whendeleting it. This can be reproduced by receiving a message notificationfrom a contact, deleting the contact and then messing with thenotification (clicking it, replying, etc.).

inlinesplit
atox/src/main/kotlin/ActionReceiver.kt added: 15, removed: 3, total 12
@@ -74,6 +74,11 @@ class ActionReceiver : BroadcastReceiver() {
Log.e(TAG, "Got intent without required key $KEY_CONTACT_PK $intent")
return@launch
}
if (!contactRepository.exists(pk.string())) {
notificationHelper.dismissNotifications(pk)
notificationHelper.dismissCallNotification(pk)
return@launch
}
 
RemoteInput.getResultsFromIntent(intent)?.let { results ->
results.getCharSequence(KEY_TEXT_REPLY)?.toString()?.let { input ->
 
atox/src/main/kotlin/ui/chat/ChatFragment.kt added: 15, removed: 3, total 12
@@ -173,6 +173,10 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
}
 
viewModel.contact.observe(viewLifecycleOwner) {
if (it == null) {
findNavController().popBackStack()
return@observe
}
it.name = it.name.ifEmpty { getString(R.string.contact_default_name) }
 
contactName = it.name
 
atox/src/main/kotlin/ui/contactlist/ContactListViewModel.kt added: 15, removed: 3, total 12
@@ -20,6 +20,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ltd.evilcorp.atox.R
import ltd.evilcorp.atox.tox.ToxStarter
import ltd.evilcorp.atox.ui.NotificationHelper
import ltd.evilcorp.core.vo.Contact
import ltd.evilcorp.core.vo.FriendRequest
import ltd.evilcorp.core.vo.User
@@ -43,6 +44,7 @@ class ContactListViewModel @Inject constructor(
private val contactManager: ContactManager,
private val fileTransferManager: FileTransferManager,
private val friendRequestManager: FriendRequestManager,
private val notificationHelper: NotificationHelper,
private val tox: Tox,
private val toxStarter: ToxStarter,
userManager: UserManager
@@ -60,6 +62,7 @@ class ContactListViewModel @Inject constructor(
fun acceptFriendRequest(friendRequest: FriendRequest) = friendRequestManager.accept(friendRequest)
fun rejectFriendRequest(friendRequest: FriendRequest) = friendRequestManager.reject(friendRequest)
fun deleteContact(publicKey: PublicKey) {
notificationHelper.dismissNotifications(publicKey)
contactManager.delete(publicKey)
chatManager.clearHistory(publicKey)
scope.launch {