feat: add support for basic web of trust #65
@@ -455,6 +455,11 @@ impl WebOfTrust {
|
|||||||
self.ready
|
self.ready
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the graph is loaded and score queries are meaningful
|
||||||
|
pub fn is_loaded(&self) -> bool {
|
||||||
|
self.ready && !self.disabled
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether scoring is disabled due to an oversized follow set
|
/// Whether scoring is disabled due to an oversized follow set
|
||||||
pub fn is_disabled(&self) -> bool {
|
pub fn is_disabled(&self) -> bool {
|
||||||
self.disabled
|
self.disabled
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
use instant::Duration;
|
use instant::Duration;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{Directory, Person, PersonRegistry, shorten_pubkey};
|
use person::{Directory, Person, PersonRegistry, WebOfTrust, shorten_pubkey};
|
||||||
use settings::AppSettings;
|
use settings::AppSettings;
|
||||||
use state::{NostrRegistry, upload};
|
use state::{NostrRegistry, upload};
|
||||||
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
|
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
|
||||||
@@ -459,9 +459,24 @@ impl Render for ProfileDialog {
|
|||||||
.filter(|website| !website.trim().is_empty())
|
.filter(|website| !website.trim().is_empty())
|
||||||
.map(SharedString::from);
|
.map(SharedString::from);
|
||||||
|
|
||||||
|
let score = {
|
||||||
|
let wot = WebOfTrust::global(cx).read(cx);
|
||||||
|
wot.is_loaded().then(|| wot.score(&self.public_key))
|
||||||
|
}
|
||||||
|
.map(|score| {
|
||||||
|
SharedString::from(format!(
|
||||||
|
"{} mutual {}",
|
||||||
|
score,
|
||||||
|
if score == 1 { "contact" } else { "contacts" }
|
||||||
|
))
|
||||||
|
});
|
||||||
|
|
||||||
this.child(field("Name", name, "Unknown", cx))
|
this.child(field("Name", name, "Unknown", cx))
|
||||||
.child(field("About", about, "No bio", cx))
|
.child(field("About", about, "No bio", cx))
|
||||||
.child(field("Website", website, "No website", cx))
|
.child(field("Website", website, "No website", cx))
|
||||||
|
.when(!self.is_current_user, |this| {
|
||||||
|
this.child(field("Web of Trust", score, "Not loaded yet", cx))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ impl Screening {
|
|||||||
fn check_wot(&mut self, cx: &mut Context<Self>) {
|
fn check_wot(&mut self, cx: &mut Context<Self>) {
|
||||||
let trusted = {
|
let trusted = {
|
||||||
let wot = WebOfTrust::global(cx).read(cx);
|
let wot = WebOfTrust::global(cx).read(cx);
|
||||||
(wot.is_ready() && !wot.is_disabled()).then(|| wot.mutuals(&self.public_key))
|
wot.is_loaded().then(|| wot.mutuals(&self.public_key))
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(contacts) = trusted {
|
if let Some(contacts) = trusted {
|
||||||
@@ -166,11 +166,11 @@ impl Screening {
|
|||||||
let contacts = task.await;
|
let contacts = task.await;
|
||||||
|
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
let wot = WebOfTrust::global(cx).read(cx);
|
|
||||||
// The web of trust wins once its load has finished
|
// The web of trust wins once its load has finished
|
||||||
if wot.is_ready() && !wot.is_disabled() {
|
if WebOfTrust::global(cx).read(cx).is_loaded() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mutual_contacts = contacts;
|
this.mutual_contacts = contacts;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -150,8 +150,10 @@ Status: **partially implemented**. Request rooms whose members are all outside
|
|||||||
the web of trust show a `SPAM` badge in the sidebar
|
the web of trust show a `SPAM` badge in the sidebar
|
||||||
(`Room::is_spam` + `WebOfTrust::is_outside`, rendered in
|
(`Room::is_spam` + `WebOfTrust::is_outside`, rendered in
|
||||||
`crates/workspace/src/sidebar/rows.rs`; the sidebar subscribes to `WoTEvent` so
|
`crates/workspace/src/sidebar/rows.rs`; the sidebar subscribes to `WoTEvent` so
|
||||||
badges update when the graph loads). The mutual-count caption below is still
|
badges update when the graph loads). The profile dialog shows the score as a
|
||||||
open and will follow a different flow.
|
"Web of Trust" field (`crates/workspace/src/dialogs/profile.rs`, other users
|
||||||
|
only). The mutual-count caption below is still open and will follow a
|
||||||
|
different flow.
|
||||||
|
|
||||||
Where request rooms are rendered, show the mutual count for the sender:
|
Where request rooms are rendered, show the mutual count for the sender:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user