Skip to content

Commit

Permalink
resolve detekt warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Jan 6, 2025
1 parent 472420a commit c7e8e1f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class OutcomingTextMessageViewHolder(itemView: View) :

lateinit var commonMessageInterface: CommonMessageInterface

@Suppress("Detekt.LongMethod")
override fun onBind(message: ChatMessage) {
super.onBind(message)
sharedApplication!!.componentApplication.inject(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import retrofit2.http.Query
import retrofit2.http.QueryMap
import retrofit2.http.Url

@Suppress("TooManyFunctions")
interface NcApiCoroutines {
@GET
@JvmSuppressWildcards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import kotlinx.coroutines.launch
import java.io.IOException
import javax.inject.Inject

@Suppress("LargeClass", "TooManyFunctions")
class OfflineFirstChatRepository @Inject constructor(
private val chatDao: ChatMessagesDao,
private val chatBlocksDao: ChatBlocksDao,
Expand Down Expand Up @@ -178,34 +179,38 @@ class OfflineFirstChatRepository @Inject constructor(
Log.d(TAG, "newestMessageIdFromDb after sync: $newestMessageIdFromDb")
}

if (newestMessageIdFromDb.toInt() != 0) {
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)
handleMessagesFromDb(newestMessageIdFromDb)

val list = getMessagesBeforeAndEqual(
newestMessageIdFromDb,
internalConversationId,
limit
)
if (list.isNotEmpty()) {
handleNewAndTempMessages(
receivedChatMessages = list,
lookIntoFuture = false,
showUnreadMessagesMarker = false
)
}

sendTempChatMessages(credentials, urlForChatting)
initMessagePolling(newestMessageIdFromDb)
}

// delay is a dirty workaround to make sure messages are added to adapter on initial load before dealing
// with them (otherwise there is a race condition).
delay(DELAY_TO_ENSURE_MESSAGES_ARE_ADDED)
private suspend fun handleMessagesFromDb(newestMessageIdFromDb: Long) {
if (newestMessageIdFromDb.toInt() != 0) {
val limit = getCappedMessagesAmountOfChatBlock(newestMessageIdFromDb)

updateUiForLastCommonRead()
updateUiForLastReadMessage(newestMessageIdFromDb)
val list = getMessagesBeforeAndEqual(
newestMessageIdFromDb,
internalConversationId,
limit
)
if (list.isNotEmpty()) {
handleNewAndTempMessages(
receivedChatMessages = list,
lookIntoFuture = false,
showUnreadMessagesMarker = false
)
}

initMessagePolling(newestMessageIdFromDb)
sendTempChatMessages(credentials, urlForChatting)

// delay is a dirty workaround to make sure messages are added to adapter on initial load before dealing
// with them (otherwise there is a race condition).
delay(DELAY_TO_ENSURE_MESSAGES_ARE_ADDED)

updateUiForLastCommonRead()
updateUiForLastReadMessage(newestMessageIdFromDb)
}
}

private suspend fun getCappedMessagesAmountOfChatBlock(messageId: Long): Int {
val chatBlock = getBlockOfMessage(messageId.toInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.reactivex.disposables.Disposable
import kotlinx.coroutines.launch
import javax.inject.Inject

@Suppress("Detekt.TooManyFunctions")
class MessageInputViewModel @Inject constructor(
private val audioRecorderManager: AudioRecorderManager,
private val mediaPlayerManager: MediaPlayerManager,
Expand Down Expand Up @@ -116,6 +117,7 @@ class MessageInputViewModel @Inject constructor(
val callStartedFlow: LiveData<Pair<ChatMessage, Boolean>>
get() = _callStartedFlow

@Suppress("LongParameterList")
fun sendChatMessage(
credentials: String,
url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import com.nextcloud.talk.translate.repositories.TranslateRepositoryImpl
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import com.nextcloud.talk.utils.preferences.AppPreferences
import dagger.Module
import dagger.Provides
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -156,15 +155,13 @@ class RepositoryModule {
chatMessagesDao: ChatMessagesDao,
chatBlocksDao: ChatBlocksDao,
dataSource: ChatNetworkDataSource,
appPreferences: AppPreferences,
networkMonitor: NetworkMonitor,
userProvider: CurrentUserProviderNew
): ChatMessageRepository =
OfflineFirstChatRepository(
chatMessagesDao,
chatBlocksDao,
dataSource,
appPreferences,
networkMonitor,
userProvider
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.nextcloud.talk.data.database.model.ChatMessageEntity
import kotlinx.coroutines.flow.Flow

@Dao
@Suppress("Detekt.TooManyFunctions")
interface ChatMessagesDao {
@Query(
"""
Expand Down

0 comments on commit c7e8e1f

Please sign in to comment.