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