Skip to content

Commit

Permalink
update ContactsViewModelTest - shareTypes
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <[email protected]>
  • Loading branch information
sowjanyakch committed Aug 13, 2024
1 parent abf6d85 commit fcb0972
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class ChatBlocksDaoTest {
@Test
fun testGetConnectedChatBlocks() =
runTest {

usersDao.saveUser(createUserEntity("account1", "Account 1"))
val account1 = usersDao.getUserWithUserId("account1").blockingGet()

Expand All @@ -67,7 +66,7 @@ class ChatBlocksDaoTest {
accountId = account1.id,
"def",
roomName = "Conversation Two"
),
)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.OutcomingPollMessageViewHolder.Companion
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import android.view.MotionEvent
import android.view.View
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.IncomingPollMessageViewHolder.Companion
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.chat.ChatActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.IncomingTextMessageViewHolder.Companion
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.util.Log
import android.util.TypedValue
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
Expand All @@ -37,9 +36,7 @@ import com.nextcloud.talk.utils.preferences.AppPreferences
import com.stfalcon.chatkit.messages.MessageHolders
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import android.content.Context
import android.util.Log
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.OutcomingPollMessageViewHolder.Companion
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
Expand Down Expand Up @@ -164,32 +162,32 @@ class OutcomingLinkPreviewMessageViewHolder(outcomingView: View, payload: Any) :
message.parentMessageId!!
).first()
}
parentChatMessage.activeUser = message.activeUser
parentChatMessage.imageUrl?.let {
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
binding.messageQuote.quotedMessageImage.load(it) {
addHeader(
"Authorization",
ApiUtils.getCredentials(message.activeUser!!.username, message.activeUser!!.token)!!
)
}
} ?: run {
binding.messageQuote.quotedMessageImage.visibility = View.GONE
}
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = messageUtils
.enrichChatReplyMessageText(
binding.messageQuote.quotedMessage.context,
parentChatMessage,
false,
viewThemeUtils
parentChatMessage.activeUser = message.activeUser
parentChatMessage.imageUrl?.let {
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
binding.messageQuote.quotedMessageImage.load(it) {
addHeader(
"Authorization",
ApiUtils.getCredentials(message.activeUser!!.username, message.activeUser!!.token)!!
)
viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.talk.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.talk.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)

binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
}
} ?: run {
binding.messageQuote.quotedMessageImage.visibility = View.GONE
}
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = messageUtils
.enrichChatReplyMessageText(
binding.messageQuote.quotedMessage.context,
parentChatMessage,
false,
viewThemeUtils
)
viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.talk.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.talk.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)

binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
} catch (e: Exception) {
Log.d(TAG, "Error when processing parent message in view holder", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import android.view.View
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.content.res.AppCompatResources
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.google.android.flexbox.FlexboxLayout
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.IncomingPollMessageViewHolder.Companion
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.chat.ChatActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import android.content.Context
import android.util.Log
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.lifecycle.lifecycleScope
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.IncomingPollMessageViewHolder.Companion
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import android.view.View
import android.widget.SeekBar
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.work.WorkInfo
import androidx.work.WorkManager
import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.messages.IncomingPollMessageViewHolder.Companion
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.chat.ChatActivity
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_BREAKOUT_ROOM
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_MODERATOR
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM
Expand All @@ -187,7 +186,6 @@ import kotlinx.coroutines.withContext
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import retrofit2.HttpException
import retrofit2.Response
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
Expand Down Expand Up @@ -291,6 +289,7 @@ class ChatActivity :
var newMessagesCount = 0
var startCallFromNotification: Boolean = false
var startCallFromRoomSwitch: Boolean = false

// lateinit var roomId: String
var voiceOnly: Boolean = true
private lateinit var path: String
Expand Down Expand Up @@ -600,7 +599,7 @@ class ChatActivity :

chatViewModel.loadMessages(
withCredentials = credentials!!,
withUrl = urlForChatting,
withUrl = urlForChatting
)
}

Expand Down Expand Up @@ -985,7 +984,8 @@ class ChatActivity :

if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0 &&
!binding.unreadMessagesPopup.isShown) {
!binding.unreadMessagesPopup.isShown
) {
binding.scrollDownButton.visibility = View.VISIBLE
} else {
binding.scrollDownButton.visibility = View.GONE
Expand Down Expand Up @@ -2504,7 +2504,6 @@ class ChatActivity :
unreadChatMessage.message = context.getString(R.string.nc_new_messages)
adapter?.addToStart(unreadChatMessage, false)


if (scrollToEndOnUpdate) {
binding.scrollDownButton.visibility = View.GONE
newMessagesCount = 0
Expand All @@ -2519,7 +2518,6 @@ class ChatActivity :
}
}


for (chatMessage in chatMessageList) {
chatMessage.activeUser = conversationUser

Expand Down Expand Up @@ -2630,7 +2628,6 @@ class ChatActivity :
// see getImageUrl() source code
setUpWaveform(currentlyPlayedVoiceMessage!!, voiceMessageToRestoreWasPlaying)
Log.d(RESUME_AUDIO_TAG, "resume audio procedure completed")

} else {
Log.d(RESUME_AUDIO_TAG, "No voice message to restore")
}
Expand All @@ -2639,7 +2636,7 @@ class ChatActivity :
voiceMessageToRestoreWasPlaying = false
}

