mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-09 15:42:10 +00:00
simplify "sent messages are queued" hint
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
656be3ffce
commit
f62941f6aa
@ -581,35 +581,6 @@ class ChatActivity :
|
|||||||
private fun initObservers() {
|
private fun initObservers() {
|
||||||
Log.d(TAG, "initObservers Called")
|
Log.d(TAG, "initObservers Called")
|
||||||
|
|
||||||
// messageInputViewModel.messageQueueFlow.observe(this) { list ->
|
|
||||||
// list.forEachIndexed { _, qMsg ->
|
|
||||||
// val temporaryChatMessage = ChatMessage()
|
|
||||||
// temporaryChatMessage.jsonMessageId = TEMPORARY_MESSAGE_ID_INT
|
|
||||||
// temporaryChatMessage.actorId = TEMPORARY_MESSAGE_ID_STRING
|
|
||||||
// temporaryChatMessage.timestamp = System.currentTimeMillis() / ONE_SECOND_IN_MILLIS
|
|
||||||
// temporaryChatMessage.message = qMsg.message.toString()
|
|
||||||
// temporaryChatMessage.tempMessageId = qMsg.id
|
|
||||||
// temporaryChatMessage.isTempMessage = true
|
|
||||||
// temporaryChatMessage.parentMessageId = qMsg.replyTo!!.toLong()
|
|
||||||
// val pos = adapter?.getMessagePositionById(qMsg.replyTo.toString())
|
|
||||||
// adapter?.addToStart(temporaryChatMessage, true)
|
|
||||||
// adapter?.notifyDataSetChanged()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
messageInputViewModel.messageQueueSizeFlow.observe(this) { size ->
|
|
||||||
// if (size == 0) {
|
|
||||||
// var i = 0
|
|
||||||
// var pos = adapter?.getMessagePositionById(TEMPORARY_MESSAGE_ID_STRING)
|
|
||||||
// while (pos != null && pos > -1) {
|
|
||||||
// adapter?.items?.removeAt(pos)
|
|
||||||
// i++
|
|
||||||
// pos = adapter?.getMessagePositionById(TEMPORARY_MESSAGE_ID_STRING)
|
|
||||||
// }
|
|
||||||
// adapter?.notifyDataSetChanged()
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lifecycleScope.launch {
|
this.lifecycleScope.launch {
|
||||||
chatViewModel.getConversationFlow
|
chatViewModel.getConversationFlow
|
||||||
.onEach { conversationModel ->
|
.onEach { conversationModel ->
|
||||||
|
@ -212,14 +212,6 @@ class MessageInputFragment : Fragment() {
|
|||||||
}.collect()
|
}.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
chatActivity.messageInputViewModel.messageQueueSizeFlow.observe(viewLifecycleOwner) { size ->
|
|
||||||
if (size > 0) {
|
|
||||||
binding.fragmentConnectionLost.text = getString(R.string.connection_lost_queued, size)
|
|
||||||
} else {
|
|
||||||
binding.fragmentConnectionLost.text = getString(R.string.connection_lost_sent_messages_are_queued)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chatActivity.messageInputViewModel.callStartedFlow.observe(viewLifecycleOwner) {
|
chatActivity.messageInputViewModel.callStartedFlow.observe(viewLifecycleOwner) {
|
||||||
val (message, show) = it
|
val (message, show) = it
|
||||||
if (show) {
|
if (show) {
|
||||||
@ -300,23 +292,6 @@ class MessageInputFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun handleMessageQueue(isOnline: Boolean) {
|
|
||||||
// if (isOnline) {
|
|
||||||
// chatActivity.messageInputViewModel.switchToMessageQueue(false)
|
|
||||||
// chatActivity.messageInputViewModel.sendAndEmptyMessageQueue(
|
|
||||||
// conversationInternalId,
|
|
||||||
// chatActivity.conversationUser!!.getCredentials(),
|
|
||||||
// ApiUtils.getUrlForChat(
|
|
||||||
// chatActivity.chatApiVersion,
|
|
||||||
// chatActivity.conversationUser!!.baseUrl!!,
|
|
||||||
// chatActivity.roomToken
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// } else {
|
|
||||||
// chatActivity.messageInputViewModel.switchToMessageQueue(true)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun restoreState() {
|
private fun restoreState() {
|
||||||
if (binding.fragmentMessageInputView.inputEditText.text.isEmpty()) {
|
if (binding.fragmentMessageInputView.inputEditText.text.isEmpty()) {
|
||||||
requireContext().getSharedPreferences(chatActivity.localClassName, AppCompatActivity.MODE_PRIVATE).apply {
|
requireContext().getSharedPreferences(chatActivity.localClassName, AppCompatActivity.MODE_PRIVATE).apply {
|
||||||
|
@ -55,17 +55,6 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
chatRepository = chatMessageRepository
|
chatRepository = chatMessageRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
// data class QueuedMessage(
|
|
||||||
// val id: Int,
|
|
||||||
// var message: CharSequence? = null,
|
|
||||||
// val displayName: String? = null,
|
|
||||||
// val replyTo: Int? = null,
|
|
||||||
// val sendWithoutNotification: Boolean? = null
|
|
||||||
// )
|
|
||||||
|
|
||||||
// private var isQueueing: Boolean = false
|
|
||||||
// private var messageQueue: MutableList<QueuedMessage> = mutableListOf()
|
|
||||||
|
|
||||||
override fun onResume(owner: LifecycleOwner) {
|
override fun onResume(owner: LifecycleOwner) {
|
||||||
super.onResume(owner)
|
super.onResume(owner)
|
||||||
currentLifeCycleFlag = LifeCycleFlag.RESUMED
|
currentLifeCycleFlag = LifeCycleFlag.RESUMED
|
||||||
@ -117,7 +106,6 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
private val _sendChatMessageViewState: MutableLiveData<ViewState> = MutableLiveData(SendChatMessageStartState)
|
private val _sendChatMessageViewState: MutableLiveData<ViewState> = MutableLiveData(SendChatMessageStartState)
|
||||||
val sendChatMessageViewState: LiveData<ViewState>
|
val sendChatMessageViewState: LiveData<ViewState>
|
||||||
get() = _sendChatMessageViewState
|
get() = _sendChatMessageViewState
|
||||||
object EditMessageStartState : ViewState
|
|
||||||
object EditMessageErrorState : ViewState
|
object EditMessageErrorState : ViewState
|
||||||
class EditMessageSuccessState(val messageEdited: ChatOverallSingleMessage) : ViewState
|
class EditMessageSuccessState(val messageEdited: ChatOverallSingleMessage) : ViewState
|
||||||
|
|
||||||
@ -129,14 +117,6 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
val isVoicePreviewPlaying: LiveData<Boolean>
|
val isVoicePreviewPlaying: LiveData<Boolean>
|
||||||
get() = _isVoicePreviewPlaying
|
get() = _isVoicePreviewPlaying
|
||||||
|
|
||||||
private val _messageQueueSizeFlow = MutableStateFlow(666)
|
|
||||||
val messageQueueSizeFlow: LiveData<Int>
|
|
||||||
get() = _messageQueueSizeFlow.asLiveData()
|
|
||||||
|
|
||||||
// private val _messageQueueFlow: MutableLiveData<List<QueuedMessage>> = MutableLiveData()
|
|
||||||
// val messageQueueFlow: LiveData<List<QueuedMessage>>
|
|
||||||
// get() = _messageQueueFlow
|
|
||||||
|
|
||||||
private val _callStartedFlow: MutableLiveData<Pair<ChatMessage, Boolean>> = MutableLiveData()
|
private val _callStartedFlow: MutableLiveData<Pair<ChatMessage, Boolean>> = MutableLiveData()
|
||||||
val callStartedFlow: LiveData<Pair<ChatMessage, Boolean>>
|
val callStartedFlow: LiveData<Pair<ChatMessage, Boolean>>
|
||||||
get() = _callStartedFlow
|
get() = _callStartedFlow
|
||||||
@ -171,17 +151,6 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (isQueueing) {
|
|
||||||
// val tempID = System.currentTimeMillis().toInt()
|
|
||||||
// val qMsg = QueuedMessage(tempID, message, displayName, replyTo, sendWithoutNotification)
|
|
||||||
// messageQueue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// messageQueue.add(qMsg)
|
|
||||||
// appPreferences.saveMessageQueue(internalId, messageQueue)
|
|
||||||
// _messageQueueSizeFlow.update { messageQueue.size }
|
|
||||||
// _messageQueueFlow.postValue(listOf(qMsg))
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
chatRepository.sendChatMessage(
|
chatRepository.sendChatMessage(
|
||||||
credentials,
|
credentials,
|
||||||
@ -295,69 +264,6 @@ class MessageInputViewModel @Inject constructor(
|
|||||||
_getRecordingTime.postValue(time)
|
_getRecordingTime.postValue(time)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun sendAndEmptyMessageQueue(internalId: String, credentials: String, url: String) {
|
|
||||||
// if (isQueueing) return
|
|
||||||
// messageQueue.clear()
|
|
||||||
//
|
|
||||||
// val queue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// appPreferences.saveMessageQueue(internalId, null) // empties the queue
|
|
||||||
// while (queue.size > 0) {
|
|
||||||
// val msg = queue.removeAt(0)
|
|
||||||
// sendChatMessage(
|
|
||||||
// internalId,
|
|
||||||
// credentials,
|
|
||||||
// url,
|
|
||||||
// msg.message!!,
|
|
||||||
// msg.displayName!!,
|
|
||||||
// msg.replyTo!!,
|
|
||||||
// msg.sendWithoutNotification!!
|
|
||||||
// )
|
|
||||||
// sleep(DELAY_BETWEEN_QUEUED_MESSAGES)
|
|
||||||
// }
|
|
||||||
// _messageQueueSizeFlow.tryEmit(0)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun getTempMessagesFromMessageQueue(internalId: String) {
|
|
||||||
// val queue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// val list = mutableListOf<QueuedMessage>()
|
|
||||||
// for (msg in queue) {
|
|
||||||
// list.add(msg)
|
|
||||||
// }
|
|
||||||
// _messageQueueFlow.postValue(list)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun switchToMessageQueue(shouldQueue: Boolean) {
|
|
||||||
// isQueueing = shouldQueue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun restoreMessageQueue(internalId: String) {
|
|
||||||
// messageQueue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// _messageQueueSizeFlow.tryEmit(messageQueue.size)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun removeFromQueue(internalId: String, id: Int) {
|
|
||||||
// val queue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// for (qMsg in queue) {
|
|
||||||
// if (qMsg.id == id) {
|
|
||||||
// queue.remove(qMsg)
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// appPreferences.saveMessageQueue(internalId, queue)
|
|
||||||
// _messageQueueSizeFlow.tryEmit(queue.size)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fun editQueuedMessage(internalId: String, id: Int, newMessage: String) {
|
|
||||||
// val queue = appPreferences.getMessageQueue(internalId)
|
|
||||||
// for (qMsg in queue) {
|
|
||||||
// if (qMsg.id == id) {
|
|
||||||
// qMsg.message = newMessage
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// appPreferences.saveMessageQueue(internalId, queue)
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun showCallStartedIndicator(recent: ChatMessage, show: Boolean) {
|
fun showCallStartedIndicator(recent: ChatMessage, show: Boolean) {
|
||||||
_callStartedFlow.postValue(Pair(recent, show))
|
_callStartedFlow.postValue(Pair(recent, show))
|
||||||
}
|
}
|
||||||
|
@ -501,76 +501,6 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
|
|||||||
return if (lastReadId.isNotEmpty()) lastReadId.toInt() else defaultValue
|
return if (lastReadId.isNotEmpty()) lastReadId.toInt() else defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// override fun saveMessageQueue(
|
|
||||||
// internalConversationId: String,
|
|
||||||
// queue: MutableList<MessageInputViewModel.QueuedMessage>?
|
|
||||||
// ) {
|
|
||||||
// runBlocking<Unit> {
|
|
||||||
// async {
|
|
||||||
// var queueStr = ""
|
|
||||||
// queue?.let {
|
|
||||||
// for (msg in queue) {
|
|
||||||
// val msgStr = "${msg.id},${msg.message},${msg.replyTo},${msg.displayName},${
|
|
||||||
// msg
|
|
||||||
// .sendWithoutNotification
|
|
||||||
// }^"
|
|
||||||
// queueStr += msgStr
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// writeString(internalConversationId + MESSAGE_QUEUE, queueStr)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Suppress("Detekt.TooGenericExceptionCaught")
|
|
||||||
// override fun getMessageQueue(internalConversationId: String): MutableList<MessageInputViewModel.QueuedMessage> {
|
|
||||||
// val queueStr =
|
|
||||||
// runBlocking { async { readString(internalConversationId + MESSAGE_QUEUE).first() } }.getCompleted()
|
|
||||||
//
|
|
||||||
// val queue: MutableList<MessageInputViewModel.QueuedMessage> = mutableListOf()
|
|
||||||
// if (queueStr.isEmpty()) return queue
|
|
||||||
//
|
|
||||||
// for (msgStr in queueStr.split("^")) {
|
|
||||||
// try {
|
|
||||||
// if (msgStr.isNotEmpty()) {
|
|
||||||
// val msgArray = msgStr.split(",")
|
|
||||||
// val id = msgArray[ID].toInt()
|
|
||||||
// val message = msgArray[MESSAGE_INDEX]
|
|
||||||
// val replyTo = msgArray[REPLY_TO_INDEX].toInt()
|
|
||||||
// val displayName = msgArray[DISPLAY_NAME_INDEX]
|
|
||||||
// val silent = msgArray[SILENT_INDEX].toBoolean()
|
|
||||||
//
|
|
||||||
// val qMsg = MessageInputViewModel.QueuedMessage(id, message, displayName, replyTo, silent)
|
|
||||||
// queue.add(qMsg)
|
|
||||||
// }
|
|
||||||
// } catch (e: IndexOutOfBoundsException) {
|
|
||||||
// Log.e(TAG, "Message string: $msgStr\n Queue String: $queueStr \n$e")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return queue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// override fun deleteAllMessageQueuesFor(userId: String) {
|
|
||||||
// runBlocking {
|
|
||||||
// async {
|
|
||||||
// val keyList = mutableListOf<Preferences.Key<*>>()
|
|
||||||
// val preferencesMap = context.dataStore.data.first().asMap()
|
|
||||||
// for (preference in preferencesMap) {
|
|
||||||
// if (preference.key.name.contains("$userId@")) {
|
|
||||||
// keyList.add(preference.key)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (key in keyList) {
|
|
||||||
// context.dataStore.edit {
|
|
||||||
// it.remove(key)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
override fun saveVoiceMessagePlaybackSpeedPreferences(speeds: Map<String, PlaybackSpeed>) {
|
override fun saveVoiceMessagePlaybackSpeedPreferences(speeds: Map<String, PlaybackSpeed>) {
|
||||||
Json.encodeToString(speeds).let {
|
Json.encodeToString(speeds).let {
|
||||||
runBlocking<Unit> { async { writeString(VOICE_MESSAGE_PLAYBACK_SPEEDS, it) } }
|
runBlocking<Unit> { async { writeString(VOICE_MESSAGE_PLAYBACK_SPEEDS, it) } }
|
||||||
|
@ -820,7 +820,6 @@ How to translate with transifex:
|
|||||||
<string name="show_banned_participants">Show banned participants</string>
|
<string name="show_banned_participants">Show banned participants</string>
|
||||||
<string name="bans_list">Bans list</string>
|
<string name="bans_list">Bans list</string>
|
||||||
<string name="connection_lost_sent_messages_are_queued">Connection lost - Sent messages are queued</string>
|
<string name="connection_lost_sent_messages_are_queued">Connection lost - Sent messages are queued</string>
|
||||||
<string name="connection_lost_queued">Connection lost - %1$d are queued</string>
|
|
||||||
<string name="connection_established">Connection established</string>
|
<string name="connection_established">Connection established</string>
|
||||||
<string name="message_deleted_by_you">Message deleted by you</string>
|
<string name="message_deleted_by_you">Message deleted by you</string>
|
||||||
<string name="unban">Unban</string>
|
<string name="unban">Unban</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user