mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Added some experimental 'Question' posting code.
This commit is contained in:
parent
9bc4825507
commit
0d8a040d90
4 changed files with 54 additions and 25 deletions
|
@ -678,14 +678,22 @@ d_char *msg_actor(snac *snac)
|
|||
}
|
||||
|
||||
|
||||
d_char *msg_create(snac *snac, char *object)
|
||||
xs_dict *msg_create(snac *snac, const xs_dict *object)
|
||||
/* creates a 'Create' message */
|
||||
{
|
||||
d_char *msg = msg_base(snac, "Create", "@object", snac->actor, "@now", object);
|
||||
xs_dict *msg = msg_base(snac, "Create", "@object", snac->actor, "@now", object);
|
||||
xs_val *v;
|
||||
|
||||
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"));
|
||||
if ((v = xs_dict_get(object, "attributedTo")))
|
||||
msg = xs_dict_append(msg, "attributedTo", v);
|
||||
|
||||
if ((v = xs_dict_get(object, "cc")))
|
||||
msg = xs_dict_append(msg, "cc", v);
|
||||
|
||||
if ((v = xs_dict_get(object, "to")))
|
||||
msg = xs_dict_append(msg, "to", v);
|
||||
else
|
||||
msg = xs_dict_append(msg, "to", public_address);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@ -951,7 +959,7 @@ xs_dict *msg_question(snac *user, const char *content, const xs_list *opts, int
|
|||
time_t t = time(NULL) + end_secs;
|
||||
xs *et = xs_str_utctime(t, "%Y-%m-%dT%H:%M:%SZ");
|
||||
|
||||
msg = xs_dict_append(msg, "endTime", msg);
|
||||
msg = xs_dict_append(msg, "endTime", et);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
|
4
html.c
4
html.c
|
@ -852,7 +852,9 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
|
|||
#endif
|
||||
|
||||
{
|
||||
xs *c = sanitize(xs_dict_get(msg, "content"));
|
||||
const char *content = xs_dict_get(msg, "content");
|
||||
|
||||
xs *c = sanitize(xs_is_null(content) ? "" : content);
|
||||
char *p, *v;
|
||||
|
||||
/* do some tweaks to the content */
|
||||
|
|
53
main.c
53
main.c
|
@ -30,6 +30,7 @@ int usage(void)
|
|||
printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
|
||||
printf("resetpwd {basedir} {uid} Resets the password of a user\n");
|
||||
printf("ping {basedir} {uid} {actor} Pings an actor\n");
|
||||
/* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -63,7 +64,7 @@ int main(int argc, char *argv[])
|
|||
if ((cmd = GET_ARGV()) == NULL)
|
||||
return usage();
|
||||
|
||||
if (strcmp(cmd, "init") == 0) {
|
||||
if (strcmp(cmd, "init") == 0) { /** **/
|
||||
/* initialize the data storage */
|
||||
/* ... */
|
||||
basedir = GET_ARGV();
|
||||
|
@ -71,7 +72,7 @@ int main(int argc, char *argv[])
|
|||
return snac_init(basedir);
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "upgrade") == 0) {
|
||||
if (strcmp(cmd, "upgrade") == 0) { /** **/
|
||||
int ret;
|
||||
|
||||
/* upgrade */
|
||||
|
@ -84,7 +85,7 @@ int main(int argc, char *argv[])
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "markdown") == 0) {
|
||||
if (strcmp(cmd, "markdown") == 0) { /** **/
|
||||
/* undocumented, for testing only */
|
||||
xs *c = xs_readall(stdin);
|
||||
xs *fc = not_really_markdown(c, NULL);
|
||||
|
@ -101,7 +102,7 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "adduser") == 0) {
|
||||
if (strcmp(cmd, "adduser") == 0) { /** **/
|
||||
user = GET_ARGV();
|
||||
|
||||
return adduser(user);
|
||||
|
@ -109,13 +110,13 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "httpd") == 0) {
|
||||
if (strcmp(cmd, "httpd") == 0) { /** **/
|
||||
httpd();
|
||||
srv_free();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "purge") == 0) {
|
||||
if (strcmp(cmd, "purge") == 0) { /** **/
|
||||
purge_all();
|
||||
return 0;
|
||||
}
|
||||
|
@ -123,7 +124,7 @@ int main(int argc, char *argv[])
|
|||
if ((user = GET_ARGV()) == NULL)
|
||||
return usage();
|
||||
|
||||
if (strcmp(cmd, "webfinger") == 0) {
|
||||
if (strcmp(cmd, "webfinger") == 0) { /** **/
|
||||
xs *actor = NULL;
|
||||
xs *uid = NULL;
|
||||
int status;
|
||||
|
@ -146,16 +147,16 @@ int main(int argc, char *argv[])
|
|||
|
||||
lastlog_write(&snac, "cmdline");
|
||||
|
||||
if (strcmp(cmd, "resetpwd") == 0) {
|
||||
if (strcmp(cmd, "resetpwd") == 0) { /** **/
|
||||
return resetpwd(&snac);
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "queue") == 0) {
|
||||
if (strcmp(cmd, "queue") == 0) { /** **/
|
||||
process_user_queue(&snac);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "timeline") == 0) {
|
||||
if (strcmp(cmd, "timeline") == 0) { /** **/
|
||||
#if 0
|
||||
xs *list = local_list(&snac, XS_ALL);
|
||||
xs *body = html_timeline(&snac, list, 1);
|
||||
|
@ -178,7 +179,7 @@ int main(int argc, char *argv[])
|
|||
if ((url = GET_ARGV()) == NULL)
|
||||
return usage();
|
||||
|
||||
if (strcmp(cmd, "announce") == 0) {
|
||||
if (strcmp(cmd, "announce") == 0) { /** **/
|
||||
xs *msg = msg_admiration(&snac, url, "Announce");
|
||||
|
||||
if (msg != NULL) {
|
||||
|
@ -193,7 +194,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "follow") == 0) {
|
||||
if (strcmp(cmd, "follow") == 0) { /** **/
|
||||
xs *msg = msg_follow(&snac, url);
|
||||
|
||||
if (msg != NULL) {
|
||||
|
@ -212,7 +213,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "unfollow") == 0) {
|
||||
if (strcmp(cmd, "unfollow") == 0) { /** **/
|
||||
xs *object = NULL;
|
||||
|
||||
if (valid_status(following_get(&snac, url, &object))) {
|
||||
|
@ -230,7 +231,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "ping") == 0) {
|
||||
if (strcmp(cmd, "ping") == 0) { /** **/
|
||||
xs *actor_o = NULL;
|
||||
|
||||
if (valid_status(actor_request(&snac, url, &actor_o))) {
|
||||
|
@ -251,7 +252,25 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "request") == 0) {
|
||||
if (strcmp(cmd, "question") == 0) { /** **/
|
||||
xs *opts = xs_split(url, ";");
|
||||
|
||||
xs *msg = msg_question(&snac, "Poll", opts, 0, 5 * 60);
|
||||
xs *c_msg = msg_create(&snac, msg);
|
||||
|
||||
if (dbglevel) {
|
||||
xs *j = xs_json_dumps_pp(c_msg, 4);
|
||||
printf("%s\n", j);
|
||||
}
|
||||
|
||||
enqueue_message(&snac, c_msg);
|
||||
|
||||
timeline_add(&snac, xs_dict_get(msg, "id"), msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "request") == 0) { /** **/
|
||||
int status;
|
||||
xs *data = NULL;
|
||||
|
||||
|
@ -267,7 +286,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "actor") == 0) {
|
||||
if (strcmp(cmd, "actor") == 0) { /** **/
|
||||
int status;
|
||||
xs *data = NULL;
|
||||
|
||||
|
@ -283,7 +302,7 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "note") == 0) {
|
||||
if (strcmp(cmd, "note") == 0) { /** **/
|
||||
xs *content = NULL;
|
||||
xs *msg = NULL;
|
||||
xs *c_msg = NULL;
|
||||
|
|
2
snac.h
2
snac.h
|
@ -193,7 +193,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
|
|||
const char *default_avatar_base64(void);
|
||||
|
||||
d_char *msg_admiration(snac *snac, char *object, char *type);
|
||||
d_char *msg_create(snac *snac, char *object);
|
||||
xs_dict *msg_create(snac *snac, const xs_dict *object);
|
||||
xs_dict *msg_follow(snac *snac, const char *actor);
|
||||
|
||||
xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
|
||||
|
|
Loading…
Reference in a new issue