got replying working

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2024-09-30 08:43:03 -05:00 committed by Marcel Hibbe
parent 411a4f1dce
commit 399fa7eb70
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
2 changed files with 85 additions and 2 deletions

View file

@ -8,18 +8,28 @@
package com.nextcloud.talk.adapters.messages package com.nextcloud.talk.adapters.messages
import android.content.Context import android.content.Context
import android.util.Log
import android.view.View import android.view.View
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import autodagger.AutoInjector import autodagger.AutoInjector
import coil.load
import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.chat.data.model.ChatMessage import com.nextcloud.talk.chat.data.model.ChatMessage
import com.nextcloud.talk.databinding.ItemTemporaryMessageBinding import com.nextcloud.talk.databinding.ItemTemporaryMessageBinding
import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.message.MessageUtils
import com.stfalcon.chatkit.messages.MessagesListAdapter import com.stfalcon.chatkit.messages.MessagesListAdapter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
@ -34,6 +44,9 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) :
@Inject @Inject
lateinit var context: Context lateinit var context: Context
@Inject
lateinit var messageUtils: MessageUtils
lateinit var temporaryMessageInterface: TemporaryMessageInterface lateinit var temporaryMessageInterface: TemporaryMessageInterface
var isEditing = false var isEditing = false
@ -77,6 +90,14 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) :
temporaryMessageInterface.deleteTemporaryMessage(message.tempMessageId) temporaryMessageInterface.deleteTemporaryMessage(message.tempMessageId)
} }
// parent message handling
if (!message.isDeleted && message.parentMessageId != null) {
processParentMessage(message)
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
} else {
binding.messageQuote.quotedChatMessageView.visibility = View.GONE
}
val bgBubbleColor = bubble.resources.getColor(R.color.bg_message_list_incoming_bubble, null) val bgBubbleColor = bubble.resources.getColor(R.color.bg_message_list_incoming_bubble, null)
val layout = R.drawable.shape_outcoming_message val layout = R.drawable.shape_outcoming_message
val bubbleDrawable = DisplayUtils.getMessageSelector( val bubbleDrawable = DisplayUtils.getMessageSelector(
@ -89,6 +110,62 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) :
} }
private fun processParentMessage(message: ChatMessage) {
if (message.parentMessageId != null && !message.isDeleted) {
CoroutineScope(Dispatchers.Main).launch {
try {
val chatActivity = temporaryMessageInterface as ChatActivity
val urlForChatting = ApiUtils.getUrlForChat(
chatActivity.chatApiVersion,
chatActivity.conversationUser?.baseUrl,
chatActivity.roomToken
)
val parentChatMessage = withContext(Dispatchers.IO) {
chatActivity.chatViewModel.getMessageById(
urlForChatting,
chatActivity.currentConversation!!,
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
)
viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.talk.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.talk.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)
binding.messageQuote.quotedChatMessageView.setOnClickListener {
val chatActivity = temporaryMessageInterface as ChatActivity
chatActivity.jumpToQuotedMessage(parentChatMessage)
}
} catch (e: Exception) {
Log.d(TAG, "Error when processing parent message in view holder", e)
}
}
}
}
fun assignTemporaryMessageInterface(temporaryMessageInterface: TemporaryMessageInterface) { fun assignTemporaryMessageInterface(temporaryMessageInterface: TemporaryMessageInterface) {
this.temporaryMessageInterface = temporaryMessageInterface this.temporaryMessageInterface = temporaryMessageInterface
} }
@ -104,4 +181,8 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) :
override fun viewRecycled() { override fun viewRecycled() {
// unused atm // unused atm
} }
companion object {
private val TAG = TemporaryMessageViewHolder::class.java.simpleName
}
} }

View file

@ -547,6 +547,8 @@ class ChatActivity :
temporaryChatMessage.message = qMsg.message.toString() temporaryChatMessage.message = qMsg.message.toString()
temporaryChatMessage.tempMessageId = qMsg.id temporaryChatMessage.tempMessageId = qMsg.id
temporaryChatMessage.isTempMessage = true temporaryChatMessage.isTempMessage = true
temporaryChatMessage.parentMessageId = qMsg.replyTo!!.toLong()
val pos = adapter?.getMessagePositionById(qMsg.replyTo.toString())
adapter?.addToStart(temporaryChatMessage, true) adapter?.addToStart(temporaryChatMessage, true)
} }
} }
@ -3675,8 +3677,8 @@ class ChatActivity :
messageInputViewModel.removeFromQueue(roomToken, id) messageInputViewModel.removeFromQueue(roomToken, id)
var i = 0 var i = 0
val max = messageInputViewModel.messageQueueSizeFlow.value?.plus(1) val max = messageInputViewModel.messageQueueSizeFlow.value?.plus(1)
for (item in adapter?.items!!) { // add limit? for (item in adapter?.items!!) { // TODO fix weird delay
if (i >= max!!) break if (i > max!!) break
if (item.item is ChatMessage && if (item.item is ChatMessage &&
(item.item as ChatMessage).isTempMessage && (item.item as ChatMessage).isTempMessage &&
(item.item as ChatMessage).tempMessageId == id (item.item as ChatMessage).tempMessageId == id