mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-30 00:40:49 +00:00
created HttpClient class
This commit is contained in:
parent
4f8d33d850
commit
c648f54b51
@ -5,7 +5,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TranslatableRichTextViewer(
|
fun TranslatableRichTextViewer(
|
||||||
@ -15,8 +14,7 @@ fun TranslatableRichTextViewer(
|
|||||||
tags: List<List<String>>?,
|
tags: List<List<String>>?,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
proxy: Proxy?
|
|
||||||
) = ExpandableRichTextViewer(
|
) = ExpandableRichTextViewer(
|
||||||
content,
|
content,
|
||||||
canPreview,
|
canPreview,
|
||||||
@ -24,6 +22,5 @@ fun TranslatableRichTextViewer(
|
|||||||
tags,
|
tags,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
proxy
|
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst
|
|||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrChatroomListDataSource
|
import com.vitorpamplona.amethyst.service.NostrChatroomListDataSource
|
||||||
@ -25,7 +26,7 @@ object ServiceManager {
|
|||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
val myAccount = account
|
val myAccount = account
|
||||||
|
HttpClient.start(account)
|
||||||
if (myAccount != null) {
|
if (myAccount != null) {
|
||||||
Client.connect(myAccount.activeRelays() ?: myAccount.convertLocalRelays())
|
Client.connect(myAccount.activeRelays() ?: myAccount.convertLocalRelays())
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import java.net.Proxy
|
||||||
|
|
||||||
|
object HttpClient {
|
||||||
|
private var proxy: Proxy? = null
|
||||||
|
|
||||||
|
fun start(account: Account?) {
|
||||||
|
this.proxy = account?.proxy
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getHttpClient(): OkHttpClient {
|
||||||
|
return OkHttpClient.Builder().proxy(proxy).build()
|
||||||
|
}
|
||||||
|
}
|
@ -9,13 +9,11 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
import okhttp3.Callback
|
import okhttp3.Callback
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
class Nip05Verifier(proxy: Proxy?) {
|
class Nip05Verifier() {
|
||||||
val client = OkHttpClient.Builder().proxy(proxy).build()
|
val client = HttpClient.getHttpClient()
|
||||||
|
|
||||||
fun assembleUrl(nip05address: String): String? {
|
fun assembleUrl(nip05address: String): String? {
|
||||||
val parts = nip05address.trim().split("@")
|
val parts = nip05address.trim().split("@")
|
||||||
|
@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.service.lnurl
|
|||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -10,15 +11,13 @@ import kotlinx.coroutines.withContext
|
|||||||
import nostr.postr.Bech32
|
import nostr.postr.Bech32
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
import okhttp3.Callback
|
import okhttp3.Callback
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.net.Proxy
|
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
class LightningAddressResolver(proxy: Proxy?) {
|
class LightningAddressResolver() {
|
||||||
val client = OkHttpClient.Builder().proxy(proxy).build()
|
val client = HttpClient.getHttpClient()
|
||||||
|
|
||||||
fun assembleUrl(lnaddress: String): String? {
|
fun assembleUrl(lnaddress: String): String? {
|
||||||
val parts = lnaddress.split("@")
|
val parts = lnaddress.split("@")
|
||||||
|
@ -9,12 +9,12 @@ import android.os.Environment
|
|||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import okio.BufferedSource
|
import okio.BufferedSource
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
import okio.sink
|
import okio.sink
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
object ImageSaver {
|
object ImageSaver {
|
||||||
/**
|
/**
|
||||||
@ -27,10 +27,9 @@ object ImageSaver {
|
|||||||
url: String,
|
url: String,
|
||||||
context: Context,
|
context: Context,
|
||||||
onSuccess: () -> Any?,
|
onSuccess: () -> Any?,
|
||||||
onError: (Throwable) -> Any?,
|
onError: (Throwable) -> Any?
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
val client = OkHttpClient.Builder().proxy(proxy).build()
|
val client = HttpClient.getHttpClient()
|
||||||
|
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
|
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
|
||||||
|
@ -4,12 +4,12 @@ import android.content.ContentResolver
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okio.BufferedSink
|
import okio.BufferedSink
|
||||||
import okio.source
|
import okio.source
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.Proxy
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object ImageUploader {
|
object ImageUploader {
|
||||||
@ -17,15 +17,14 @@ object ImageUploader {
|
|||||||
uri: Uri,
|
uri: Uri,
|
||||||
contentResolver: ContentResolver,
|
contentResolver: ContentResolver,
|
||||||
onSuccess: (String) -> Unit,
|
onSuccess: (String) -> Unit,
|
||||||
onError: (Throwable) -> Unit,
|
onError: (Throwable) -> Unit
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
val contentType = contentResolver.getType(uri)
|
val contentType = contentResolver.getType(uri)
|
||||||
val category = contentType?.toMediaType()?.toString()?.split("/")?.get(0) ?: "image"
|
val category = contentType?.toMediaType()?.toString()?.split("/")?.get(0) ?: "image"
|
||||||
|
|
||||||
val url = if (category == "image") "https://api.imgur.com/3/image" else "https://api.imgur.com/3/upload"
|
val url = if (category == "image") "https://api.imgur.com/3/image" else "https://api.imgur.com/3/upload"
|
||||||
|
|
||||||
val client = OkHttpClient.Builder().proxy(proxy).build()
|
val client = HttpClient.getHttpClient()
|
||||||
|
|
||||||
val requestBody: RequestBody = MultipartBody.Builder()
|
val requestBody: RequestBody = MultipartBody.Builder()
|
||||||
.setType(MultipartBody.FORM)
|
.setType(MultipartBody.FORM)
|
||||||
|
@ -124,8 +124,7 @@ open class NewPostViewModel : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
imageUploadingError.emit("Failed to upload the image / video")
|
imageUploadingError.emit("Failed to upload the image / video")
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
account!!.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,7 @@ class NewUserMetadataViewModel : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
imageUploadingError.emit("Failed to upload the image / video")
|
imageUploadingError.emit("Failed to upload the image / video")
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import com.google.accompanist.permissions.isGranted
|
|||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A button to save the remote image to the gallery.
|
* A button to save the remote image to the gallery.
|
||||||
@ -28,7 +27,7 @@ import java.net.Proxy
|
|||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalPermissionsApi::class)
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SaveToGallery(url: String, proxy: Proxy?) {
|
fun SaveToGallery(url: String) {
|
||||||
val localContext = LocalContext.current
|
val localContext = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
@ -55,8 +54,7 @@ fun SaveToGallery(url: String, proxy: Proxy?) {
|
|||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
proxy = proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
const val SHORT_TEXT_LENGTH = 350
|
const val SHORT_TEXT_LENGTH = 350
|
||||||
|
|
||||||
@ -39,8 +38,7 @@ fun ExpandableRichTextViewer(
|
|||||||
tags: List<List<String>>?,
|
tags: List<List<String>>?,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
var showFullText by remember { mutableStateOf(false) }
|
var showFullText by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@ -64,8 +62,7 @@ fun ExpandableRichTextViewer(
|
|||||||
tags,
|
tags,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
proxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (content.length > whereToCut && !showFullText) {
|
if (content.length > whereToCut && !showFullText) {
|
||||||
|
@ -138,7 +138,7 @@ fun InvoiceRequest(
|
|||||||
onClick = {
|
onClick = {
|
||||||
val zapRequest = account.createZapRequestFor(toUserPubKeyHex, message, LnZapEvent.ZapType.PUBLIC)
|
val zapRequest = account.createZapRequestFor(toUserPubKeyHex, message, LnZapEvent.ZapType.PUBLIC)
|
||||||
|
|
||||||
LightningAddressResolver(account.proxy).lnAddressInvoice(
|
LightningAddressResolver().lnAddressInvoice(
|
||||||
lud16,
|
lud16,
|
||||||
amount * 1000,
|
amount * 1000,
|
||||||
message,
|
message,
|
||||||
|
@ -43,7 +43,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.net.MalformedURLException
|
import java.net.MalformedURLException
|
||||||
import java.net.Proxy
|
|
||||||
import java.net.URISyntaxException
|
import java.net.URISyntaxException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
@ -81,8 +80,7 @@ fun RichTextViewer(
|
|||||||
tags: List<List<String>>?,
|
tags: List<List<String>>?,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
if (content.startsWith("# ") ||
|
if (content.startsWith("# ") ||
|
||||||
@ -161,9 +159,9 @@ fun RichTextViewer(
|
|||||||
if (isValidURL(word)) {
|
if (isValidURL(word)) {
|
||||||
val removedParamsFromUrl = word.split("?")[0].lowercase()
|
val removedParamsFromUrl = word.split("?")[0].lowercase()
|
||||||
if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
ZoomableImageView(word, imagesForPager, proxy)
|
ZoomableImageView(word, imagesForPager)
|
||||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
ZoomableImageView(word, imagesForPager, proxy)
|
ZoomableImageView(word, imagesForPager)
|
||||||
} else {
|
} else {
|
||||||
UrlPreview(word, "$word ")
|
UrlPreview(word, "$word ")
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,10 @@ import com.vitorpamplona.amethyst.ui.actions.LoadingAnimation
|
|||||||
import com.vitorpamplona.amethyst.ui.actions.SaveToGallery
|
import com.vitorpamplona.amethyst.ui.actions.SaveToGallery
|
||||||
import net.engawapg.lib.zoomable.rememberZoomState
|
import net.engawapg.lib.zoomable.rememberZoomState
|
||||||
import net.engawapg.lib.zoomable.zoomable
|
import net.engawapg.lib.zoomable.zoomable
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
fun ZoomableImageView(word: String, images: List<String> = listOf(word), proxy: Proxy?) {
|
fun ZoomableImageView(word: String, images: List<String> = listOf(word)) {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = LocalClipboardManager.current
|
||||||
|
|
||||||
// store the dialog open or close state
|
// store the dialog open or close state
|
||||||
@ -127,13 +126,13 @@ fun ZoomableImageView(word: String, images: List<String> = listOf(word), proxy:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dialogOpen) {
|
if (dialogOpen) {
|
||||||
ZoomableImageDialog(word, images, onDismiss = { dialogOpen = false }, proxy)
|
ZoomableImageDialog(word, images, onDismiss = { dialogOpen = false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalPagerApi::class)
|
@OptIn(ExperimentalPagerApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(imageUrl), onDismiss: () -> Unit, proxy: Proxy?) {
|
fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(imageUrl), onDismiss: () -> Unit) {
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false)
|
properties = DialogProperties(usePlatformDefaultWidth = false)
|
||||||
@ -151,7 +150,7 @@ fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(image
|
|||||||
) {
|
) {
|
||||||
CloseButton(onCancel = onDismiss)
|
CloseButton(onCancel = onDismiss)
|
||||||
|
|
||||||
SaveToGallery(url = allImages[pagerState.currentPage], proxy)
|
SaveToGallery(url = allImages[pagerState.currentPage])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allImages.size > 1) {
|
if (allImages.size > 1) {
|
||||||
|
@ -290,8 +290,7 @@ fun ChatroomMessageCompose(
|
|||||||
note.event?.tags(),
|
note.event?.tags(),
|
||||||
backgroundBubbleColor,
|
backgroundBubbleColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
TranslatableRichTextViewer(
|
TranslatableRichTextViewer(
|
||||||
@ -301,8 +300,7 @@ fun ChatroomMessageCompose(
|
|||||||
note.event?.tags(),
|
note.event?.tags(),
|
||||||
backgroundBubbleColor,
|
backgroundBubbleColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,10 @@ import com.vitorpamplona.amethyst.service.Nip05Verifier
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.net.Proxy
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String, proxy: Proxy?): State<Boolean?> {
|
fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Boolean?> {
|
||||||
var nip05Verified = remember { mutableStateOf<Boolean?>(null) }
|
var nip05Verified = remember { mutableStateOf<Boolean?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = user) {
|
LaunchedEffect(key1 = user) {
|
||||||
@ -49,7 +48,7 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String, proxy: Prox
|
|||||||
if ((user.nip05LastVerificationTime ?: 0) > (now - 60 * 60)) { // 1hour
|
if ((user.nip05LastVerificationTime ?: 0) > (now - 60 * 60)) { // 1hour
|
||||||
nip05Verified.value = user.nip05Verified
|
nip05Verified.value = user.nip05Verified
|
||||||
} else {
|
} else {
|
||||||
Nip05Verifier(proxy).verifyNip05(
|
Nip05Verifier().verifyNip05(
|
||||||
nip05,
|
nip05,
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
// Marks user as verified
|
// Marks user as verified
|
||||||
@ -78,18 +77,18 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String, proxy: Prox
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ObserveDisplayNip05Status(baseNote: Note, columnModifier: Modifier = Modifier, proxy: Proxy?) {
|
fun ObserveDisplayNip05Status(baseNote: Note, columnModifier: Modifier = Modifier) {
|
||||||
val noteState by baseNote.live().metadata.observeAsState()
|
val noteState by baseNote.live().metadata.observeAsState()
|
||||||
val note = noteState?.note ?: return
|
val note = noteState?.note ?: return
|
||||||
|
|
||||||
val author = note.author
|
val author = note.author
|
||||||
if (author != null) {
|
if (author != null) {
|
||||||
ObserveDisplayNip05Status(author, columnModifier, proxy)
|
ObserveDisplayNip05Status(author, columnModifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ObserveDisplayNip05Status(baseUser: User, columnModifier: Modifier = Modifier, proxy: Proxy?) {
|
fun ObserveDisplayNip05Status(baseUser: User, columnModifier: Modifier = Modifier) {
|
||||||
val userState by baseUser.live().metadata.observeAsState()
|
val userState by baseUser.live().metadata.observeAsState()
|
||||||
val user = userState?.user ?: return
|
val user = userState?.user ?: return
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ fun ObserveDisplayNip05Status(baseUser: User, columnModifier: Modifier = Modifie
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val nip05Verified by nip05VerificationAsAState(user.info!!, user.pubkeyHex, proxy)
|
val nip05Verified by nip05VerificationAsAState(user.info!!, user.pubkeyHex)
|
||||||
if (nip05Verified == null) {
|
if (nip05Verified == null) {
|
||||||
Icon(
|
Icon(
|
||||||
tint = Color.Yellow,
|
tint = Color.Yellow,
|
||||||
@ -152,12 +151,12 @@ fun ObserveDisplayNip05Status(baseUser: User, columnModifier: Modifier = Modifie
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DisplayNip05ProfileStatus(user: User, proxy: Proxy?) {
|
fun DisplayNip05ProfileStatus(user: User) {
|
||||||
val uri = LocalUriHandler.current
|
val uri = LocalUriHandler.current
|
||||||
|
|
||||||
user.nip05()?.let { nip05 ->
|
user.nip05()?.let { nip05 ->
|
||||||
if (nip05.split("@").size == 2) {
|
if (nip05.split("@").size == 2) {
|
||||||
val nip05Verified by nip05VerificationAsAState(user.info!!, user.pubkeyHex, proxy)
|
val nip05Verified by nip05VerificationAsAState(user.info!!, user.pubkeyHex)
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
if (nip05Verified == null) {
|
if (nip05Verified == null) {
|
||||||
Icon(
|
Icon(
|
||||||
|
@ -353,7 +353,7 @@ fun NoteComposeInner(
|
|||||||
|
|
||||||
if (note.author != null && !makeItShort && !isQuotedNote) {
|
if (note.author != null && !makeItShort && !isQuotedNote) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
ObserveDisplayNip05Status(note.author!!, Modifier.weight(1f), account.proxy)
|
ObserveDisplayNip05Status(note.author!!, Modifier.weight(1f))
|
||||||
|
|
||||||
val baseReward = noteEvent.getReward()
|
val baseReward = noteEvent.getReward()
|
||||||
if (baseReward != null) {
|
if (baseReward != null) {
|
||||||
@ -509,8 +509,7 @@ fun NoteComposeInner(
|
|||||||
noteEvent.tags(),
|
noteEvent.tags(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!makeItShort) {
|
if (!makeItShort) {
|
||||||
@ -540,8 +539,7 @@ fun NoteComposeInner(
|
|||||||
noteEvent.tags(),
|
noteEvent.tags(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DisplayUncitedHashtags(noteEvent.hashtags(), eventContent, navController)
|
DisplayUncitedHashtags(noteEvent.hashtags(), eventContent, navController)
|
||||||
@ -553,8 +551,7 @@ fun NoteComposeInner(
|
|||||||
canPreview = canPreview && !makeItShort,
|
canPreview = canPreview && !makeItShort,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.net.Proxy
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ -47,8 +46,7 @@ fun PollNote(
|
|||||||
canPreview: Boolean,
|
canPreview: Boolean,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
val zapsState by baseNote.live().zaps.observeAsState()
|
val zapsState by baseNote.live().zaps.observeAsState()
|
||||||
val zappedNote = zapsState?.note ?: return
|
val zappedNote = zapsState?.note ?: return
|
||||||
@ -113,8 +111,7 @@ fun PollNote(
|
|||||||
pollViewModel.pollEvent?.tags(),
|
pollViewModel.pollEvent?.tags(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,8 +144,7 @@ fun PollNote(
|
|||||||
pollViewModel.pollEvent?.tags(),
|
pollViewModel.pollEvent?.tags(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ fun NoteMaster(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
ObserveDisplayNip05Status(baseNote, Modifier.weight(1f), account.proxy)
|
ObserveDisplayNip05Status(baseNote, Modifier.weight(1f))
|
||||||
|
|
||||||
val baseReward = noteEvent.getReward()
|
val baseReward = noteEvent.getReward()
|
||||||
if (baseReward != null) {
|
if (baseReward != null) {
|
||||||
@ -362,8 +362,7 @@ fun NoteMaster(
|
|||||||
note.event?.tags(),
|
note.event?.tags(),
|
||||||
MaterialTheme.colors.background,
|
MaterialTheme.colors.background,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DisplayUncitedHashtags(noteEvent.hashtags(), eventContent, navController)
|
DisplayUncitedHashtags(noteEvent.hashtags(), eventContent, navController)
|
||||||
@ -374,8 +373,7 @@ fun NoteMaster(
|
|||||||
canPreview,
|
canPreview,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
account.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class AccountViewModel(private val account: Account) : ViewModel() {
|
|||||||
|
|
||||||
onProgress(0.10f)
|
onProgress(0.10f)
|
||||||
|
|
||||||
LightningAddressResolver(account.proxy).lnAddressInvoice(
|
LightningAddressResolver().lnAddressInvoice(
|
||||||
lud16,
|
lud16,
|
||||||
amount,
|
amount,
|
||||||
message,
|
message,
|
||||||
|
@ -59,7 +59,6 @@ import com.vitorpamplona.amethyst.ui.note.UserPicture
|
|||||||
import com.vitorpamplona.amethyst.ui.note.UsernameDisplay
|
import com.vitorpamplona.amethyst.ui.note.UsernameDisplay
|
||||||
import com.vitorpamplona.amethyst.ui.screen.ChatroomFeedView
|
import com.vitorpamplona.amethyst.ui.screen.ChatroomFeedView
|
||||||
import com.vitorpamplona.amethyst.ui.screen.NostrChatRoomFeedViewModel
|
import com.vitorpamplona.amethyst.ui.screen.NostrChatRoomFeedViewModel
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navController: NavController) {
|
fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
@ -105,7 +104,7 @@ fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navContr
|
|||||||
|
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
NostrChatroomDataSource.withUser?.let {
|
NostrChatroomDataSource.withUser?.let {
|
||||||
ChatroomHeader(it, account.userProfile(), navController = navController, account.proxy)
|
ChatroomHeader(it, account.userProfile(), navController = navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
@ -207,7 +206,7 @@ fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navContr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatroomHeader(baseUser: User, accountUser: User, navController: NavController, proxy: Proxy?) {
|
fun ChatroomHeader(baseUser: User, accountUser: User, navController: NavController) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.clickable(
|
modifier = Modifier.clickable(
|
||||||
onClick = { navController.navigate("User/${baseUser.pubkeyHex}") }
|
onClick = { navController.navigate("User/${baseUser.pubkeyHex}") }
|
||||||
@ -227,7 +226,7 @@ fun ChatroomHeader(baseUser: User, accountUser: User, navController: NavControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
ObserveDisplayNip05Status(baseUser, proxy = proxy)
|
ObserveDisplayNip05Status(baseUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import java.net.Proxy
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.*
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.gestures.scrollBy
|
import androidx.compose.foundation.gestures.scrollBy
|
||||||
@ -309,7 +308,7 @@ private fun ProfileHeader(
|
|||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = LocalClipboardManager.current
|
||||||
|
|
||||||
Box {
|
Box {
|
||||||
DrawBanner(baseUser, account.proxy)
|
DrawBanner(baseUser)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -411,7 +410,7 @@ private fun ProfileHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (zoomImageDialogOpen) {
|
if (zoomImageDialogOpen) {
|
||||||
ZoomableImageDialog(baseUser.profilePicture()!!, onDismiss = { zoomImageDialogOpen = false }, proxy = account.proxy)
|
ZoomableImageDialog(baseUser.profilePicture()!!, onDismiss = { zoomImageDialogOpen = false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +514,7 @@ private fun DrawAdditionalInfo(baseUser: User, account: Account, accountViewMode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayNip05ProfileStatus(user, account.proxy)
|
DisplayNip05ProfileStatus(user)
|
||||||
|
|
||||||
val website = user.info?.website
|
val website = user.info?.website
|
||||||
if (!website.isNullOrEmpty()) {
|
if (!website.isNullOrEmpty()) {
|
||||||
@ -617,8 +616,7 @@ private fun DrawAdditionalInfo(baseUser: User, account: Account, accountViewMode
|
|||||||
tags = null,
|
tags = null,
|
||||||
backgroundColor = MaterialTheme.colors.background,
|
backgroundColor = MaterialTheme.colors.background,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
navController = navController,
|
navController = navController
|
||||||
proxy = account.proxy
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -688,7 +686,7 @@ fun BadgeThumb(
|
|||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun DrawBanner(baseUser: User, proxy: Proxy?) {
|
private fun DrawBanner(baseUser: User) {
|
||||||
val userState by baseUser.live().metadata.observeAsState()
|
val userState by baseUser.live().metadata.observeAsState()
|
||||||
val user = userState?.user ?: return
|
val user = userState?.user ?: return
|
||||||
|
|
||||||
@ -714,7 +712,7 @@ private fun DrawBanner(baseUser: User, proxy: Proxy?) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (zoomImageDialogOpen) {
|
if (zoomImageDialogOpen) {
|
||||||
ZoomableImageDialog(imageUrl = banner, onDismiss = { zoomImageDialogOpen = false }, proxy = proxy)
|
ZoomableImageDialog(imageUrl = banner, onDismiss = { zoomImageDialogOpen = false })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Image(
|
Image(
|
||||||
|
@ -35,7 +35,6 @@ import com.vitorpamplona.amethyst.service.lang.ResultOrError
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.net.Proxy
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -46,8 +45,7 @@ fun TranslatableRichTextViewer(
|
|||||||
tags: List<List<String>>?,
|
tags: List<List<String>>?,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
proxy: Proxy?
|
|
||||||
) {
|
) {
|
||||||
val translatedTextState = remember {
|
val translatedTextState = remember {
|
||||||
mutableStateOf(ResultOrError(content, null, null, null))
|
mutableStateOf(ResultOrError(content, null, null, null))
|
||||||
@ -89,8 +87,7 @@ fun TranslatableRichTextViewer(
|
|||||||
tags,
|
tags,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController,
|
navController
|
||||||
proxy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val target = translatedTextState.value.targetLang
|
val target = translatedTextState.value.targetLang
|
||||||
|
Loading…
Reference in New Issue
Block a user