mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
New web action 'Unfollow'.
This commit is contained in:
parent
1bb52559b2
commit
2c00c7b0b5
4 changed files with 49 additions and 1 deletions
|
@ -437,6 +437,17 @@ d_char *msg_create(snac *snac, char *object)
|
|||
}
|
||||
|
||||
|
||||
d_char *msg_undo(snac *snac, char *object)
|
||||
/* creates an 'Undo' message */
|
||||
{
|
||||
d_char *msg = msg_base(snac, "Undo", "@object", snac->actor, "@now", object);
|
||||
|
||||
msg = xs_dict_append(msg, "to", xs_dict_get(object, "object"));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
d_char *msg_follow(snac *snac, char *actor)
|
||||
/* creates a 'Follow' message */
|
||||
{
|
||||
|
|
21
data.c
21
data.c
|
@ -693,6 +693,27 @@ int following_check(snac *snac, char *actor)
|
|||
}
|
||||
|
||||
|
||||
int following_get(snac *snac, char *actor, d_char **data)
|
||||
/* returns the 'Follow' object */
|
||||
{
|
||||
xs *fn = _following_fn(snac, actor);
|
||||
FILE *f;
|
||||
int status = 200;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
xs *j = xs_readall(f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
*data = xs_json_loads(j);
|
||||
}
|
||||
else
|
||||
status = 404;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
d_char *_muted_fn(snac *snac, char *actor)
|
||||
{
|
||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||
|
|
16
html.c
16
html.c
|
@ -867,7 +867,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
|
|||
}
|
||||
else
|
||||
if (strcmp(action, L("Follow")) == 0) {
|
||||
char *msg = msg_follow(&snac, actor);
|
||||
xs *msg = msg_follow(&snac, actor);
|
||||
|
||||
/* reload the actor from the message, in may be different */
|
||||
actor = xs_dict_get(msg, "object");
|
||||
|
@ -878,6 +878,20 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
|
|||
}
|
||||
else
|
||||
if (strcmp(action, L("Unfollow")) == 0) {
|
||||
/* get the following object */
|
||||
xs *object = NULL;
|
||||
|
||||
if (valid_status(following_get(&snac, actor, &object))) {
|
||||
xs *msg = msg_undo(&snac, xs_dict_get(object, "object"));
|
||||
|
||||
following_del(&snac, actor);
|
||||
|
||||
enqueue_output(&snac, msg, actor, 0);
|
||||
|
||||
snac_log(&snac, xs_fmt("unfollowed actor %s", actor));
|
||||
}
|
||||
else
|
||||
snac_log(&snac, xs_fmt("actor is not being followed %s", actor));
|
||||
}
|
||||
else
|
||||
if (strcmp(action, L("Delete")) == 0) {
|
||||
|
|
2
snac.h
2
snac.h
|
@ -75,6 +75,7 @@ d_char *local_list(snac *snac, int max);
|
|||
int following_add(snac *snac, char *actor, char *msg);
|
||||
int following_del(snac *snac, char *actor);
|
||||
int following_check(snac *snac, char *actor);
|
||||
int following_get(snac *snac, char *actor, d_char **data);
|
||||
|
||||
void mute(snac *snac, char *actor);
|
||||
void unmute(snac *snac, char *actor);
|
||||
|
@ -112,6 +113,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);
|
||||
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to);
|
||||
d_char *msg_undo(snac *snac, char *object);
|
||||
|
||||
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