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

View File

@ -564,7 +564,12 @@ fun SearchButton(onPost: () -> Unit = {}, isActive: Boolean, modifier: Modifier
} }
enum class ServersAvailable { enum class ServersAvailable {
IMGUR, NOSTR_BUILD, NOSTR_IMG, NIP95 IMGUR,
NOSTR_BUILD,
NOSTRIMG,
IMGUR_NIP_94,
NOSTRIMG_NIP_94,
NIP95
} }
@Composable @Composable
@ -582,12 +587,15 @@ fun ImageVideoDescription(
val isVideo = mediaType.startsWith("video") val isVideo = mediaType.startsWith("video")
val fileServers = listOf( val fileServers = listOf(
Pair(ServersAvailable.IMGUR, "imgur.com"), Triple(ServersAvailable.IMGUR, "imgur.com", "Uploads to ImgUR. ImgUR can change your image at any time"),
Pair(ServersAvailable.NOSTR_IMG, "nostrimg.com"), Triple(ServersAvailable.NOSTRIMG, "nostrimg.com", "Regular NostrImg. NostrImg can change your image at any time"),
Pair(ServersAvailable.NIP95, "your relays (NIP-95)") 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 fileServerOptions = fileServers.map { it.second }
val fileServerExplainers = fileServers.map { it.third }
var selectedServer by remember { mutableStateOf(defaultServer) } var selectedServer by remember { mutableStateOf(defaultServer) }
var message by remember { mutableStateOf("") } var message by remember { mutableStateOf("") }
@ -697,6 +705,7 @@ fun ImageVideoDescription(
label = stringResource(id = R.string.file_server), label = stringResource(id = R.string.file_server),
placeholder = fileServers.filter { it.first == defaultServer }.firstOrNull()?.second ?: fileServers[0].second, placeholder = fileServers.filter { it.first == defaultServer }.firstOrNull()?.second ?: fileServers[0].second,
options = fileServerOptions, options = fileServerOptions,
explainers = fileServerExplainers,
onSelect = { onSelect = {
selectedServer = fileServers[it].first selectedServer = fileServers[it].first
}, },
@ -705,25 +714,32 @@ fun ImageVideoDescription(
) )
} }
Row( if (selectedServer == ServersAvailable.NOSTRIMG_NIP_94 ||
verticalAlignment = Alignment.CenterVertically, selectedServer == ServersAvailable.IMGUR_NIP_94 ||
modifier = Modifier.fillMaxWidth().windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)) selectedServer == ServersAvailable.NIP95
) { ) {
OutlinedTextField( Row(
label = { Text(text = stringResource(R.string.content_description)) }, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)), modifier = Modifier.fillMaxWidth()
value = message, .windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp))
onValueChange = { message = it }, ) {
placeholder = { OutlinedTextField(
Text( label = { Text(text = stringResource(R.string.content_description)) },
text = stringResource(R.string.content_description_example), modifier = Modifier.fillMaxWidth()
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) .windowInsetsPadding(WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)),
value = message,
onValueChange = { message = it },
placeholder = {
Text(
text = stringResource(R.string.content_description_example),
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
)
},
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Sentences
) )
},
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Sentences
) )
) }
} }
Button( Button(

View File

@ -147,7 +147,13 @@ open class NewPostViewModel : ViewModel() {
server = server, server = server,
contentResolver = contentResolver, contentResolver = contentResolver,
onSuccess = { imageUrl, mimeType -> onSuccess = { imageUrl, mimeType ->
createNIP94Record(imageUrl, mimeType, description) 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 = { onError = {
isUploadingImage = false isUploadingImage = false