Skip to content

Commit

Permalink
Add option to add the relay if it doesnt support retrieving bunker ev…
Browse files Browse the repository at this point in the history
…ents eg (ditto instances)
  • Loading branch information
greenart7c3 committed Nov 18, 2024
1 parent 9f053e5 commit 3e19e59
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 14 deletions.
67 changes: 67 additions & 0 deletions app/src/main/java/com/greenart7c3/nostrsigner/ui/AccountScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 = {},
)
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 3e19e59

Please sign in to comment.