Implement NIP-40 (event expiration)
This commit is contained in:
parent
255905021c
commit
bf08ac12e0
|
@ -844,6 +844,12 @@ impl NostrSqlite {
|
|||
|
||||
let event = row.clone().to_event();
|
||||
|
||||
if event.is_expired() {
|
||||
return Err(Error::internal_with_message(
|
||||
"Event has expired. Ignoring...",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(event)
|
||||
})
|
||||
.await
|
||||
|
@ -1059,8 +1065,10 @@ impl NostrSqlite {
|
|||
let mut event_vec: Vec<Event> = vec![];
|
||||
while let Ok(Some(row)) = rows.next() {
|
||||
let event = EventRow::from(row).to_event();
|
||||
if !event.is_expired() {
|
||||
event_vec.push(event);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(event_vec)
|
||||
})
|
||||
|
@ -1134,8 +1142,6 @@ impl NostrSqlite {
|
|||
let Ok(query_result) = connection
|
||||
.interact(move |conn| {
|
||||
let (sql, values) = sql_statement
|
||||
.clear_selects()
|
||||
.column(EventsTable::EventId)
|
||||
.order_by(EventsTable::CreatedAt, sq_order.to_owned())
|
||||
.build_rusqlite(SqliteQueryBuilder);
|
||||
|
||||
|
@ -1144,9 +1150,10 @@ impl NostrSqlite {
|
|||
|
||||
let mut event_vec: Vec<EventId> = vec![];
|
||||
while let Ok(Some(row)) = rows.next() {
|
||||
let event_id_string: String = row.get(0).unwrap();
|
||||
let event_id = EventId::from_str(&event_id_string).unwrap();
|
||||
event_vec.push(event_id);
|
||||
let event = EventRow::from(row).to_event();
|
||||
if !event.is_expired() {
|
||||
event_vec.push(event.id);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(event_vec)
|
||||
|
@ -1178,7 +1185,8 @@ impl NostrSqlite {
|
|||
};
|
||||
|
||||
let Ok(query_result) = connection
|
||||
.interact(move |conn: &mut rusqlite::Connection| -> Result<bool, Error> {
|
||||
.interact(
|
||||
move |conn: &mut rusqlite::Connection| -> Result<bool, Error> {
|
||||
let (sql, value) = Query::select()
|
||||
.from(EventsTable::Table)
|
||||
.columns([EventsTable::EventId, EventsTable::CreatedAt])
|
||||
|
@ -1188,7 +1196,9 @@ impl NostrSqlite {
|
|||
.equals((EventsTable::Table, EventsTable::EventId)),
|
||||
)
|
||||
.and_where(sea_query::Expr::col((TagsTable::Table, TagsTable::Tag)).eq("a"))
|
||||
.and_where(sea_query::Expr::col((TagsTable::Table, TagsTable::Value)).eq(ident))
|
||||
.and_where(
|
||||
sea_query::Expr::col((TagsTable::Table, TagsTable::Value)).eq(ident),
|
||||
)
|
||||
.and_where(
|
||||
sea_query::Expr::col((EventsTable::Table, EventsTable::CreatedAt))
|
||||
.gte(timestamp.as_i64()),
|
||||
|
@ -1200,11 +1210,12 @@ impl NostrSqlite {
|
|||
let mut rows = stmt.query(&*value.as_params()).unwrap();
|
||||
|
||||
if let Ok(Some(record)) = rows.next() {
|
||||
return Ok(false)
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
})
|
||||
},
|
||||
)
|
||||
.await
|
||||
else {
|
||||
return Err(Error::internal_with_message(
|
||||
|
@ -1272,7 +1283,8 @@ impl NostrDatabase for NostrSqlite {
|
|||
coordinate: &Coordinate,
|
||||
timestamp: Timestamp,
|
||||
) -> Result<bool, Self::Err> {
|
||||
self.has_coordinate_been_deleted(coordinate, timestamp).await
|
||||
self.has_coordinate_been_deleted(coordinate, timestamp)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Set [`EventId`] as seen by relay
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Config {
|
|||
"contact": "klink@zhitno.st",
|
||||
"name": "zhitno.st",
|
||||
"description": "Very *special* nostr relay",
|
||||
"supported_nips": [ 1, 9, 11, 12, 15, 16, 20, 22, 28, 33, 45 ],
|
||||
"supported_nips": [ 1, 2, 9, 11, 12, 15, 16, 20, 22, 28, 33, 40, 45 ],
|
||||
"software": "git+https://git.zhitno.st/Klink/sneedstr.git",
|
||||
"version": "0.1.0"
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue