mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 13:21:50 +01:00
Fixes loading iMeta from drafts and reset them after use
This commit is contained in:
parent
64f7401b46
commit
350e2a5a90
@ -301,6 +301,8 @@ open class ChatNewMessageViewModel : ViewModel() {
|
||||
TextFieldValue(draftEvent.content)
|
||||
}
|
||||
|
||||
iMetaAttachments.addAll(draftEvent.imetas())
|
||||
|
||||
requiresNIP17 = draftEvent is NIP17Group
|
||||
nip17 = draftEvent is NIP17Group
|
||||
|
||||
@ -348,9 +350,15 @@ open class ChatNewMessageViewModel : ViewModel() {
|
||||
val uploadState = uploadState ?: return
|
||||
|
||||
if (nip17) {
|
||||
ChatFileUploader(room, account).uploadNIP17(uploadState, viewModelScope, onError, context, onceUploaded)
|
||||
ChatFileUploader(room, account).uploadNIP17(uploadState, viewModelScope, onError, context) {
|
||||
saveDraft()
|
||||
onceUploaded()
|
||||
}
|
||||
} else {
|
||||
ChatFileUploader(room, account).uploadNIP04(uploadState, viewModelScope, onError, context, onceUploaded)
|
||||
ChatFileUploader(room, account).uploadNIP04(uploadState, viewModelScope, onError, context) {
|
||||
saveDraft()
|
||||
onceUploaded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,6 +441,8 @@ open class ChatNewMessageViewModel : ViewModel() {
|
||||
userSuggestions.reset()
|
||||
userSuggestionsMainMessage = null
|
||||
|
||||
iMetaAttachments.reset()
|
||||
|
||||
if (emojiSearch.value.isNotEmpty()) {
|
||||
emojiSearch.tryEmit("")
|
||||
}
|
||||
|
@ -67,6 +67,10 @@ class IMetaAttachments {
|
||||
}
|
||||
}
|
||||
|
||||
fun addAll(imetas: List<IMetaTag>) {
|
||||
iMetaAttachments = iMetaAttachments + imetas
|
||||
}
|
||||
|
||||
fun remove(url: String) {
|
||||
iMetaAttachments = iMetaAttachments.filter { it.url != url }
|
||||
}
|
||||
@ -101,4 +105,8 @@ class IMetaAttachments {
|
||||
}
|
||||
|
||||
fun filterIsIn(urls: Set<String>) = iMetaAttachments.filter { it.url in urls }
|
||||
|
||||
fun reset() {
|
||||
iMetaAttachments = emptyList()
|
||||
}
|
||||
}
|
||||
|
@ -262,6 +262,8 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
||||
|
||||
message = TextFieldValue(draftEvent.content)
|
||||
|
||||
iMetaAttachments.addAll(draftEvent.imetas())
|
||||
|
||||
urlPreview = findUrlInMessage()
|
||||
}
|
||||
|
||||
@ -351,6 +353,7 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
||||
|
||||
uploadState.reset()
|
||||
onceUploaded()
|
||||
saveDraft()
|
||||
} else {
|
||||
val errorMessages = results.errors.map { stringRes(context, it.errorResource, *it.params) }.distinct()
|
||||
|
||||
@ -496,6 +499,8 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
||||
userSuggestions.reset()
|
||||
userSuggestionsMainMessage = null
|
||||
|
||||
iMetaAttachments.reset()
|
||||
|
||||
if (emojiSearch.value.isNotEmpty()) {
|
||||
emojiSearch.tryEmit("")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user