ssb: Invite support progress. Now the pub accepts the invite, tracks its use, and follows. The client still needs to react.

This commit is contained in:
2025-01-19 17:02:08 -05:00
parent faca63946c
commit 616f3ad76d
3 changed files with 163 additions and 6 deletions

View File

@ -2164,7 +2164,6 @@ bool tf_ssb_db_generate_invite(sqlite3* db, const char* id, const char* host, in
char public[k_id_base64_len];
tf_ssb_id_bin_to_str(public, sizeof(public), public_key);
tf_printf("invite is for public key %s\n", public);
char seed_b64[64];
tf_base64_encode(seed, sizeof(seed), seed_b64, sizeof(seed_b64));
@ -2188,3 +2187,22 @@ bool tf_ssb_db_generate_invite(sqlite3* db, const char* id, const char* host, in
snprintf(out_invite, size, "%s:%d:%s~%s", host, port, id, seed_b64);
return inserted;
}
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_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;
}
sqlite3_finalize(statement);
}
return used;
}