Skip to content

Commit

Permalink
style(detekt): Shorten methods
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger authored and mahibi committed Dec 13, 2024
1 parent 2024969 commit 73bf99a
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 406 deletions.
28 changes: 8 additions & 20 deletions app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MessageInputFragment : Fragment() {
private var mentionAutocomplete: Autocomplete<*>? = null
private var xcounter = 0f
private var ycounter = 0f
private var isCollapsed = false
private var collapsed = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -219,11 +219,7 @@ class MessageInputFragment : Fragment() {
binding.fragmentCallStarted.callAuthorChipSecondary.text = message.actorDisplayName
val user = userManager.currentUser.blockingGet()
val url: String = if (message.actorType == "guests" || message.actorType == "guest") {
ApiUtils.getUrlForGuestAvatar(
user!!.baseUrl!!,
message.actorDisplayName,
true
)
ApiUtils.getUrlForGuestAvatar(user!!.baseUrl!!, message.actorDisplayName, true)
} else {
ApiUtils.getUrlForAvatar(user!!.baseUrl!!, message.actorId, false)
}
Expand Down Expand Up @@ -457,20 +453,12 @@ class MessageInputFragment : Fragment() {
}

binding.fragmentCallStarted.callStartedCloseBtn.setOnClickListener {
isCollapsed = !isCollapsed
if (isCollapsed) {
binding.fragmentCallStarted.callAuthorLayout.visibility = View.GONE
binding.fragmentCallStarted.callBtnLayout.visibility = View.GONE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = View.VISIBLE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = View.VISIBLE
} else {
binding.fragmentCallStarted.callAuthorLayout.visibility = View.VISIBLE
binding.fragmentCallStarted.callBtnLayout.visibility = View.VISIBLE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = View.GONE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = View.GONE
}

setDropDown(isCollapsed)
collapsed = !collapsed
binding.fragmentCallStarted.callAuthorLayout.visibility = if (collapsed) View.GONE else View.VISIBLE
binding.fragmentCallStarted.callBtnLayout.visibility = if (collapsed) View.GONE else View.VISIBLE
binding.fragmentCallStarted.callAuthorChipSecondary.visibility = if (collapsed) View.VISIBLE else View.GONE
binding.fragmentCallStarted.callStartedSecondaryText.visibility = if (collapsed) View.VISIBLE else View.GONE
setDropDown(collapsed)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,55 +506,67 @@ class OfflineFirstChatRepository @Inject constructor(
}

if (result.second.isNotEmpty()) {
val chatMessagesJson = result.second
chatMessagesFromSync = updateMessagesData(
result.second,
blockContainingQueriedMessage,
lookIntoFuture,
hasHistory)
} else {
Log.d(TAG, "no data is updated...")
}

handleUpdateMessages(chatMessagesJson)
return chatMessagesFromSync
}

chatMessagesFromSync = chatMessagesJson.map {
it.asEntity(currentUser.id!!)
}
private suspend fun OfflineFirstChatRepository.updateMessagesData(
chatMessagesJson: List<ChatMessageJson>,
blockContainingQueriedMessage: ChatBlockEntity?,
lookIntoFuture: Boolean,
hasHistory: Boolean
): List<ChatMessageEntity> {
handleUpdateMessages(chatMessagesJson)

chatDao.upsertChatMessages(chatMessagesFromSync)
val chatMessagesFromSyncToProcess = chatMessagesJson.map {
it.asEntity(currentUser.id!!)
}

val oldestIdFromSync = chatMessagesFromSync.minByOrNull { it.id }!!.id
val newestIdFromSync = chatMessagesFromSync.maxByOrNull { it.id }!!.id
Log.d(TAG, "oldestIdFromSync: $oldestIdFromSync")
Log.d(TAG, "newestIdFromSync: $newestIdFromSync")
chatDao.upsertChatMessages(chatMessagesFromSyncToProcess)

var oldestMessageIdForNewChatBlock = oldestIdFromSync
var newestMessageIdForNewChatBlock = newestIdFromSync
val oldestIdFromSync = chatMessagesFromSyncToProcess.minByOrNull { it.id }!!.id
val newestIdFromSync = chatMessagesFromSyncToProcess.maxByOrNull { it.id }!!.id
Log.d(TAG, "oldestIdFromSync: $oldestIdFromSync")
Log.d(TAG, "newestIdFromSync: $newestIdFromSync")

if (blockContainingQueriedMessage != null) {
if (lookIntoFuture) {
val oldestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.oldestMessageId
Log.d(TAG, "oldestMessageIdFromBlockOfQueriedMessage: $oldestMessageIdFromBlockOfQueriedMessage")
oldestMessageIdForNewChatBlock = oldestMessageIdFromBlockOfQueriedMessage
} else {
val newestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.newestMessageId
Log.d(TAG, "newestMessageIdFromBlockOfQueriedMessage: $newestMessageIdFromBlockOfQueriedMessage")
newestMessageIdForNewChatBlock = newestMessageIdFromBlockOfQueriedMessage
}
}
var oldestMessageIdForNewChatBlock = oldestIdFromSync
var newestMessageIdForNewChatBlock = newestIdFromSync

Log.d(TAG, "oldestMessageIdForNewChatBlock: $oldestMessageIdForNewChatBlock")
Log.d(TAG, "newestMessageIdForNewChatBlock: $newestMessageIdForNewChatBlock")
if (blockContainingQueriedMessage != null) {
if (lookIntoFuture) {
val oldestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.oldestMessageId
Log.d(TAG, "oldestMessageIdFromBlockOfQueriedMessage: $oldestMessageIdFromBlockOfQueriedMessage")
oldestMessageIdForNewChatBlock = oldestMessageIdFromBlockOfQueriedMessage
} else {
val newestMessageIdFromBlockOfQueriedMessage = blockContainingQueriedMessage.newestMessageId
Log.d(TAG, "newestMessageIdFromBlockOfQueriedMessage: $newestMessageIdFromBlockOfQueriedMessage")
newestMessageIdForNewChatBlock = newestMessageIdFromBlockOfQueriedMessage
}
}

val newChatBlock = ChatBlockEntity(
internalConversationId = internalConversationId,
accountId = conversationModel.accountId,
token = conversationModel.token,
oldestMessageId = oldestMessageIdForNewChatBlock,
newestMessageId = newestMessageIdForNewChatBlock,
hasHistory = hasHistory
)
chatBlocksDao.upsertChatBlock(newChatBlock)
Log.d(TAG, "oldestMessageIdForNewChatBlock: $oldestMessageIdForNewChatBlock")
Log.d(TAG, "newestMessageIdForNewChatBlock: $newestMessageIdForNewChatBlock")

updateBlocks(newChatBlock)
} else {
Log.d(TAG, "no data is updated...")
}
val newChatBlock = ChatBlockEntity(
internalConversationId = internalConversationId,
accountId = conversationModel.accountId,
token = conversationModel.token,
oldestMessageId = oldestMessageIdForNewChatBlock,
newestMessageId = newestMessageIdForNewChatBlock,
hasHistory = hasHistory
)
chatBlocksDao.upsertChatBlock(newChatBlock)

return chatMessagesFromSync
updateBlocks(newChatBlock)
return chatMessagesFromSyncToProcess
}

private suspend fun handleUpdateMessages(messagesJson: List<ChatMessageJson>) {
Expand Down
Loading

0 comments on commit 73bf99a

Please sign in to comment.