feat: limit the number of published relays instead of all relays

This commit is contained in:
link2xt
2026-07-15 14:22:30 +00:00
committed by l
parent e5c920f1a1
commit d940f96a5c
2 changed files with 21 additions and 11 deletions

View File

@@ -237,9 +237,20 @@ def test_transport_limit(acfactory) -> None:
account.add_transport_from_qr(qr)
second_addr = account.list_transports()[1]["addr"]
account.delete_transport(second_addr)
third_addr = account.list_transports()[2]["addr"]
# test that adding a transport after deleting one works again
# test that adding a transport after unpublishing one works again
account.set_transport_unpublished(second_addr)
account.add_transport_from_qr(qr)
with pytest.raises(JsonRpcError):
account.add_transport_from_qr(qr)
# UIs are not expected to delete transports directly,
# but we still test that adding a transport
# after deleting one instead of unpublishing works.
account.delete_transport(third_addr)
account.add_transport_from_qr(qr)
with pytest.raises(JsonRpcError):
account.add_transport_from_qr(qr)

View File

@@ -45,9 +45,11 @@ use crate::transport::{
use crate::{EventType, stock_str};
use crate::{chat, provider};
/// Maximum number of relays
/// see <https://github.com/chatmail/core/issues/7608>
pub(crate) const MAX_TRANSPORT_RELAYS: usize = 5;
/// Maximum number of published relays.
///
/// See <https://github.com/chatmail/core/issues/7608>
/// and <https://github.com/chatmail/core/issues/8421>.
pub(crate) const MAX_PUBLISHED_RELAYS: usize = 5;
/// Hard-coded candidates for default relays.
/// In the future, we want to use it during onboarding;
@@ -336,14 +338,11 @@ impl Context {
.await?
&& self
.sql
.count("SELECT COUNT(*) FROM transports", ())
.count("SELECT COUNT(*) FROM transports WHERE is_published", ())
.await?
>= MAX_TRANSPORT_RELAYS
>= MAX_PUBLISHED_RELAYS
{
bail!(
"You have reached the maximum number of relays ({}).",
MAX_TRANSPORT_RELAYS
)
bail!("You have reached the maximum number of relays ({MAX_PUBLISHED_RELAYS}).")
}
let provider = match configure(self, param).await {