-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
353 changed files
with
5,692 additions
and
3,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
root = true | ||
|
||
[*.kt] | ||
[*.{kt,kts}] | ||
indent_size = 2 | ||
ktlint_standard_trailing-comma-on-call-site = disable | ||
ktlint_standard_trailing-comma-on-declaration-site = disable | ||
ktlink_standard_spacing-between-declarations-with-annotations = disable | ||
ktlint_code_style = intellij_idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...e/securesms/components/settings/app/internal/conversation/ConversationElementGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.thoughtcrime.securesms.components.settings.app.internal.conversation | ||
|
||
import org.thoughtcrime.securesms.conversation.ConversationMessage.ConversationMessageFactory | ||
import org.thoughtcrime.securesms.conversation.v2.data.ConversationElementKey | ||
import org.thoughtcrime.securesms.conversation.v2.data.IncomingTextOnly | ||
import org.thoughtcrime.securesms.conversation.v2.data.OutgoingTextOnly | ||
import org.thoughtcrime.securesms.database.MessageTypes | ||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord | ||
import org.thoughtcrime.securesms.database.model.StoryType | ||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies | ||
import org.thoughtcrime.securesms.mms.SlideDeck | ||
import org.thoughtcrime.securesms.recipients.Recipient | ||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel | ||
import java.security.SecureRandom | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
/** | ||
* Generates random conversation messages via the given set of parameters. | ||
*/ | ||
class ConversationElementGenerator { | ||
private val mappingModelCache = mutableMapOf<ConversationElementKey, MappingModel<*>>() | ||
private val random = SecureRandom() | ||
|
||
private val wordBank = listOf( | ||
"A", | ||
"Test", | ||
"Message", | ||
"To", | ||
"Display", | ||
"Content", | ||
"In", | ||
"Bubbles", | ||
"User", | ||
"Signal", | ||
"The" | ||
) | ||
|
||
fun getMappingModel(key: ConversationElementKey): MappingModel<*> { | ||
val cached = mappingModelCache[key] | ||
if (cached != null) { | ||
return cached | ||
} | ||
|
||
val messageModel = generateMessage(key) | ||
mappingModelCache[key] = messageModel | ||
return messageModel | ||
} | ||
|
||
private fun getIncomingType(): Long { | ||
return MessageTypes.BASE_INBOX_TYPE or MessageTypes.SECURE_MESSAGE_BIT | ||
} | ||
|
||
private fun getSentOutgoingType(): Long { | ||
return MessageTypes.BASE_SENT_TYPE or MessageTypes.SECURE_MESSAGE_BIT | ||
} | ||
|
||
private fun generateMessage(key: ConversationElementKey): MappingModel<*> { | ||
val messageId = key.requireMessageId() | ||
val now = getNow() | ||
|
||
val testMessageWordLength = random.nextInt(40) + 1 | ||
val testMessage = (0 until testMessageWordLength).map { | ||
wordBank.random() | ||
}.joinToString(" ") | ||
|
||
val isIncoming = random.nextBoolean() | ||
|
||
val record = MediaMmsMessageRecord( | ||
messageId, | ||
if (isIncoming) Recipient.UNKNOWN else Recipient.self(), | ||
0, | ||
if (isIncoming) Recipient.self() else Recipient.UNKNOWN, | ||
now, | ||
now, | ||
now, | ||
1, | ||
1, | ||
testMessage, | ||
SlideDeck(), | ||
if (isIncoming) getIncomingType() else getSentOutgoingType(), | ||
emptySet(), | ||
emptySet(), | ||
0, | ||
0, | ||
0, | ||
false, | ||
1, | ||
null, | ||
emptyList(), | ||
emptyList(), | ||
false, | ||
emptyList(), | ||
false, | ||
false, | ||
now, | ||
1, | ||
now, | ||
null, | ||
StoryType.NONE, | ||
null, | ||
null, | ||
null, | ||
null, | ||
-1, | ||
null, | ||
null, | ||
0 | ||
) | ||
|
||
val conversationMessage = ConversationMessageFactory.createWithUnresolvedData( | ||
ApplicationDependencies.getApplication(), | ||
record, | ||
Recipient.UNKNOWN | ||
) | ||
|
||
return if (isIncoming) { | ||
IncomingTextOnly(conversationMessage) | ||
} else { | ||
OutgoingTextOnly(conversationMessage) | ||
} | ||
} | ||
|
||
private fun getNow(): Long { | ||
val now = System.currentTimeMillis() | ||
return now - random.nextInt(20.milliseconds.inWholeMilliseconds.toInt()).toLong() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...resms/components/settings/app/internal/conversation/InternalConversationTestDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.thoughtcrime.securesms.components.settings.app.internal.conversation | ||
|
||
import org.signal.paging.PagedDataSource | ||
import org.thoughtcrime.securesms.conversation.v2.data.ConversationElementKey | ||
import org.thoughtcrime.securesms.conversation.v2.data.ConversationMessageElement | ||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel | ||
import kotlin.math.min | ||
|
||
class InternalConversationTestDataSource( | ||
private val size: Int, | ||
private val generator: ConversationElementGenerator | ||
) : PagedDataSource<ConversationElementKey, MappingModel<*>> { | ||
override fun size(): Int = size | ||
|
||
override fun load(start: Int, length: Int, totalSize: Int, cancellationSignal: PagedDataSource.CancellationSignal): MutableList<MappingModel<*>> { | ||
val end = min(start + length, totalSize) | ||
return (start until end).map { | ||
load(ConversationElementKey.forMessage(it.toLong()))!! | ||
}.toMutableList() | ||
} | ||
|
||
override fun getKey(data: MappingModel<*>): ConversationElementKey { | ||
check(data is ConversationMessageElement) | ||
|
||
return ConversationElementKey.forMessage(data.conversationMessage.messageRecord.id) | ||
} | ||
|
||
override fun load(key: ConversationElementKey?): MappingModel<*>? { | ||
return key?.let { generator.getMappingModel(it) } | ||
} | ||
} |
Oops, something went wrong.