mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Fix debug tool to insert messages with attachments.
This commit is contained in:
@@ -202,10 +202,10 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa
|
||||
}
|
||||
}
|
||||
|
||||
override fun add10Messages(recipientId: RecipientId) {
|
||||
override fun add100MessagesWithAttachments(recipientId: RecipientId) {
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
val recipient = Recipient.live(recipientId).get()
|
||||
val messageCount = 10
|
||||
val messageCount = 100
|
||||
val startTime = System.currentTimeMillis() - messageCount
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
val targetThread = SignalDatabase.threads.getOrCreateThreadIdFor(recipient)
|
||||
@@ -217,6 +217,10 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa
|
||||
threadId = targetThread
|
||||
)
|
||||
SignalDatabase.messages.markAsSent(id, true)
|
||||
SignalDatabase.attachments.getAttachmentsForMessage(id).forEach {
|
||||
SignalDatabase.attachments.debugMakeValidForArchive(it.attachmentId)
|
||||
SignalDatabase.attachments.createRemoteKeyIfNecessary(it.attachmentId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ private enum class Dialog {
|
||||
DELETE_AVATAR,
|
||||
CLEAR_RECIPIENT_DATA,
|
||||
ADD_1000_MESSAGES,
|
||||
ADD_10_MESSAGES,
|
||||
ADD_100_MESSAGES_WITH_ATTACHMENTS,
|
||||
SPLIT_AND_CREATE_THREADS,
|
||||
SPLIT_WITHOUT_CREATING_THREADS
|
||||
}
|
||||
@@ -273,10 +273,10 @@ fun InternalConversationSettingsScreen(
|
||||
|
||||
item {
|
||||
Rows.TextRow(
|
||||
text = "Add 10 dummy messages with attachments",
|
||||
label = "Adds 10 random messages to the chat with attachments of a random image. Attachments are not uploaded.",
|
||||
text = "Add 100 dummy messages with attachments",
|
||||
label = "Adds 100 random messages to the chat with attachments of a random image. Attachments are not uploaded.",
|
||||
onClick = {
|
||||
dialog = Dialog.ADD_10_MESSAGES
|
||||
dialog = Dialog.ADD_100_MESSAGES_WITH_ATTACHMENTS
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -364,8 +364,8 @@ private fun rememberOnConfirm(
|
||||
Dialog.ADD_1000_MESSAGES -> {
|
||||
{ callbacks.add1000Messages(state.recipientId) }
|
||||
}
|
||||
Dialog.ADD_10_MESSAGES -> {
|
||||
{ callbacks.add10Messages(state.recipientId) }
|
||||
Dialog.ADD_100_MESSAGES_WITH_ATTACHMENTS -> {
|
||||
{ callbacks.add100MessagesWithAttachments(state.recipientId) }
|
||||
}
|
||||
Dialog.SPLIT_AND_CREATE_THREADS -> {
|
||||
{ callbacks.splitAndCreateThreads(state.recipientId) }
|
||||
@@ -470,7 +470,7 @@ interface InternalConversationSettingsScreenCallbacks {
|
||||
fun deleteAvatar(recipientId: RecipientId) = Unit
|
||||
fun clearRecipientData(recipientId: RecipientId) = Unit
|
||||
fun add1000Messages(recipientId: RecipientId) = Unit
|
||||
fun add10Messages(recipientId: RecipientId) = Unit
|
||||
fun add100MessagesWithAttachments(recipientId: RecipientId) = Unit
|
||||
fun splitAndCreateThreads(recipientId: RecipientId) = Unit
|
||||
fun splitWithoutCreatingThreads(recipientId: RecipientId) = Unit
|
||||
fun clearSenderKey(recipientId: RecipientId) = Unit
|
||||
|
||||
@@ -1986,6 +1986,24 @@ class AttachmentTable(
|
||||
.run()
|
||||
}
|
||||
|
||||
fun debugMakeValidForArchive(attachmentId: AttachmentId) {
|
||||
writableDatabase
|
||||
.execSQL(
|
||||
"""
|
||||
UPDATE $TABLE_NAME
|
||||
SET $DATA_HASH_END = $DATA_HASH_START
|
||||
WHERE $ID = ${attachmentId.id}
|
||||
"""
|
||||
)
|
||||
|
||||
writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(
|
||||
REMOTE_KEY to Base64.encodeWithPadding(Util.getSecretBytes(64)),
|
||||
REMOTE_DIGEST to Util.getSecretBytes(64)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the data file if there's no strong references to other attachments.
|
||||
* If deleted, it will also clear all weak references (i.e. quotes) of the attachment.
|
||||
|
||||
Reference in New Issue
Block a user