api!: Change list_transports to additionally return whether a transport is unpublished

This commit is contained in:
Hocuri
2026-03-17 16:12:22 +01:00
parent b94d9f95b6
commit b08ba4bb8c
4 changed files with 26 additions and 41 deletions

View File

@@ -553,25 +553,10 @@ impl CommandApi {
} }
/// Returns the list of all email accounts that are used as a transport in the current profile. /// Returns the list of all email accounts that are used as a transport in the current profile.
/// Use [Self::add_or_update_transport()] to add or change a transport /// Use [Self::add_or_update_transport()] to add or change a transport,
/// [Self::set_transport_unpublished()] to publish or unpublish a transport,
/// and [Self::delete_transport()] to delete a transport. /// and [Self::delete_transport()] to delete a transport.
/// Use [Self::list_transports_ex()] to additionally query async fn list_transports(&self, account_id: u32) -> Result<Vec<Transport>> {
/// whether the transports are marked as 'unpublished'.
async fn list_transports(&self, account_id: u32) -> Result<Vec<EnteredLoginParam>> {
let ctx = self.get_context(account_id).await?;
let res = ctx
.list_transports()
.await?
.into_iter()
.map(|t| t.param.into())
.collect();
Ok(res)
}
/// Returns the list of all email accounts that are used as a transport in the current profile.
/// Use [Self::add_or_update_transport()] to add or change a transport
/// and [Self::delete_transport()] to delete a transport.
async fn list_transports_ex(&self, account_id: u32) -> Result<Vec<Transport>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let res = ctx let res = ctx
.list_transports() .list_transports()

View File

@@ -99,7 +99,7 @@ class ACFactory:
ac.remove() ac.remove()
ac_clone = self.get_unconfigured_account() ac_clone = self.get_unconfigured_account()
for transport in transports: for transport in transports:
ac_clone.add_or_update_transport(transport) ac_clone.add_or_update_transport(transport["param"])
ac_clone.bring_online() ac_clone.bring_online()
return ac_clone return ac_clone

View File

