From acc467c0346535f9f71b62bf68cbfbea7d1db0ee Mon Sep 17 00:00:00 2001 From: default Date: Mon, 26 Sep 2022 10:08:14 +0200 Subject: [PATCH] New function msg_admiration(). --- activitypub.c | 20 ++++++++++++++++++++ data.c | 2 +- main.c | 11 +++++++++++ snac.h | 2 ++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/activitypub.c b/activitypub.c index f08c44c..091e4bf 100644 --- a/activitypub.c +++ b/activitypub.c @@ -191,6 +191,26 @@ d_char *msg_update(snac *snac, char *object) } +d_char *msg_admiration(snac *snac, char *object, char *type) +/* creates a Like or Announce message */ +{ + xs *ntid = tid(0); + xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type); + d_char *msg = msg_base(snac, type, id, snac->actor, ""); + xs *rcpts = xs_list_new(); + + /* call the object */ + timeline_request(snac, object, snac->actor); + + rcpts = xs_list_append(rcpts, public_address); + + msg = xs_dict_append(msg, "to", rcpts); + msg = xs_dict_append(msg, "object", object); + + return msg; +} + + d_char *msg_actor(snac *snac) /* create a Person message for this actor */ { diff --git a/data.c b/data.c index 3df09dd..ac6e225 100644 --- a/data.c +++ b/data.c @@ -554,7 +554,7 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer md = xs_dict_set(md, "parent", parent); if (!xs_is_null(referrer)) - md = xs_dict_set(md, "parent", referrer); + md = xs_dict_set(md, "referrer", referrer); msg = xs_dict_set(msg, "_snac", md); diff --git a/main.c b/main.c index acd9ef2..8efbc36 100644 --- a/main.c +++ b/main.c @@ -116,6 +116,17 @@ int main(int argc, char *argv[]) if ((url = GET_ARGV()) == NULL) return usage(); + if (strcmp(cmd, "announce") == 0) { + xs *msg = msg_admiration(&snac, url, "Announce"); + + { + xs *j = xs_json_dumps_pp(msg, 4); + printf("%s\n", j); + } + + return 0; + } + if (strcmp(cmd, "request") == 0) { int status; xs *data = NULL; diff --git a/snac.h b/snac.h index 40fda20..f39e383 100644 --- a/snac.h +++ b/snac.h @@ -87,6 +87,8 @@ int webfinger_request(char *qs, char **actor, char **user); int webfinger_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype); +d_char *msg_admiration(snac *snac, char *object, char *type); + int activitypub_request(snac *snac, char *url, d_char **data); int actor_request(snac *snac, char *actor, d_char **data); int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);