forked from cory/tildefriends
Add a callback for when messages are added to the database. Abuse it to forward messages semi-live.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3686 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
21
src/ssb.js.c
21
src/ssb.js.c
@ -456,6 +456,17 @@ static JSValue _tf_ssb_add_rpc(JSContext* context, JSValueConst this_val, int ar
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static void _tf_ssb_on_message_added_callback(tf_ssb_t* ssb, const char* id, void* user_data)
|
||||
{
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
||||
JSValue string = JS_NewString(context, id);
|
||||
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 1, &string);
|
||||
tf_util_report_error(context, response);
|
||||
JS_FreeValue(context, response);
|
||||
JS_FreeValue(context, string);
|
||||
}
|
||||
|
||||
static void _tf_ssb_on_blob_want_added_callback(tf_ssb_t* ssb, const char* id, void* user_data)
|
||||
{
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
@ -606,6 +617,11 @@ static JSValue _tf_ssb_add_event_listener(JSContext* context, JSValueConst this_
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
tf_ssb_add_broadcasts_changed_callback(ssb, _tf_ssb_on_broadcasts_changed_callback, _tf_ssb_cleanup_value, ptr);
|
||||
}
|
||||
else if (strcmp(event_name, "message") == 0)
|
||||
{
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
tf_ssb_add_message_added_callback(ssb, _tf_ssb_on_message_added_callback, _tf_ssb_cleanup_value, ptr);
|
||||
}
|
||||
else if (strcmp(event_name, "blob_want_added") == 0)
|
||||
{
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
@ -644,6 +660,11 @@ static JSValue _tf_ssb_remove_event_listener(JSContext* context, JSValueConst th
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
tf_ssb_remove_broadcasts_changed_callback(ssb, _tf_ssb_on_broadcasts_changed_callback, ptr);
|
||||
}
|
||||
else if (strcmp(event_name, "message_added") == 0)
|
||||
{
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
tf_ssb_remove_message_added_callback(ssb, _tf_ssb_on_message_added_callback, ptr);
|
||||
}
|
||||
else if (strcmp(event_name, "blob_want_added") == 0)
|
||||
{
|
||||
void* ptr = JS_VALUE_GET_PTR(JS_DupValue(context, callback));
|
||||
|
Reference in New Issue
Block a user