@@ -22,8 +22,8 @@ def test_add_second_address(acfactory) -> None:
account.add_transport_from_qr(qr) account.add_transport_from_qr(qr)
assert len(account.list_transports()) == 3 assert len(account.list_transports()) == 3
first_addr = account.list_transports()[0]["addr"] first_addr = account.list_transports()[0]["param"]["addr"]
second_addr = account.list_transports()[1]["addr"] second_addr = account.list_transports()[1]["param"]["addr"]
# Cannot delete the first address. # Cannot delete the first address.
with pytest.raises(JsonRpcError): with pytest.raises(JsonRpcError):
@@ -90,7 +90,7 @@ def test_change_address(acfactory) -> None:
assert old_alice_addr in alice_vcard assert old_alice_addr in alice_vcard
qr = acfactory.get_account_qr() qr = acfactory.get_account_qr()
alice.add_transport_from_qr(qr) alice.add_transport_from_qr(qr)
new_alice_addr = alice.list_transports()[1]["addr"] new_alice_addr = alice.list_transports()[1]["param"]["addr"]
with pytest.raises(JsonRpcError): with pytest.raises(JsonRpcError):
# Cannot use the address that is not # Cannot use the address that is not
# configured for any transport. # configured for any transport.
@@ -179,7 +179,7 @@ def test_reconfigure_transport(acfactory) -> None:
account.set_config("mvbox_move", "1") account.set_config("mvbox_move", "1")
[transport] = account.list_transports() [transport] = account.list_transports()
account.add_or_update_transport(transport) account.add_or_update_transport(transport["param"])
# Reconfiguring the transport should not reset # Reconfiguring the transport should not reset
# the settings as if when configuring the first transport. # the settings as if when configuring the first transport.
@@ -215,15 +215,15 @@ def test_transport_synchronization(acfactory, log) -> None:
log.section("ac1 clone removes second transport") log.section("ac1 clone removes second transport")
[transport1, transport2, transport3] = ac1_clone.list_transports() [transport1, transport2, transport3] = ac1_clone.list_transports()
addr3 = transport3["addr"] addr3 = transport3["param"]["addr"]
ac1_clone.delete_transport(transport2["addr"]) ac1_clone.delete_transport(transport2["param"]["addr"])
ac1.wait_for_event(EventType.TRANSPORTS_MODIFIED) ac1.wait_for_event(EventType.TRANSPORTS_MODIFIED)
wait_for_io_started(ac1) wait_for_io_started(ac1)
[transport1, transport3] = ac1.list_transports() [transport1, transport3] = ac1.list_transports()
log.section("ac1 changes the primary transport") log.section("ac1 changes the primary transport")
ac1.set_config("configured_addr", transport3["addr"]) ac1.set_config("configured_addr", transport3["param"]["addr"])
# One event for updated `add_timestamp` of the new primary transport, # One event for updated `add_timestamp` of the new primary transport,
# one event for the `configured_addr` update. # one event for the `configured_addr` update.
@@ -233,12 +233,12 @@ def test_transport_synchronization(acfactory, log) -> None:
assert ac1_clone.get_config("configured_addr") == addr3 assert ac1_clone.get_config("configured_addr") == addr3
log.section("ac1 removes the first transport") log.section("ac1 removes the first transport")
ac1.delete_transport(transport1["addr"]) ac1.delete_transport(transport1["param"]["addr"])
ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED) ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED)
wait_for_io_started(ac1_clone) wait_for_io_started(ac1_clone)
[transport3] = ac1_clone.list_transports() [transport3] = ac1_clone.list_transports()
assert transport3["addr"] == addr3 assert transport3["param"]["addr"] == addr3
assert ac1_clone.get_config("configured_addr") == addr3 assert ac1_clone.get_config("configured_addr") == addr3
ac2_chat = ac2.create_chat(ac1) ac2_chat = ac2.create_chat(ac1)
@@ -262,13 +262,13 @@ def test_transport_sync_new_as_primary(acfactory, log) -> None:
[transport1, transport2] = ac1_transports [transport1, transport2] = ac1_transports
ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED) ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED)
assert len(ac1_clone.list_transports()) == 2 assert len(ac1_clone.list_transports()) == 2
assert ac1_clone.get_config("configured_addr") == transport1["addr"] assert ac1_clone.get_config("configured_addr") == transport1["param"]["addr"]
log.section("ac1 changes the primary transport") log.section("ac1 changes the primary transport")
ac1.set_config("configured_addr", transport2["addr"]) ac1.set_config("configured_addr", transport2["param"]["addr"])
ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED) ac1_clone.wait_for_event(EventType.TRANSPORTS_MODIFIED)
assert ac1_clone.get_config("configured_addr") == transport2["addr"] assert ac1_clone.get_config("configured_addr") == transport2["param"]["addr"]
log.section("ac1_clone receives a message via the new primary transport") log.section("ac1_clone receives a message via the new primary transport")
ac1_chat = ac1.create_chat(bob) ac1_chat = ac1.create_chat(bob)
@@ -288,7 +288,7 @@ def test_recognize_self_address(acfactory) -> None:
qr = acfactory.get_account_qr() qr = acfactory.get_account_qr()
alice.add_transport_from_qr(qr) alice.add_transport_from_qr(qr)
new_alice_addr = alice.list_transports()[1]["addr"] new_alice_addr = alice.list_transports()[1]["param"]["addr"]
alice.set_config("configured_addr", new_alice_addr) alice.set_config("configured_addr", new_alice_addr)
bob_chat.send_text("Hello!") bob_chat.send_text("Hello!")
@@ -311,7 +311,7 @@ def test_transport_limit(acfactory) -> None:
with pytest.raises(JsonRpcError): with pytest.raises(JsonRpcError):
account.add_transport_from_qr(qr) account.add_transport_from_qr(qr)
second_addr = account.list_transports()[1]["addr"] second_addr = account.list_transports()[1]["param"]["addr"]
account.delete_transport(second_addr) account.delete_transport(second_addr)
# test that adding a transport after deleting one works again # test that adding a transport after deleting one works again
@@ -337,13 +337,13 @@ def test_message_info_imap_urls(acfactory) -> None:
bob_chat = bob.create_chat(alice) bob_chat = bob.create_chat(alice)
# Alice switches to another transport and removes the rest of the transports. # Alice switches to another transport and removes the rest of the transports.
new_alice_addr = alice.list_transports()[1]["addr"] new_alice_addr = alice.list_transports()[1]["param"]["addr"]
alice.set_config("configured_addr", new_alice_addr) alice.set_config("configured_addr", new_alice_addr)
removed_addrs = [] removed_addrs = []
for transport in alice.list_transports(): for transport in alice.list_transports():
if transport["addr"] != new_alice_addr: if transport["param"]["addr"] != new_alice_addr:
alice.delete_transport(transport["addr"]) alice.delete_transport(transport["param"]["addr"])
removed_addrs.append(transport["addr"]) removed_addrs.append(transport["param"]["addr"])
alice.stop_io() alice.stop_io()
alice.start_io() alice.start_io()
@@ -370,14 +370,14 @@ def test_remove_primary_transport(acfactory) -> None:
# Alice changes the transport. # Alice changes the transport.
[transport1, transport2] = alice.list_transports() [transport1, transport2] = alice.list_transports()
alice.set_config("configured_addr", transport2["addr"]) alice.set_config("configured_addr", transport2["param"]["addr"])
bob_chat.send_text("Hello!") bob_chat.send_text("Hello!")
msg1 = alice.wait_for_incoming_msg().get_snapshot() msg1 = alice.wait_for_incoming_msg().get_snapshot()
assert msg1.text == "Hello!" assert msg1.text == "Hello!"
# Alice deletes the first transport. # Alice deletes the first transport.
alice.delete_transport(transport1["addr"]) alice.delete_transport(transport1["param"]["addr"])
alice.stop_io() alice.stop_io()
alice.start_io() alice.start_io()

View File

@@ -88,7 +88,7 @@ def test_lowercase_address(acfactory) -> None:
assert account.is_configured() assert account.is_configured()
assert addr_upper != addr assert addr_upper != addr
assert account.get_config("configured_addr") == addr assert account.get_config("configured_addr") == addr
assert account.list_transports()[0]["addr"] == addr assert account.list_transports()[0]["param"]["addr"] == addr
param = account.get_info()["used_transport_settings"] param = account.get_info()["used_transport_settings"]
assert addr in param assert addr in param
@@ -138,7 +138,7 @@ def test_list_transports(acfactory) -> None:
) )
transports = account.list_transports() transports = account.list_transports()
assert len(transports) == 1 assert len(transports) == 1
params = transports[0] params = transports[0]["param"]
assert params["addr"] == addr assert params["addr"] == addr
assert params["password"] == password assert params["password"] == password
assert params["imapUser"] == addr assert params["imapUser"] == addr