Support deleting identities, too.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4736 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-06 19:22:49 +00:00
parent ebc4533b10
commit 39c942a205
6 changed files with 118 additions and 24 deletions

View File

@ -139,6 +139,27 @@ static JSValue _tf_ssb_addIdentity(JSContext* context, JSValueConst this_val, in
return result;
}
static JSValue _tf_ssb_deleteIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
JSValue result = JS_UNDEFINED;
if (ssb)
{
const char* user = JS_ToCString(context, argv[0]);
const char* id = JS_ToCString(context, argv[1]);
if (id && user)
{
if (tf_ssb_db_identity_delete(ssb, user, *id == '@' ? id + 1 : id))
{
result = JS_TRUE;
}
}
JS_FreeCString(context, id);
JS_FreeCString(context, user);
}
return result;
}
static JSValue _set_server_following_internal(tf_ssb_t* ssb, JSValueConst this_val, JSValue id, JSValue following)
{
JSContext* context = tf_ssb_get_context(ssb);
@ -1720,6 +1741,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
/* Requires an identity. */
JS_SetPropertyStr(context, object, "createIdentity", JS_NewCFunction(context, _tf_ssb_createIdentity, "createIdentity", 1));
JS_SetPropertyStr(context, object, "addIdentity", JS_NewCFunction(context, _tf_ssb_addIdentity, "addIdentity", 2));
JS_SetPropertyStr(context, object, "deleteIdentity", JS_NewCFunction(context, _tf_ssb_deleteIdentity, "deleteIdentity", 2));
JS_SetPropertyStr(context, object, "setServerFollowingMe", JS_NewCFunction(context, _tf_ssb_set_server_following_me, "setServerFollowingMe", 3));
JS_SetPropertyStr(context, object, "getIdentities", JS_NewCFunction(context, _tf_ssb_getIdentities, "getIdentities", 1));
JS_SetPropertyStr(context, object, "getPrivateKey", JS_NewCFunction(context, _tf_ssb_getPrivateKey, "getPrivateKey", 2));