Merge pull request #772 from hjubb/activate_unsends

Activate un-sending messages
This commit is contained in:
Harris 2021-10-27 17:34:45 +11:00 committed by GitHub
commit a1b2e79108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 8 deletions

View file

@ -224,7 +224,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
const val INVITE_CONTACTS = 124
//flag
const val IS_UNSEND_REQUESTS_ENABLED = false
const val IS_UNSEND_REQUESTS_ENABLED = true
}
// endregion

View file

@ -6,21 +6,38 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.android.synthetic.main.fragment_conversation_bottom_sheet.*
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.android.synthetic.main.fragment_delete_message_bottom_sheet.*
import network.loki.messenger.R
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.database.SessionContactDatabase
import org.thoughtcrime.securesms.util.UiModeUtilities
import javax.inject.Inject
class DeleteOptionsBottomSheet: BottomSheetDialogFragment(), View.OnClickListener {
@AndroidEntryPoint
class DeleteOptionsBottomSheet : BottomSheetDialogFragment(), View.OnClickListener {
@Inject
lateinit var contactDatabase: SessionContactDatabase
lateinit var recipient: Recipient
val contact by lazy {
val senderId = recipient.address.serialize()
// this dialog won't show for open group contacts
contactDatabase.getContactWithSessionID(senderId)
?.displayName(Contact.ContactContext.REGULAR)
}
var onDeleteForMeTapped: (() -> Unit?)? = null
var onDeleteForEveryoneTapped: (() -> Unit)? = null
var onCancelTapped: (() -> Unit)? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_delete_message_bottom_sheet, container, false)
}
@ -34,10 +51,14 @@ class DeleteOptionsBottomSheet: BottomSheetDialogFragment(), View.OnClickListene
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (!this::recipient.isInitialized) { return dismiss() }
if (!recipient.isGroupRecipient) {
deleteForEveryoneTextView.text = resources.getString(R.string.delete_message_for_me_and_recipient, recipient.name)
if (!this::recipient.isInitialized) {
return dismiss()
}
if (!recipient.isGroupRecipient && !contact.isNullOrEmpty()) {
deleteForEveryoneTextView.text =
resources.getString(R.string.delete_message_for_me_and_recipient, contact)
}
deleteForEveryoneTextView.isVisible = !recipient.isClosedGroupRecipient
deleteForMeTextView.setOnClickListener(this)
deleteForEveryoneTextView.setOnClickListener(this)
cancelTextView.setOnClickListener(this)

View file

@ -144,7 +144,8 @@ private fun handleConfigurationMessage(message: ConfigurationMessage) {
}
fun MessageReceiver.handleUnsendRequest(message: UnsendRequest) {
if (message.sender != message.author) { return }
val userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
if (message.sender != message.author && (message.sender != userPublicKey && userPublicKey != null)) { return }
val context = MessagingModuleConfiguration.shared.context
val storage = MessagingModuleConfiguration.shared.storage
val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider