diff options
| author | 2023-04-15 19:05:26 +0200 | |
|---|---|---|
| committer | 2023-04-15 19:05:26 +0200 | |
| commit | 81100cb825853ab7b370e91bdde88bf337bea743 (patch) | |
| tree | ec81bb9efb75d27d31025a7a4647e319230f658e | |
| parent | Force failure in Mastodon API before it gets to a crash-on-startup situation. (diff) | |
| download | penes-snac2-81100cb825853ab7b370e91bdde88bf337bea743.tar.gz penes-snac2-81100cb825853ab7b370e91bdde88bf337bea743.tar.xz penes-snac2-81100cb825853ab7b370e91bdde88bf337bea743.zip | |
Posts can now be sent (still no images).
| -rw-r--r-- | activitypub.c | 2 | ||||
| -rw-r--r-- | mastoapi.c | 47 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 48 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c index 98baf8b..6fa7607 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -695,7 +695,7 @@ d_char *msg_follow(snac *snac, char *url_or_uid) | |||
| 695 | } | 695 | } |
| 696 | 696 | ||
| 697 | 697 | ||
| 698 | xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, | 698 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 699 | xs_str *in_reply_to, xs_list *attach, int priv) | 699 | xs_str *in_reply_to, xs_list *attach, int priv) |
| 700 | /* creates a 'Note' message */ | 700 | /* creates a 'Note' message */ |
| 701 | { | 701 | { |
| @@ -1239,7 +1239,52 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1239 | if (strcmp(cmd, "/statuses") == 0) { | 1239 | if (strcmp(cmd, "/statuses") == 0) { |
| 1240 | if (logged_in) { | 1240 | if (logged_in) { |
| 1241 | /* post a new Note */ | 1241 | /* post a new Note */ |
| 1242 | /* TBD */ | 1242 | /* { |
| 1243 | xs *j = xs_json_dumps_pp(args, 4); | ||
| 1244 | printf("%s\n", j); | ||
| 1245 | }*/ | ||
| 1246 | const char *content = xs_dict_get(args, "status"); | ||
| 1247 | const char *mid = xs_dict_get(args, "in_reply_to_id"); | ||
| 1248 | const char *visibility = xs_dict_get(args, "visibility"); | ||
| 1249 | const char *summary = xs_dict_get(args, "spoiler_text"); | ||
| 1250 | |||
| 1251 | xs *attach_list = xs_list_new(); | ||
| 1252 | char *irt = NULL; | ||
| 1253 | |||
| 1254 | /* is it a reply? */ | ||
| 1255 | if (mid != NULL) { | ||
| 1256 | xs *r_msg = NULL; | ||
| 1257 | const char *md5 = MID_TO_MD5(mid); | ||
| 1258 | |||
| 1259 | if (valid_status(object_get_by_md5(md5, &r_msg))) | ||
| 1260 | irt = xs_dict_get(r_msg, "id"); | ||
| 1261 | } | ||
| 1262 | |||
| 1263 | /* prepare the message */ | ||
| 1264 | xs *msg = msg_note(&snac, content, NULL, irt, attach_list, | ||
| 1265 | strcmp(visibility, "public") == 0 ? 0 : 1); | ||
| 1266 | |||
| 1267 | if (!xs_is_null(summary) && *summary) { | ||
| 1268 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 1269 | msg = xs_dict_set(msg, "sensitive", t); | ||
| 1270 | msg = xs_dict_set(msg, "summary", summary); | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | /* store */ | ||
| 1274 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 1275 | |||
| 1276 | /* 'Create' message */ | ||
| 1277 | xs *c_msg = msg_create(&snac, msg); | ||
| 1278 | enqueue_message(&snac, c_msg); | ||
| 1279 | |||
| 1280 | timeline_touch(&snac); | ||
| 1281 | |||
| 1282 | /* convert to a mastodon status as a response code */ | ||
| 1283 | xs *st = mastoapi_status(&snac, msg); | ||
| 1284 | |||
| 1285 | *body = xs_json_dumps_pp(st, 4); | ||
| 1286 | *ctype = "application/json"; | ||
| 1287 | status = 200; | ||
| 1243 | } | 1288 | } |
| 1244 | else | 1289 | else |
| 1245 | status = 401; | 1290 | status = 401; |
| @@ -190,7 +190,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type); | |||
| 190 | d_char *msg_create(snac *snac, char *object); | 190 | d_char *msg_create(snac *snac, char *object); |
| 191 | d_char *msg_follow(snac *snac, char *actor); | 191 | d_char *msg_follow(snac *snac, char *actor); |
| 192 | 192 | ||
| 193 | xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, | 193 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 194 | xs_str *in_reply_to, xs_list *attach, int priv); | 194 | xs_str *in_reply_to, xs_list *attach, int priv); |
| 195 | 195 | ||
| 196 | d_char *msg_undo(snac *snac, char *object); | 196 | d_char *msg_undo(snac *snac, char *object); |