auto-trust web of trust chat requests behind a setting

This commit is contained in:
2026-10-20 10:01:13 +07:00
parent 66768e71a6
commit 10d74c5396
5 changed files with 81 additions and 22 deletions
+21 -2
View File
@@ -577,7 +577,12 @@ impl ChatRegistry {
return;
};
let room: Room = room.into().organize(&public_key);
let mut room: Room = room.into().organize(&public_key);
if room.auto_trusted(public_key, cx) {
room.kind = RoomKind::Ongoing;
}
let room_id = room.id;
let entity = cx.new(|_| room);
entity.update(cx, |room, cx| room.ensure_directory(cx));
@@ -652,6 +657,11 @@ impl ChatRegistry {
/// Extend the registry with new rooms.
fn extend_rooms(&mut self, rooms: HashSet<Room>, cx: &mut Context<Self>) {
let nostr = NostrRegistry::global(cx);
let Some(me) = nostr.read(cx).current_user() else {
return;
};
let mut room_map: HashMap<u64, usize> = self
.rooms
.iter()
@@ -660,6 +670,13 @@ impl ChatRegistry {
.collect();
for new_room in rooms.into_iter() {
// Auto-trust also applies to rooms loaded from the database
let new_room = if new_room.kind == RoomKind::Request && new_room.auto_trusted(me, cx) {
new_room.kind(RoomKind::Ongoing)
} else {
new_room
};
// Check if we already have a room with this ID
if let Some(&index) = room_map.get(&new_room.id) {
self.rooms[index].update(cx, |this, cx| {
@@ -789,7 +806,9 @@ impl ChatRegistry {
match self.room_index.get(&message.room).cloned() {
Some(room) => {
room.update(cx, |this, cx| {
if this.kind == RoomKind::Request && message.rumor.pubkey == public_key {
if this.kind == RoomKind::Request
&& (message.rumor.pubkey == public_key || this.auto_trusted(public_key, cx))
{
this.set_ongoing(cx);
}
this.push_message(message, cx);
+28 -2
View File
@@ -8,8 +8,8 @@ use instant::Duration;
use itertools::Itertools;
use nip4e::DeviceRegistry;
use nostr_sdk::prelude::*;
use person::{Directory, Person};
use settings::{RoomConfig, SignerKind};
use person::{Directory, Person, WebOfTrust};
use settings::{AppSettings, RoomConfig, SignerKind};
use state::{NostrRegistry, TIMEOUT, UniversalSigner};
use crate::{FileAttachment, KIND_FILE_MESSAGE, NewMessage};
@@ -183,6 +183,32 @@ impl Room {
self
}
/// Whether the auto-trust setting promotes this room out of the requests:
/// everyone other than the current user is inside the web of trust
pub fn auto_trusted(&self, me: PublicKey, cx: &App) -> bool {
if !AppSettings::get_wot_auto_trust(cx) {
return false;
}
let wot = WebOfTrust::global(cx).read(cx);
let mut others = false;
for key in &self.members {
if *key == me {
continue;
}
others = true;
if !wot.is_in_network(key) {
return false;
}
}
others
}
/// Sets this room is ongoing conversation
pub(crate) fn set_ongoing(&mut self, cx: &mut Context<Self>) {
self.kind = RoomKind::Ongoing;