createHistoryStream JS -> C.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4110 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
46
src/ssb.db.c
46
src/ssb.db.c
@ -711,7 +711,7 @@ JSValue tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue bi
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_format_message(JSContext* context, const char* previous, const char* author, int64_t sequence, double timestamp, const char* hash, const char* content, const char* signature, bool sequence_before_author)
|
||||
JSValue tf_ssb_format_message(JSContext* context, const char* previous, const char* author, int64_t sequence, double timestamp, const char* hash, const char* content, const char* signature, bool sequence_before_author)
|
||||
{
|
||||
JSValue value = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, value, "previous", previous ? JS_NewString(context, previous) : JS_NULL);
|
||||
@ -779,7 +779,7 @@ bool tf_ssb_db_check(sqlite3* db, const char* check_author)
|
||||
const char* content = (const char*)sqlite3_column_text(statement, 6);
|
||||
const char* signature = (const char*)sqlite3_column_text(statement, 7);
|
||||
bool sequence_before_author = sqlite3_column_int(statement, 8);
|
||||
JSValue message = _tf_ssb_format_message(context, previous, author, sequence, timestamp, hash, content, signature, sequence_before_author);
|
||||
JSValue message = tf_ssb_format_message(context, previous, author, sequence, timestamp, hash, content, signature, sequence_before_author);
|
||||
char out_signature[512];
|
||||
char actual_id[k_id_base64_len];
|
||||
bool actual_sequence_before_author = false;
|
||||
@ -1182,3 +1182,45 @@ void tf_ssb_db_private(sqlite3* db)
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
}
|
||||
|
||||
JSValue tf_ssb_db_get_message_by_id( tf_ssb_t* ssb, const char* id, bool is_keys)
|
||||
{
|
||||
JSValue result = JS_UNDEFINED;
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
sqlite3* db = tf_ssb_get_db(ssb);
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare(db, "SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE id = ?", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
JSValue message = JS_UNDEFINED;
|
||||
JSValue formatted = tf_ssb_format_message(
|
||||
context,
|
||||
(const char*)sqlite3_column_text(statement, 0),
|
||||
(const char*)sqlite3_column_text(statement, 1),
|
||||
sqlite3_column_int64(statement, 3),
|
||||
sqlite3_column_double(statement, 4),
|
||||
(const char*)sqlite3_column_text(statement, 5),
|
||||
(const char*)sqlite3_column_text(statement, 6),
|
||||
(const char*)sqlite3_column_text(statement, 7),
|
||||
sqlite3_column_int(statement, 8));
|
||||
if (is_keys)
|
||||
{
|
||||
message = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, message, "key", JS_NewString(context, (const char*)sqlite3_column_text(statement, 2)));
|
||||
JS_SetPropertyStr(context, message, "value", formatted);
|
||||
JS_SetPropertyStr(context, message, "timestamp", JS_NewString(context, (const char*)sqlite3_column_text(statement, 4)));
|
||||
}
|
||||
else
|
||||
{
|
||||
message = formatted;
|
||||
}
|
||||
result = message;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user