More message work.

This commit is contained in:
default 2022-09-24 11:04:35 +02:00
parent ea57b47264
commit a7202dcd1c

View file

@ -117,7 +117,7 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
/** messages **/ /** messages **/
d_char *msg_base(snac *snac, char *type, char *id, char *actor) d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date)
/* creates a base ActivityPub message */ /* creates a base ActivityPub message */
{ {
d_char *msg = xs_dict_new(); d_char *msg = xs_dict_new();
@ -128,12 +128,12 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor)
if (id != NULL) if (id != NULL)
msg = xs_dict_append(msg, "id", id); msg = xs_dict_append(msg, "id", id);
if (actor != NULL) { if (actor != NULL)
/* if actor is "", replace it with this actor */
if (actor[0] == '\0')
actor = snac->actor;
msg = xs_dict_append(msg, "actor", actor); msg = xs_dict_append(msg, "actor", actor);
if (date != NULL) {
xs *published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ");
msg = xs_dict_append(msg, "published", published);
} }
return msg; return msg;
@ -143,7 +143,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor)
d_char *msg_collection(snac *snac, char *id) d_char *msg_collection(snac *snac, char *id)
/* creates an empty OrderedCollection message */ /* creates an empty OrderedCollection message */
{ {
d_char *msg = msg_base(snac, "OrderedCollection", id, NULL); d_char *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL);
xs *ol = xs_list_new(); xs *ol = xs_list_new();
xs *nz = xs_number_new(0); xs *nz = xs_number_new(0);
@ -155,6 +155,18 @@ d_char *msg_collection(snac *snac, char *id)
} }
d_char *msg_update(snac *snac, char *object)
{
xs *id = xs_fmt("%s/Update", xs_dict_get(object, "id"));
d_char *msg = msg_base(snac, "Update", id, snac->actor, "");
msg = xs_dict_append(msg, "to", public_address);
msg = xs_dict_append(msg, "object", object);
return msg;
}
/** queues **/ /** queues **/
void process_message(snac *snac, char *msg, char *req) void process_message(snac *snac, char *msg, char *req)
@ -248,7 +260,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
char *headers = xs_dict_get(req, "headers"); char *headers = xs_dict_get(req, "headers");
char *accept = xs_dict_get(headers, "accept"); char *accept = xs_dict_get(headers, "accept");
snac snac; snac snac;
xs *msg = xs_dict_new(); xs *msg = NULL;
if (accept == NULL) if (accept == NULL)
return 400; return 400;
@ -276,6 +288,9 @@ int activitypub_get_handler(d_char *req, char *q_path,
if (strcmp(p_path, "outbox") == 0) { if (strcmp(p_path, "outbox") == 0) {
xs *id = xs_fmt("%s/outbox", snac.actor); xs *id = xs_fmt("%s/outbox", snac.actor);
msg = msg_collection(&snac, id); msg = msg_collection(&snac, id);
/* replace the 'orderedItems' with the latest posts */
/* ... */
} }
else else
if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {
@ -288,7 +303,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
else else
status = 404; status = 404;
if (status == 200) { if (status == 200 && msg != NULL) {
*body = xs_json_dumps_pp(msg, 4); *body = xs_json_dumps_pp(msg, 4);
*b_size = strlen(*body); *b_size = strlen(*body);
} }