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