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

Create a DM session if one do not alredy exists

parent 69a8dfe2
......@@ -47,4 +47,4 @@ class MembersAdapter(private val listener: (MemberUiModel) -> Unit) :
setOnClickListener { listener(memberUiModel) }
}
}
}
\ No newline at end of file
}
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)
}
}
\ No newline at end of file
}
......@@ -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?
......@@ -52,4 +53,4 @@ class MemberUiModel(
private fun getUserUtcOffset(): Float? = member.utcOffset
private fun getUserStatus(): UserStatus? = member.status
}
\ No newline at end of file
}
......@@ -7,11 +7,14 @@ 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()
fun mapToUiModelList(memberList: List<User>): List<MemberUiModel> {
return memberList.map { MemberUiModel(it, settings, baseUrl) }
}
}
\ No newline at end of file
}
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,38 +48,41 @@ 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) {
ChatRoom(
id = "$id$userId",
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = u.username ?: u.name.orEmpty(),
fullName = u.name,
favorite = false,
open = false,
alert = false,
status = status,
client = client,
broadcast = false,
archived = false,
default = false,
description = null,
groupMentions = null,
userMentions = null,
lastMessage = null,
lastSeen = null,
topic = null,
announcement = null,
roles = null,
unread = 0,
readonly = false,
muted = null,
subscriptionId = "",
timestamp = null,
updatedAt = null,
user = null
val result = retryIO("createDirectMessage(${matchFromSpotlight.id}") {
client.createDirectMessage(username = matchFromSpotlight.id)
}
with(matchFromSpotlight) {
ChatRoom(
id = result.id,
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = u.username ?: u.name.orEmpty(),
fullName = u.name,
favorite = false,
open = false,
alert = false,
status = status,
client = client,
broadcast = false,
archived = false,
default = false,
description = null,
groupMentions = null,
userMentions = null,
lastMessage = null,
lastSeen = null,
topic = null,
announcement = null,
roles = null,
unread = 0,
readonly = false,
muted = null,
subscriptionId = "",
timestamp = null,
updatedAt = null,
user = null
)
}
} else null
......@@ -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