Unverified Commit 65db658e authored by Divyanshu Bhargava's avatar Divyanshu Bhargava Committed by GitHub

Merge branch 'beta' into fix-2133

parents c8cd83d1 81dc71d8
...@@ -85,20 +85,20 @@ class LoginPresenter @Inject constructor( ...@@ -85,20 +85,20 @@ class LoginPresenter @Inject constructor(
} }
} }
val myself = retryIO("me()") { client.me() } val myself = retryIO("me()") { client.me() }
if (myself.username != null) { myself.username?.let { username ->
val user = User( val user = User(
id = myself.id, id = myself.id,
roles = myself.roles, roles = myself.roles,
status = myself.status, status = myself.status,
name = myself.name, name = myself.name,
emails = myself.emails?.map { Email(it.address ?: "", it.verified) }, emails = myself.emails?.map { Email(it.address ?: "", it.verified) },
username = myself.username, username = username,
utcOffset = myself.utcOffset utcOffset = myself.utcOffset
) )
localRepository.saveCurrentUser(currentServer, user) localRepository.saveCurrentUser(currentServer, user)
saveCurrentServer.save(currentServer) saveCurrentServer.save(currentServer)
localRepository.save(LocalRepository.CURRENT_USERNAME_KEY, myself.username) localRepository.save(LocalRepository.CURRENT_USERNAME_KEY, username)
saveAccount(myself.username!!) saveAccount(username)
saveToken(token) saveToken(token)
analyticsManager.logLogin( analyticsManager.logLogin(
AuthenticationEvent.AuthenticationWithUserAndPassword, AuthenticationEvent.AuthenticationWithUserAndPassword,
...@@ -133,7 +133,7 @@ class LoginPresenter @Inject constructor( ...@@ -133,7 +133,7 @@ class LoginPresenter @Inject constructor(
fun forgotPassword() = navigator.toForgotPassword() fun forgotPassword() = navigator.toForgotPassword()
private suspend fun saveAccount(username: String) { private fun saveAccount(username: String) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
currentServer.serverLogoUrl(it) currentServer.serverLogoUrl(it)
} }
......
...@@ -173,7 +173,7 @@ class LoginOptionsPresenter @Inject constructor( ...@@ -173,7 +173,7 @@ class LoginOptionsPresenter @Inject constructor(
settings = settingsInteractor.get(currentServer) settings = settingsInteractor.get(currentServer)
} }
private suspend fun saveAccount(username: String) { private fun saveAccount(username: String) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
currentServer.serverLogoUrl(it) currentServer.serverLogoUrl(it)
} }
......
...@@ -94,7 +94,7 @@ class TwoFAPresenter @Inject constructor( ...@@ -94,7 +94,7 @@ class TwoFAPresenter @Inject constructor(
} }
} }
private suspend fun saveAccount(me: Myself) { private fun saveAccount(me: Myself) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
currentServer.serverLogoUrl(it) currentServer.serverLogoUrl(it)
} }
......
...@@ -210,7 +210,7 @@ class MainPresenter @Inject constructor( ...@@ -210,7 +210,7 @@ class MainPresenter @Inject constructor(
} }
} }
private suspend fun saveAccount(uiModel: NavHeaderUiModel) { private fun saveAccount(uiModel: NavHeaderUiModel) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
currentServer.serverLogoUrl(it) currentServer.serverLogoUrl(it)
} }
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.server.domain ...@@ -3,6 +3,7 @@ package chat.rocket.android.server.domain
import chat.rocket.android.server.domain.model.Account import chat.rocket.android.server.domain.model.Account
interface AccountsRepository { interface AccountsRepository {
fun save(account: Account) fun save(account: Account)
fun load(): List<Account> fun load(): List<Account>
fun remove(serverUrl: String) fun remove(serverUrl: String)
......
...@@ -3,7 +3,8 @@ package chat.rocket.android.server.domain ...@@ -3,7 +3,8 @@ package chat.rocket.android.server.domain
import javax.inject.Inject import javax.inject.Inject
class GetAccountInteractor @Inject constructor(val repository: AccountsRepository) { class GetAccountInteractor @Inject constructor(val repository: AccountsRepository) {
suspend fun get(url: String) = repository.load().firstOrNull { account ->
fun get(url: String) = repository.load().firstOrNull { account ->
url == account.serverUrl url == account.serverUrl
} }
} }
\ No newline at end of file
...@@ -3,7 +3,8 @@ package chat.rocket.android.server.domain ...@@ -3,7 +3,8 @@ package chat.rocket.android.server.domain
import javax.inject.Inject import javax.inject.Inject
class RemoveAccountInteractor @Inject constructor(val repository: AccountsRepository) { class RemoveAccountInteractor @Inject constructor(val repository: AccountsRepository) {
suspend fun remove(serverUrl: String) {
fun remove(serverUrl: String) {
repository.remove(serverUrl) repository.remove(serverUrl)
} }
} }
\ No newline at end of file
...@@ -4,5 +4,5 @@ import chat.rocket.android.server.domain.model.Account ...@@ -4,5 +4,5 @@ import chat.rocket.android.server.domain.model.Account
import javax.inject.Inject import javax.inject.Inject
class SaveAccountInteractor @Inject constructor(val repository: AccountsRepository) { class SaveAccountInteractor @Inject constructor(val repository: AccountsRepository) {
suspend fun save(account: Account) = repository.save(account) fun save(account: Account) = repository.save(account)
} }
\ No newline at end of file
...@@ -15,7 +15,12 @@ class SharedPreferencesAccountsRepository( ...@@ -15,7 +15,12 @@ class SharedPreferencesAccountsRepository(
) : AccountsRepository { ) : AccountsRepository {
override fun save(account: Account) { override fun save(account: Account) {
save(load().filter { item -> item.serverUrl != item.serverUrl }.toMutableList().apply { add(0, account) }) load().filter { it.serverUrl != account.serverUrl }
.toMutableList()
.apply {
add(0, account)
save(this)
}
} }
override fun load(): List<Account> { override fun load(): List<Account> {
...@@ -23,7 +28,7 @@ class SharedPreferencesAccountsRepository( ...@@ -23,7 +28,7 @@ class SharedPreferencesAccountsRepository(
val type = Types.newParameterizedType(List::class.java, Account::class.java) val type = Types.newParameterizedType(List::class.java, Account::class.java)
val adapter = moshi.adapter<List<Account>>(type) val adapter = moshi.adapter<List<Account>>(type)
return json?.let { adapter.fromJson(it) ?: emptyList() } ?: emptyList() return json?.let { adapter.fromJson(it) } ?: emptyList()
} }
override fun remove(serverUrl: String) { override fun remove(serverUrl: String) {
...@@ -33,8 +38,6 @@ class SharedPreferencesAccountsRepository( ...@@ -33,8 +38,6 @@ class SharedPreferencesAccountsRepository(
private fun save(accounts: List<Account>) { private fun save(accounts: List<Account>) {
val type = Types.newParameterizedType(List::class.java, Account::class.java) val type = Types.newParameterizedType(List::class.java, Account::class.java)
val adapter = moshi.adapter<List<Account>>(type) val adapter = moshi.adapter<List<Account>>(type)
preferences.edit { preferences.edit { putString(ACCOUNTS_KEY, adapter.toJson(accounts)) }
putString(ACCOUNTS_KEY, adapter.toJson(accounts))
}
} }
} }
\ No newline at end of file
...@@ -3,27 +3,27 @@ ...@@ -3,27 +3,27 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:background="?selectableItemBackground"
android:background="?selectableItemBackground"> android:padding="16dp">
<ImageView <ImageView
android:id="@+id/server_logo" android:id="@+id/server_logo"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:src="@drawable/ic_add_24dp" android:src="@drawable/ic_add_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintBottom_toBottomOf="parent" />
<TextView <TextView
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:text="@string/action_add_account" android:text="@string/action_add_account"
app:layout_constraintTop_toTopOf="parent" android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/server_logo" app:layout_constraintStart_toEndOf="@id/server_logo"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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