ssb: Add a command-line action to generate an invite, and verified that Patchwork can accept it.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 26m50s

This commit is contained in:
2025-01-19 21:00:38 -05:00
parent 97fc22ce57
commit 3f3deb665c
4 changed files with 128 additions and 39 deletions

View File

@ -2170,14 +2170,10 @@ bool tf_ssb_db_generate_invite(sqlite3* db, const char* id, const char* host, in
bool inserted = false;
sqlite3_stmt* statement;
if (sqlite3_prepare(db,
"INSERT INTO invites (invite_public_key, account, use_count, expires) VALUES (?, ?, ?, ?)",
-1, &statement, NULL) == SQLITE_OK)
if (sqlite3_prepare(db, "INSERT INTO invites (invite_public_key, account, use_count, expires) VALUES (?, ?, ?, ?)", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, public, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 2, id, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int(statement, 3, use_count) == SQLITE_OK &&
sqlite3_bind_int64(statement, 4, (int64_t)time(NULL) + expires_seconds) == SQLITE_OK)
if (sqlite3_bind_text(statement, 1, public, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, id, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int(statement, 3, use_count) == SQLITE_OK && sqlite3_bind_int64(statement, 4, (int64_t)time(NULL) + expires_seconds) == SQLITE_OK)
{
inserted = sqlite3_step(statement) == SQLITE_DONE;
}
@ -2192,15 +2188,12 @@ bool tf_ssb_db_use_invite(sqlite3* db, const char* id)
{
bool used = false;
sqlite3_stmt* statement;
if (sqlite3_prepare(db,
"UPDATE invites SET use_count = use_count - 1 WHERE invite_public_key = ? AND expires > ? AND (use_count > 0 OR use_count = -1)",
-1, &statement, NULL) == SQLITE_OK)
if (sqlite3_prepare(db, "UPDATE invites SET use_count = use_count - 1 WHERE invite_public_key = ? AND expires > ? AND (use_count > 0 OR use_count = -1)", -1, &statement,
NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int64(statement, 2, (int64_t)time(NULL)) == SQLITE_OK)
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, (int64_t)time(NULL)) == SQLITE_OK)
{
used = sqlite3_step(statement) == SQLITE_DONE &&
sqlite3_changes(db) > 0;
used = sqlite3_step(statement) == SQLITE_DONE && sqlite3_changes(db) > 0;
}
sqlite3_finalize(statement);
}