private fun getItemFromAdapter(messageId: String): Pair<ChatMessage,Int>? {
private fun getItemFromAdapter(messageId: String): Pair<ChatMessage, Int>? {
if (adapter != null) {
val messagePosition = adapter!!.items!!.indexOfFirst {
it.item is ChatMessage && (it.item as ChatMessage).id == messageId
Expand All @@ -2653,7 +2650,8 @@ class ChatActivity :
}
} else {
Log.d(
TAG, "messagePosition is -1, adapter # of items: " + adapter!!.itemCount
TAG,
"messagePosition is -1, adapter # of items: " + adapter!!.itemCount
)
}
} else {
Expand Down Expand Up @@ -2831,7 +2829,6 @@ class ChatActivity :
while (chatMessageIterator.hasNext()) {
val currentMessage = chatMessageIterator.next()


if (isInfoMessageAboutDeletion(currentMessage) ||
isReactionsMessage(currentMessage) ||
isPollVotedMessage(currentMessage) ||
Expand Down Expand Up @@ -3176,7 +3173,7 @@ class ChatActivity :
val lon = data["longitude"]!!
metaData =
"{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," +
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
}

when (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ interface ChatMessageRepository : LifecycleAwareManager {

val lastCommonReadFlow: Flow<Int>

fun setData(
conversationModel: ConversationModel,
credentials: String,
urlForChatting: String
)
fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String)

fun loadInitialMessages(withNetworkParams: Bundle): Job

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ class OfflineFirstChatRepository @Inject constructor(
private lateinit var credentials: String
private lateinit var urlForChatting: String

override fun setData(
conversationModel: ConversationModel,
credentials: String,
urlForChatting: String
) {
override fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) {
this.conversationModel = conversationModel
this.credentials = credentials
this.urlForChatting = urlForChatting
Expand Down Expand Up @@ -213,9 +209,7 @@ class OfflineFirstChatRepository @Inject constructor(
}
}

private suspend fun hasToLoadPreviousMessagesFromServer(
beforeMessageId: Long
): Boolean {
private suspend fun hasToLoadPreviousMessagesFromServer(beforeMessageId: Long): Boolean {
val loadFromServer: Boolean

val blockForMessage = getBlockOfMessage(beforeMessageId.toInt())
Expand All @@ -239,7 +233,8 @@ class OfflineFirstChatRepository @Inject constructor(
loadFromServer = amountBetween < 100

Log.d(
TAG, "Amount between messageId " + beforeMessageId + " and " + blockForMessage.oldestMessageId +
TAG,
"Amount between messageId " + beforeMessageId + " and " + blockForMessage.oldestMessageId +
" is: " + amountBetween + " so 'loadFromServer' is " + loadFromServer
)
}
Expand Down Expand Up @@ -272,9 +267,7 @@ class OfflineFirstChatRepository @Inject constructor(
return fieldMap
}

override suspend fun getMessage(messageId: Long, bundle: Bundle):
Flow<ChatMessage> {

override suspend fun getMessage(messageId: Long, bundle: Bundle): Flow<ChatMessage> {
Log.d(TAG, "Get message with id $messageId")
val loadFromServer = hasToLoadPreviousMessagesFromServer(messageId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,7 @@ class ChatViewModel @Inject constructor(
val reactionDeletedViewState: LiveData<ViewState>
get() = _reactionDeletedViewState

fun setData(
conversationModel: ConversationModel,
credentials: String,
urlForChatting: String
) {
fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) {
chatRepository.setData(
conversationModel,
credentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FORWARD_MSG_FLAG
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FORWARD_MSG_TEXT
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NEW_CONVERSATION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SHARED_TEXT
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ interface ChatBlocksDao {
)
fun getChatBlocksContainingMessageId(internalConversationId: String, messageId: Long): Flow<List<ChatBlockEntity?>>


@Query(
"""
SELECT *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ package com.nextcloud.talk.data.database.mappers
import com.nextcloud.talk.models.json.chat.ChatMessageJson
import com.nextcloud.talk.data.database.model.ChatMessageEntity
import com.nextcloud.talk.chat.data.model.ChatMessage
import com.nextcloud.talk.data.database.dao.ChatMessagesDao
import kotlinx.coroutines.flow.first

fun ChatMessageJson.asEntity(accountId: Long) =
ChatMessageEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ data class ChatMessageEntity(
@ColumnInfo(name = "reactions") var reactions: LinkedHashMap<String, Int>? = null,
@ColumnInfo(name = "reactionsSelf") var reactionsSelf: ArrayList<String>? = null,
@ColumnInfo(name = "systemMessage") var systemMessageType: ChatMessage.SystemMessageType,
@ColumnInfo(name = "timestamp") var timestamp: Long = 0,
@ColumnInfo(name = "timestamp") var timestamp: Long = 0
// missing/not needed: referenceId
// missing/not needed: silent
)
Loading

0 comments on commit fcb0972

Please sign in to comment.