mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
implement reply draft
This commit is contained in:
parent
2c086f76e2
commit
cdd620987b
@ -112,6 +112,7 @@ private object PrefKeys {
|
||||
const val AUTOMATICALLY_SHOW_PROFILE_PICTURE = "automatically_show_profile_picture"
|
||||
const val SIGNER_PACKAGE_NAME = "signer_package_name"
|
||||
const val NEW_POST_DRAFT = "draft_new_post"
|
||||
const val DRAFT_REPLY_POST = "draft_reply_post"
|
||||
|
||||
const val ALL_ACCOUNT_INFO = "all_saved_accounts_info"
|
||||
const val SHARED_SETTINGS = "shared_settings"
|
||||
@ -461,15 +462,22 @@ object LocalPreferences {
|
||||
|
||||
fun saveDraft(
|
||||
message: String,
|
||||
replyPost: String?,
|
||||
account: Account,
|
||||
) {
|
||||
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||
with(prefs.edit()) {
|
||||
putString(PrefKeys.NEW_POST_DRAFT, message)
|
||||
putString(PrefKeys.DRAFT_REPLY_POST, replyPost)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun loadReplyDraft(account: Account): String? {
|
||||
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||
return prefs.getString(PrefKeys.DRAFT_REPLY_POST, null)
|
||||
}
|
||||
|
||||
fun loadDraft(account: Account): String? {
|
||||
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||
return prefs.getString(PrefKeys.NEW_POST_DRAFT, null)
|
||||
@ -478,6 +486,7 @@ object LocalPreferences {
|
||||
fun clearDraft(account: Account) {
|
||||
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||
with(prefs.edit()) {
|
||||
remove(PrefKeys.DRAFT_REPLY_POST)
|
||||
remove(PrefKeys.NEW_POST_DRAFT)
|
||||
apply()
|
||||
}
|
||||
|
@ -130,7 +130,9 @@ import com.fonfon.kgeohash.toGeoHash
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
import com.vitorpamplona.amethyst.LocalPreferences
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
||||
@ -207,9 +209,19 @@ fun NewPostView(
|
||||
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
postViewModel.load(accountViewModel, baseReplyTo, quote)
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val replyDraft = LocalPreferences.loadReplyDraft(accountViewModel.account)
|
||||
if (replyDraft.isNullOrBlank()) {
|
||||
postViewModel.load(accountViewModel, baseReplyTo, quote)
|
||||
} else {
|
||||
val note = LocalCache.checkGetOrCreateNote(replyDraft)
|
||||
if (note == null) {
|
||||
postViewModel.load(accountViewModel, baseReplyTo, quote)
|
||||
} else {
|
||||
postViewModel.load(accountViewModel, note, quote)
|
||||
}
|
||||
}
|
||||
|
||||
postViewModel.imageUploadingError.collect { error ->
|
||||
withContext(Dispatchers.Main) { Toast.makeText(context, error, Toast.LENGTH_SHORT).show() }
|
||||
}
|
||||
|
@ -515,6 +515,7 @@ open class NewPostViewModel() : ViewModel() {
|
||||
urlPreview = null
|
||||
isUploadingImage = false
|
||||
pTags = null
|
||||
eTags = null
|
||||
|
||||
wantsDirectMessage = false
|
||||
|
||||
@ -543,6 +544,7 @@ open class NewPostViewModel() : ViewModel() {
|
||||
userSuggestions = emptyList()
|
||||
userSuggestionAnchor = null
|
||||
userSuggestionsMainMessage = null
|
||||
originalNote = null
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
clearDraft()
|
||||
@ -564,7 +566,7 @@ open class NewPostViewModel() : ViewModel() {
|
||||
}
|
||||
|
||||
open fun saveDraft(message: String) {
|
||||
account?.let { LocalPreferences.saveDraft(message, it) }
|
||||
account?.let { LocalPreferences.saveDraft(message, originalNote?.idHex, it) }
|
||||
}
|
||||
|
||||
open fun loadDraft(): String? {
|
||||
|
@ -638,7 +638,7 @@ fun ListContent(
|
||||
},
|
||||
{
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
LocalPreferences.saveDraft(it, accountViewModel.account)
|
||||
LocalPreferences.saveDraft(it, null, accountViewModel.account)
|
||||
draftText = null
|
||||
showDraft = false
|
||||
wantsToPost = true
|
||||
|
Loading…
Reference in New Issue
Block a user