make source and content have mime_type fields (not yet connected to JSON parser)

master
teknomunk 1 year ago
parent 1fb3f84b9b
commit b2110eece3

@ -174,7 +174,7 @@ static bool route_emoji_react( struct ap_activity* act )
struct account* reactor = lookup_actor_account(act);
if( !s || !reactor ) { return false; }
status_add_react( s, act->content, reactor );
status_add_react( s, act->content.value, reactor );
return true;
}

@ -35,6 +35,10 @@ struct ap_activity* ap_activity_dup( struct ap_activity* act )
new_act->actor = strdup(act->actor);
new_act->published = act->published;
if( act->source.value ) {
new_act->source.value = strdup(act->source.value);
}
array_dup( &new_act->to, sizeof(char*), &act->to );
for( int i = 0; i < new_act->to.count; ++i ) {
new_act->to.items[i] = strdup(new_act->to.items[i]);
@ -84,7 +88,8 @@ void ap_activity_free_composite( struct ap_activity* act )
{
free(act->id);
free(act->actor);
free(act->content);
free(act->content.value);
free(act->source.value);
for( int i = 0; i < act->to.count; ++i ) {
free(act->to.items[i]);
@ -161,7 +166,7 @@ struct ap_activity* ap_activity_create_emoji_react( struct status* s, const char
act->id = aformat( "https://%s/activity/%d", g_server_name, id );
act->actor = aformat( "https://%s/owner/actor", g_server_name );
act->type = apat_emoji_react;
act->content = strdup(react);
act->content.value = strdup(react);
act->published = time(NULL);
act->object.tag = apaot_ref;
act->object.ref = strdup( s->url );

@ -73,10 +73,18 @@ struct ap_activity
char* attributed_to;
char* content;
struct {
char* value;
char* mime_type;
} content;
char* conversation;
time_t published;
char* source;
struct {
char* value;
char* mime_type;
} source;
char* summary;
bool sensitive;

@ -64,33 +64,66 @@ struct json_object_field signature_types[] = {
{ NULL },
};
struct json_object_field ap_activity_layout[] = {
{ "@context", offsetof( struct ap_activity, ap_context ), false, &ap_activity_context_type },
{ "id", offsetof( struct ap_activity, id ), true, &json_field_string },
{ "actor", offsetof( struct ap_activity, actor ), true, &json_field_string },
{ "state", offsetof( struct ap_activity, state ), false, &json_field_string },
{ "content", offsetof( struct ap_activity, content ), false, &json_field_string },
{ "conversation", offsetof( struct ap_activity, conversation ), false, &json_field_string },
{ "published", offsetof( struct ap_activity, published ), false, &json_field_date_time },
{ "sensitive", offsetof( struct ap_activity, sensitive ), false, &json_field_bool_or_null },
{ "source", offsetof( struct ap_activity, source ), false, &json_field_string },
{ "summary", offsetof( struct ap_activity, summary), false, &json_field_string },
{ "tag", offsetof( struct ap_activity, tags ), false, &json_field_array_of, &ap_activity_tag_type },
{ "context", offsetof( struct ap_activity, context ), false, &json_field_string },
//{ "context_id", offsetof( struct ap_activity, context_id ), false, &json_field_integer },
{ "attributedTo", offsetof( struct ap_activity, attributed_to ), false, &json_field_string },
#define OBJ_TYPE struct ap_activity
struct json_object_field ap_activity_layout[] = {
{
.key = "@context",
.offset = offsetof( OBJ_TYPE, ap_context ),
.required = false,
.type = &ap_activity_context_type
},
JSON_FIELD_STRING(id,true),
JSON_FIELD_STRING(actor,true),
JSON_FIELD_STRING(state,false),
{
.key = "content",
.offset = offsetof( struct ap_activity, content.value ),
.required = false,
.type = &json_field_string
},
JSON_FIELD_STRING(conversation,false),
JSON_FIELD_DATETIME(published,false),
{
.key = "sensitive",
.offset = offsetof( struct ap_activity, sensitive ),
.required = false,
.type = &json_field_bool_or_null
},
{
.key = "source",
.offset = offsetof( struct ap_activity, source.value ),
.required = false,
.type = &json_field_string
},
JSON_FIELD_STRING(summary,false),
{
.key = "tag",
.offset = offsetof( struct ap_activity, tags ),
.required = false,
.type = &json_field_array_of,
.type_data = &ap_activity_tag_type
},
JSON_FIELD_STRING(context,false),
{
.key = "attributedTo",
.required = false,
.offset = offsetof(OBJ_TYPE,attributed_to),
.type = &json_field_string,
},
{ "directMessage", offsetof( struct ap_activity, direct_message ), false, &json_field_bool },
{ "attachment", offsetof( struct ap_activity, attachments ), false, &json_field_array_of, &json_field_string },
{ "to", offsetof( struct ap_activity, to ), true, &json_field_array_of, &json_field_string },
{ "cc", offsetof( struct ap_activity, cc ), false, &json_field_array_of, &json_field_string },
{ "bcc", offsetof( struct ap_activity, bcc ), false, &json_field_array_of, &json_field_string },
JSON_FIELD_ARRAY_OF_STRINGS(to,true),
JSON_FIELD_ARRAY_OF_STRINGS(cc,false),
JSON_FIELD_ARRAY_OF_STRINGS(bcc,false),
{ "object", offsetof( struct ap_activity, object.tag ), false, &json_field_tagged_union, &activity_ref_types },
@ -100,6 +133,7 @@ struct json_object_field ap_activity_layout[] = {
{ NULL, 0, true, NULL, &ap_activity_type },
};
#undef OBJ_TYPE
static void ap_activity_free_shim( void* ptr )

@ -97,7 +97,7 @@ static bool status_sync_from_activity_pub( struct status* s, struct ap_activity*
s->published = act->published;
s->remote = true;
s->source = strdup(act->source);
s->source = strdup(act->source.value);
s->url = strdup( act->id );
status_save(s);

Loading…
Cancel
Save