commit 81100cb

default  ·  2023-04-15 17:05:26 +0000 UTC
parent 5ec593d
Posts can now be sent (still no images).
3 files changed,  +48, -3
M snac.h
+1, -1
1@@ -695,7 +695,7 @@ d_char *msg_follow(snac *snac, char *url_or_uid)
2 }
3 
4 
5-xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
6+xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
7                   xs_str *in_reply_to, xs_list *attach, int priv)
8 /* creates a 'Note' message */
9 {
+46, -1
 1@@ -1239,7 +1239,52 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
 2     if (strcmp(cmd, "/statuses") == 0) {
 3         if (logged_in) {
 4             /* post a new Note */
 5-            /* TBD */
 6+/*    {
 7+        xs *j = xs_json_dumps_pp(args, 4);
 8+        printf("%s\n", j);
 9+    }*/
10+            const char *content    = xs_dict_get(args, "status");
11+            const char *mid        = xs_dict_get(args, "in_reply_to_id");
12+            const char *visibility = xs_dict_get(args, "visibility");
13+            const char *summary    = xs_dict_get(args, "spoiler_text");
14+
15+            xs *attach_list = xs_list_new();
16+            char *irt = NULL;
17+
18+            /* is it a reply? */
19+            if (mid != NULL) {
20+                xs *r_msg = NULL;
21+                const char *md5 = MID_TO_MD5(mid);
22+
23+                if (valid_status(object_get_by_md5(md5, &r_msg)))
24+                    irt = xs_dict_get(r_msg, "id");
25+            }
26+
27+            /* prepare the message */
28+            xs *msg = msg_note(&snac, content, NULL, irt, attach_list,
29+                        strcmp(visibility, "public") == 0 ? 0 : 1);
30+
31+            if (!xs_is_null(summary) && *summary) {
32+                xs *t = xs_val_new(XSTYPE_TRUE);
33+                msg = xs_dict_set(msg, "sensitive", t);
34+                msg = xs_dict_set(msg, "summary",   summary);
35+            }
36+
37+            /* store */
38+            timeline_add(&snac, xs_dict_get(msg, "id"), msg);
39+
40+            /* 'Create' message */
41+            xs *c_msg = msg_create(&snac, msg);
42+            enqueue_message(&snac, c_msg);
43+
44+            timeline_touch(&snac);
45+
46+            /* convert to a mastodon status as a response code */
47+            xs *st = mastoapi_status(&snac, msg);
48+
49+            *body  = xs_json_dumps_pp(st, 4);
50+            *ctype = "application/json";
51+            status = 200;
52         }
53         else
54             status = 401;
M snac.h
+1, -1
1@@ -190,7 +190,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type);
2 d_char *msg_create(snac *snac, char *object);
3 d_char *msg_follow(snac *snac, char *actor);
4 
5-xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
6+xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
7                   xs_str *in_reply_to, xs_list *attach, int priv);
8 
9 d_char *msg_undo(snac *snac, char *object);