2020-05-11 08:19:26 +02:00
|
|
|
package org.thoughtcrime.securesms.loki.activities
|
2019-12-17 14:27:59 +01:00
|
|
|
|
2020-02-19 05:34:02 +01:00
|
|
|
import android.app.AlertDialog
|
2020-07-16 04:49:37 +02:00
|
|
|
import android.content.BroadcastReceiver
|
|
|
|
import android.content.Context
|
2019-12-17 15:15:13 +01:00
|
|
|
import android.content.Intent
|
2020-07-16 04:49:37 +02:00
|
|
|
import android.content.IntentFilter
|
2019-12-19 11:49:23 +01:00
|
|
|
import android.database.Cursor
|
2019-12-17 14:27:59 +01:00
|
|
|
import android.os.Bundle
|
2020-01-09 01:35:43 +01:00
|
|
|
import android.text.Spannable
|
|
|
|
import android.text.SpannableString
|
|
|
|
import android.text.style.ForegroundColorSpan
|
2020-03-16 05:35:14 +01:00
|
|
|
import android.util.DisplayMetrics
|
2020-01-09 01:35:43 +01:00
|
|
|
import android.view.View
|
2020-03-16 05:35:14 +01:00
|
|
|
import android.widget.RelativeLayout
|
2020-02-19 05:34:02 +01:00
|
|
|
import android.widget.Toast
|
2020-09-03 14:15:03 +02:00
|
|
|
import androidx.lifecycle.Observer
|
2020-11-23 06:59:44 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2020-09-03 14:15:03 +02:00
|
|
|
import androidx.loader.app.LoaderManager
|
|
|
|
import androidx.loader.content.Loader
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2019-12-17 14:27:59 +01:00
|
|
|
import kotlinx.android.synthetic.main.activity_home.*
|
2020-11-23 06:59:44 +01:00
|
|
|
import kotlinx.coroutines.Dispatchers
|
2021-03-01 07:16:15 +01:00
|
|
|
import kotlinx.coroutines.flow.*
|
2020-11-23 06:59:44 +01:00
|
|
|
import kotlinx.coroutines.launch
|
2019-12-17 14:27:59 +01:00
|
|
|
import network.loki.messenger.R
|
2021-03-03 01:33:35 +01:00
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
2021-03-17 01:30:03 +01:00
|
|
|
import org.session.libsession.messaging.jobs.JobQueue
|
2021-03-31 06:15:50 +02:00
|
|
|
import org.session.libsession.messaging.sending_receiving.MessageSender
|
2021-03-12 03:37:16 +01:00
|
|
|
import org.session.libsession.utilities.*
|
2021-03-03 01:33:35 +01:00
|
|
|
import org.session.libsignal.utilities.ThreadUtils
|
2021-06-09 07:56:20 +02:00
|
|
|
import org.session.libsignal.utilities.toHexString
|
2019-12-17 14:27:59 +01:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
|
|
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
2021-06-09 07:56:20 +02:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
2021-05-31 06:29:11 +02:00
|
|
|
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
|
2019-12-17 14:27:59 +01:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
2019-12-17 15:15:13 +01:00
|
|
|
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
2021-05-19 03:12:29 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.api.OpenGroupManager
|
2021-03-03 01:33:35 +01:00
|
|
|
import org.thoughtcrime.securesms.loki.dialogs.*
|
2021-03-04 04:19:07 +01:00
|
|
|
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
2020-06-02 07:18:09 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.utilities.*
|
2020-05-11 08:19:26 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.views.ConversationView
|
|
|
|
import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegate
|
|
|
|
import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate
|
2019-12-19 11:15:58 +01:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
2020-09-11 01:03:57 +02:00
|
|
|
import java.io.IOException
|
2019-12-17 14:27:59 +01:00
|
|
|
|
2021-05-27 07:00:16 +02:00
|
|
|
class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickListener, SeedReminderViewDelegate, NewConversationButtonSetViewDelegate {
|
2019-12-19 11:15:58 +01:00
|
|
|
private lateinit var glide: GlideRequests
|
2020-07-16 04:49:37 +02:00
|
|
|
private var broadcastReceiver: BroadcastReceiver? = null
|
2019-12-17 14:27:59 +01:00
|
|
|
|
2020-07-15 06:26:20 +02:00
|
|
|
private val publicKey: String
|
2021-05-27 07:00:16 +02:00
|
|
|
get() = TextSecurePreferences.getLocalNumber(this)!!
|
2020-01-06 04:26:52 +01:00
|
|
|
|
2019-12-18 11:36:09 +01:00
|
|
|
// region Lifecycle
|
2019-12-17 14:27:59 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
|
|
|
super.onCreate(savedInstanceState, isReady)
|
2020-02-04 04:20:42 +01:00
|
|
|
// Double check that the long poller is up
|
2020-03-24 03:48:23 +01:00
|
|
|
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
2019-12-17 14:27:59 +01:00
|
|
|
// Set content view
|
|
|
|
setContentView(R.layout.activity_home)
|
2020-01-07 02:00:30 +01:00
|
|
|
// Set custom toolbar
|
2020-01-06 02:07:55 +01:00
|
|
|
setSupportActionBar(toolbar)
|
2019-12-19 11:15:58 +01:00
|
|
|
// Set up Glide
|
|
|
|
glide = GlideApp.with(this)
|
2020-01-06 02:07:55 +01:00
|
|
|
// Set up toolbar buttons
|
|
|
|
profileButton.glide = glide
|
2021-03-01 07:16:15 +01:00
|
|
|
updateProfileButton()
|
2020-01-06 02:07:55 +01:00
|
|
|
profileButton.setOnClickListener { openSettings() }
|
2020-09-08 08:21:50 +02:00
|
|
|
pathStatusViewContainer.disableClipping()
|
2020-05-29 03:16:52 +02:00
|
|
|
pathStatusViewContainer.setOnClickListener { showPath() }
|
2020-01-09 01:35:43 +01:00
|
|
|
// Set up seed reminder view
|
|
|
|
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
|
2021-02-18 05:12:30 +01:00
|
|
|
if (!hasViewedSeed) {
|
2020-05-25 07:46:53 +02:00
|
|
|
val seedReminderViewTitle = SpannableString("You're almost finished! 80%") // Intentionally not yet translated
|
2020-01-09 01:35:43 +01:00
|
|
|
seedReminderViewTitle.setSpan(ForegroundColorSpan(resources.getColorWithID(R.color.accent, theme)), 24, 27, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
|
|
seedReminderView.title = seedReminderViewTitle
|
2020-05-25 07:46:53 +02:00
|
|
|
seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_1)
|
2020-01-09 01:35:43 +01:00
|
|
|
seedReminderView.setProgress(80, false)
|
|
|
|
seedReminderView.delegate = this
|
|
|
|
} else {
|
|
|
|
seedReminderView.visibility = View.GONE
|
|
|
|
}
|
2019-12-17 14:27:59 +01:00
|
|
|
// Set up recycler view
|
|
|
|
val cursor = DatabaseFactory.getThreadDatabase(this).conversationList
|
2019-12-19 11:15:58 +01:00
|
|
|
val homeAdapter = HomeAdapter(this, cursor)
|
2021-02-04 06:57:24 +01:00
|
|
|
homeAdapter.setHasStableIds(true)
|
2019-12-19 11:15:58 +01:00
|
|
|
homeAdapter.glide = glide
|
|
|
|
homeAdapter.conversationClickListener = this
|
|
|
|
recyclerView.adapter = homeAdapter
|
2019-12-17 14:27:59 +01:00
|
|
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
2020-04-20 03:54:56 +02:00
|
|
|
// Set up empty state view
|
2020-10-06 05:19:52 +02:00
|
|
|
createNewPrivateChatButton.setOnClickListener { createNewPrivateChat() }
|
2019-12-19 11:49:23 +01:00
|
|
|
// This is a workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update (even though it says it will)
|
|
|
|
LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks<Cursor> {
|
|
|
|
|
|
|
|
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<Cursor> {
|
|
|
|
return HomeLoader(this@HomeActivity)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onLoadFinished(loader: Loader<Cursor>, cursor: Cursor?) {
|
|
|
|
homeAdapter.changeCursor(cursor)
|
2020-04-20 03:54:56 +02:00
|
|
|
updateEmptyState()
|
2019-12-19 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onLoaderReset(cursor: Loader<Cursor>) {
|
|
|
|
homeAdapter.changeCursor(null)
|
|
|
|
}
|
|
|
|
})
|
2020-03-16 05:35:14 +01:00
|
|
|
// Set up gradient view
|
|
|
|
val gradientViewLayoutParams = gradientView.layoutParams as RelativeLayout.LayoutParams
|
|
|
|
val displayMetrics = DisplayMetrics()
|
|
|
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
|
|
val height = displayMetrics.heightPixels
|
|
|
|
gradientViewLayoutParams.topMargin = (0.15 * height.toFloat()).toInt()
|
|
|
|
// Set up new conversation button set
|
2020-03-12 05:57:53 +01:00
|
|
|
newConversationButtonSet.delegate = this
|
2019-12-19 11:15:58 +01:00
|
|
|
// Set up typing observer
|
2019-12-19 11:49:23 +01:00
|
|
|
ApplicationContext.getInstance(this).typingStatusRepository.typingThreads.observe(this, Observer<Set<Long>> { threadIDs ->
|
|
|
|
val adapter = recyclerView.adapter as HomeAdapter
|
|
|
|
adapter.typingThreadIDs = threadIDs ?: setOf()
|
2019-12-19 11:15:58 +01:00
|
|
|
})
|
2020-05-14 05:52:20 +02:00
|
|
|
// Set up remaining components if needed
|
2020-05-26 00:55:29 +02:00
|
|
|
val application = ApplicationContext.getInstance(this)
|
2020-05-14 05:52:20 +02:00
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
|
|
|
|
if (userPublicKey != null) {
|
2021-05-19 03:12:29 +02:00
|
|
|
OpenGroupManager.startPolling()
|
2021-03-17 01:30:03 +01:00
|
|
|
JobQueue.shared.resumePendingJobs()
|
2019-12-17 14:27:59 +01:00
|
|
|
}
|
2020-06-03 03:52:30 +02:00
|
|
|
IP2Country.configureIfNeeded(this)
|
2020-09-24 01:43:18 +02:00
|
|
|
application.registerForFCMIfNeeded(false)
|
2020-07-16 04:49:37 +02:00
|
|
|
// Observe blocked contacts changed events
|
|
|
|
val broadcastReceiver = object : BroadcastReceiver() {
|
|
|
|
|
|
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
recyclerView.adapter!!.notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.broadcastReceiver = broadcastReceiver
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, IntentFilter("blockedContactsChanged"))
|
2021-03-03 01:33:35 +01:00
|
|
|
lifecycleScope.launch {
|
2021-03-01 07:16:15 +01:00
|
|
|
// update things based on TextSecurePrefs (profile info etc)
|
|
|
|
TextSecurePreferences.events.filter { it == TextSecurePreferences.PROFILE_NAME_PREF }.collect {
|
|
|
|
updateProfileButton()
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 01:33:35 +01:00
|
|
|
EventBus.getDefault().register(this@HomeActivity)
|
2019-12-17 14:27:59 +01:00
|
|
|
}
|
2019-12-18 15:25:23 +01:00
|
|
|
|
2020-01-09 01:35:43 +01:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2021-06-09 07:56:20 +02:00
|
|
|
if (TextSecurePreferences.getLocalNumber(this) == null) { return; } // This can be the case after a secondary device is auto-cleared
|
|
|
|
IdentityKeyUtil.checkUpdate(this)
|
2021-02-25 00:18:38 +01:00
|
|
|
profileButton.recycle() // clear cached image before update tje profilePictureView
|
2020-06-03 09:03:35 +02:00
|
|
|
profileButton.update()
|
2020-01-09 01:35:43 +01:00
|
|
|
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
|
2021-02-18 05:12:30 +01:00
|
|
|
if (hasViewedSeed) {
|
2020-01-09 01:35:43 +01:00
|
|
|
seedReminderView.visibility = View.GONE
|
|
|
|
}
|
2021-03-04 04:19:07 +01:00
|
|
|
if (TextSecurePreferences.getConfigurationMessageSynced(this)) {
|
2021-03-04 04:43:02 +01:00
|
|
|
lifecycleScope.launch(Dispatchers.IO) {
|
|
|
|
MultiDeviceProtocol.syncConfigurationIfNeeded(this@HomeActivity)
|
|
|
|
}
|
2021-03-04 04:19:07 +01:00
|
|
|
}
|
2021-01-13 06:13:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 01:16:07 +01:00
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
2020-08-18 00:55:17 +02:00
|
|
|
if (resultCode == CreateClosedGroupActivity.closedGroupCreatedResultCode) {
|
2020-03-12 05:57:53 +01:00
|
|
|
createNewPrivateChat()
|
2020-03-12 01:16:07 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-16 04:49:37 +02:00
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
val broadcastReceiver = this.broadcastReceiver
|
|
|
|
if (broadcastReceiver != null) {
|
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver)
|
|
|
|
}
|
|
|
|
super.onDestroy()
|
2021-03-03 01:33:35 +01:00
|
|
|
EventBus.getDefault().unregister(this)
|
2020-07-16 04:49:37 +02:00
|
|
|
}
|
2020-01-09 01:35:43 +01:00
|
|
|
// endregion
|
|
|
|
|
2020-04-20 03:54:56 +02:00
|
|
|
// region Updating
|
|
|
|
private fun updateEmptyState() {
|
|
|
|
val threadCount = (recyclerView.adapter as HomeAdapter).itemCount
|
|
|
|
emptyStateContainer.visibility = if (threadCount == 0) View.VISIBLE else View.GONE
|
|
|
|
}
|
2021-03-01 07:16:15 +01:00
|
|
|
|
2021-03-03 01:33:35 +01:00
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
fun onUpdateProfileEvent(event: ProfilePictureModifiedEvent) {
|
|
|
|
if (event.recipient.isLocalNumber) {
|
|
|
|
updateProfileButton()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 07:16:15 +01:00
|
|
|
private fun updateProfileButton() {
|
|
|
|
profileButton.publicKey = publicKey
|
|
|
|
profileButton.displayName = TextSecurePreferences.getProfileName(this)
|
|
|
|
profileButton.recycle()
|
|
|
|
profileButton.update()
|
|
|
|
}
|
2020-04-20 03:54:56 +02:00
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Interaction
|
2020-01-09 01:35:43 +01:00
|
|
|
override fun handleSeedReminderViewContinueButtonTapped() {
|
|
|
|
val intent = Intent(this, SeedActivity::class.java)
|
|
|
|
show(intent)
|
|
|
|
}
|
|
|
|
|
2019-12-17 15:15:13 +01:00
|
|
|
override fun onConversationClick(view: ConversationView) {
|
|
|
|
val thread = view.thread ?: return
|
|
|
|
openConversation(thread)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onLongConversationClick(view: ConversationView) {
|
2020-07-16 03:58:11 +02:00
|
|
|
val thread = view.thread ?: return
|
|
|
|
val bottomSheet = ConversationOptionsBottomSheet()
|
|
|
|
bottomSheet.recipient = thread.recipient
|
2020-09-07 02:57:25 +02:00
|
|
|
bottomSheet.onViewDetailsTapped = {
|
|
|
|
bottomSheet.dismiss()
|
|
|
|
val userDetailsBottomSheet = UserDetailsBottomSheet()
|
2020-09-07 07:20:32 +02:00
|
|
|
val bundle = Bundle()
|
2021-01-15 05:36:30 +01:00
|
|
|
bundle.putString("publicKey", thread.recipient.address.toString())
|
2020-09-07 07:20:32 +02:00
|
|
|
userDetailsBottomSheet.arguments = bundle
|
2020-09-07 02:57:25 +02:00
|
|
|
userDetailsBottomSheet.show(supportFragmentManager, userDetailsBottomSheet.tag)
|
|
|
|
}
|
2020-08-21 07:06:39 +02:00
|
|
|
bottomSheet.onBlockTapped = {
|
|
|
|
bottomSheet.dismiss()
|
|
|
|
if (!thread.recipient.isBlocked) {
|
|
|
|
blockConversation(thread)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bottomSheet.onUnblockTapped = {
|
2020-07-16 03:58:11 +02:00
|
|
|
bottomSheet.dismiss()
|
|
|
|
if (thread.recipient.isBlocked) {
|
|
|
|
unblockConversation(thread)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bottomSheet.onDeleteTapped = {
|
|
|
|
bottomSheet.dismiss()
|
|
|
|
deleteConversation(thread)
|
|
|
|
}
|
|
|
|
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun blockConversation(thread: ThreadRecord) {
|
|
|
|
AlertDialog.Builder(this)
|
2021-03-03 01:33:35 +01:00
|
|
|
.setTitle(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
|
|
|
.setMessage(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_block) { dialog, _ ->
|
|
|
|
ThreadUtils.queue {
|
|
|
|
DatabaseFactory.getRecipientDatabase(this).setBlocked(thread.recipient, true)
|
|
|
|
Util.runOnMain {
|
|
|
|
recyclerView.adapter!!.notifyDataSetChanged()
|
|
|
|
dialog.dismiss()
|
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
2021-03-03 01:33:35 +01:00
|
|
|
}.show()
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun unblockConversation(thread: ThreadRecord) {
|
|
|
|
AlertDialog.Builder(this)
|
2021-03-03 01:33:35 +01:00
|
|
|
.setTitle(R.string.RecipientPreferenceActivity_unblock_this_contact_question)
|
|
|
|
.setMessage(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_unblock) { dialog, _ ->
|
|
|
|
ThreadUtils.queue {
|
|
|
|
DatabaseFactory.getRecipientDatabase(this).setBlocked(thread.recipient, false)
|
|
|
|
Util.runOnMain {
|
|
|
|
recyclerView.adapter!!.notifyDataSetChanged()
|
|
|
|
dialog.dismiss()
|
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
2021-03-03 01:33:35 +01:00
|
|
|
}.show()
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun deleteConversation(thread: ThreadRecord) {
|
|
|
|
val threadID = thread.threadId
|
|
|
|
val recipient = thread.recipient
|
|
|
|
val threadDB = DatabaseFactory.getThreadDatabase(this)
|
2021-05-14 05:13:02 +02:00
|
|
|
val message: String
|
2021-01-13 06:13:49 +01:00
|
|
|
if (recipient.isGroupRecipient) {
|
|
|
|
val group = DatabaseFactory.getGroupDatabase(this).getGroup(recipient.address.toString()).orNull()
|
2021-01-15 05:36:30 +01:00
|
|
|
if (group != null && group.admins.map { it.toString() }.contains(TextSecurePreferences.getLocalNumber(this))) {
|
2021-05-14 05:13:02 +02:00
|
|
|
message = "Because you are the creator of this group it will be deleted for everyone. This cannot be undone."
|
2021-01-13 06:13:49 +01:00
|
|
|
} else {
|
2021-05-14 05:13:02 +02:00
|
|
|
message = resources.getString(R.string.activity_home_leave_group_dialog_message)
|
2021-01-13 06:13:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-14 05:13:02 +02:00
|
|
|
message = resources.getString(R.string.activity_home_delete_conversation_dialog_message)
|
2021-01-13 06:13:49 +01:00
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
val dialog = AlertDialog.Builder(this)
|
2021-05-14 05:13:02 +02:00
|
|
|
dialog.setMessage(message)
|
2021-03-03 01:33:35 +01:00
|
|
|
dialog.setPositiveButton(R.string.yes) { _, _ ->
|
|
|
|
lifecycleScope.launch(Dispatchers.Main) {
|
|
|
|
val context = this@HomeActivity as Context
|
2021-05-14 05:13:02 +02:00
|
|
|
// Cancel any outstanding jobs
|
|
|
|
DatabaseFactory.getSessionJobDatabase(context).cancelPendingMessageSendJobs(threadID)
|
2021-03-03 01:33:35 +01:00
|
|
|
// Send a leave group message if this is an active closed group
|
|
|
|
if (recipient.address.isClosedGroup && DatabaseFactory.getGroupDatabase(context).isActive(recipient.address.toGroupString())) {
|
|
|
|
var isClosedGroup: Boolean
|
|
|
|
var groupPublicKey: String?
|
|
|
|
try {
|
|
|
|
groupPublicKey = GroupUtil.doubleDecodeGroupID(recipient.address.toString()).toHexString()
|
|
|
|
isClosedGroup = DatabaseFactory.getLokiAPIDatabase(context).isClosedGroup(groupPublicKey)
|
|
|
|
} catch (e: IOException) {
|
|
|
|
groupPublicKey = null
|
|
|
|
isClosedGroup = false
|
|
|
|
}
|
|
|
|
if (isClosedGroup) {
|
2021-03-26 05:46:37 +01:00
|
|
|
MessageSender.explicitLeave(groupPublicKey!!, false)
|
2021-03-03 01:33:35 +01:00
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
2021-05-14 05:13:02 +02:00
|
|
|
// Delete the conversation
|
|
|
|
val v2OpenGroup = DatabaseFactory.getLokiThreadDatabase(context).getOpenGroupChat(threadID)
|
2021-05-21 07:02:34 +02:00
|
|
|
if (v2OpenGroup != null) {
|
2021-05-19 03:12:29 +02:00
|
|
|
OpenGroupManager.delete(v2OpenGroup.server, v2OpenGroup.room, this@HomeActivity)
|
2021-05-14 05:13:02 +02:00
|
|
|
} else {
|
2021-05-20 05:35:43 +02:00
|
|
|
ThreadUtils.queue {
|
|
|
|
threadDB.deleteConversation(threadID)
|
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
}
|
2021-05-14 05:13:02 +02:00
|
|
|
// Update the badge count
|
|
|
|
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
|
2021-03-03 01:33:35 +01:00
|
|
|
// Notify the user
|
|
|
|
val toastMessage = if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
|
|
|
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 03:58:11 +02:00
|
|
|
dialog.setNegativeButton(R.string.no) { _, _ ->
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
dialog.create().show()
|
2019-12-17 15:15:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun openConversation(thread: ThreadRecord) {
|
2021-05-31 06:29:11 +02:00
|
|
|
val intent = Intent(this, ConversationActivityV2::class.java)
|
|
|
|
intent.putExtra(ConversationActivityV2.THREAD_ID, thread.threadId)
|
2019-12-17 15:15:13 +01:00
|
|
|
push(intent)
|
|
|
|
}
|
|
|
|
|
2020-01-06 02:07:55 +01:00
|
|
|
private fun openSettings() {
|
2020-01-06 04:26:52 +01:00
|
|
|
val intent = Intent(this, SettingsActivity::class.java)
|
2021-03-01 07:16:15 +01:00
|
|
|
show(intent, isForResult = true)
|
2020-01-06 02:07:55 +01:00
|
|
|
}
|
|
|
|
|
2020-05-28 08:43:37 +02:00
|
|
|
private fun showPath() {
|
|
|
|
val intent = Intent(this, PathActivity::class.java)
|
|
|
|
show(intent)
|
|
|
|
}
|
|
|
|
|
2020-03-12 05:57:53 +01:00
|
|
|
override fun createNewPrivateChat() {
|
2019-12-18 15:25:23 +01:00
|
|
|
val intent = Intent(this, CreatePrivateChatActivity::class.java)
|
2020-01-08 05:16:34 +01:00
|
|
|
show(intent)
|
2019-12-17 15:15:13 +01:00
|
|
|
}
|
2019-12-18 15:25:23 +01:00
|
|
|
|
2020-03-12 05:57:53 +01:00
|
|
|
override fun createNewClosedGroup() {
|
2020-01-31 03:57:24 +01:00
|
|
|
val intent = Intent(this, CreateClosedGroupActivity::class.java)
|
2020-03-12 01:16:07 +01:00
|
|
|
show(intent, true)
|
2020-01-31 03:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 05:57:53 +01:00
|
|
|
override fun joinOpenGroup() {
|
2019-12-18 15:25:23 +01:00
|
|
|
val intent = Intent(this, JoinPublicChatActivity::class.java)
|
2020-01-08 05:16:34 +01:00
|
|
|
show(intent)
|
2019-12-18 15:25:23 +01:00
|
|
|
}
|
|
|
|
// endregion
|
2021-05-20 07:41:16 +02:00
|
|
|
}
|