implement reply draft

pull/749/head
greenart7c3 2024-01-24 09:55:31 -03:00
rodzic 2c086f76e2
commit cdd620987b
4 zmienionych plików z 27 dodań i 4 usunięć

Wyświetl plik

@ -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()
}

Wyświetl plik

@ -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() }
}

Wyświetl plik

@ -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? {

Wyświetl plik

@ -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