Fixes tagging issue on new post.
This commit is contained in:
@@ -239,17 +239,27 @@ open class NewPostViewModel :
|
||||
|
||||
fun user(): User? = account?.userProfile()
|
||||
|
||||
open fun init(accountVM: AccountViewModel) {
|
||||
this.accountViewModel = accountVM
|
||||
this.account = accountVM.account
|
||||
this.canAddInvoice = hasLnAddress()
|
||||
this.canAddZapRaiser = hasLnAddress()
|
||||
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
}
|
||||
|
||||
open fun load(
|
||||
accountViewModel: AccountViewModel,
|
||||
replyingTo: Note?,
|
||||
quote: Note?,
|
||||
fork: Note?,
|
||||
version: Note?,
|
||||
draft: Note?,
|
||||
) {
|
||||
this.accountViewModel = accountViewModel
|
||||
this.account = accountViewModel.account
|
||||
|
||||
val accountViewModel = accountViewModel ?: return
|
||||
val noteEvent = draft?.event
|
||||
val noteAuthor = draft?.author
|
||||
|
||||
|
||||
+2
-2
@@ -159,7 +159,7 @@ fun NewPostScreen(
|
||||
nav: Nav,
|
||||
) {
|
||||
val postViewModel: NewPostViewModel = viewModel()
|
||||
postViewModel.account = accountViewModel.account
|
||||
postViewModel.init(accountViewModel)
|
||||
postViewModel.wantsToAddGeoHash = enableGeolocation
|
||||
|
||||
val context = LocalContext.current
|
||||
@@ -183,7 +183,7 @@ fun NewPostScreen(
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
postViewModel.load(accountViewModel, baseReplyTo, quote, fork, version, draft)
|
||||
postViewModel.load(baseReplyTo, quote, fork, version, draft)
|
||||
message?.ifBlank { null }?.let {
|
||||
postViewModel.updateMessage(TextFieldValue(it))
|
||||
}
|
||||
|
||||
+3
@@ -162,6 +162,9 @@ open class ChannelNewMessageViewModel :
|
||||
this.userSuggestions?.reset()
|
||||
this.userSuggestions = UserSuggestionState(accountVM)
|
||||
|
||||
this.emojiSuggestions?.reset()
|
||||
this.emojiSuggestions = EmojiSuggestionState(accountVM)
|
||||
|
||||
this.uploadState =
|
||||
ChatFileUploadState(
|
||||
account?.settings?.defaultFileServer ?: DEFAULT_MEDIA_SERVERS[0],
|
||||
|
||||
+9
-5
@@ -36,6 +36,7 @@ import io.mockk.mockkObject
|
||||
import io.mockk.unmockkAll
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@@ -75,9 +76,12 @@ class NewPostViewModelTest {
|
||||
every { replyingTo.event } returns textNoteEvent
|
||||
|
||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
||||
every { accountViewModel.account.userProfile() } returns mockk<User>(relaxed = true)
|
||||
every { accountViewModel.account.myEmojis } returns mockk<StateFlow<List<Account.EmojiMedia>>>(relaxed = true)
|
||||
|
||||
// Act: Call load with mentions
|
||||
newPostViewModelUnderTest.load(accountViewModel, replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
newPostViewModelUnderTest.init(accountViewModel)
|
||||
newPostViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
|
||||
// Assert
|
||||
// Two mentions should call LocalCache.getOrCreateUser twice
|
||||
@@ -87,9 +91,9 @@ class NewPostViewModelTest {
|
||||
@Test
|
||||
fun `test load with zero mentions`() =
|
||||
runTest {
|
||||
// Arrange: Setup Note with zero mentions
|
||||
every { accountViewModel.account } returns mockk<Account>()
|
||||
|
||||
// Arrange: Setup Note with zero mentions
|
||||
val textNoteEvent = mockk<TextNoteEvent>(relaxed = true)
|
||||
every { textNoteEvent.mentions() } returns emptyList()
|
||||
every { replyingTo.event } returns textNoteEvent
|
||||
@@ -97,7 +101,7 @@ class NewPostViewModelTest {
|
||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
||||
|
||||
// Act: Call load with empty mentions
|
||||
newPostViewModelUnderTest.load(accountViewModel, replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
newPostViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
|
||||
// Assert
|
||||
// With no mentions LocalCache.getOrCreateUser should not be called
|
||||
@@ -107,9 +111,9 @@ class NewPostViewModelTest {
|
||||
@Test
|
||||
fun `test load with empty mentions`() =
|
||||
runTest {
|
||||
// Arrange: Setup empty mentions
|
||||
every { accountViewModel.account } returns mockk<Account>()
|
||||
|
||||
// Arrange: Setup empty mentions
|
||||
val textNoteEvent = mockk<TextNoteEvent>(relaxed = true)
|
||||
every { textNoteEvent.mentions() } returns emptyList()
|
||||
every { replyingTo.event } returns textNoteEvent
|
||||
@@ -117,7 +121,7 @@ class NewPostViewModelTest {
|
||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
||||
|
||||
// Act: Call load with empty mentions
|
||||
newPostViewModelUnderTest.load(accountViewModel, replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
newPostViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
||||
|
||||
// Assert
|
||||
// Verify LocalCache.getOrCreateUser(it) is not called with empty hex, it will crash the app
|
||||
|
||||
Reference in New Issue
Block a user