Commit 00278aaf authored by Leonardo Aramaki's avatar Leonardo Aramaki

Honor use real name setting

parent b0d03bea
...@@ -2,6 +2,7 @@ package chat.rocket.android.chatroom.presentation ...@@ -2,6 +2,7 @@ package chat.rocket.android.chatroom.presentation
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.common.model.BaseRoom import chat.rocket.common.model.BaseRoom
...@@ -11,6 +12,7 @@ import chat.rocket.core.internal.realtime.unsubscibre ...@@ -11,6 +12,7 @@ import chat.rocket.core.internal.realtime.unsubscibre
import chat.rocket.core.internal.rest.messages import chat.rocket.core.internal.rest.messages
import chat.rocket.core.internal.rest.sendMessage import chat.rocket.core.internal.rest.sendMessage
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Value
import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.launch
import timber.log.Timber import timber.log.Timber
...@@ -18,11 +20,17 @@ import javax.inject.Inject ...@@ -18,11 +20,17 @@ import javax.inject.Inject
class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private val strategy: CancelStrategy, private val strategy: CancelStrategy,
getSettingsInteractor: GetSettingsInteractor,
private val serverInteractor: GetCurrentServerInteractor, private val serverInteractor: GetCurrentServerInteractor,
factory: RocketChatClientFactory) { factory: RocketChatClientFactory) {
private val client = factory.create(serverInteractor.get()!!) private val client = factory.create(serverInteractor.get()!!)
private val roomMessages = ArrayList<Message>() private val roomMessages = ArrayList<Message>()
private var subId: String? = null private var subId: String? = null
private var settings: Map<String, Value<Any>>? = null
init {
settings = getSettingsInteractor.get(serverInteractor.get()!!)
}
fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Int = 0) { fun loadMessages(chatRoomId: String, chatRoomType: String, offset: Int = 0) {
launchUI(strategy) { launchUI(strategy) {
...@@ -32,7 +40,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -32,7 +40,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
synchronized(roomMessages) { synchronized(roomMessages) {
roomMessages.addAll(messages) roomMessages.addAll(messages)
} }
view.showMessages(messages, serverInteractor.get()!!) view.showMessages(messages, serverInteractor.get()!!, settings)
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
ex.message?.let { ex.message?.let {
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.chatroom.presentation ...@@ -3,6 +3,7 @@ package chat.rocket.android.chatroom.presentation
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Value
interface ChatRoomView : LoadingView, MessageView { interface ChatRoomView : LoadingView, MessageView {
...@@ -11,8 +12,9 @@ interface ChatRoomView : LoadingView, MessageView { ...@@ -11,8 +12,9 @@ interface ChatRoomView : LoadingView, MessageView {
* *
* @param dataSet The data set to show. * @param dataSet The data set to show.
* @param serverUrl The server URL. * @param serverUrl The server URL.
* @param settings The server settings.
*/ */
fun showMessages(dataSet: List<Message>, serverUrl: String) fun showMessages(dataSet: List<Message>, serverUrl: String, settings: Map<String, Value<Any>>?)
/** /**
* Send a message to a chat room. * Send a message to a chat room.
......
...@@ -9,17 +9,20 @@ import android.widget.ImageView ...@@ -9,17 +9,20 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.helper.UrlHelper import chat.rocket.android.helper.UrlHelper
import chat.rocket.android.server.domain.USE_REALNAME
import chat.rocket.android.util.inflate import chat.rocket.android.util.inflate
import chat.rocket.android.util.setVisibility import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent import chat.rocket.android.util.textContent
import chat.rocket.common.util.ifNull import chat.rocket.common.util.ifNull
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Value
import com.facebook.drawee.view.SimpleDraweeView import com.facebook.drawee.view.SimpleDraweeView
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.*
class ChatRoomAdapter(private val context: Context, class ChatRoomAdapter(private val context: Context,
private val serverUrl: String) : RecyclerView.Adapter<ChatRoomAdapter.ViewHolder>() { private val serverUrl: String,
private val settings: Map<String, Value<Any>>?) : RecyclerView.Adapter<ChatRoomAdapter.ViewHolder>() {
init { init {
setHasStableIds(true) setHasStableIds(true)
...@@ -74,12 +77,20 @@ class ChatRoomAdapter(private val context: Context, ...@@ -74,12 +77,20 @@ class ChatRoomAdapter(private val context: Context,
imageUnknownAvatar.setVisibility(true) imageUnknownAvatar.setVisibility(true)
} }
private fun bindUserName(message: Message, textView: TextView) = message.sender?.username.let { private fun bindUserName(message: Message, textView: TextView) {
textView.textContent = it.toString() val useRealName = settings?.get(USE_REALNAME)?.value as Boolean
}.ifNull { val realName = message.sender?.name
textView.textContent = context.getString(R.string.msg_unknown) val username = message.sender?.username
} val senderName = if (useRealName) realName else username
senderName.let {
// TODO: Fallback to username if real name happens to be null. ATM this could happen if the
// present message is a system message. We should handle that on the SDK
textView.textContent = if (senderName == null) username.toString() else it.toString()
}.ifNull {
textView.textContent = context.getString(R.string.msg_unknown)
}
}
private fun bindTime(message: Message, textView: TextView) { private fun bindTime(message: Message, textView: TextView) {
textView.textContent = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(message.timestamp)) textView.textContent = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(message.timestamp))
} }
......
...@@ -17,6 +17,7 @@ import chat.rocket.android.util.inflate ...@@ -17,6 +17,7 @@ import chat.rocket.android.util.inflate
import chat.rocket.android.util.setVisibility import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent import chat.rocket.android.util.textContent
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Value
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_room.* import kotlinx.android.synthetic.main.fragment_chat_room.*
import kotlinx.android.synthetic.main.message_composer.* import kotlinx.android.synthetic.main.message_composer.*
...@@ -76,10 +77,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView { ...@@ -76,10 +77,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
super.onDestroyView() super.onDestroyView()
} }
override fun showMessages(dataSet: List<Message>, serverUrl: String) { override fun showMessages(dataSet: List<Message>, serverUrl: String, settings: Map<String, Value<Any>>?) {
activity?.apply { activity?.apply {
if (recycler_view.adapter == null) { if (recycler_view.adapter == null) {
adapter = ChatRoomAdapter(this, serverUrl) adapter = ChatRoomAdapter(this, serverUrl, settings)
recycler_view.adapter = adapter recycler_view.adapter = adapter
val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true) val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
recycler_view.layoutManager = linearLayoutManager recycler_view.layoutManager = linearLayoutManager
......
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