update
This commit is contained in:
+24
-3
@@ -14,6 +14,7 @@ use gpui::{
|
||||
use instant::Duration;
|
||||
use nip4e::{DeviceEvent, DeviceRegistry};
|
||||
use nostr_sdk::prelude::*;
|
||||
use person::PersonRegistry;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use state::{DEVICE_GIFTWRAP, NostrRegistry, USER_GIFTWRAP};
|
||||
|
||||
@@ -139,13 +140,13 @@ impl ChatRegistry {
|
||||
/// Create a new chat registry instance
|
||||
fn new(cx: &mut Context<Self>) -> Self {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let device = DeviceRegistry::global(cx);
|
||||
let wot = PersonRegistry::global(cx).read(cx).wot();
|
||||
let entity = cx.entity().downgrade();
|
||||
|
||||
let (tx, rx) = flume::unbounded::<Signal>();
|
||||
let mut subscriptions = smallvec![];
|
||||
|
||||
let device = DeviceRegistry::global(cx);
|
||||
|
||||
subscriptions.push(cx.subscribe(&nostr, |this, _nostr, event, cx| {
|
||||
if event.signer_changed() {
|
||||
this.reset(cx);
|
||||
@@ -163,6 +164,10 @@ impl ChatRegistry {
|
||||
}
|
||||
}));
|
||||
|
||||
subscriptions.push(cx.subscribe(&wot, |this, _wot, _event, cx| {
|
||||
this.promote_trusted(cx);
|
||||
}));
|
||||
|
||||
cx.defer(move |cx| {
|
||||
let _ = entity.update(cx, |this, cx| {
|
||||
this.get_rooms(cx);
|
||||
@@ -567,7 +572,23 @@ impl ChatRegistry {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Add a new room to the start of list.
|
||||
/// Promote request rooms whose senders are inside the web of trust
|
||||
fn promote_trusted(&mut self, cx: &mut Context<Self>) {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let Some(me) = nostr.read(cx).current_user() else {
|
||||
return;
|
||||
};
|
||||
|
||||
for room in &self.rooms {
|
||||
room.update(cx, |room, cx| {
|
||||
if room.kind == RoomKind::Request && room.auto_trusted(me, cx) {
|
||||
room.set_ongoing(cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Promote a room to ongoing when its latest message is from the current user
|
||||
pub(crate) fn add_room<I>(&mut self, room: I, cx: &mut Context<Self>)
|
||||
where
|
||||
I: Into<Room>,
|
||||
|
||||
+11
-4
@@ -195,17 +195,24 @@ impl Room {
|
||||
Self::trusted_by(&self.members, me, |key| wot.is_in_network(key))
|
||||
}
|
||||
|
||||
/// Whether the room looks like spam: everyone other than the current user
|
||||
/// is outside the web of trust
|
||||
/// Whether the room looks like spam: the web of trust is loaded and
|
||||
/// everyone other than the current user is outside of it
|
||||
pub fn is_spam(&self, cx: &App) -> bool {
|
||||
let person = PersonRegistry::global(cx);
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
|
||||
let Some(me) = nostr.read(cx).current_user() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let wot = PersonRegistry::global(cx).read(cx).wot().read(cx);
|
||||
let wot = person.read(cx).wot().read(cx);
|
||||
|
||||
Self::trusted_by(&self.members, me, |key| !wot.is_outside(key))
|
||||
// An unloaded graph cannot classify anything as spam
|
||||
if !wot.is_loaded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Self::trusted_by(&self.members, me, |key| wot.is_outside(key))
|
||||
}
|
||||
|
||||
/// Whether every member other than `me` passes the check
|
||||
|
||||
Reference in New Issue
Block a user