mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
replace CharSequence with String for sendChatMessage
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
0f53244652
commit
ec466e58f0
@ -14,7 +14,6 @@ import android.util.Log
|
|||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import autodagger.AutoInjector
|
import autodagger.AutoInjector
|
||||||
import coil.load
|
import coil.load
|
||||||
import com.google.android.flexbox.FlexboxLayout
|
import com.google.android.flexbox.FlexboxLayout
|
||||||
@ -73,6 +72,7 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
|||||||
layoutParams.isWrapBefore = false
|
layoutParams.isWrapBefore = false
|
||||||
var textSize = context.resources.getDimension(R.dimen.chat_text_size)
|
var textSize = context.resources.getDimension(R.dimen.chat_text_size)
|
||||||
viewThemeUtils.platform.colorTextView(binding.messageTime, ColorRole.ON_SURFACE_VARIANT)
|
viewThemeUtils.platform.colorTextView(binding.messageTime, ColorRole.ON_SURFACE_VARIANT)
|
||||||
|
|
||||||
var processedMessageText = messageUtils.enrichChatMessageText(
|
var processedMessageText = messageUtils.enrichChatMessageText(
|
||||||
binding.messageText.context,
|
binding.messageText.context,
|
||||||
message,
|
message,
|
||||||
@ -121,18 +121,20 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
|||||||
|
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
if (message.sendingFailed) {
|
// if (message.sendingFailed) {
|
||||||
updateStatus(
|
// updateStatus(
|
||||||
R.drawable.baseline_report_problem_24,
|
// R.drawable.baseline_report_problem_24,
|
||||||
"failed"
|
// "failed"
|
||||||
)
|
// )
|
||||||
} else if (message.isTempMessage && !networkMonitor.isOnline.first()) {
|
// } else
|
||||||
|
|
||||||
|
if (message.isTempMessage && !networkMonitor.isOnline.first()) {
|
||||||
updateStatus(
|
updateStatus(
|
||||||
R.drawable.ic_signal_wifi_off_white_24dp,
|
R.drawable.ic_signal_wifi_off_white_24dp,
|
||||||
"offline"
|
"offline"
|
||||||
)
|
)
|
||||||
} else if (message.isTempMessage) {
|
} else if (message.isTempMessage) {
|
||||||
updateSendingStatus()
|
showSendingSpinner()
|
||||||
} else if(message.readStatus == ReadStatus.READ){
|
} else if(message.readStatus == ReadStatus.READ){
|
||||||
updateStatus(R.drawable.ic_check_all, context.resources?.getString(R.string.nc_message_read))
|
updateStatus(R.drawable.ic_check_all, context.resources?.getString(R.string.nc_message_read))
|
||||||
} else if(message.readStatus == ReadStatus.SENT) {
|
} else if(message.readStatus == ReadStatus.SENT) {
|
||||||
@ -165,7 +167,7 @@ class OutcomingTextMessageViewHolder(itemView: View) :
|
|||||||
binding.checkMark.contentDescription = description
|
binding.checkMark.contentDescription = description
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSendingStatus() {
|
private fun showSendingSpinner() {
|
||||||
binding.sendingProgress.visibility = View.VISIBLE
|
binding.sendingProgress.visibility = View.VISIBLE
|
||||||
binding.checkMark.visibility = View.GONE
|
binding.checkMark.visibility = View.GONE
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ interface NcApiCoroutines {
|
|||||||
suspend fun sendChatMessage(
|
suspend fun sendChatMessage(
|
||||||
@Header("Authorization") authorization: String,
|
@Header("Authorization") authorization: String,
|
||||||
@Url url: String,
|
@Url url: String,
|
||||||
@Field("message") message: CharSequence,
|
@Field("message") message: String,
|
||||||
@Field("actorDisplayName") actorDisplayName: String,
|
@Field("actorDisplayName") actorDisplayName: String,
|
||||||
@Field("replyTo") replyTo: Int,
|
@Field("replyTo") replyTo: Int,
|
||||||
@Field("silent") sendWithoutNotification: Boolean,
|
@Field("silent") sendWithoutNotification: Boolean,
|
||||||
|
@ -867,7 +867,7 @@ class MessageInputFragment : Fragment() {
|
|||||||
.findViewById<RelativeLayout>(R.id.quotedChatMessageView)?.tag as Int? ?: 0
|
.findViewById<RelativeLayout>(R.id.quotedChatMessageView)?.tag as Int? ?: 0
|
||||||
|
|
||||||
sendMessage(
|
sendMessage(
|
||||||
editable,
|
editable.toString(),
|
||||||
replyMessageId,
|
replyMessageId,
|
||||||
sendWithoutNotification
|
sendWithoutNotification
|
||||||
)
|
)
|
||||||
@ -875,7 +875,7 @@ class MessageInputFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendMessage(message: CharSequence, replyTo: Int?, sendWithoutNotification: Boolean) {
|
private fun sendMessage(message: String, replyTo: Int?, sendWithoutNotification: Boolean) {
|
||||||
chatActivity.messageInputViewModel.sendChatMessage(
|
chatActivity.messageInputViewModel.sendChatMessage(
|
||||||
conversationInternalId,
|
conversationInternalId,
|
||||||
chatActivity.conversationUser!!.getCredentials(),
|
chatActivity.conversationUser!!.getCredentials(),
|
||||||
|
@ -82,7 +82,7 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
|||||||
suspend fun sendChatMessage(
|
suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: String,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
|
@ -53,7 +53,7 @@ interface ChatNetworkDataSource {
|
|||||||
suspend fun sendChatMessage(
|
suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: String,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
|
@ -13,6 +13,10 @@ import android.util.Log
|
|||||||
import com.nextcloud.talk.chat.ChatActivity
|
import com.nextcloud.talk.chat.ChatActivity
|
||||||
import com.nextcloud.talk.chat.data.ChatMessageRepository
|
import com.nextcloud.talk.chat.data.ChatMessageRepository
|
||||||
import com.nextcloud.talk.chat.data.model.ChatMessage
|
import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||||
|
import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel
|
||||||
|
import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel.Companion
|
||||||
|
import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel.SendChatMessageErrorState
|
||||||
|
import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel.SendChatMessageSuccessState
|
||||||
import com.nextcloud.talk.data.database.dao.ChatBlocksDao
|
import com.nextcloud.talk.data.database.dao.ChatBlocksDao
|
||||||
import com.nextcloud.talk.data.database.dao.ChatMessagesDao
|
import com.nextcloud.talk.data.database.dao.ChatMessagesDao
|
||||||
import com.nextcloud.talk.data.database.mappers.asEntity
|
import com.nextcloud.talk.data.database.mappers.asEntity
|
||||||
@ -185,7 +189,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
if (list.isNotEmpty()) {
|
if (list.isNotEmpty()) {
|
||||||
updateUiMessages(
|
handleNewAndTempMessages(
|
||||||
receivedChatMessages = list,
|
receivedChatMessages = list,
|
||||||
lookIntoFuture = false,
|
lookIntoFuture = false,
|
||||||
showUnreadMessagesMarker = false
|
showUnreadMessagesMarker = false
|
||||||
@ -307,7 +311,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
val weHaveMessagesFromOurself = chatMessages.any { it.actorId == currentUser.userId }
|
val weHaveMessagesFromOurself = chatMessages.any { it.actorId == currentUser.userId }
|
||||||
showUnreadMessagesMarker = showUnreadMessagesMarker && !weHaveMessagesFromOurself
|
showUnreadMessagesMarker = showUnreadMessagesMarker && !weHaveMessagesFromOurself
|
||||||
|
|
||||||
updateUiMessages(
|
handleNewAndTempMessages(
|
||||||
receivedChatMessages = chatMessages,
|
receivedChatMessages = chatMessages,
|
||||||
lookIntoFuture = true,
|
lookIntoFuture = true,
|
||||||
showUnreadMessagesMarker = showUnreadMessagesMarker
|
showUnreadMessagesMarker = showUnreadMessagesMarker
|
||||||
@ -334,7 +338,33 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateUiMessages(
|
// TODO replace with WorkManager?
|
||||||
|
// private suspend fun tryToSendPendingMessages() {
|
||||||
|
// val tempMessages = chatDao.getTempMessagesForConversation(internalConversationId).first()
|
||||||
|
//
|
||||||
|
// tempMessages.forEach {
|
||||||
|
// Log.d(TAG, "Sending chat message ${it.message} another time!!")
|
||||||
|
//
|
||||||
|
// sendChatMessage(
|
||||||
|
// credentials,
|
||||||
|
// urlForChatting,
|
||||||
|
// it.message,
|
||||||
|
// it.actorDisplayName,
|
||||||
|
// it.parentMessageId?.toInt() ?: 0,
|
||||||
|
// false,
|
||||||
|
// it.referenceId ?: ""
|
||||||
|
// ).collect { result ->
|
||||||
|
// if (result.isSuccess) {
|
||||||
|
// Log.d(TAG, "success. received ref id: " + (result.getOrNull()?.referenceId ?: "none"))
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// Log.d(TAG, "fail. received ref id: " + (result.getOrNull()?.referenceId ?: "none"))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private suspend fun handleNewAndTempMessages(
|
||||||
receivedChatMessages : List<ChatMessage>,
|
receivedChatMessages : List<ChatMessage>,
|
||||||
lookIntoFuture: Boolean,
|
lookIntoFuture: Boolean,
|
||||||
showUnreadMessagesMarker: Boolean
|
showUnreadMessagesMarker: Boolean
|
||||||
@ -792,7 +822,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
override suspend fun sendChatMessage(
|
override suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: String,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
@ -820,11 +850,11 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
failedMessage.sendingFailed = true
|
failedMessage.sendingFailed = true
|
||||||
chatDao.updateChatMessage(failedMessage)
|
chatDao.updateChatMessage(failedMessage)
|
||||||
|
|
||||||
val failedMessageModel = failedMessage.asModel()
|
// val failedMessageModel = failedMessage.asModel()
|
||||||
_removeMessageFlow.emit(failedMessageModel)
|
// _removeMessageFlow.emit(failedMessageModel)
|
||||||
|
//
|
||||||
val tripleChatMessages = Triple(true, false, listOf(failedMessageModel))
|
// val tripleChatMessages = Triple(true, false, listOf(failedMessageModel))
|
||||||
_messageFlow.emit(tripleChatMessages)
|
// _messageFlow.emit(tripleChatMessages)
|
||||||
|
|
||||||
emit(Result.failure(e))
|
emit(Result.failure(e))
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ class RetrofitChatNetwork(
|
|||||||
override suspend fun sendChatMessage(
|
override suspend fun sendChatMessage(
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: String,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean,
|
sendWithoutNotification: Boolean,
|
||||||
|
@ -146,7 +146,7 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
internalId: String,
|
internalId: String,
|
||||||
credentials: String,
|
credentials: String,
|
||||||
url: String,
|
url: String,
|
||||||
message: CharSequence,
|
message: String,
|
||||||
displayName: String,
|
displayName: String,
|
||||||
replyTo: Int,
|
replyTo: Int,
|
||||||
sendWithoutNotification: Boolean
|
sendWithoutNotification: Boolean
|
||||||
|
@ -79,13 +79,6 @@
|
|||||||
android:textIsSelectable="false"
|
android:textIsSelectable="false"
|
||||||
tools:text="Talk to you later!" />
|
tools:text="Talk to you later!" />
|
||||||
|
|
||||||
<!-- <com.google.android.material.textfield.TextInputEditText-->
|
|
||||||
<!-- android:id="@+id/message_edit"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:visibility="gone"-->
|
|
||||||
<!-- tools:visibility="visible"/>-->
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@id/messageTime"
|
android:id="@id/messageTime"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user