mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 14:08:47 +01:00
enhancement: improve login use case (#930)
This commit is contained in:
parent
5cb0c28352
commit
541cf7255d
@ -55,12 +55,12 @@ internal class DefaultLoginUseCase(
|
||||
instance = instance,
|
||||
jwt = auth,
|
||||
)
|
||||
val existingId = accountRepository.getBy(username, instance)?.id
|
||||
val id =
|
||||
existingId ?: run {
|
||||
val existing = accountRepository.getBy(username, instance)
|
||||
val accountId =
|
||||
if (existing == null) {
|
||||
// new account with a copy of the anonymous settings
|
||||
// (except a couple of fields from the Lemmy accounts)
|
||||
val res = accountRepository.createAccount(account)
|
||||
val newAccountId = accountRepository.createAccount(account)
|
||||
val anonymousSettings =
|
||||
settingsRepository.getSettings(null)
|
||||
.copy(
|
||||
@ -69,20 +69,22 @@ internal class DefaultLoginUseCase(
|
||||
)
|
||||
settingsRepository.createSettings(
|
||||
settings = anonymousSettings,
|
||||
accountId = res,
|
||||
accountId = newAccountId,
|
||||
)
|
||||
res
|
||||
newAccountId
|
||||
} else {
|
||||
existing.id ?: 0
|
||||
}
|
||||
val oldActiveAccountId = accountRepository.getActive()?.id
|
||||
if (oldActiveAccountId != null) {
|
||||
accountRepository.setActive(oldActiveAccountId, false)
|
||||
}
|
||||
accountRepository.setActive(id, true)
|
||||
accountRepository.setActive(accountId, true)
|
||||
|
||||
communitySortRepository.clear()
|
||||
communityPreferredLanguageRepository.clear()
|
||||
|
||||
val newSettings = settingsRepository.getSettings(id)
|
||||
val newSettings = settingsRepository.getSettings(accountId)
|
||||
settingsRepository.changeCurrentSettings(newSettings)
|
||||
}
|
||||
}
|
||||
|
@ -753,7 +753,8 @@ class PostDetailScreen(
|
||||
.fillMaxSize(),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
modifier =
|
||||
Modifier
|
||||
.then(
|
||||
if (uiState.enableButtonsToScrollBetweenComments) {
|
||||
Modifier.nestedScroll(buttonBarScrollConnection)
|
||||
@ -1319,13 +1320,13 @@ class PostDetailScreen(
|
||||
OptionId.PurgeCreator,
|
||||
buildString {
|
||||
append(
|
||||
LocalXmlStrings.current.adminActionPurge
|
||||
LocalXmlStrings.current.adminActionPurge,
|
||||
)
|
||||
append(" ")
|
||||
append(
|
||||
creator.readableName(
|
||||
uiState.preferNicknames
|
||||
)
|
||||
uiState.preferNicknames,
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
@ -1344,7 +1345,8 @@ class PostDetailScreen(
|
||||
OptionId.Edit -> {
|
||||
detailOpener.openReply(
|
||||
originalPost = PostModel(id = comment.postId),
|
||||
originalComment = comment.parentId?.let {
|
||||
originalComment =
|
||||
comment.parentId?.let {
|
||||
CommentModel(id = it)
|
||||
},
|
||||
editedComment = comment,
|
||||
@ -1358,7 +1360,7 @@ class PostDetailScreen(
|
||||
contentId = comment.id,
|
||||
)
|
||||
navigationCoordinator.pushScreen(
|
||||
screen
|
||||
screen,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1380,7 +1382,7 @@ class PostDetailScreen(
|
||||
contentId = comment.id,
|
||||
)
|
||||
navigationCoordinator.pushScreen(
|
||||
screen
|
||||
screen,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1418,7 +1420,7 @@ class PostDetailScreen(
|
||||
contentId = comment.id,
|
||||
)
|
||||
navigationCoordinator.pushScreen(
|
||||
screen
|
||||
screen,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1430,7 +1432,7 @@ class PostDetailScreen(
|
||||
contentId = userId,
|
||||
)
|
||||
navigationCoordinator.pushScreen(
|
||||
screen
|
||||
screen,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1588,7 +1590,8 @@ class PostDetailScreen(
|
||||
OptionId.Edit -> {
|
||||
detailOpener.openReply(
|
||||
originalPost = PostModel(id = comment.postId),
|
||||
originalComment = comment.parentId?.let {
|
||||
originalComment =
|
||||
comment.parentId?.let {
|
||||
CommentModel(id = it)
|
||||
},
|
||||
editedComment = comment,
|
||||
@ -1728,7 +1731,8 @@ class PostDetailScreen(
|
||||
)
|
||||
} else if (uiState.searching) {
|
||||
Text(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.padding(top = Spacing.xs),
|
||||
textAlign = TextAlign.Center,
|
||||
text = LocalXmlStrings.current.messageEmptyList,
|
||||
|
@ -84,7 +84,8 @@ class PostDetailViewModel(
|
||||
}
|
||||
if (uiState.value.post.id == 0L) {
|
||||
val post = itemCache.getPost(postId) ?: PostModel()
|
||||
val downVoteEnabled = siteRepository.isDownVoteEnabled(identityRepository.authToken.value)
|
||||
val downVoteEnabled =
|
||||
siteRepository.isDownVoteEnabled(identityRepository.authToken.value)
|
||||
updateState {
|
||||
it.copy(
|
||||
post = post,
|
||||
|
Loading…
x
Reference in New Issue
Block a user