mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
New function msg_follow().
This commit is contained in:
parent
6144e0eeeb
commit
05bf4b2c3c
3 changed files with 55 additions and 5 deletions
|
@ -380,6 +380,34 @@ d_char *msg_create(snac *snac, char *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
d_char *msg_follow(snac *snac, char *actor)
|
||||||
|
/* creates a 'Follow' message */
|
||||||
|
{
|
||||||
|
d_char *actor_o = NULL;
|
||||||
|
d_char *msg = NULL;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
/* request the actor */
|
||||||
|
status = actor_request(snac, actor, &actor_o);
|
||||||
|
|
||||||
|
if (valid_status(status)) {
|
||||||
|
/* check if the actor is an alias */
|
||||||
|
char *r_actor = xs_dict_get(actor_o, "id");
|
||||||
|
|
||||||
|
if (r_actor && strcmp(actor, r_actor) != 0) {
|
||||||
|
snac_log(snac, xs_fmt("actor to follow is an alias %s -> %s", actor, r_actor));
|
||||||
|
actor = r_actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = msg_base(snac, "Follow", "@dummy", snac->actor, NULL, actor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
snac_log(snac, xs_fmt("cannot get actor to follow %s %d", actor, status));
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to)
|
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to)
|
||||||
/* creates a 'Note' message */
|
/* creates a 'Note' message */
|
||||||
{
|
{
|
||||||
|
|
31
main.c
31
main.c
|
@ -19,13 +19,14 @@ int usage(void)
|
||||||
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
||||||
printf("webfinger {basedir} {user} Queries about a @user@host or actor\n");
|
printf("webfinger {basedir} {user} Queries about a @user@host or actor\n");
|
||||||
printf("queue {basedir} {uid} Processes a user queue\n");
|
printf("queue {basedir} {uid} Processes a user queue\n");
|
||||||
|
printf("follow {basedir} {uid} {actor} Follows an actor\n");
|
||||||
|
|
||||||
// printf("check {basedir} [{uid}] Checks the database\n");
|
// printf("check {basedir} [{uid}] Checks the database\n");
|
||||||
// printf("purge {basedir} [{uid}] Purges old data\n");
|
// printf("purge {basedir} [{uid}] Purges old data\n");
|
||||||
// printf("adduser {basedir} [{uid}] Adds a new user\n");
|
// printf("adduser {basedir} [{uid}] Adds a new user\n");
|
||||||
|
|
||||||
// printf("update {basedir} {uid} Sends a user update to followers\n");
|
// printf("update {basedir} {uid} Sends a user update to followers\n");
|
||||||
// printf("passwd {basedir} {uid} Sets the password for {uid}\n");
|
// printf("passwd {basedir} {uid} Sets the password for {uid}\n");
|
||||||
// printf("follow {basedir} {uid} {actor} Follows an actor\n");
|
|
||||||
// printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
|
// printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
|
||||||
// printf("mute {basedir} {uid} {actor} Mutes an actor\n");
|
// printf("mute {basedir} {uid} {actor} Mutes an actor\n");
|
||||||
// printf("unmute {basedir} {uid} {actor} Unmutes an actor\n");
|
// printf("unmute {basedir} {uid} {actor} Unmutes an actor\n");
|
||||||
|
@ -124,8 +125,29 @@ int main(int argc, char *argv[])
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
post(&snac, msg);
|
post(&snac, msg);
|
||||||
|
|
||||||
xs *j = xs_json_dumps_pp(msg, 4);
|
if (dbglevel) {
|
||||||
printf("%s\n", j);
|
xs *j = xs_json_dumps_pp(msg, 4);
|
||||||
|
printf("%s\n", j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(cmd, "follow") == 0) {
|
||||||
|
xs *msg = msg_follow(&snac, url);
|
||||||
|
|
||||||
|
if (msg != NULL) {
|
||||||
|
char *actor = xs_dict_get(msg, "object");
|
||||||
|
|
||||||
|
following_add(&snac, actor, msg);
|
||||||
|
|
||||||
|
enqueue_output(&snac, msg, actor, 0);
|
||||||
|
|
||||||
|
if (dbglevel) {
|
||||||
|
xs *j = xs_json_dumps_pp(msg, 4);
|
||||||
|
printf("%s\n", j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -164,7 +186,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "note") == 0) {
|
if (strcmp(cmd, "note") == 0) {
|
||||||
int status;
|
|
||||||
xs *content = NULL;
|
xs *content = NULL;
|
||||||
xs *msg = NULL;
|
xs *msg = NULL;
|
||||||
xs *c_msg = NULL;
|
xs *c_msg = NULL;
|
||||||
|
@ -194,7 +215,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
c_msg = msg_create(&snac, msg);
|
c_msg = msg_create(&snac, msg);
|
||||||
|
|
||||||
{
|
if (dbglevel) {
|
||||||
xs *j = xs_json_dumps_pp(c_msg, 4);
|
xs *j = xs_json_dumps_pp(c_msg, 4);
|
||||||
printf("%s\n", j);
|
printf("%s\n", j);
|
||||||
}
|
}
|
||||||
|
|
1
snac.h
1
snac.h
|
@ -89,6 +89,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
|
||||||
|
|
||||||
d_char *msg_admiration(snac *snac, char *object, char *type);
|
d_char *msg_admiration(snac *snac, char *object, char *type);
|
||||||
d_char *msg_create(snac *snac, char *object);
|
d_char *msg_create(snac *snac, char *object);
|
||||||
|
d_char *msg_follow(snac *snac, char *actor);
|
||||||
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to);
|
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 activitypub_request(snac *snac, char *url, d_char **data);
|
||||||
|
|
Loading…
Reference in a new issue