Skip to content

Commit 6232f96

Browse files
authored
Minor contact fallback fixes (#669)
1 parent b34d6a2 commit 6232f96

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

crates/bcr-ebill-api/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub const MAX_FILE_NAME_CHARACTERS: usize = 200;
66
pub const VALID_FILE_MIME_TYPES: [&str; 3] = ["image/jpeg", "image/png", "application/pdf"];
77

88
// When subscribing events we subtract this from the last received event time
9-
pub const NOSTR_EVENT_TIME_SLACK: u64 = 3600 * 24; // 1 day
9+
pub const NOSTR_EVENT_TIME_SLACK: u64 = 3600 * 24 * 7; // 1 week
1010
pub use bcr_ebill_core::constants::CURRENCY_SAT;

crates/bcr-ebill-api/src/service/company_service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ impl CompanyServiceApi for CompanyService {
300300
.iter()
301301
.any(|c| c.node_id == identity.node_id)
302302
{
303-
signatory_contacts.push(identity.as_contact());
303+
// we force person for this as it will be thrown out in later validation
304+
signatory_contacts.push(identity.as_contact(Some(ContactType::Person)));
304305
}
305306

306307
// if we are still missing some signatory details try to fill them from nostr contacts
@@ -317,7 +318,7 @@ impl CompanyServiceApi for CompanyService {
317318
.by_node_ids(missing)
318319
.await?
319320
.into_iter()
320-
.filter_map(|c| c.into_contact())
321+
.filter_map(|c| c.into_contact(Some(ContactType::Person)))
321322
.collect();
322323

323324
signatory_contacts.extend(nostr_contacts);

crates/bcr-ebill-api/src/service/contact_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl ContactServiceApi for ContactService {
254254
.filter_map(|c| {
255255
// only return nostr contacts that are not in contacts and have a name
256256
if !lookup.contains(&c.node_id) {
257-
c.into_contact()
257+
c.into_contact(None)
258258
} else {
259259
None
260260
}

crates/bcr-ebill-api/src/service/identity_service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,10 @@ impl IdentityService {
202202
}
203203

204204
async fn on_identity_contact_change(&self, identity: &Identity, keys: &BcrKeys) -> Result<()> {
205-
debug!("Company change, publishing our company contact to nostr profile");
205+
debug!("Identity change, publishing our identity contact to nostr profile");
206206
let bcr_data = get_bcr_data(identity, keys)?;
207207
let contact_data =
208208
NostrContactData::new(&identity.name, identity.nostr_relays.clone(), bcr_data);
209-
debug!("Publishing company contact data: {contact_data:?}");
210209
self.notification_service
211210
.publish_contact(&identity.node_id, &contact_data)
212211
.await?;
@@ -217,7 +216,8 @@ impl IdentityService {
217216
/// Derives a child key, encrypts the contact data with it and returns the bcr metadata
218217
fn get_bcr_data(identity: &Identity, keys: &BcrKeys) -> Result<BcrMetadata> {
219218
let derived_keys = keys.derive_keypair()?;
220-
let contact = identity.as_contact();
219+
let contact = identity.as_contact(None);
220+
debug!("Publishing identity contact data: {contact:?}");
221221
let payload = serde_json::to_string(&contact)?;
222222
let encrypted = base58_encode(&util::crypto::encrypt_ecies(
223223
payload.as_bytes(),

crates/bcr-ebill-core/src/identity/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ impl Identity {
136136
}
137137
}
138138

139-
pub fn as_contact(&self) -> Contact {
140-
let contact_type = match self.t {
139+
pub fn as_contact(&self, t: Option<ContactType>) -> Contact {
140+
let contact_type = t.unwrap_or(match self.t {
141141
IdentityType::Ident => ContactType::Person,
142142
IdentityType::Anon => ContactType::Anon,
143-
};
143+
});
144144
Contact {
145145
t: contact_type,
146146
node_id: self.node_id.clone(),

crates/bcr-ebill-core/src/nostr_contact.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ impl NostrContact {
6767
}
6868

6969
/// Returns a lightweight version of the contact if all required data is present.
70-
pub fn into_contact(self) -> Option<Contact> {
70+
pub fn into_contact(self, t: Option<ContactType>) -> Option<Contact> {
7171
if self.name.is_some() {
7272
Some(Contact {
7373
node_id: self.node_id,
74-
t: ContactType::Anon,
74+
t: t.unwrap_or(ContactType::Anon),
7575
name: self.name.unwrap(),
7676
email: None,
7777
postal_address: None,

crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ impl CompanyChainEventProcessor {
165165
self.nostr_contact_processor
166166
.ensure_nostr_contact(&company_id)
167167
.await;
168+
169+
// as well as all the company signatories
170+
for signatory in company.signatories.iter() {
171+
self.nostr_contact_processor
172+
.ensure_nostr_contact(signatory)
173+
.await;
174+
}
168175
} else {
169176
info!("We are not a signatory for company {company_id} so skipping chain");
170177
}
@@ -588,7 +595,7 @@ pub mod tests {
588595
.expect_ensure_nostr_contact()
589596
.with(eq(node_id.clone()))
590597
.returning(|_| ())
591-
.once();
598+
.times(2);
592599

593600
let handler = CompanyChainEventProcessor::new(
594601
Arc::new(chain_store),

crates/bcr-ebill-wasm/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ async function listCompanies() {
339339
}
340340

341341
async function listSignatories() {
342-
let signatories = await companyApi.list_signatories(document.getElementById("company_update_id").value);
343-
console.log("signatories:", signatories);
342+
let measured = measure(async () => {
343+
return await companyApi.list_signatories(document.getElementById("company_update_id").value);
344+
});
345+
await measured();
344346
}
345347

346348
async function triggerContact() {

crates/bcr-ebill-wasm/src/data/company.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ pub struct SignatoryResponse {
115115
#[tsify(type = "string")]
116116
pub node_id: NodeId,
117117
pub name: String,
118-
pub postal_address: PostalAddressWeb,
118+
pub postal_address: Option<PostalAddressWeb>,
119119
pub avatar_file: Option<FileWeb>,
120+
pub is_logical: bool,
120121
}
121122

122123
impl TryFrom<Contact> for SignatoryResponse {
@@ -130,11 +131,9 @@ impl TryFrom<Contact> for SignatoryResponse {
130131
t: value.t.into(),
131132
node_id: value.node_id.clone(),
132133
name: value.name,
133-
postal_address: value
134-
.postal_address
135-
.ok_or(ValidationError::InvalidContact(value.node_id.to_string()))
136-
.map(|pa| pa.into())?,
134+
postal_address: value.postal_address.map(|pa| pa.into()),
137135
avatar_file: value.avatar_file.map(|f| f.into()),
136+
is_logical: value.is_logical,
138137
})
139138
}
140139
}

0 commit comments

Comments
 (0)