Skip to content

Commit 136efec

Browse files
Merge pull request #1274 from session-foundation/fix/store-issues
Capturing exception thrown while uploading attachments
2 parents 7bd838c + b92f1bc commit 136efec

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ import org.thoughtcrime.securesms.mms.AudioSlide
183183
import org.thoughtcrime.securesms.mms.GifSlide
184184
import org.thoughtcrime.securesms.mms.ImageSlide
185185
import org.thoughtcrime.securesms.mms.MediaConstraints
186+
import org.thoughtcrime.securesms.mms.MmsException
186187
import org.thoughtcrime.securesms.mms.Slide
187188
import org.thoughtcrime.securesms.mms.SlideDeck
188189
import org.thoughtcrime.securesms.mms.VideoSlide
@@ -2092,25 +2093,36 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
20922093

20932094
// do the heavy work in the bg
20942095
lifecycleScope.launch(Dispatchers.Default) {
2095-
// Put the message in the database and send it
2096-
message.id = MessageId(mmsDb.insertMessageOutbox(
2097-
outgoingTextMessage,
2098-
viewModel.threadId,
2099-
false,
2100-
runThreadUpdate = true
2101-
), mms = true)
2096+
runCatching {
2097+
// Put the message in the database and send it
2098+
message.id = MessageId(
2099+
mmsDb.insertMessageOutbox(
2100+
outgoingTextMessage,
2101+
viewModel.threadId,
2102+
false,
2103+
runThreadUpdate = true
2104+
), mms = true
2105+
)
21022106

2103-
if (deleteAttachmentFilesAfterSave) {
2104-
attachments
2105-
.asSequence()
2106-
.mapNotNull { a -> a.dataUri?.takeIf { it.scheme == "file" }?.path?.let(::File) }
2107-
.filter { it.exists() }
2108-
.forEach { it.delete() }
2109-
}
2107+
if (deleteAttachmentFilesAfterSave) {
2108+
attachments
2109+
.asSequence()
2110+
.mapNotNull { a -> a.dataUri?.takeIf { it.scheme == "file" }?.path?.let(::File) }
2111+
.filter { it.exists() }
2112+
.forEach { it.delete() }
2113+
}
21102114

2111-
waitForApprovalJobToBeSubmitted()
2115+
waitForApprovalJobToBeSubmitted()
21122116

2113-
MessageSender.send(message, recipient.address, quote, linkPreview)
2117+
MessageSender.send(message, recipient.address, quote, linkPreview)
2118+
}.onFailure {
2119+
withContext(Dispatchers.Main){
2120+
when (it) {
2121+
is MmsException -> Toast.makeText(this@ConversationActivityV2, R.string.attachmentsErrorSending, Toast.LENGTH_LONG).show()
2122+
else -> Toast.makeText(this@ConversationActivityV2, R.string.errorGeneric, Toast.LENGTH_LONG).show()
2123+
}
2124+
}
2125+
}
21142126
}
21152127

21162128
// Send a typing stopped message

0 commit comments

Comments
 (0)