Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/java/chat/rocket/android/helper/UserHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class UserHelper @Inject constructor(
*/
fun user(): User? = getCurrentServerInteractor.get()?.let { localRepository.getCurrentUser(it) }

/**
* Saves current User data.
*/
fun updateUser(url: String, user: User) = localRepository.saveCurrentUser(url, user)

/**
* Return the username for the current logged [User].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import chat.rocket.android.util.extension.toHex
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO
import chat.rocket.common.RocketChatException
import chat.rocket.common.model.Email
import chat.rocket.common.model.User
import chat.rocket.common.util.ifNull
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.deleteOwnAccount
import chat.rocket.core.internal.rest.resetAvatar
import chat.rocket.core.internal.rest.setAvatar
import chat.rocket.core.internal.rest.updateProfile
import chat.rocket.core.internal.rest.*
Comment thread
dev-ritik marked this conversation as resolved.
Outdated
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.withContext
import timber.log.Timber
import java.util.*
import javax.inject.Inject

Expand Down Expand Up @@ -73,6 +73,7 @@ class ProfilePresenter @Inject constructor(
view.showMessage(exception)
} finally {
view.hideLoading()
updateLocal()
}
}
}
Expand Down Expand Up @@ -176,6 +177,32 @@ class ProfilePresenter @Inject constructor(
}
}

fun updateLocal() {
launchUI(strategy) {
try {
val myself = retryIO { client.me() }
val user = User(
id = myself.id,
Comment thread
dev-ritik marked this conversation as resolved.
Outdated
username = myself.username,
name = myself.name,
status = myself.status,
utcOffset = myself.utcOffset,
emails = myself.emails?.map { Email(it.address ?: "", it.verified) },
roles = myself.roles
)
userHelper.updateUser(serverUrl, user)
view.showProfile(
serverUrl.avatarUrl(user.username ?: ""),
user.name ?: "",
user.username ?: "",
user.emails?.getOrNull(0)?.address ?: ""
)
} catch (exception: Exception) {
Timber.e(exception)
}
}
}

fun deleteAccount(password: String) {
launchUI(strategy) {
view.showLoading()
Expand Down