Add option to add the relay if it doesnt support retrieving bunker events eg (ditto instances)

This commit is contained in:
greenart7c3
2024-11-18 11:15:12 -03:00
parent 9f053e5171
commit 3e19e59e29
4 changed files with 109 additions and 14 deletions
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Done
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
@@ -183,10 +184,76 @@ private fun DisplayErrorMessages(accountViewModel: AccountStateViewModel) {
obj.onOk()
accountViewModel.clearToasts()
}
is AcceptRejectToastMsg ->
InformationDialog(
obj.title,
obj.msg,
onAccept = {
obj.onAccept()
accountViewModel.clearToasts()
},
onReject = {
obj.onReject()
accountViewModel.clearToasts()
},
)
}
}
}
@Composable
fun InformationDialog(
title: String,
textContent: String,
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
onAccept: () -> Unit,
onReject: () -> Unit,
) {
AlertDialog(
onDismissRequest = onReject,
title = { Text(title) },
text = { SelectionContainer { Text(textContent) } },
dismissButton = {
Button(
onClick = onReject,
colors = buttonColors,
contentPadding = PaddingValues(horizontal = 16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Outlined.Close,
contentDescription = null,
tint = Color.Black,
)
Spacer(Modifier.width(5.dp))
Text(stringResource(R.string.no))
}
}
},
confirmButton = {
Button(
onClick = onAccept,
colors = buttonColors,
contentPadding = PaddingValues(horizontal = 16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Outlined.Done,
contentDescription = null,
tint = Color.Black,
)
Spacer(Modifier.width(5.dp))
Text(stringResource(R.string.yes))
}
}
},
)
}
@Composable
fun InformationDialog(
title: String,
@@ -31,6 +31,9 @@ class StringToastMsg(val title: String, val msg: String) : ToastMsg()
@Immutable
class ConfirmationToastMsg(val title: String, val msg: String, val onOk: () -> Unit) : ToastMsg()
@Immutable
class AcceptRejectToastMsg(val title: String, val msg: String, val onAccept: () -> Unit, val onReject: () -> Unit) : ToastMsg()
@Immutable
class ResourceToastMsg(
val titleResId: Int,
@@ -67,6 +70,15 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
viewModelScope.launch { toasts.emit(ConfirmationToastMsg(title, message, onOk)) }
}
fun toast(
title: String,
message: String,
onAccept: () -> Unit,
onReject: () -> Unit,
) {
viewModelScope.launch { toasts.emit(AcceptRejectToastMsg(title, message, onAccept, onReject)) }
}
private fun tryLoginExistingAccount(
route: String?,
npub: String?,
@@ -349,21 +349,25 @@ suspend fun onAddRelay(
signedEvent = signedEvent,
relayList = listOf(RelaySetupInfo(addedWSS, read = true, write = true, setOf())),
)
relay.sendFilter(
UUID.randomUUID().toString().substring(0, 4),
filters = listOf(
TypedFilter(
types = COMMON_FEED_TYPES,
filter = SincePerRelayFilter(
ids = listOf(event.id),
if (result) {
relay.sendFilter(
UUID.randomUUID().toString().substring(0, 4),
filters = listOf(
TypedFilter(
types = COMMON_FEED_TYPES,
filter = SincePerRelayFilter(
ids = listOf(event.id),
),
),
),
),
)
var count = 0
while (!filterResult && count < 10) {
delay(1000)
count++
)
var count = 0
while (!filterResult && count < 10) {
delay(1000)
count++
}
} else {
filterResult = true
}
AmberListenerSingleton.getListener()?.let { listener ->
@@ -388,6 +392,18 @@ suspend fun onAddRelay(
accountStateViewModel.toast(
context.getString(R.string.relay),
context.getString(R.string.relay_filter_failed),
onAccept = {
relays2.add(
RelaySetupInfo(
addedWSS,
read = true,
write = true,
feedTypes = COMMON_FEED_TYPES,
),
)
onDone()
},
onReject = {},
)
}
+1 -1
View File
@@ -427,5 +427,5 @@
<string name="is_requiring_some_permissions_please_review_them">%1$s is requiring some permissions, please review them.</string>
<string name="always_approve_this_permission">Always approve this permission</string>
<string name="is_requiring_to_sign_these_events_related_to_permission">%1$s is requiring to sign these events related to %2$s permission.</string>
<string name="relay_filter_failed">Relay does not support receiving Bunker events</string>
<string name="relay_filter_failed">Relay does not support retrieving Bunker events. Would you like to add it anyway?</string>
</resources>