summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c2
-rw-r--r--mastoapi.c47
-rw-r--r--snac.h2
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)
}
-xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
+xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
xs_str *in_reply_to, xs_list *attach, int priv)
/* creates a 'Note' message */
{
diff --git a/mastoapi.c b/mastoapi.c
index 9eaacb9..5ab1282 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1239,7 +1239,52 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
if (strcmp(cmd, "/statuses") == 0) {
if (logged_in) {
/* post a new Note */
- /* TBD */
+/* {
+ xs *j = xs_json_dumps_pp(args, 4);
+ printf("%s\n", j);
+ }*/
+ const char *content = xs_dict_get(args, "status");
+ const char *mid = xs_dict_get(args, "in_reply_to_id");
+ const char *visibility = xs_dict_get(args, "visibility");
+ const char *summary = xs_dict_get(args, "spoiler_text");
+
+ xs *attach_list = xs_list_new();
+ char *irt = NULL;
+
+ /* is it a reply? */
+ if (mid != NULL) {
+ xs *r_msg = NULL;
+ const char *md5 = MID_TO_MD5(mid);
+
+ if (valid_status(object_get_by_md5(md5, &r_msg)))
+ irt = xs_dict_get(r_msg, "id");
+ }
+
+ /* prepare the message */
+ xs *msg = msg_note(&snac, content, NULL, irt, attach_list,
+ strcmp(visibility, "public") == 0 ? 0 : 1);
+
+ if (!xs_is_null(summary) && *summary) {
+ xs *t = xs_val_new(XSTYPE_TRUE);
+ msg = xs_dict_set(msg, "sensitive", t);
+ msg = xs_dict_set(msg, "summary", summary);
+ }
+
+ /* store */
+ timeline_add(&snac, xs_dict_get(msg, "id"), msg);
+
+ /* 'Create' message */
+ xs *c_msg = msg_create(&snac, msg);
+ enqueue_message(&snac, c_msg);
+
+ timeline_touch(&snac);
+
+ /* convert to a mastodon status as a response code */
+ xs *st = mastoapi_status(&snac, msg);
+
+ *body = xs_json_dumps_pp(st, 4);
+ *ctype = "application/json";
+ status = 200;
}
else
status = 401;
diff --git a/snac.h b/snac.h
index d65b5ac..2ab4402 100644
--- a/snac.h
+++ b/snac.h
@@ -190,7 +190,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type);
d_char *msg_create(snac *snac, char *object);
d_char *msg_follow(snac *snac, char *actor);
-xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
+xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
xs_str *in_reply_to, xs_list *attach, int priv);
d_char *msg_undo(snac *snac, char *object);