feat: verify nip65 relays before set messaging relays
This commit is contained in:
@@ -424,7 +424,7 @@ impl Chat {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get message
|
// Get message
|
||||||
let mut content = self.input.read(cx).text().to_string();
|
let mut content = self.input.read(cx).text();
|
||||||
|
|
||||||
// Get all attaches and merge its with message
|
// Get all attaches and merge its with message
|
||||||
if let Some(attaches) = self.attaches.read(cx).as_ref() {
|
if let Some(attaches) = self.attaches.read(cx).as_ref() {
|
||||||
@@ -434,7 +434,7 @@ impl Chat {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
content = format!("{}\n{}", content, merged)
|
content = format!("{}\n{}", content, merged).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
if content.is_empty() {
|
if content.is_empty() {
|
||||||
@@ -454,7 +454,7 @@ impl Chat {
|
|||||||
|
|
||||||
let room = model.read(cx);
|
let room = model.read(cx);
|
||||||
let pubkeys = room.pubkeys();
|
let pubkeys = room.pubkeys();
|
||||||
let async_content = content.clone();
|
let async_content = content.clone().to_string();
|
||||||
let tags: Vec<Tag> = room
|
let tags: Vec<Tag> = room
|
||||||
.pubkeys()
|
.pubkeys()
|
||||||
.iter()
|
.iter()
|
||||||
@@ -487,7 +487,7 @@ impl Chat {
|
|||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
_ = cx.update_window(window_handle, |_, window, cx| {
|
_ = cx.update_window(window_handle, |_, window, cx| {
|
||||||
_ = this.update(cx, |this, cx| {
|
_ = this.update(cx, |this, cx| {
|
||||||
this.push_message(content.clone(), window, cx);
|
this.push_message(content.to_string(), window, cx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -76,19 +76,30 @@ impl Relays {
|
|||||||
.await
|
.await
|
||||||
.expect("Cannot get public key");
|
.expect("Cannot get public key");
|
||||||
|
|
||||||
|
// If user didn't have any NIP-65 relays, add default ones
|
||||||
|
// TODO: Is this really necessary?
|
||||||
|
if let Ok(relay_list) = client.database().relay_list(public_key).await {
|
||||||
|
if relay_list.is_empty() {
|
||||||
|
let builder = EventBuilder::relay_list(vec![
|
||||||
|
(RelayUrl::parse("wss://relay.damus.io/").unwrap(), None),
|
||||||
|
(RelayUrl::parse("wss://relay.primal.net/").unwrap(), None),
|
||||||
|
(RelayUrl::parse("wss://nos.lol/").unwrap(), None),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if let Err(e) = client.send_event_builder(builder).await {
|
||||||
|
log::error!("Failed to send relay list event: {}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let tags: Vec<Tag> = relays
|
let tags: Vec<Tag> = relays
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| Tag::custom(TagKind::Relay, vec![relay.to_string()]))
|
.map(|relay| Tag::custom(TagKind::Relay, vec![relay.to_string()]))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let event = EventBuilder::new(Kind::InboxRelays, "")
|
let builder = EventBuilder::new(Kind::InboxRelays, "").tags(tags);
|
||||||
.tags(tags)
|
|
||||||
.build(public_key)
|
|
||||||
.sign(&signer)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Ok(output) = client.send_event(&event).await {
|
if let Ok(output) = client.send_event_builder(builder).await {
|
||||||
_ = tx.send(output.val);
|
_ = tx.send(output.val);
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user