updated tests + make logic async + removed old code

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2025-07-18 09:17:56 -05:00 committed by Marcel Hibbe
parent b040ebc6b4
commit 53c6511d00
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 27 additions and 42 deletions

View File

@ -57,6 +57,7 @@ class ChatBlocksDaoTest {
val account1 = usersDao.getUserWithUserId("account1").blockingGet() val account1 = usersDao.getUserWithUserId("account1").blockingGet()
conversationsDao.upsertConversations( conversationsDao.upsertConversations(
account1.id,
listOf( listOf(
createConversationEntity( createConversationEntity(
accountId = account1.id, accountId = account1.id,
@ -182,6 +183,7 @@ class ChatBlocksDaoTest {
val account1 = usersDao.getUserWithUserId("account1").blockingGet() val account1 = usersDao.getUserWithUserId("account1").blockingGet()
conversationsDao.upsertConversations( conversationsDao.upsertConversations(
account1.id,
listOf( listOf(
createConversationEntity( createConversationEntity(
accountId = account1.id, accountId = account1.id,

View File

@ -66,6 +66,7 @@ class ChatMessagesDaoTest {
// Problem: lets say we want to update the conv list -> We don#t know the primary keys! // Problem: lets say we want to update the conv list -> We don#t know the primary keys!
// with account@token that would be easier! // with account@token that would be easier!
conversationsDao.upsertConversations( conversationsDao.upsertConversations(
account1.id,
listOf( listOf(
createConversationEntity( createConversationEntity(
accountId = account1.id, accountId = account1.id,

View File

@ -81,10 +81,12 @@ import com.nextcloud.talk.utils.message.MessageUtils
import com.nextcloud.talk.utils.text.Spans import com.nextcloud.talk.utils.text.Spans
import com.otaliastudios.autocomplete.Autocomplete import com.otaliastudios.autocomplete.Autocomplete
import com.vanniktech.emoji.EmojiPopup import com.vanniktech.emoji.EmojiPopup
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext
import java.util.Objects import java.util.Objects
import javax.inject.Inject import javax.inject.Inject
@ -111,10 +113,6 @@ class MessageInputFragment : Fragment() {
private const val CONNECTION_ESTABLISHED_ANIM_DURATION: Long = 3000 private const val CONNECTION_ESTABLISHED_ANIM_DURATION: Long = 3000
private const val FULLY_OPAQUE: Float = 1.0f private const val FULLY_OPAQUE: Float = 1.0f
private const val FULLY_TRANSPARENT: Float = 0.0f private const val FULLY_TRANSPARENT: Float = 0.0f
const val QUOTED_MESSAGE_TEXT = "QUOTED_MESSAGE_TEXT"
const val QUOTED_MESSAGE_ID = "QUOTED_MESSAGE_ID"
const val QUOTED_MESSAGE_URL = "QUOTED_MESSAGE_URL"
const val QUOTED_MESSAGE_NAME = "QUOTED_MESSAGE_NAME"
} }
@Inject @Inject
@ -164,10 +162,6 @@ class MessageInputFragment : Fragment() {
return binding.root return binding.root
} }
override fun onPause() {
super.onPause()
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) { if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) {
@ -306,24 +300,26 @@ class MessageInputFragment : Fragment() {
} }
private fun restoreState() { private fun restoreState() {
runBlocking { CoroutineScope(Dispatchers.IO).launch {
chatActivity.chatViewModel.updateMessageDraft() chatActivity.chatViewModel.updateMessageDraft()
}
val draft = chatActivity.chatViewModel.messageDraft withContext(Dispatchers.Main) {
binding.fragmentMessageInputView.messageInput.setText(draft.messageText) val draft = chatActivity.chatViewModel.messageDraft
binding.fragmentMessageInputView.messageInput.setSelection(draft.messageCursor) binding.fragmentMessageInputView.messageInput.setText(draft.messageText)
if (draft.messageText != "") { binding.fragmentMessageInputView.messageInput.setSelection(draft.messageCursor)
binding.fragmentMessageInputView.messageInput.requestFocus() if (draft.messageText != "") {
} binding.fragmentMessageInputView.messageInput.requestFocus()
}
if (isInReplyState()) { if (isInReplyState()) {
replyToMessage( replyToMessage(
chatActivity.chatViewModel.messageDraft.quotedMessageText, chatActivity.chatViewModel.messageDraft.quotedMessageText,
chatActivity.chatViewModel.messageDraft.quotedDisplayName, chatActivity.chatViewModel.messageDraft.quotedDisplayName,
chatActivity.chatViewModel.messageDraft.quotedImageUrl, chatActivity.chatViewModel.messageDraft.quotedImageUrl,
chatActivity.chatViewModel.messageDraft.quotedJsonId ?: 0 chatActivity.chatViewModel.messageDraft.quotedJsonId ?: 0
) )
}
}
} }
} }

View File

@ -61,7 +61,6 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File import java.io.File
import javax.inject.Inject import javax.inject.Inject
@ -113,7 +112,7 @@ class ChatViewModel @Inject constructor(
chatRepository.handleOnPause() chatRepository.handleOnPause()
mediaPlayerManager.handleOnPause() mediaPlayerManager.handleOnPause()
runBlocking(Dispatchers.IO) { CoroutineScope(Dispatchers.IO).launch {
val model = conversationRepository.getLocallyStoredConversation(chatRoomToken) val model = conversationRepository.getLocallyStoredConversation(chatRoomToken)
model?.let { model?.let {
it.messageDraft = messageDraft it.messageDraft = messageDraft
@ -295,6 +294,7 @@ class ChatViewModel @Inject constructor(
fun initData(credentials: String, urlForChatting: String, roomToken: String, threadId: Long?) { fun initData(credentials: String, urlForChatting: String, roomToken: String, threadId: Long?) {
chatRepository.initData(credentials, urlForChatting, roomToken, threadId) chatRepository.initData(credentials, urlForChatting, roomToken, threadId)
chatRoomToken = roomToken
} }
fun updateConversation(currentConversation: ConversationModel) { fun updateConversation(currentConversation: ConversationModel) {

View File

@ -307,16 +307,6 @@ class ConversationsListActivity :
showNotificationWarning() showNotificationWarning()
showShareToScreen = hasActivityActionSendIntent() showShareToScreen = hasActivityActionSendIntent()
// context.getSharedPreferences(
// CHAT_ACTIVITY_LOCAL_NAME,
// MODE_PRIVATE
// ).edit().apply {
// putInt(QUOTED_MESSAGE_ID, -1)
// putString(QUOTED_MESSAGE_NAME, null)
// putString(QUOTED_MESSAGE_TEXT, "")
// putString(QUOTED_MESSAGE_URL, null)
// apply()
// }
if (!eventBus.isRegistered(this)) { if (!eventBus.isRegistered(this)) {
eventBus.register(this) eventBus.register(this)

View File

@ -13,7 +13,6 @@ import androidx.room.OnConflictStrategy.Companion.REPLACE
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction import androidx.room.Transaction
import androidx.room.Update import androidx.room.Update
import androidx.room.Upsert
import com.nextcloud.talk.data.database.model.ConversationEntity import com.nextcloud.talk.data.database.model.ConversationEntity
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -26,15 +25,12 @@ interface ConversationsDao {
@Query("SELECT * FROM Conversations where accountId = :accountId AND token = :token") @Query("SELECT * FROM Conversations where accountId = :accountId AND token = :token")
fun getConversationForUser(accountId: Long, token: String): Flow<ConversationEntity?> fun getConversationForUser(accountId: Long, token: String): Flow<ConversationEntity?>
@Upsert()
fun upsertConversations(conversationEntities: List<ConversationEntity>)
@Transaction @Transaction
suspend fun upsertConversations(accountId: Long, serverItems: List<ConversationEntity>) { suspend fun upsertConversations(accountId: Long, serverItems: List<ConversationEntity>) {
serverItems.forEach { serverItem -> serverItems.forEach { serverItem ->
val existingItem = getConversationForUser(accountId, serverItem.token).first() val existingItem = getConversationForUser(accountId, serverItem.token).first()
if (existingItem != null) { if (existingItem != null) {
val mergedItem = serverItem val mergedItem = serverItem.copy()
mergedItem.messageDraft = existingItem.messageDraft mergedItem.messageDraft = existingItem.messageDraft
updateConversation(mergedItem) updateConversation(mergedItem)
} else { } else {

View File

@ -192,7 +192,7 @@ class DummyConversationDaoImpl : ConversationsDao {
override fun getConversationForUser(accountId: Long, token: String): Flow<ConversationEntity?> = flowOf() override fun getConversationForUser(accountId: Long, token: String): Flow<ConversationEntity?> = flowOf()
override fun upsertConversations(conversationEntities: List<ConversationEntity>) { /* */ } override suspend fun upsertConversations(accountId: Long, serverItems: List<ConversationEntity>) { /* */ }
override fun deleteConversations(conversationIds: List<String>) { /* */ } override fun deleteConversations(conversationIds: List<String>) { /* */ }