ssb: Add some plausible API and a table for storing instance-wide blocks.

This commit is contained in:
2025-11-27 14:33:57 -05:00
parent 759b522cd1
commit ddc4603f13
4 changed files with 139 additions and 11 deletions

View File

@@ -271,7 +271,6 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
")");
_tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS identities_user ON identities (user, public_key)");
_tf_ssb_db_exec(db, "DELETE FROM identities WHERE user = ':auth'");
_tf_ssb_db_exec(db,
"CREATE TABLE IF NOT EXISTS invites ("
" invite_public_key TEXT PRIMARY KEY,"
@@ -279,6 +278,11 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
" use_count INTEGER,"
" expires INTEGER"
")");
_tf_ssb_db_exec(db,
"CREATE TABLE IF NOT EXISTS blocks ("
" id TEXT PRIMARY KEY,"
" timestamp REAL"
")");
bool populate_fts = false;
if (!_tf_ssb_db_has_rows(db, "PRAGMA table_list('messages_fts')"))
@@ -2868,3 +2872,35 @@ tf_ssb_identity_info_t* tf_ssb_db_get_identity_info(tf_ssb_t* ssb, const char* u
tf_free(info);
return copy;
}
void tf_ssb_db_add_block(sqlite3* db, const char* id)
{
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare_v2(db, "INSERT INTO blocks (id, timestamp) VALUES (?, ?) ON CONFLICT DO NOTHING", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) != SQLITE_DONE)
{
tf_printf("add block: %s\n", sqlite3_errmsg(db));
}
}
sqlite3_finalize(statement);
}
}
void tf_ssb_db_remove_block(sqlite3* db, const char* id)
{
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare_v2(db, "DELETE FROM blocks WHERE id = ?", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) != SQLITE_DONE)
{
tf_printf("remove block: %s\n", sqlite3_errmsg(db));
}
}
sqlite3_finalize(statement);
}
}