mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Notes can be posted WOW!.
This commit is contained in:
parent
f516866f9e
commit
0b6540f503
3 changed files with 97 additions and 11 deletions
|
@ -258,6 +258,7 @@ d_char *msg_actor(snac *snac)
|
|||
xs *keys = xs_dict_new();
|
||||
xs *avtr = NULL;
|
||||
xs *kid = NULL;
|
||||
xs *f_bio = NULL;
|
||||
d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL, NULL);
|
||||
char *p;
|
||||
int n;
|
||||
|
@ -271,10 +272,11 @@ d_char *msg_actor(snac *snac)
|
|||
msg = xs_dict_set(msg, "name", xs_dict_get(snac->config, "name"));
|
||||
msg = xs_dict_set(msg, "preferredUsername", snac->uid);
|
||||
msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published"));
|
||||
msg = xs_dict_set(msg, "summary", xs_dict_get(snac->config, "bio"));
|
||||
|
||||
not_really_markdown(xs_dict_get(snac->config, "bio"), &f_bio);
|
||||
msg = xs_dict_set(msg, "summary", f_bio);
|
||||
|
||||
char *folders[] = { "inbox", "outbox", "followers", "following", NULL };
|
||||
|
||||
for (n = 0; folders[n]; n++) {
|
||||
xs *f = xs_fmt("%s/%s", snac->actor, folders[n]);
|
||||
msg = xs_dict_set(msg, folders[n], f);
|
||||
|
@ -303,6 +305,81 @@ d_char *msg_actor(snac *snac)
|
|||
}
|
||||
|
||||
|
||||
d_char *msg_create(snac *snac, char *object)
|
||||
/* creates a 'Create' message */
|
||||
{
|
||||
d_char *msg = msg_base(snac, "Create", "@object", snac->actor, "@now", object);
|
||||
|
||||
msg = xs_dict_append(msg, "attributedTo", xs_dict_get(object, "attributedTo"));
|
||||
msg = xs_dict_append(msg, "to", xs_dict_get(object, "to"));
|
||||
msg = xs_dict_append(msg, "cc", xs_dict_get(object, "cc"));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to)
|
||||
/* creates a 'Note' message */
|
||||
{
|
||||
xs *ntid = tid(0);
|
||||
xs *id = xs_fmt("%s/p/%s", snac->actor, ntid);
|
||||
xs *ctxt = xs_fmt("%s#ctxt", id);
|
||||
xs *fc1 = NULL;
|
||||
xs *to = NULL;
|
||||
xs *cc = xs_list_new();
|
||||
xs *irt = NULL;
|
||||
xs *tag = NULL;
|
||||
d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
|
||||
char *p, *v;
|
||||
|
||||
if (rcpts == NULL)
|
||||
to = xs_list_new();
|
||||
else
|
||||
to = xs_dup(rcpts);
|
||||
|
||||
/* format the content */
|
||||
not_really_markdown(content, &fc1);
|
||||
|
||||
if (in_reply_to != NULL) {
|
||||
irt = xs_dup(in_reply_to);
|
||||
}
|
||||
else
|
||||
irt = xs_val_new(XSTYPE_NULL);
|
||||
|
||||
if (tag == NULL)
|
||||
tag = xs_list_new();
|
||||
|
||||
/* add all mentions to the cc */
|
||||
p = tag;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
if (xs_type(v) == XSTYPE_DICT) {
|
||||
char *t;
|
||||
|
||||
if ((t = xs_dict_get(v, "type")) != NULL && strcmp(t, "Mention") == 0) {
|
||||
if ((t = xs_dict_get(v, "href")) != NULL)
|
||||
cc = xs_list_append(cc, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no recipients? must be for everybody */
|
||||
if (xs_list_len(to) == 0)
|
||||
to = xs_list_append(to, public_address);
|
||||
|
||||
msg = xs_dict_append(msg, "attributedTo", snac->actor);
|
||||
msg = xs_dict_append(msg, "summary", "");
|
||||
msg = xs_dict_append(msg, "content", fc1);
|
||||
msg = xs_dict_append(msg, "context", ctxt);
|
||||
msg = xs_dict_append(msg, "url", id);
|
||||
msg = xs_dict_append(msg, "to", to);
|
||||
msg = xs_dict_append(msg, "cc", cc);
|
||||
msg = xs_dict_append(msg, "inReplyTo", irt);
|
||||
msg = xs_dict_append(msg, "tag", tag);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
/** queues **/
|
||||
|
||||
void process_message(snac *snac, char *msg, char *req)
|
||||
|
|
15
main.c
15
main.c
|
@ -165,9 +165,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (strcmp(cmd, "note") == 0) {
|
||||
int status;
|
||||
xs *data = NULL;
|
||||
xs *content = NULL;
|
||||
xs *f_content = NULL;
|
||||
xs *msg = NULL;
|
||||
xs *c_msg = NULL;
|
||||
|
||||
if (strcmp(url, "-") == 0) {
|
||||
/* get the content from an editor */
|
||||
|
@ -189,9 +189,16 @@ int main(int argc, char *argv[])
|
|||
else
|
||||
content = xs_dup(url);
|
||||
|
||||
not_really_markdown(content, &f_content);
|
||||
msg = msg_note(&snac, content, NULL, NULL);
|
||||
|
||||
printf("%s\n", f_content);
|
||||
c_msg = msg_create(&snac, msg);
|
||||
|
||||
{
|
||||
xs *j = xs_json_dumps_pp(c_msg, 4);
|
||||
printf("%s\n", j);
|
||||
}
|
||||
|
||||
post(&snac, c_msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
2
snac.h
2
snac.h
|
@ -88,6 +88,8 @@ 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);
|
||||
d_char *msg_create(snac *snac, char *object);
|
||||
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to);
|
||||
|
||||
int activitypub_request(snac *snac, char *url, d_char **data);
|
||||
int actor_request(snac *snac, char *actor, d_char **data);
|
||||
|
|
Loading…
Reference in a new issue