Commit 07d9c48a authored by Hussein El Feky's avatar Hussein El Feky

Typing +:emoji_name: reacts to last message

parent 521f0a8b
......@@ -121,6 +121,7 @@ class ChatRoomPresenter @Inject constructor(
private var lastState = manager.state
private var typingStatusList = arrayListOf<String>()
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
private var lastMessageId: String? = null
private lateinit var draftKey: String
fun setupChatRoom(
......@@ -220,6 +221,7 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast = chatIsBroadcast, isRoom = true
)
)
lastMessageId = localMessages.first().id
val lastSyncDate = messagesRepository.getLastSyncDate(chatRoomId)
if (oldMessages.isNotEmpty() && lastSyncDate != null) {
view.showMessages(oldMessages, clearDataSet)
......@@ -368,6 +370,7 @@ class ChatRoomPresenter @Inject constructor(
throw ex
}
}
lastMessageId = id
} else {
client.updateMessage(chatRoomId, messageId, text)
}
......@@ -1071,7 +1074,7 @@ class ChatRoomPresenter @Inject constructor(
/**
* Send an emoji reaction to a message.
*/
fun react(messageId: String, emoji: String) {
fun react(messageId: String, emoji: String, roomId: String) {
launchUI(strategy) {
try {
retryIO("toggleEmoji($messageId, $emoji)") {
......@@ -1080,6 +1083,10 @@ class ChatRoomPresenter @Inject constructor(
logReactionEvent()
} catch (ex: RocketChatException) {
Timber.e(ex)
// emoji is not valid, post it
sendMessage(roomId, "+$emoji", null)
} finally {
view.clearMessageComposition(true)
}
}
}
......@@ -1178,6 +1185,7 @@ class ChatRoomPresenter @Inject constructor(
// command is not valid, post it
sendMessage(roomId, text, null)
} finally {
view.clearMessageComposition(true)
view.enableSendMessageButton()
}
}
......@@ -1246,8 +1254,8 @@ class ChatRoomPresenter @Inject constructor(
launchUI(strategy) {
val viewModelStreamedMessage = mapper.map(
streamedMessage, RoomUiModel(
roles = chatRoles, isBroadcast = chatIsBroadcast, isRoom = true
)
roles = chatRoles, isBroadcast = chatIsBroadcast, isRoom = true
)
)
val roomMessages = messagesRepository.getByRoomId(streamedMessage.roomId)
val index = roomMessages.indexOfFirst { msg -> msg.id == streamedMessage.id }
......@@ -1281,6 +1289,7 @@ class ChatRoomPresenter @Inject constructor(
fun clearDraftMessage() {
localRepository.clear(draftKey)
}
/**
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
......@@ -1290,4 +1299,8 @@ class ChatRoomPresenter @Inject constructor(
fun getDraftUnfinishedMessage(): String? {
return localRepository.get(draftKey)
}
fun getLastMessageId(): String? {
return lastMessageId
}
}
......@@ -148,10 +148,14 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiReactionListener,
ChatRoomAdapter.OnActionSelected, Drawable.Callback {
@Inject lateinit var presenter: ChatRoomPresenter
@Inject lateinit var parser: MessageParser
@Inject lateinit var analyticsManager: AnalyticsManager
@Inject lateinit var navigator: ChatRoomNavigator
@Inject
lateinit var presenter: ChatRoomPresenter
@Inject
lateinit var parser: MessageParser
@Inject
lateinit var analyticsManager: AnalyticsManager
@Inject
lateinit var navigator: ChatRoomNavigator
private lateinit var adapter: ChatRoomAdapter
internal lateinit var chatRoomId: String
private lateinit var chatRoomName: String
......@@ -476,11 +480,17 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun sendMessage(text: String) {
ui {
if (!text.isBlank()) {
if (!text.startsWith("/")) {
presenter.sendMessage(chatRoomId, text, editingMessageId)
} else {
if (text.startsWith("/")) {
presenter.runCommand(text, chatRoomId)
return@ui
} else if (text.startsWith("+") && presenter.getLastMessageId() != null) {
val trimmedText = text.substring(1).trimEnd()
if (trimmedText.length - trimmedText.removeSurrounding(":").length == 2) {
presenter.react(presenter.getLastMessageId()!!, trimmedText, chatRoomId)
return@ui
}
}
presenter.sendMessage(chatRoomId, text, editingMessageId)
}
}
}
......@@ -524,7 +534,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override fun clearMessageComposition(deleteMessage: Boolean) {
ui {
citation = null
......@@ -671,11 +680,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
override fun onReactionTouched(messageId: String, emojiShortname: String) {
presenter.react(messageId, emojiShortname)
presenter.react(messageId, emojiShortname, chatRoomId)
}
override fun onReactionAdded(messageId: String, emoji: Emoji) {
presenter.react(messageId, emoji.shortname)
presenter.react(messageId, emoji.shortname, chatRoomId)
}
override fun onReactionLongClicked(
......@@ -896,7 +905,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_take_a_photo.setOnClickListener {
// Check for camera permission
context?.let {
if(hasCameraPermission(it)) {
if (hasCameraPermission(it)) {
dispatchTakePictureIntent()
} else {
getCameraPermission(this)
......@@ -964,7 +973,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when(requestCode) {
when (requestCode) {
AndroidPermissionsHelper.CAMERA_CODE -> {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
......
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