Skip to content

Commit dc01c2d

Browse files
committed
refactor(whitenoise/accounts/groups): use contact#get_relays_of_type method for automatic default relay fallback
1 parent 95a8bf1 commit dc01c2d

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/whitenoise/accounts/groups.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::whitenoise::accounts::Account;
22
use crate::whitenoise::error::{Result, WhitenoiseError};
33
use crate::whitenoise::Whitenoise;
4+
use crate::RelayType;
45
use nostr_mls::prelude::*;
56
use std::time::Duration;
67

@@ -46,11 +47,7 @@ impl Whitenoise {
4647

4748
for pk in member_pubkeys.iter() {
4849
let contact = self.load_contact(pk).await?;
49-
let relays_to_use = if contact.key_package_relays.is_empty() {
50-
Account::default_relays()
51-
} else {
52-
contact.key_package_relays.clone()
53-
};
50+
let relays_to_use = contact.get_relays_of_type(RelayType::KeyPackage);
5451
let some_event = self
5552
.fetch_key_package_event_from(relays_to_use, *pk)
5653
.await?;
@@ -121,11 +118,7 @@ impl Whitenoise {
121118
// Create a timestamp 1 month in the future
122119
use std::ops::Add;
123120
let one_month_future = Timestamp::now().add(30 * 24 * 60 * 60);
124-
let relays_to_use = if contact.inbox_relays.is_empty() {
125-
Account::default_relays()
126-
} else {
127-
contact.inbox_relays.clone()
128-
};
121+
let relays_to_use = contact.get_relays_of_type(RelayType::Inbox);
129122

130123
self.nostr
131124
.publish_gift_wrap_with_signer(
@@ -255,11 +248,7 @@ impl Whitenoise {
255248
// Fetch key packages for all members
256249
for pk in members.iter() {
257250
let contact = self.load_contact(pk).await?;
258-
let relays_to_use = if contact.key_package_relays.is_empty() {
259-
Account::default_relays()
260-
} else {
261-
contact.key_package_relays.clone()
262-
};
251+
let relays_to_use = contact.get_relays_of_type(RelayType::KeyPackage);
263252
let some_event = self
264253
.fetch_key_package_event_from(relays_to_use, *pk)
265254
.await?;
@@ -357,11 +346,7 @@ impl Whitenoise {
357346
let one_month_future = Timestamp::now() + Duration::from_secs(30 * 24 * 60 * 60);
358347

359348
// Use fallback relays if contact has no inbox relays configured
360-
let relays_to_use = if contact.inbox_relays.is_empty() {
361-
Account::default_relays()
362-
} else {
363-
contact.inbox_relays
364-
};
349+
let relays_to_use = contact.get_relays_of_type(RelayType::Inbox);
365350

366351
self.nostr
367352
.publish_gift_wrap_with_signer(

0 commit comments

Comments
 (0)