add trust_media_from_pk2 method
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
use crate::{
|
use crate::error::Error;
|
||||||
error::Error,
|
use crate::search::SearchQuery;
|
||||||
search::SearchQuery,
|
use crate::timeline::{Timeline, TimelineTab};
|
||||||
timeline::{Timeline, TimelineTab},
|
|
||||||
};
|
|
||||||
use enostr::{Filter, NoteId, Pubkey};
|
use enostr::{Filter, NoteId, Pubkey};
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
filter::{self, default_limit},
|
filter::{self, default_limit},
|
||||||
FilterError, FilterState, NoteCache, RootIdError, RootNoteIdBuf,
|
FilterError, FilterState, NoteCache, RootIdError, RootNoteIdBuf,
|
||||||
};
|
};
|
||||||
|
use notedeck_ui::contacts::contacts_filter;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::{borrow::Cow, fmt::Display};
|
use std::{borrow::Cow, fmt::Display};
|
||||||
@@ -666,11 +665,7 @@ impl<'a> ColumnTitle<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn contact_filter_state(txn: &Transaction, ndb: &Ndb, pk: &Pubkey) -> FilterState {
|
fn contact_filter_state(txn: &Transaction, ndb: &Ndb, pk: &Pubkey) -> FilterState {
|
||||||
let contact_filter = Filter::new()
|
let contact_filter = contacts_filter(pk);
|
||||||
.authors([pk.bytes()])
|
|
||||||
.kinds([3])
|
|
||||||
.limit(1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let results = ndb
|
let results = ndb
|
||||||
.query(txn, &[contact_filter.clone()], 1)
|
.query(txn, &[contact_filter.clone()], 1)
|
||||||
|
|||||||
62
crates/notedeck_ui/src/contacts.rs
Normal file
62
crates/notedeck_ui/src/contacts.rs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
use nostrdb::{Filter, Ndb, Note, Transaction};
|
||||||
|
|
||||||
|
fn pk1_is_following_pk2(
|
||||||
|
ndb: &Ndb,
|
||||||
|
txn: &Transaction,
|
||||||
|
pk1: &[u8; 32],
|
||||||
|
pk2: &[u8; 32],
|
||||||
|
) -> Option<bool> {
|
||||||
|
let note = get_contacts_note(ndb, txn, pk1)?;
|
||||||
|
|
||||||
|
Some(note_follows(note, pk2))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trust_media_from_pk2(
|
||||||
|
ndb: &Ndb,
|
||||||
|
txn: &Transaction,
|
||||||
|
pk1: Option<&[u8; 32]>,
|
||||||
|
pk2: &[u8; 32],
|
||||||
|
) -> bool {
|
||||||
|
pk1.map(|pk| pk1_is_following_pk2(ndb, txn, pk, pk2).unwrap_or(false))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_contacts_note<'a>(ndb: &'a Ndb, txn: &'a Transaction, user: &[u8; 32]) -> Option<Note<'a>> {
|
||||||
|
Some(
|
||||||
|
ndb.query(txn, &[contacts_filter(user)], 1)
|
||||||
|
.ok()?
|
||||||
|
.first()?
|
||||||
|
.note
|
||||||
|
.clone(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn contacts_filter(pk: &[u8; 32]) -> Filter {
|
||||||
|
Filter::new().authors([pk]).kinds([3]).limit(1).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn note_follows(contacts_note: Note<'_>, pk: &[u8; 32]) -> bool {
|
||||||
|
for tag in contacts_note.tags() {
|
||||||
|
if tag.count() < 2 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(t) = tag.get_str(0) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if t != "p" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(author) = tag.get_id(1) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if *pk == *author {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod anim;
|
pub mod anim;
|
||||||
pub mod colors;
|
pub mod colors;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
pub mod contacts;
|
||||||
pub mod gif;
|
pub mod gif;
|
||||||
pub mod icons;
|
pub mod icons;
|
||||||
pub mod images;
|
pub mod images;
|
||||||
|
|||||||
Reference in New Issue
Block a user