Commit a0486d28 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Implement pin and unpin a message from a chat

parent c9314b15
...@@ -246,6 +246,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -246,6 +246,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
} }
} }
fun unpinMessage(messageId: String) {
launchUI(strategy) {
//TODO: Check permissions.
try {
client.unpinMessage(messageId)
} catch (e: RocketChatException) {
Timber.e(e)
}
}
}
private suspend fun listenMessages(roomId: String) { private suspend fun listenMessages(roomId: String) {
launch(CommonPool + strategy.jobs) { launch(CommonPool + strategy.jobs) {
for (message in client.messagesChannel) { for (message in client.messagesChannel) {
......
...@@ -21,7 +21,8 @@ import com.stfalcon.frescoimageviewer.ImageViewer ...@@ -21,7 +21,8 @@ import com.stfalcon.frescoimageviewer.ImageViewer
import kotlinx.android.synthetic.main.avatar.view.* import kotlinx.android.synthetic.main.avatar.view.*
import kotlinx.android.synthetic.main.item_message.view.* import kotlinx.android.synthetic.main.item_message.view.*
import kotlinx.android.synthetic.main.message_attachment.view.* import kotlinx.android.synthetic.main.message_attachment.view.*
import ru.whalemare.sheetmenu.SheetMenu import ru.whalemare.sheetmenu.extension.inflate
import ru.whalemare.sheetmenu.extension.toList
class ChatRoomAdapter(private val serverUrl: String, class ChatRoomAdapter(private val serverUrl: String,
private val roomType: String, private val roomType: String,
...@@ -98,10 +99,16 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -98,10 +99,16 @@ class ChatRoomAdapter(private val serverUrl: String,
file_name) file_name)
text_content.setOnClickListener { text_content.setOnClickListener {
if (!message.systemMessage) { if (!message.isSystemMessage) {
SheetMenu().apply { val menuItems = it.context.inflate(R.menu.message_actions).toList()
click = this@ViewHolder menuItems.find { it.itemId == R.id.action_menu_msg_pin_unpin }?.apply {
menu = R.menu.message_actions val isPinned = message.isPinned
setTitle(if (isPinned) R.string.action_msg_unpin else R.string.action_msg_pin)
setChecked(isPinned)
}
val adapter = ActionListAdapter(menuItems, this@ViewHolder)
BottomSheetMenu(adapter).apply {
}.show(it.context) }.show(it.context)
} }
} }
...@@ -115,7 +122,15 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -115,7 +122,15 @@ class ChatRoomAdapter(private val serverUrl: String,
R.id.action_menu_msg_reply -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", true) R.id.action_menu_msg_reply -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", true)
R.id.action_menu_msg_copy -> presenter.copyMessage(id) R.id.action_menu_msg_copy -> presenter.copyMessage(id)
R.id.action_menu_msg_edit -> presenter.editMessage(roomId, id, getOriginalMessage()) R.id.action_menu_msg_edit -> presenter.editMessage(roomId, id, getOriginalMessage())
R.id.action_menu_msg_pin -> presenter.pinMessage(id) R.id.action_menu_msg_pin_unpin -> {
with(item) {
if (!isChecked) {
presenter.pinMessage(id)
} else {
presenter.unpinMessage(id)
}
}
}
else -> TODO("Not implemented") else -> TODO("Not implemented")
} }
} }
......
...@@ -44,11 +44,13 @@ data class MessageViewModel(val context: Context, ...@@ -44,11 +44,13 @@ data class MessageViewModel(val context: Context,
var attachmentMessageAuthor: String? = null var attachmentMessageAuthor: String? = null
var attachmentMessageIcon: String? = null var attachmentMessageIcon: String? = null
var attachmentTimestamp: Long? = null var attachmentTimestamp: Long? = null
var systemMessage: Boolean = false var isSystemMessage: Boolean = false
var isPinned: Boolean = false
init { init {
sender = getSenderName() sender = getSenderName()
time = getTime(message.timestamp) time = getTime(message.timestamp)
isPinned = message.pinned
val baseUrl = settings.get(SITE_URL) val baseUrl = settings.get(SITE_URL)
message.urls?.let { message.urls?.let {
...@@ -153,7 +155,7 @@ data class MessageViewModel(val context: Context, ...@@ -153,7 +155,7 @@ data class MessageViewModel(val context: Context,
} }
private fun getSystemMessage(content: String): CharSequence { private fun getSystemMessage(content: String): CharSequence {
systemMessage = true isSystemMessage = true
val spannableMsg = SpannableStringBuilder(content) val spannableMsg = SpannableStringBuilder(content)
spannableMsg.setSpan(StyleSpan(Typeface.ITALIC), 0, spannableMsg.length, spannableMsg.setSpan(StyleSpan(Typeface.ITALIC), 0, spannableMsg.length,
0) 0)
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<!--android:title="@string/action_msg_share" />--> <!--android:title="@string/action_msg_share" />-->
<item <item
android:id="@+id/action_menu_msg_pin" android:id="@+id/action_menu_msg_pin_unpin"
android:icon="@drawable/ic_pin_black_24dp" android:icon="@drawable/ic_pin_black_24dp"
android:title="@string/action_msg_pin" /> android:title="@string/action_msg_pin" />
......
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
<string name="action_msg_copy">Copiar</string> <string name="action_msg_copy">Copiar</string>
<string name="action_msg_quote">Citar</string> <string name="action_msg_quote">Citar</string>
<string name="action_msg_delete">Remover</string> <string name="action_msg_delete">Remover</string>
<string name="action_msg_pin">Pinar Mensagem</string> <string name="action_msg_pin">Fixar Mensagem</string>
<string name="action_msg_unpin">Desafixar Messagem</string>
<string name="action_msg_star">Favoritar Mensagem</string> <string name="action_msg_star">Favoritar Mensagem</string>
<string name="action_msg_share">Compartilhar</string> <string name="action_msg_share">Compartilhar</string>
<string name="action_title_editing">Editando Mensagem</string> <string name="action_title_editing">Editando Mensagem</string>
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
<string name="action_msg_quote">Quote</string> <string name="action_msg_quote">Quote</string>
<string name="action_msg_delete">Delete</string> <string name="action_msg_delete">Delete</string>
<string name="action_msg_pin">Pin Message</string> <string name="action_msg_pin">Pin Message</string>
<string name="action_msg_unpin">Unpin Message</string>
<string name="action_msg_star">Star Message</string> <string name="action_msg_star">Star Message</string>
<string name="action_msg_share">Share</string> <string name="action_msg_share">Share</string>
<string name="action_title_editing">Editing Message</string> <string name="action_title_editing">Editing Message</string>
......
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