Skip to content

Commit

Permalink
Fixed updating existing drafts.| #74
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 7, 2024
1 parent 0e23d07 commit 4fc51f0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ class DraftViewModel(

fun setupWithInitializationData(
initializationData: InitializationData,
timeInMilliseconds: Long
timeInMilliseconds: Long,
skipCheckingSignature: Boolean
) {
draftFingerprint = DraftFingerprint(
msgText = initializationData.body ?: "",
msgSubject = initializationData.subject,
toRecipients = initializationData.toAddresses.map { it.lowercase() }.toSet(),
ccRecipients = initializationData.ccAddresses.map { it.lowercase() }.toSet(),
bccRecipients = initializationData.bccAddresses.map { it.lowercase() }.toSet(),
timeInMilliseconds = timeInMilliseconds
timeInMilliseconds = timeInMilliseconds,
skipCheckingSignature = skipCheckingSignature
)
}

Expand All @@ -148,7 +150,8 @@ class DraftViewModel(
internetAddress.address.lowercase()
}?.toSet() ?: emptySet()

val isTextTheSame = if (outgoingMessageInfo.signature != null) {
val isTextTheSame =
if (outgoingMessageInfo.signature != null && !draftFingerprint.skipCheckingSignature) {
val textWithoutSignature = outgoingMessageInfo.msg?.replaceFirst(
regex = ("\n\n" + outgoingMessageInfo.signature).toRegex(RegexOption.MULTILINE),
replacement = ""
Expand Down Expand Up @@ -323,7 +326,8 @@ class DraftViewModel(
val toRecipients: Set<String> = setOf(),
val ccRecipients: Set<String> = setOf(),
val bccRecipients: Set<String> = setOf(),
val timeInMilliseconds: Long = System.currentTimeMillis()
val timeInMilliseconds: Long = System.currentTimeMillis(),
val skipCheckingSignature: Boolean = false,
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,8 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),

draftViewModel.setupWithInitializationData(
initializationData = initializationData,
timeInMilliseconds = startOfSessionInMilliseconds
timeInMilliseconds = startOfSessionInMilliseconds,
skipCheckingSignature = args.messageType == MessageType.DRAFT
)
}

Expand Down Expand Up @@ -1387,6 +1388,11 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
Result.Status.SUCCESS -> {
val accountEntity = it.data ?: return@collect

if (args.messageType == MessageType.DRAFT) {
composeMsgViewModel.markSignatureUsed()
return@collect
}

if (accountEntity.useAliasSignatures) {
val position = binding?.spinnerFrom?.selectedItemPosition?.takeIf { position ->
position != Spinner.INVALID_POSITION
Expand Down Expand Up @@ -2128,6 +2134,24 @@ class CreateMessageFragment : BaseFragment<FragmentCreateMessageBinding>(),
var useNewSignature = false

val oldSignature = composeMsgViewModel.outgoingMessageInfoStateFlow.value.signature
if (oldSignature == null && args.messageType == MessageType.DRAFT) {
val extractedSignature = aliases.firstOrNull { alias ->
alias.plainTextSignature != null && binding?.editTextEmailMessage?.text?.contains(
("^${alias.plainTextSignature}$").toRegex(RegexOption.MULTILINE)
) == true
}?.plainTextSignature

if (!extractedSignature.isNullOrEmpty()) {
composeMsgViewModel.updateOutgoingMessageInfo(
composeMsgViewModel.outgoingMessageInfoStateFlow.value.copy(
signature = extractedSignature
)
)
}

return
}

val messageHasOldSignature = oldSignature != null && binding?.editTextEmailMessage?.text?.contains(
("^$oldSignature$").toRegex(RegexOption.MULTILINE)
) == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ class MessagesInThreadListAdapter(private val onMessageActionsListener: OnMessag
)
}

//temporary disabled ability to edit a draft from a thread
binding.imageButtonEditDraft.visibleOrGone(false)
binding.imageButtonEditDraft.visibleOrGone(message.messageEntity.isDraft)
binding.imageButtonEditDraft.setOnClickListener {
onMessageActionsListener.onEditDraft(message)
}
Expand Down
15 changes: 15 additions & 0 deletions FlowCrypt/src/main/res/drawable/ic_baseline_edit_draft_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
~ © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
~ Contributors: denbond7
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#888888"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M18.41,5.8L17.2,4.59c-0.78,-0.78 -2.05,-0.78 -2.83,0l-2.68,2.68L3,15.96V20h4.04l8.74,-8.74 2.63,-2.63c0.79,-0.78 0.79,-2.05 0,-2.83zM6.21,18H5v-1.21l8.66,-8.66 1.21,1.21L6.21,18zM11,20l4,-4h6v4H11z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginRight="@dimen/default_margin_medium"
app:srcCompat="@drawable/ic_baseline_edit_draft_32" />
app:srcCompat="@drawable/ic_baseline_edit_draft_24" />

<TextView
android:id="@+id/textViewDate"
Expand Down

0 comments on commit 4fc51f0

Please sign in to comment.