2022-10-27 20:33:33 +00:00
|
|
|
package org.thoughtcrime.securesms.conversation
|
|
|
|
|
|
|
|
import androidx.test.core.app.ActivityScenario
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
import org.junit.Ignore
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.signal.core.util.ThreadUtil
|
|
|
|
import org.thoughtcrime.securesms.attachments.PointerAttachment
|
|
|
|
import org.thoughtcrime.securesms.database.SignalDatabase
|
|
|
|
import org.thoughtcrime.securesms.mms.IncomingMediaMessage
|
2022-12-14 21:19:12 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMessage
|
2022-10-27 20:33:33 +00:00
|
|
|
import org.thoughtcrime.securesms.profiles.ProfileName
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
|
|
|
import org.thoughtcrime.securesms.releasechannel.ReleaseChannel
|
|
|
|
import org.thoughtcrime.securesms.testing.SignalActivityRule
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId
|
|
|
|
import java.util.Optional
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper test for rendering conversation items for preview.
|
|
|
|
*/
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
@Ignore("For testing/previewing manually, no assertions")
|
|
|
|
class ConversationItemPreviewer {
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
val harness = SignalActivityRule(othersCount = 10)
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testShowLongName() {
|
|
|
|
val other: Recipient = Recipient.resolved(harness.others.first())
|
|
|
|
|
|
|
|
SignalDatabase.recipients.setProfileName(other.id, ProfileName.fromParts("Seef", "$$$"))
|
|
|
|
|
|
|
|
insertFailedMediaMessage(other = other, attachmentCount = 1)
|
|
|
|
insertFailedMediaMessage(other = other, attachmentCount = 2)
|
|
|
|
insertFailedMediaMessage(other = other, body = "Test", attachmentCount = 1)
|
|
|
|
// insertFailedOutgoingMediaMessage(other = other, body = "Test", attachmentCount = 1)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
// insertMediaMessage(other = other)
|
|
|
|
|
|
|
|
val scenario: ActivityScenario<ConversationActivity> = harness.launchActivity { putExtra("recipient_id", other.id.serialize()) }
|
|
|
|
scenario.onActivity {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uncomment to make dialog stay on screen, otherwise will show/dismiss immediately
|
|
|
|
// ThreadUtil.sleep(45000)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun insertMediaMessage(other: Recipient, body: String? = null, attachmentCount: Int = 1) {
|
|
|
|
val attachments: List<SignalServiceAttachmentPointer> = (0 until attachmentCount).map {
|
|
|
|
attachment()
|
|
|
|
}
|
|
|
|
|
|
|
|
val message = IncomingMediaMessage(
|
|
|
|
from = other.id,
|
|
|
|
body = body,
|
|
|
|
sentTimeMillis = System.currentTimeMillis(),
|
|
|
|
serverTimeMillis = System.currentTimeMillis(),
|
|
|
|
receivedTimeMillis = System.currentTimeMillis(),
|
2023-02-06 15:04:40 +00:00
|
|
|
attachments = PointerAttachment.forPointers(Optional.of(attachments))
|
2022-10-27 20:33:33 +00:00
|
|
|
)
|
|
|
|
|
2022-12-15 01:08:23 +00:00
|
|
|
SignalDatabase.messages.insertSecureDecryptedMessageInbox(message, SignalDatabase.threads.getOrCreateThreadIdFor(other)).get()
|
2022-10-27 20:33:33 +00:00
|
|
|
|
|
|
|
ThreadUtil.sleep(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun insertFailedMediaMessage(other: Recipient, body: String? = null, attachmentCount: Int = 1) {
|
|
|
|
val attachments: List<SignalServiceAttachmentPointer> = (0 until attachmentCount).map {
|
|
|
|
attachment()
|
|
|
|
}
|
|
|
|
|
|
|
|
val message = IncomingMediaMessage(
|
|
|
|
from = other.id,
|
|
|
|
body = body,
|
|
|
|
sentTimeMillis = System.currentTimeMillis(),
|
|
|
|
serverTimeMillis = System.currentTimeMillis(),
|
|
|
|
receivedTimeMillis = System.currentTimeMillis(),
|
2023-02-06 15:04:40 +00:00
|
|
|
attachments = PointerAttachment.forPointers(Optional.of(attachments))
|
2022-10-27 20:33:33 +00:00
|
|
|
)
|
|
|
|
|
2022-12-15 01:08:23 +00:00
|
|
|
val insert = SignalDatabase.messages.insertSecureDecryptedMessageInbox(message, SignalDatabase.threads.getOrCreateThreadIdFor(other)).get()
|
2022-10-27 20:33:33 +00:00
|
|
|
|
|
|
|
SignalDatabase.attachments.getAttachmentsForMessage(insert.messageId).forEachIndexed { index, attachment ->
|
|
|
|
// if (index != 1) {
|
|
|
|
SignalDatabase.attachments.setTransferProgressPermanentFailure(attachment.attachmentId, insert.messageId)
|
|
|
|
// } else {
|
|
|
|
// SignalDatabase.attachments.setTransferState(insert.messageId, attachment, TRANSFER_PROGRESS_STARTED)
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadUtil.sleep(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun insertFailedOutgoingMediaMessage(other: Recipient, body: String? = null, attachmentCount: Int = 1) {
|
|
|
|
val attachments: List<SignalServiceAttachmentPointer> = (0 until attachmentCount).map {
|
|
|
|
attachment()
|
|
|
|
}
|
|
|
|
|
2022-12-14 21:19:12 +00:00
|
|
|
val message = OutgoingMessage(
|
2022-12-09 14:48:16 +00:00
|
|
|
recipient = other,
|
|
|
|
body = body,
|
|
|
|
attachments = PointerAttachment.forPointers(Optional.of(attachments)),
|
|
|
|
timestamp = System.currentTimeMillis(),
|
|
|
|
isSecure = true
|
2022-10-27 20:33:33 +00:00
|
|
|
)
|
|
|
|
|
2022-12-15 01:08:23 +00:00
|
|
|
val insert = SignalDatabase.messages.insertMessageOutbox(
|
2022-12-09 14:48:16 +00:00
|
|
|
message,
|
2022-10-27 20:33:33 +00:00
|
|
|
SignalDatabase.threads.getOrCreateThreadIdFor(other),
|
|
|
|
false,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
|
|
|
|
SignalDatabase.attachments.getAttachmentsForMessage(insert).forEachIndexed { index, attachment ->
|
|
|
|
SignalDatabase.attachments.setTransferProgressPermanentFailure(attachment.attachmentId, insert)
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadUtil.sleep(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun attachment(): SignalServiceAttachmentPointer {
|
|
|
|
return SignalServiceAttachmentPointer(
|
|
|
|
ReleaseChannel.CDN_NUMBER,
|
|
|
|
SignalServiceAttachmentRemoteId.from(""),
|
|
|
|
"image/webp",
|
|
|
|
null,
|
|
|
|
Optional.empty(),
|
|
|
|
Optional.empty(),
|
|
|
|
1024,
|
|
|
|
1024,
|
|
|
|
Optional.empty(),
|
|
|
|
Optional.of("/not-there.jpg"),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
Optional.empty(),
|
|
|
|
Optional.empty(),
|
|
|
|
System.currentTimeMillis()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|