diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 47 |
1 files changed, 46 insertions, 1 deletions
| @@ -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; |