Converts pubkey to pubkey hash on vanish events.
This commit is contained in:
+13
-11
@@ -24,20 +24,22 @@ import android.database.sqlite.SQLiteDatabase
|
|||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
||||||
|
|
||||||
class RightToVanishModule : IModule {
|
class RightToVanishModule(
|
||||||
|
val hasher: (db: SQLiteDatabase) -> TagNameValueHasher,
|
||||||
|
) : IModule {
|
||||||
override fun create(db: SQLiteDatabase) {
|
override fun create(db: SQLiteDatabase) {
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE event_vanish (
|
CREATE TABLE event_vanish (
|
||||||
pubkey TEXT NOT NULL,
|
|
||||||
event_header_row_id INTEGER PRIMARY KEY NOT NULL,
|
event_header_row_id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
pubkey_hash INTEGER NOT NULL,
|
||||||
created_at INTEGER NOT NULL,
|
created_at INTEGER NOT NULL,
|
||||||
FOREIGN KEY (event_header_row_id) REFERENCES event_headers(row_id) ON DELETE CASCADE
|
FOREIGN KEY (event_header_row_id) REFERENCES event_headers(row_id) ON DELETE CASCADE
|
||||||
)
|
)
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
)
|
)
|
||||||
|
|
||||||
db.execSQL("CREATE UNIQUE INDEX event_vanish_key ON event_vanish (pubkey)")
|
db.execSQL("CREATE UNIQUE INDEX event_vanish_key ON event_vanish (pubkey_hash)")
|
||||||
|
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"""
|
"""
|
||||||
@@ -48,8 +50,8 @@ class RightToVanishModule : IModule {
|
|||||||
-- Delete older records if this is the newest
|
-- Delete older records if this is the newest
|
||||||
DELETE FROM event_vanish
|
DELETE FROM event_vanish
|
||||||
WHERE
|
WHERE
|
||||||
event_vanish.created_at < NEW.created_at AND
|
event_vanish.pubkey_hash = NEW.pubkey_hash AND
|
||||||
event_vanish.pubkey = NEW.pubkey;
|
event_vanish.created_at < NEW.created_at;
|
||||||
END;
|
END;
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
)
|
)
|
||||||
@@ -61,8 +63,8 @@ class RightToVanishModule : IModule {
|
|||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
DELETE FROM event_headers
|
DELETE FROM event_headers
|
||||||
WHERE created_at < NEW.created_at AND
|
WHERE event_headers.created_at < NEW.created_at AND
|
||||||
pubkey = NEW.pubkey;
|
event_headers.pubkey_owner_hash = NEW.pubkey_hash;
|
||||||
END;
|
END;
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
)
|
)
|
||||||
@@ -78,8 +80,8 @@ class RightToVanishModule : IModule {
|
|||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1 FROM event_vanish
|
SELECT 1 FROM event_vanish
|
||||||
WHERE
|
WHERE
|
||||||
event_vanish.created_at >= NEW.created_at AND
|
event_vanish.pubkey_hash = NEW.pubkey_owner_hash AND
|
||||||
event_vanish.pubkey = NEW.pubkey
|
event_vanish.created_at >= NEW.created_at
|
||||||
);
|
);
|
||||||
END;
|
END;
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
@@ -92,7 +94,7 @@ class RightToVanishModule : IModule {
|
|||||||
|
|
||||||
val insertRTV =
|
val insertRTV =
|
||||||
"""
|
"""
|
||||||
INSERT OR ROLLBACK INTO event_vanish (event_header_row_id, pubkey, created_at)
|
INSERT OR ROLLBACK INTO event_vanish (event_header_row_id, pubkey_hash, created_at)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@@ -105,7 +107,7 @@ class RightToVanishModule : IModule {
|
|||||||
if (event is RequestToVanishEvent && event.shouldVanishFrom(relayUrl)) {
|
if (event is RequestToVanishEvent && event.shouldVanishFrom(relayUrl)) {
|
||||||
val stmt = db.compileStatement(insertRTV)
|
val stmt = db.compileStatement(insertRTV)
|
||||||
stmt.bindLong(1, headerId)
|
stmt.bindLong(1, headerId)
|
||||||
stmt.bindString(2, event.pubKey)
|
stmt.bindLong(2, hasher(db).hash(event.pubKey))
|
||||||
stmt.bindLong(3, event.createdAt)
|
stmt.bindLong(3, event.createdAt)
|
||||||
stmt.executeInsert()
|
stmt.executeInsert()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ class SQLiteEventStore(
|
|||||||
|
|
||||||
val deletionModule = DeletionRequestModule()
|
val deletionModule = DeletionRequestModule()
|
||||||
val expirationModule = ExpirationModule()
|
val expirationModule = ExpirationModule()
|
||||||
val rightToVanishModule = RightToVanishModule()
|
val rightToVanishModule = RightToVanishModule(seedModule::hasher)
|
||||||
|
|
||||||
val modules =
|
val modules =
|
||||||
listOf(
|
listOf(
|
||||||
|
|||||||
Reference in New Issue
Block a user