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,
}
}
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) {
launch(CommonPool + strategy.jobs) {
for (message in client.messagesChannel) {
......
......@@ -21,7 +21,8 @@ import com.stfalcon.frescoimageviewer.ImageViewer
import kotlinx.android.synthetic.main.avatar.view.*
import kotlinx.android.synthetic.main.item_message.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,
private val roomType: String,
......@@ -98,10 +99,16 @@ class ChatRoomAdapter(private val serverUrl: String,
file_name)
text_content.setOnClickListener {
if (!message.systemMessage) {
SheetMenu().apply {
click = this@ViewHolder
menu = R.menu.message_actions
if (!message.isSystemMessage) {
val menuItems = it.context.inflate(R.menu.message_actions).toList()
menuItems.find { it.itemId == R.id.action_menu_msg_pin_unpin }?.apply {
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)
}
}
......@@ -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_copy -> presenter.copyMessage(id)
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")
}
}
......
......@@ -44,11 +44,13 @@ data class MessageViewModel(val context: Context,
var attachmentMessageAuthor: String? = null
var attachmentMessageIcon: String? = null
var attachmentTimestamp: Long? = null
var systemMessage: Boolean = false
var isSystemMessage: Boolean = false
var isPinned: Boolean = false
init {
sender = getSenderName()
time = getTime(message.timestamp)
isPinned = message.pinned
val baseUrl = settings.get(SITE_URL)
message.urls?.let {
......@@ -153,7 +155,7 @@ data class MessageViewModel(val context: Context,
}
private fun getSystemMessage(content: String): CharSequence {
systemMessage = true
isSystemMessage = true
val spannableMsg = SpannableStringBuilder(content)
spannableMsg.setSpan(StyleSpan(Typeface.ITALIC), 0, spannableMsg.length,
0)
......
......@@ -28,7 +28,7 @@
<!--android:title="@string/action_msg_share" />-->
<item
android:id="@+id/action_menu_msg_pin"
android:id="@+id/action_menu_msg_pin_unpin"
android:icon="@drawable/ic_pin_black_24dp"
android:title="@string/action_msg_pin" />
......
......@@ -63,7 +63,8 @@
<string name="action_msg_copy">Copiar</string>
<string name="action_msg_quote">Citar</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_share">Compartilhar</string>
<string name="action_title_editing">Editando Mensagem</string>
......
......@@ -66,6 +66,7 @@
<string name="action_msg_quote">Quote</string>
<string name="action_msg_delete">Delete</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_share">Share</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