Commit 368d1c5f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Send permalink to DM on reply to message at broadcast channels

parent 98f4530f
package chat.rocket.android.chatroom.adapter
import android.support.v7.widget.RecyclerView
import android.view.View
import chat.rocket.android.chatroom.viewmodel.MessageReplyViewModel
import chat.rocket.android.util.extensions.isBroadcastReplyAvailable
import chat.rocket.android.util.extensions.setVisible
import chat.rocket.android.widget.emoji.EmojiReactionListener
import kotlinx.android.synthetic.main.item_message_reply.view.*
......@@ -20,11 +23,17 @@ class MessageReplyViewHolder(
override fun bindViews(data: MessageReplyViewModel) {
with(itemView) {
button_message_reply.setOnClickListener {
with(data.rawData) {
replyCallback.invoke(roomName, permalink)
// if (data.isBroadcastReplyAvailable()) {
// setVisible(true)
button_message_reply.setOnClickListener {
with(data.rawData) {
replyCallback.invoke(roomName, permalink)
}
}
}
// } else {
// visibility = View.GONE
// itemView.layoutParams = RecyclerView.LayoutParams(0, 0)
// }
}
}
}
\ No newline at end of file
......@@ -16,8 +16,8 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
}
fun toPinnedMessageList(chatRoomId: String, chatRoomType: String) {
activity.addFragmentBackStack("PinnedMessages", R.id.fragment_container){
chat.rocket.android.pinnedmessages.ui.newInstance(chatRoomId,chatRoomType)
activity.addFragmentBackStack("PinnedMessages", R.id.fragment_container) {
chat.rocket.android.pinnedmessages.ui.newInstance(chatRoomId, chatRoomType)
}
}
......@@ -27,14 +27,15 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
}
fun toDirectMessage(chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomOwner: Boolean) {
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomOwner: Boolean,
chatRoomMessage: String) {
activity.startActivity(activity.chatRoomIntent(chatRoomId, chatRoomName, chatRoomType,
isChatRoomReadOnly, chatRoomLastSeen, isChatRoomSubscribed, isChatRoomOwner))
isChatRoomReadOnly, chatRoomLastSeen, isChatRoomSubscribed, isChatRoomOwner, chatRoomMessage))
activity.overridePendingTransition(R.anim.open_enter, R.anim.open_exit)
}
}
\ No newline at end of file
......@@ -624,7 +624,8 @@ class ChatRoomPresenter @Inject constructor(
chatRoomName = roomName,
isChatRoomOwner = false,
isChatRoomReadOnly = false,
isChatRoomSubscribed = it.open
isChatRoomSubscribed = it.open,
chatRoomMessage = permalink
)
} else {
throw IllegalStateException("Not a direct-message")
......
......@@ -28,7 +28,8 @@ fun Context.chatRoomIntent(
isChatRoomReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean = true,
isChatRoomOwner: Boolean = false
isChatRoomOwner: Boolean = false,
chatRoomMessage: String? = null
): Intent {
return Intent(this, ChatRoomActivity::class.java).apply {
putExtra(INTENT_CHAT_ROOM_ID, chatRoomId)
......@@ -38,6 +39,7 @@ fun Context.chatRoomIntent(
putExtra(INTENT_CHAT_ROOM_LAST_SEEN, chatRoomLastSeen)
putExtra(INTENT_CHAT_IS_SUBSCRIBED, isChatRoomSubscribed)
putExtra(INTENT_CHAT_ROOM_IS_OWNER, isChatRoomOwner)
putExtra(INTENT_CHAT_ROOM_MESSAGE, chatRoomMessage)
}
}
......@@ -48,6 +50,7 @@ private const val INTENT_CHAT_ROOM_IS_READ_ONLY = "chat_room_is_read_only"
private const val INTENT_CHAT_ROOM_IS_OWNER = "chat_room_is_owner"
private const val INTENT_CHAT_ROOM_LAST_SEEN = "chat_room_last_seen"
private const val INTENT_CHAT_IS_SUBSCRIBED = "is_chat_room_subscribed"
private const val INTENT_CHAT_ROOM_MESSAGE = "chat_room_message"
class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
@Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
......@@ -94,6 +97,8 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
isChatRoomOwner = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_OWNER, false)
requireNotNull(isChatRoomOwner) { "no chat_room_is_owner provided in Intent extras" }
val chatRoomMessage = intent.getStringExtra(INTENT_CHAT_ROOM_MESSAGE)
setupToolbar()
chatRoomLastSeen = intent.getLongExtra(INTENT_CHAT_ROOM_LAST_SEEN, -1)
......@@ -103,7 +108,7 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
if (supportFragmentManager.findFragmentByTag(TAG_CHAT_ROOM_FRAGMENT) == null) {
addFragment(TAG_CHAT_ROOM_FRAGMENT, R.id.fragment_container) {
newInstance(chatRoomId, chatRoomName, chatRoomType, isChatRoomReadOnly, chatRoomLastSeen,
isChatRoomSubscribed, isChatRoomOwner)
isChatRoomSubscribed, isChatRoomOwner, chatRoomMessage)
}
}
}
......
......@@ -79,7 +79,8 @@ fun newInstance(
isChatRoomReadOnly: Boolean,
chatRoomLastSeen: Long,
isSubscribed: Boolean = true,
isChatRoomOwner: Boolean = false
isChatRoomOwner: Boolean = false,
chatRoomMessage: String? = null
): Fragment {
return ChatRoomFragment().apply {
arguments = Bundle(1).apply {
......@@ -90,6 +91,7 @@ fun newInstance(
putLong(BUNDLE_CHAT_ROOM_LAST_SEEN, chatRoomLastSeen)
putBoolean(BUNDLE_CHAT_ROOM_IS_SUBSCRIBED, isSubscribed)
putBoolean(BUNDLE_CHAT_ROOM_IS_OWNER, isChatRoomOwner)
putString(BUNDLE_CHAT_ROOM_MESSAGE, chatRoomMessage)
}
}
}
......@@ -102,6 +104,7 @@ private const val REQUEST_CODE_FOR_PERFORM_SAF = 42
private const val BUNDLE_CHAT_ROOM_LAST_SEEN = "chat_room_last_seen"
private const val BUNDLE_CHAT_ROOM_IS_SUBSCRIBED = "chat_room_is_subscribed"
private const val BUNDLE_CHAT_ROOM_IS_OWNER = "chat_room_is_owner"
private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiReactionListener {
......@@ -113,6 +116,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
private lateinit var chatRoomId: String
private lateinit var chatRoomName: String
private lateinit var chatRoomType: String
private var chatRoomMessage: String? = null
private var isSubscribed: Boolean = true
private var isChatRoomReadOnly: Boolean = false
private var isChatRoomOwner: Boolean = false
......@@ -147,7 +151,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
isSubscribed = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_SUBSCRIBED)
chatRoomLastSeen = bundle.getLong(BUNDLE_CHAT_ROOM_LAST_SEEN)
isChatRoomOwner = bundle.getBoolean(BUNDLE_CHAT_ROOM_IS_OWNER)
chatRoomMessage = bundle.getString(BUNDLE_CHAT_ROOM_MESSAGE)
} else {
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" }
}
......@@ -615,6 +619,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_join_chat.setVisible(true)
button_join_chat.setOnClickListener { presenter.joinChat(chatRoomId) }
} else {
text_message.textContent = chatRoomMessage ?: ""
button_send.alpha = 0f
button_send.setVisible(false)
button_show_attachment_options.alpha = 1f
......
......@@ -15,12 +15,12 @@ import androidx.core.text.scale
import chat.rocket.android.R
import chat.rocket.android.chatroom.domain.MessageReply
import chat.rocket.android.helper.MessageParser
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.*
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.extensions.isNotNullNorEmpty
import chat.rocket.android.widget.emoji.EmojiParser
import chat.rocket.core.model.ChatRoom
import chat.rocket.core.model.Message
import chat.rocket.core.model.MessageType
import chat.rocket.core.model.Value
......@@ -36,7 +36,7 @@ import javax.inject.Inject
class ViewModelMapper @Inject constructor(
private val context: Context,
private val parser: MessageParser,
private val userHelper: UserHelper,
private val roomsInteractor: GetChatRoomsInteractor,
tokenRepository: TokenRepository,
serverInteractor: GetCurrentServerInteractor,
getSettingsInteractor: GetSettingsInteractor,
......@@ -89,16 +89,22 @@ class ViewModelMapper @Inject constructor(
list[i].nextDownStreamMessage = next
}
if (onBroadcastChannel) {
val replyViewModel = mapMessageReply(message)
list.first().nextDownStreamMessage = replyViewModel
list.add(0, replyViewModel)
if (onBroadcastChannel && isBroadcastReplyAvailable(message)) {
roomsInteractor.getById(currentServer, message.roomId)?.let { chatRoom ->
val replyViewModel = mapMessageReply(message, chatRoom)
list.first().nextDownStreamMessage = replyViewModel
list.add(0, replyViewModel)
}
}
return@withContext list
}
private fun mapMessageReply(message: Message): MessageReplyViewModel {
private fun isBroadcastReplyAvailable(message: Message): Boolean {
return !message.isSystemMessage() && message.sender?.username != currentUsername
}
private fun mapMessageReply(message: Message, chatRoom: ChatRoom): MessageReplyViewModel {
val name = message.sender?.name
val roomName = if (settings.useRealName() && name != null) name else message.sender?.username ?: ""
return MessageReplyViewModel(
......@@ -107,13 +113,15 @@ class ViewModelMapper @Inject constructor(
reactions = emptyList(),
message = message,
preview = mapMessagePreview(message),
rawData = MessageReply(roomName = roomName, permalink = makePermalink(message)),
rawData = MessageReply(roomName = roomName, permalink = makePermalink(message, chatRoom)),
nextDownStreamMessage = null
)
}
private fun makePermalink(message: Message): String {
return "[ ]($currentServer/direct/${message.sender?.username}?msg=${message.id}) "
private fun makePermalink(message: Message, chatRoom: ChatRoom): String {
val type = chatRoom.type.toString()
val name = if (settings.useRealName()) chatRoom.fullName ?: chatRoom.name else chatRoom.name
return "[ ]($currentServer/$type/$name?msg=${message.id}) "
}
private fun mapUrl(message: Message, url: Url): BaseViewModel<*>? {
......@@ -340,7 +348,6 @@ class ViewModelMapper @Inject constructor(
}
private fun getSystemMessage(message: Message): CharSequence {
println(message)
val content = when (message.type) {
//TODO: Add implementation for Welcome type.
is MessageType.MessageRemoved -> context.getString(R.string.message_removed)
......
package chat.rocket.android.util.extensions
import chat.rocket.core.model.Message
import chat.rocket.core.model.isSystemMessage
fun Message.isBroadcastReplyAvailable(isBroadcastChannel: Boolean): Boolean {
return (isTemporary == false) && !isSystemMessage() && isBroadcastChannel
}
\ No newline at end of file
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