Fixes loading iMeta from drafts and reset them after use
This commit is contained in:
+12
-2
@@ -301,6 +301,8 @@ open class ChatNewMessageViewModel : ViewModel() {
|
|||||||
TextFieldValue(draftEvent.content)
|
TextFieldValue(draftEvent.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iMetaAttachments.addAll(draftEvent.imetas())
|
||||||
|
|
||||||
requiresNIP17 = draftEvent is NIP17Group
|
requiresNIP17 = draftEvent is NIP17Group
|
||||||
nip17 = draftEvent is NIP17Group
|
nip17 = draftEvent is NIP17Group
|
||||||
|
|
||||||
@@ -348,9 +350,15 @@ open class ChatNewMessageViewModel : ViewModel() {
|
|||||||
val uploadState = uploadState ?: return
|
val uploadState = uploadState ?: return
|
||||||
|
|
||||||
if (nip17) {
|
if (nip17) {
|
||||||
ChatFileUploader(room, account).uploadNIP17(uploadState, viewModelScope, onError, context, onceUploaded)
|
ChatFileUploader(room, account).uploadNIP17(uploadState, viewModelScope, onError, context) {
|
||||||
|
saveDraft()
|
||||||
|
onceUploaded()
|
||||||
|
}
|
||||||
} else {
|
} 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()
|
userSuggestions.reset()
|
||||||
userSuggestionsMainMessage = null
|
userSuggestionsMainMessage = null
|
||||||
|
|
||||||
|
iMetaAttachments.reset()
|
||||||
|
|
||||||
if (emojiSearch.value.isNotEmpty()) {
|
if (emojiSearch.value.isNotEmpty()) {
|
||||||
emojiSearch.tryEmit("")
|
emojiSearch.tryEmit("")
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -67,6 +67,10 @@ class IMetaAttachments {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addAll(imetas: List<IMetaTag>) {
|
||||||
|
iMetaAttachments = iMetaAttachments + imetas
|
||||||
|
}
|
||||||
|
|
||||||
fun remove(url: String) {
|
fun remove(url: String) {
|
||||||
iMetaAttachments = iMetaAttachments.filter { it.url != url }
|
iMetaAttachments = iMetaAttachments.filter { it.url != url }
|
||||||
}
|
}
|
||||||
@@ -101,4 +105,8 @@ class IMetaAttachments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun filterIsIn(urls: Set<String>) = iMetaAttachments.filter { it.url in urls }
|
fun filterIsIn(urls: Set<String>) = iMetaAttachments.filter { it.url in urls }
|
||||||
|
|
||||||
|
fun reset() {
|
||||||
|
iMetaAttachments = emptyList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -262,6 +262,8 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
|||||||
|
|
||||||
message = TextFieldValue(draftEvent.content)
|
message = TextFieldValue(draftEvent.content)
|
||||||
|
|
||||||
|
iMetaAttachments.addAll(draftEvent.imetas())
|
||||||
|
|
||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +353,7 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
|||||||
|
|
||||||
uploadState.reset()
|
uploadState.reset()
|
||||||
onceUploaded()
|
onceUploaded()
|
||||||
|
saveDraft()
|
||||||
} else {
|
} else {
|
||||||
val errorMessages = results.errors.map { stringRes(context, it.errorResource, *it.params) }.distinct()
|
val errorMessages = results.errors.map { stringRes(context, it.errorResource, *it.params) }.distinct()
|
||||||
|
|
||||||
@@ -496,6 +499,8 @@ open class ChannelNewMessageViewModel : ViewModel() {
|
|||||||
userSuggestions.reset()
|
userSuggestions.reset()
|
||||||
userSuggestionsMainMessage = null
|
userSuggestionsMainMessage = null
|
||||||
|
|
||||||
|
iMetaAttachments.reset()
|
||||||
|
|
||||||
if (emojiSearch.value.isNotEmpty()) {
|
if (emojiSearch.value.isNotEmpty()) {
|
||||||
emojiSearch.tryEmit("")
|
emojiSearch.tryEmit("")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user