Commit 2e15f4a7 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Create a DM session if one do not alredy exists

parent 69a8dfe2
package chat.rocket.android.members.presentation package chat.rocket.android.members.presentation
import chat.rocket.android.chatdetails.ui.ChatDetailsActivity import chat.rocket.android.chatdetails.ui.ChatDetailsActivity
import chat.rocket.android.members.ui.TAG_MEMBER_BOTTOM_SHEET_FRAGMENT import chat.rocket.android.userdetails.ui.userDetailsIntent
import chat.rocket.android.members.ui.newInstance
class MembersNavigator(internal val activity: ChatDetailsActivity) { class MembersNavigator(internal val activity: ChatDetailsActivity) {
fun toMemberDetails(avatarUri: String, realName: String, username: String, email: String, utcOffset: String) { fun toMemberDetails(userId: String) {
activity.apply { activity.apply {
newInstance(avatarUri, realName, username, email, utcOffset) startActivity(this.userDetailsIntent(userId, ""))
.show(supportFragmentManager, TAG_MEMBER_BOTTOM_SHEET_FRAGMENT)
} }
} }
} }
...@@ -59,12 +59,6 @@ class MembersPresenter @Inject constructor( ...@@ -59,12 +59,6 @@ class MembersPresenter @Inject constructor(
} }
fun toMemberDetails(memberUiModel: MemberUiModel) { fun toMemberDetails(memberUiModel: MemberUiModel) {
navigator.toMemberDetails( navigator.toMemberDetails(memberUiModel.userId)
memberUiModel.avatarUri.toString(),
memberUiModel.realName.toString(),
"@${memberUiModel.username}",
memberUiModel.email ?: "",
memberUiModel.utcOffset.toString()
)
} }
} }
...@@ -11,6 +11,7 @@ class MemberUiModel( ...@@ -11,6 +11,7 @@ class MemberUiModel(
private val settings: Map<String, Value<Any>>, private val settings: Map<String, Value<Any>>,
private val baseUrl: String? private val baseUrl: String?
) { ) {
val userId: String = member.id
val avatarUri: String? val avatarUri: String?
val displayName: String val displayName: String
val realName: String? val realName: String?
......
...@@ -7,7 +7,10 @@ import chat.rocket.common.model.User ...@@ -7,7 +7,10 @@ import chat.rocket.common.model.User
import chat.rocket.core.model.Value import chat.rocket.core.model.Value
import javax.inject.Inject import javax.inject.Inject
class MemberUiModelMapper @Inject constructor(serverInteractor: GetCurrentServerInteractor, getSettingsInteractor: GetSettingsInteractor) { class MemberUiModelMapper @Inject constructor(
serverInteractor: GetCurrentServerInteractor,
getSettingsInteractor: GetSettingsInteractor
) {
private var settings: Map<String, Value<Any>> = getSettingsInteractor.get(serverInteractor.get()!!) private var settings: Map<String, Value<Any>> = getSettingsInteractor.get(serverInteractor.get()!!)
private val baseUrl = settings.baseUrl() private val baseUrl = settings.baseUrl()
......
package chat.rocket.android.userdetails.presentation package chat.rocket.android.userdetails.presentation
import androidx.core.text.toSpannable
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManager import chat.rocket.android.db.DatabaseManager
import chat.rocket.android.helper.UserHelper import chat.rocket.android.helper.UserHelper
...@@ -10,8 +9,8 @@ import chat.rocket.android.util.extension.launchUI ...@@ -10,8 +9,8 @@ import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.avatarUrl import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO import chat.rocket.android.util.retryIO
import chat.rocket.common.model.RoomType import chat.rocket.common.model.RoomType
import chat.rocket.common.model.SimpleUser
import chat.rocket.common.model.roomTypeOf import chat.rocket.common.model.roomTypeOf
import chat.rocket.core.internal.rest.createDirectMessage
import chat.rocket.core.internal.rest.spotlight import chat.rocket.core.internal.rest.spotlight
import chat.rocket.core.model.ChatRoom import chat.rocket.core.model.ChatRoom
import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.CommonPool
...@@ -30,7 +29,7 @@ class UserDetailsPresenter @Inject constructor( ...@@ -30,7 +29,7 @@ class UserDetailsPresenter @Inject constructor(
private var currentServer = serverInteractor.get()!! private var currentServer = serverInteractor.get()!!
private val manager = factory.create(currentServer) private val manager = factory.create(currentServer)
private val client = manager.client private val client = manager.client
private val userId = userHelper.user()?.id private val currentUserId = userHelper.user()?.id
fun loadUserDetails(userId: String) { fun loadUserDetails(userId: String) {
launchUI(strategy) { launchUI(strategy) {
...@@ -49,12 +48,15 @@ class UserDetailsPresenter @Inject constructor( ...@@ -49,12 +48,15 @@ class UserDetailsPresenter @Inject constructor(
client.spotlight(query = query) client.spotlight(query = query)
} }
val matchFromSpotlight = spotlightResult.users.firstOrNull() val matchFromSpotlight = spotlightResult.users.firstOrNull { it.username == query }
if (matchFromSpotlight != null) { if (matchFromSpotlight != null) {
with (matchFromSpotlight) { val result = retryIO("createDirectMessage(${matchFromSpotlight.id}") {
client.createDirectMessage(username = matchFromSpotlight.id)
}
with(matchFromSpotlight) {
ChatRoom( ChatRoom(
id = "$id$userId", id = result.id,
type = roomTypeOf(RoomType.DIRECT_MESSAGE), type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = u.username ?: u.name.orEmpty(), name = u.username ?: u.name.orEmpty(),
fullName = u.name, fullName = u.name,
...@@ -100,6 +102,10 @@ class UserDetailsPresenter @Inject constructor( ...@@ -100,6 +102,10 @@ class UserDetailsPresenter @Inject constructor(
} }
} }
fun createDirectMessage(username: String) {
}
private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) { private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) {
return@withContext dbManager.chatRoomDao().getAllSync().filter { return@withContext dbManager.chatRoomDao().getAllSync().filter {
if (name == null) { if (name == null) {
......
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