Commit 531c5a0f authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Draft messages improvements

parent 61318332
......@@ -123,6 +123,7 @@ class ChatRoomPresenter @Inject constructor(
private var lastState = manager.state
private var typingStatusList = arrayListOf<String>()
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
private lateinit var unfinishedMessageKey: String
fun setupChatRoom(
roomId: String,
......@@ -132,9 +133,12 @@ class ChatRoomPresenter @Inject constructor(
) {
launch(CommonPool + strategy.jobs) {
try {
unfinishedMessageKey = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$roomId"
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList()
} else {
emptyList()
}
} catch (ex: RocketChatException) {
Timber.e(ex)
chatRoles = emptyList()
......@@ -364,6 +368,7 @@ class ChatRoomPresenter @Inject constructor(
client.updateMessage(chatRoomId, messageId, text)
}
clearUnfinishedMessage()
view.enableSendMessageButton()
} catch (ex: Exception) {
Timber.d(ex, "Error sending message...")
......@@ -1281,31 +1286,26 @@ class ChatRoomPresenter @Inject constructor(
}
/**
* Save unfinished message, when user left chat room without sending a message. It also clears
* saved message from local repository when unfinishedMessage is blank.
* Save unfinished message, when user left chat room without sending a message.
*
* @param chatRoomId Chat room Id.
* @param unfinishedMessage The unfinished message to save.
*/
fun saveUnfinishedMessage(chatRoomId: String, unfinishedMessage: String) {
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId"
fun saveUnfinishedMessage(unfinishedMessage: String) {
if (unfinishedMessage.isNotBlank()) {
localRepository.save(key, unfinishedMessage)
} else {
localRepository.clear(key)
localRepository.save(unfinishedMessageKey, unfinishedMessage)
}
}
fun clearUnfinishedMessage() {
localRepository.clear(unfinishedMessageKey)
}
/**
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
*
* @param chatRoomId Chat room Id.
*
* @return Returns the unfinished message.
* @return Returns the unfinished message, null otherwise.
*/
fun getUnfinishedMessage(chatRoomId: String): String {
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId"
return localRepository.get(key) ?: ""
fun getUnfinishedMessage(): String? {
return localRepository.get(unfinishedMessageKey)
}
}
......@@ -76,6 +76,7 @@ import chat.rocket.android.util.extensions.fadeOut
import chat.rocket.android.util.extensions.getBitmpap
import chat.rocket.android.util.extensions.hideKeyboard
import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.isNotNullNorEmpty
import chat.rocket.android.util.extensions.rotateBy
import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent
......@@ -242,6 +243,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
presenter.setupChatRoom(chatRoomId, chatRoomName, chatRoomType, chatRoomMessage)
presenter.loadChatRooms()
getUnfinishedMessage()
setupRecyclerView()
setupFab()
setupSuggestionsView()
......@@ -264,9 +266,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view.removeOnScrollListener(onScrollListener)
recycler_view.removeOnLayoutChangeListener(layoutChangeListener)
presenter.disconnect()
presenter.saveUnfinishedMessage(chatRoomId, text_message.text.toString())
presenter.saveUnfinishedMessage(text_message.text.toString())
handler.removeCallbacksAndMessages(null)
presenter.disconnect()
unsubscribeComposeTextMessage()
// Hides the keyboard (if it's opened) before going to any view.
......@@ -953,15 +955,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
private fun getUnfinishedMessage() {
val unfinishedMessage = presenter.getUnfinishedMessage(chatRoomId)
if (unfinishedMessage.isNotBlank()) {
val unfinishedMessage = presenter.getUnfinishedMessage()
if (unfinishedMessage.isNotNullNorEmpty()) {
text_message.setText(unfinishedMessage)
val orientation = resources.configuration.orientation
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
KeyboardHelper.showSoftKeyboard(text_message)
} else {
//TODO show keyboard in full screen mode when landscape orientation
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment