This commit is contained in:
2025-05-30 20:29:57 +08:00
parent 034fd4a3c5
commit 2785fa3932
+20 -7
View File
@@ -3,7 +3,6 @@ use anyhow::anyhow;
use futures_util::{SinkExt, StreamExt};
use hex;
use log::{Level, debug, error, info, log_enabled};
use rand::rand_core::le;
use secp256k1::{Message as SecpMessage, PublicKey, Secp256k1, ecdsa::Signature};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
@@ -14,15 +13,12 @@ use sqlx::Row;
use sqlx::query;
use sqlx::sqlite::SqlitePool;
use std::env;
use std::error::Error;
use std::result;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::mpsc;
use tokio::{
net::{TcpListener, TcpStream},
sync::broadcast,
};
use tokio_tungstenite::tungstenite::Utf8Bytes;
use tokio_tungstenite::{WebSocketStream, accept_async, tungstenite::protocol::Message};
use uuid::Uuid;
@@ -259,12 +255,29 @@ impl NostrEvent {
async fn save(&self, pool: &SqlitePool) -> Result<(), sqlx::Error> {
let tags_json = serde_json::to_string(&self.tags).unwrap();
if self.kind == 3 {
let sql = "DELETE FROM events WHERE id = ? AND kind = 3";
sqlx::query(sql)
match self.kind {
3 => {
let sql = "DELETE FROM events WHERE id = ? AND kind = 3";
sqlx::query(sql)
.bind(&self.id)
.execute(pool)
.await?;
}
5 => {
if !self.tags.is_empty() {
for tag in &self.tags {
if tag.get(0).map(|s| s == "e").unwrap_or(false) && tag.len() > 1 {
let sql = "DELETE FROM events WHERE id = ?";
sqlx::query(sql)
.bind(&tag[1])
.execute(pool)
.await?;
}
}
}
}
_ => {}
}
let sql = "INSERT INTO events (id, pubkey, created_at, kind, tags, content, sig) VALUES (?, ?, ?, ?, ?, ?, ?)";
sqlx::query(sql)