Enabling non NIP94 uploads for the PlayStore

This commit is contained in:
Vitor Pamplona 2023-04-27 15:01:58 -04:00
parent 2ca877b3c3
commit 285a61e38f
3 changed files with 44 additions and 23 deletions

View File

@ -11,7 +11,6 @@ import okio.BufferedSink
import okio.source
import java.io.IOException
import java.io.InputStream
import java.util.*
val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')
@ -35,7 +34,7 @@ object ImageUploader {
val myServer = if (server == ServersAvailable.IMGUR) {
ImgurServer()
} else if (server == ServersAvailable.NOSTR_IMG) {
} else if (server == ServersAvailable.NOSTRIMG) {
NostrImgServer()
} else {
ImgurServer()

View File

@ -564,7 +564,12 @@ fun SearchButton(onPost: () -> Unit = {}, isActive: Boolean, modifier: Modifier
}
enum class ServersAvailable {
IMGUR, NOSTR_BUILD, NOSTR_IMG, NIP95
IMGUR,
NOSTR_BUILD,
NOSTRIMG,
IMGUR_NIP_94,
NOSTRIMG_NIP_94,
NIP95
}
@Composable
@ -582,12 +587,15 @@ fun ImageVideoDescription(
val isVideo = mediaType.startsWith("video")
val fileServers = listOf(
Pair(ServersAvailable.IMGUR, "imgur.com"),
Pair(ServersAvailable.NOSTR_IMG, "nostrimg.com"),
Pair(ServersAvailable.NIP95, "your relays (NIP-95)")
Triple(ServersAvailable.IMGUR, "imgur.com", "Uploads to ImgUR. ImgUR can change your image at any time"),
Triple(ServersAvailable.NOSTRIMG, "nostrimg.com", "Regular NostrImg. NostrImg can change your image at any time"),
Triple(ServersAvailable.IMGUR_NIP_94, "Verifiable ImgUr (NIP-94)", "Protects from ImgUr changing your image after you post"),
Triple(ServersAvailable.NOSTRIMG_NIP_94, "Verifiable NostrIMG (NIP-94)", "Protects from NostrIMG changing your image after you post"),
Triple(ServersAvailable.NIP95, "Your relays (NIP-95)", "The image is hosted in the relay itself. Your image will be free from a domain name / third-party control")
)
val fileServerOptions = fileServers.map { it.second }
val fileServerExplainers = fileServers.map { it.third }
var selectedServer by remember { mutableStateOf(defaultServer) }
var message by remember { mutableStateOf("") }
@ -697,6 +705,7 @@ fun ImageVideoDescription(
label = stringResource(id = R.string.file_server),
placeholder = fileServers.filter { it.first == defaultServer }.firstOrNull()?.second ?: fileServers[0].second,
options = fileServerOptions,
explainers = fileServerExplainers,
onSelect = {
selectedServer = fileServers[it].first
},
@ -705,13 +714,19 @@ fun ImageVideoDescription(
)
}
if (selectedServer == ServersAvailable.NOSTRIMG_NIP_94 ||
selectedServer == ServersAvailable.IMGUR_NIP_94 ||
selectedServer == ServersAvailable.NIP95
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp))
modifier = Modifier.fillMaxWidth()
.windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp))
) {
OutlinedTextField(
label = { Text(text = stringResource(R.string.content_description)) },
modifier = Modifier.fillMaxWidth().windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)),
modifier = Modifier.fillMaxWidth()
.windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)),
value = message,
onValueChange = { message = it },
placeholder = {
@ -725,6 +740,7 @@ fun ImageVideoDescription(
)
)
}
}
Button(
modifier = Modifier

View File

@ -147,7 +147,13 @@ open class NewPostViewModel : ViewModel() {
server = server,
contentResolver = contentResolver,
onSuccess = { imageUrl, mimeType ->
if (server == ServersAvailable.IMGUR_NIP_94 || server == ServersAvailable.NOSTRIMG_NIP_94) {
createNIP94Record(imageUrl, mimeType, description)
} else {
isUploadingImage = false
message = TextFieldValue(message.text + "\n\n" + imageUrl)
urlPreview = findUrlInMessage()
}
},
onError = {
isUploadingImage = false