mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-29 04:55:15 +00:00
Delete conversation on home screen
This commit is contained in:
parent
dc1075e0c7
commit
32f95337d5
@ -1212,7 +1212,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return viewModel.recipient?.let { recipient ->
|
return viewModel.recipient?.let { recipient ->
|
||||||
ConversationMenuHelper.onOptionItemSelected(this, item, recipient, configFactory, storage)
|
ConversationMenuHelper.onOptionItemSelected(
|
||||||
|
context = this,
|
||||||
|
item = item,
|
||||||
|
thread = recipient,
|
||||||
|
threadID = threadId,
|
||||||
|
factory = configFactory,
|
||||||
|
storage = storage
|
||||||
|
)
|
||||||
} ?: false
|
} ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ object ConversationMenuHelper {
|
|||||||
context: Context,
|
context: Context,
|
||||||
item: MenuItem,
|
item: MenuItem,
|
||||||
thread: Recipient,
|
thread: Recipient,
|
||||||
|
threadID: Long,
|
||||||
factory: ConfigFactory,
|
factory: ConfigFactory,
|
||||||
storage: StorageProtocol
|
storage: StorageProtocol
|
||||||
): Boolean {
|
): Boolean {
|
||||||
@ -166,7 +167,7 @@ object ConversationMenuHelper {
|
|||||||
R.id.menu_copy_account_id -> { copyAccountID(context, thread) }
|
R.id.menu_copy_account_id -> { copyAccountID(context, thread) }
|
||||||
R.id.menu_copy_open_group_url -> { copyOpenGroupUrl(context, thread) }
|
R.id.menu_copy_open_group_url -> { copyOpenGroupUrl(context, thread) }
|
||||||
R.id.menu_edit_group -> { editClosedGroup(context, thread) }
|
R.id.menu_edit_group -> { editClosedGroup(context, thread) }
|
||||||
R.id.menu_leave_group -> { leaveClosedGroup(context, thread, factory, storage) }
|
R.id.menu_leave_group -> { leaveClosedGroup(context, thread, threadID, factory, storage) }
|
||||||
R.id.menu_invite_to_open_group -> { inviteContacts(context, thread) }
|
R.id.menu_invite_to_open_group -> { inviteContacts(context, thread) }
|
||||||
R.id.menu_unmute_notifications -> { unmute(context, thread) }
|
R.id.menu_unmute_notifications -> { unmute(context, thread) }
|
||||||
R.id.menu_mute_notifications -> { mute(context, thread) }
|
R.id.menu_mute_notifications -> { mute(context, thread) }
|
||||||
@ -305,9 +306,10 @@ object ConversationMenuHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun leaveClosedGroup(
|
fun leaveClosedGroup(
|
||||||
context: Context,
|
context: Context,
|
||||||
thread: Recipient,
|
thread: Recipient,
|
||||||
|
threadID: Long,
|
||||||
configFactory: ConfigFactory,
|
configFactory: ConfigFactory,
|
||||||
storage: StorageProtocol
|
storage: StorageProtocol
|
||||||
) {
|
) {
|
||||||
@ -318,14 +320,21 @@ object ConversationMenuHelper {
|
|||||||
val accountID = TextSecurePreferences.getLocalNumber(context)
|
val accountID = TextSecurePreferences.getLocalNumber(context)
|
||||||
val isCurrentUserAdmin = admins.any { it.toString() == accountID }
|
val isCurrentUserAdmin = admins.any { it.toString() == accountID }
|
||||||
|
|
||||||
confirmAndLeaveClosedGroup(context, group.title, isCurrentUserAdmin, doLeave = {
|
confirmAndLeaveClosedGroup(
|
||||||
|
context = context,
|
||||||
|
groupName = group.title,
|
||||||
|
isAdmin = isCurrentUserAdmin,
|
||||||
|
threadID = threadID,
|
||||||
|
storage = storage,
|
||||||
|
doLeave = {
|
||||||
val groupPublicKey = doubleDecodeGroupID(thread.address.toString()).toHexString()
|
val groupPublicKey = doubleDecodeGroupID(thread.address.toString()).toHexString()
|
||||||
|
|
||||||
check(DatabaseComponent.get(context).lokiAPIDatabase().isClosedGroup(groupPublicKey)) {
|
check(DatabaseComponent.get(context).lokiAPIDatabase().isClosedGroup(groupPublicKey)) {
|
||||||
"Invalid group public key"
|
"Invalid group public key"
|
||||||
}
|
}
|
||||||
MessageSender.leave(groupPublicKey, notifyUser = false)
|
MessageSender.leave(groupPublicKey, notifyUser = false)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
thread.isClosedGroupV2Recipient -> {
|
thread.isClosedGroupV2Recipient -> {
|
||||||
@ -339,6 +348,8 @@ object ConversationMenuHelper {
|
|||||||
context = context,
|
context = context,
|
||||||
groupName = name,
|
groupName = name,
|
||||||
isAdmin = isAdmin,
|
isAdmin = isAdmin,
|
||||||
|
threadID = threadID,
|
||||||
|
storage = storage,
|
||||||
doLeave = {
|
doLeave = {
|
||||||
check(storage.leaveGroup(accountId.hexString, true))
|
check(storage.leaveGroup(accountId.hexString, true))
|
||||||
}
|
}
|
||||||
@ -351,6 +362,8 @@ object ConversationMenuHelper {
|
|||||||
context: Context,
|
context: Context,
|
||||||
groupName: String,
|
groupName: String,
|
||||||
isAdmin: Boolean,
|
isAdmin: Boolean,
|
||||||
|
threadID: Long,
|
||||||
|
storage: StorageProtocol,
|
||||||
doLeave: () -> Unit,
|
doLeave: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val message = if (isAdmin) {
|
val message = if (isAdmin) {
|
||||||
@ -375,6 +388,9 @@ object ConversationMenuHelper {
|
|||||||
text(message)
|
text(message)
|
||||||
dangerButton(R.string.leave) {
|
dangerButton(R.string.leave) {
|
||||||
try {
|
try {
|
||||||
|
// Cancel any outstanding jobs
|
||||||
|
storage.cancelPendingMessageSendJobs(threadID)
|
||||||
|
|
||||||
doLeave()
|
doLeave()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
onLeaveFailed()
|
onLeaveFailed()
|
||||||
|
@ -73,6 +73,7 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel
|
|||||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
|
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.RequestManager
|
import com.bumptech.glide.RequestManager
|
||||||
|
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions
|
import org.thoughtcrime.securesms.permissions.Permissions
|
||||||
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
||||||
import org.thoughtcrime.securesms.recoverypassword.RecoveryPasswordActivity
|
import org.thoughtcrime.securesms.recoverypassword.RecoveryPasswordActivity
|
||||||
@ -592,37 +593,35 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
private fun deleteConversation(thread: ThreadRecord) {
|
private fun deleteConversation(thread: ThreadRecord) {
|
||||||
val threadID = thread.threadId
|
val threadID = thread.threadId
|
||||||
val recipient = thread.recipient
|
val recipient = thread.recipient
|
||||||
|
|
||||||
|
if (recipient.isClosedGroupV2Recipient || recipient.isLegacyClosedGroupRecipient) {
|
||||||
|
ConversationMenuHelper.leaveClosedGroup(
|
||||||
|
context = this,
|
||||||
|
thread = recipient,
|
||||||
|
threadID = threadID,
|
||||||
|
configFactory = configFactory,
|
||||||
|
storage = storage
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val title: String
|
val title: String
|
||||||
val message: CharSequence
|
val message: CharSequence
|
||||||
var positiveButtonId: Int = R.string.yes
|
var positiveButtonId: Int = R.string.yes
|
||||||
var negativeButtonId: Int = R.string.no
|
var negativeButtonId: Int = R.string.no
|
||||||
|
|
||||||
if (recipient.isGroupRecipient) {
|
if (recipient.isCommunityRecipient) {
|
||||||
val group = groupDatabase.getGroup(recipient.address.toString()).orNull()
|
|
||||||
|
|
||||||
// If you are an admin of this group you can delete it
|
|
||||||
if (group != null && group.admins.map { it.toString() }
|
|
||||||
.contains(textSecurePreferences.getLocalNumber())) {
|
|
||||||
title = getString(R.string.groupLeave)
|
|
||||||
message = Phrase.from(this.applicationContext, R.string.groupDeleteDescription)
|
|
||||||
.put(GROUP_NAME_KEY, group.title)
|
|
||||||
.format()
|
|
||||||
} else {
|
|
||||||
// Otherwise this is either a community, or it's a group you're not an admin of
|
|
||||||
title =
|
title =
|
||||||
if (recipient.isCommunityRecipient) getString(R.string.communityLeave) else getString(
|
if (recipient.isCommunityRecipient) getString(R.string.communityLeave) else getString(
|
||||||
R.string.groupLeave
|
R.string.groupLeave
|
||||||
)
|
)
|
||||||
message = Phrase.from(this.applicationContext, R.string.groupLeaveDescription)
|
message = Phrase.from(this.applicationContext, R.string.groupLeaveDescription)
|
||||||
.put(GROUP_NAME_KEY, group.title)
|
.put(GROUP_NAME_KEY, recipient.name.orEmpty())
|
||||||
.format()
|
.format()
|
||||||
}
|
}
|
||||||
|
|
||||||
positiveButtonId = R.string.leave
|
|
||||||
negativeButtonId = R.string.cancel
|
|
||||||
} else {
|
|
||||||
// If this is a 1-on-1 conversation
|
// If this is a 1-on-1 conversation
|
||||||
if (recipient.name != null) {
|
else if (recipient.name != null) {
|
||||||
title = getString(R.string.conversationsDelete)
|
title = getString(R.string.conversationsDelete)
|
||||||
message = Phrase.from(this.applicationContext, R.string.conversationsDeleteDescription)
|
message = Phrase.from(this.applicationContext, R.string.conversationsDeleteDescription)
|
||||||
.put(NAME_KEY, recipient.name)
|
.put(NAME_KEY, recipient.name)
|
||||||
@ -635,7 +634,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
positiveButtonId = R.string.clear
|
positiveButtonId = R.string.clear
|
||||||
negativeButtonId = R.string.cancel
|
negativeButtonId = R.string.cancel
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
showSessionDialog {
|
showSessionDialog {
|
||||||
title(title)
|
title(title)
|
||||||
@ -646,23 +644,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
// Cancel any outstanding jobs
|
// Cancel any outstanding jobs
|
||||||
DatabaseComponent.get(context).sessionJobDatabase()
|
DatabaseComponent.get(context).sessionJobDatabase()
|
||||||
.cancelPendingMessageSendJobs(threadID)
|
.cancelPendingMessageSendJobs(threadID)
|
||||||
// Send a leave group message if this is an active closed group
|
|
||||||
if (recipient.address.isLegacyClosedGroup && DatabaseComponent.get(context)
|
|
||||||
.groupDatabase().isActive(recipient.address.toGroupString())
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
GroupUtil.doubleDecodeGroupID(recipient.address.toString())
|
|
||||||
.toHexString()
|
|
||||||
.takeIf(DatabaseComponent.get(context).lokiAPIDatabase()::isClosedGroup)
|
|
||||||
?.let { MessageSender.explicitLeave(it, true, deleteThread = true) }
|
|
||||||
} catch (ioe: IOException) {
|
|
||||||
Log.w(TAG, "Got an IOException while sending leave group message", ioe)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (recipient.address.isClosedGroupV2) {
|
|
||||||
val groupLeave = LibSessionGroupLeavingJob(AccountId(recipient.address.serialize()), true)
|
|
||||||
JobQueue.shared.add(groupLeave)
|
|
||||||
}
|
|
||||||
// Delete the conversation
|
// Delete the conversation
|
||||||
val v2OpenGroup = DatabaseComponent.get(context).lokiThreadDatabase()
|
val v2OpenGroup = DatabaseComponent.get(context).lokiThreadDatabase()
|
||||||
.getOpenGroupChat(threadID)
|
.getOpenGroupChat(threadID)
|
||||||
@ -672,7 +654,12 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
v2OpenGroup.room,
|
v2OpenGroup.room,
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
threadDb.deleteConversation(threadID)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the badge count
|
// Update the badge count
|
||||||
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user