mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Attend mastoapi relationships.
Now, the follow/unfollow buttons appear on each account's page.
This commit is contained in:
parent
5b93e9069e
commit
88850bdc46
3 changed files with 48 additions and 13 deletions
12
data.c
12
data.c
|
@ -1074,7 +1074,7 @@ d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
|
||||||
with a link to a cached author, because we need the Follow object
|
with a link to a cached author, because we need the Follow object
|
||||||
in case we need to unfollow (Undo + original Follow) */
|
in case we need to unfollow (Undo + original Follow) */
|
||||||
|
|
||||||
d_char *_following_fn(snac *snac, char *actor)
|
d_char *_following_fn(snac *snac, const char *actor)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
return xs_fmt("%s/following/%s.json", snac->basedir, md5);
|
return xs_fmt("%s/following/%s.json", snac->basedir, md5);
|
||||||
|
@ -1116,7 +1116,7 @@ int following_del(snac *snac, char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int following_check(snac *snac, char *actor)
|
int following_check(snac *snac, const char *actor)
|
||||||
/* checks if we are following this actor */
|
/* checks if we are following this actor */
|
||||||
{
|
{
|
||||||
xs *fn = _following_fn(snac, actor);
|
xs *fn = _following_fn(snac, actor);
|
||||||
|
@ -1185,14 +1185,14 @@ d_char *following_list(snac *snac)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *_muted_fn(snac *snac, char *actor)
|
d_char *_muted_fn(snac *snac, const char *actor)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
return xs_fmt("%s/muted/%s", snac->basedir, md5);
|
return xs_fmt("%s/muted/%s", snac->basedir, md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mute(snac *snac, char *actor)
|
void mute(snac *snac, const char *actor)
|
||||||
/* mutes a moron */
|
/* mutes a moron */
|
||||||
{
|
{
|
||||||
xs *fn = _muted_fn(snac, actor);
|
xs *fn = _muted_fn(snac, actor);
|
||||||
|
@ -1207,7 +1207,7 @@ void mute(snac *snac, char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void unmute(snac *snac, char *actor)
|
void unmute(snac *snac, const char *actor)
|
||||||
/* actor is no longer a moron */
|
/* actor is no longer a moron */
|
||||||
{
|
{
|
||||||
xs *fn = _muted_fn(snac, actor);
|
xs *fn = _muted_fn(snac, actor);
|
||||||
|
@ -1218,7 +1218,7 @@ void unmute(snac *snac, char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int is_muted(snac *snac, char *actor)
|
int is_muted(snac *snac, const char *actor)
|
||||||
/* check if someone is muted */
|
/* check if someone is muted */
|
||||||
{
|
{
|
||||||
xs *fn = _muted_fn(snac, actor);
|
xs *fn = _muted_fn(snac, actor);
|
||||||
|
|
39
mastoapi.c
39
mastoapi.c
|
@ -705,12 +705,47 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
|
if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
|
||||||
/* find if an account is followed, blocked, etc. */
|
/* find if an account is followed, blocked, etc. */
|
||||||
/* the account to get relationships about is in args "id[]" */
|
/* the account to get relationships about is in args "id[]" */
|
||||||
/* dummy by now */
|
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
*body = xs_dup("[]");
|
xs *res = xs_list_new();
|
||||||
|
const char *md5 = xs_dict_get(args, "id[]");
|
||||||
|
xs *actor_o = NULL;
|
||||||
|
|
||||||
|
if (!xs_is_null(md5) && valid_status(object_get_by_md5(md5, &actor_o))) {
|
||||||
|
xs *rel = xs_dict_new();
|
||||||
|
xs *t = xs_val_new(XSTYPE_TRUE);
|
||||||
|
xs *f = xs_val_new(XSTYPE_FALSE);
|
||||||
|
|
||||||
|
const char *actor = xs_dict_get(actor_o, "id");
|
||||||
|
|
||||||
|
rel = xs_dict_append(rel, "id", md5);
|
||||||
|
rel = xs_dict_append(rel, "following",
|
||||||
|
following_check(&snac1, actor) ? t : f);
|
||||||
|
|
||||||
|
rel = xs_dict_append(rel, "showing_reblogs", t);
|
||||||
|
rel = xs_dict_append(rel, "notifying", f);
|
||||||
|
rel = xs_dict_append(rel, "followed_by",
|
||||||
|
follower_check(&snac1, actor) ? t : f);
|
||||||
|
|
||||||
|
rel = xs_dict_append(rel, "blocking",
|
||||||
|
is_muted(&snac1, actor) ? t : f);
|
||||||
|
|
||||||
|
rel = xs_dict_append(rel, "muting", f);
|
||||||
|
rel = xs_dict_append(rel, "muting_notifications", f);
|
||||||
|
rel = xs_dict_append(rel, "requested", f);
|
||||||
|
rel = xs_dict_append(rel, "domain_blocking", f);
|
||||||
|
rel = xs_dict_append(rel, "endorsed", f);
|
||||||
|
rel = xs_dict_append(rel, "note", "");
|
||||||
|
|
||||||
|
res = xs_list_append(res, rel);
|
||||||
|
}
|
||||||
|
|
||||||
|
*body = xs_json_dumps_pp(res, 4);
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
status = 422;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(cmd, "/v1/accounts/")) {
|
if (xs_startswith(cmd, "/v1/accounts/")) {
|
||||||
|
|
10
snac.h
10
snac.h
|
@ -1,7 +1,7 @@
|
||||||
/* snac - A simple, minimalistic ActivityPub instance */
|
/* snac - A simple, minimalistic ActivityPub instance */
|
||||||
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
||||||
|
|
||||||
#define VERSION "2.28"
|
#define VERSION "2.29-dev"
|
||||||
|
|
||||||
#define USER_AGENT "snac/" VERSION
|
#define USER_AGENT "snac/" VERSION
|
||||||
|
|
||||||
|
@ -114,13 +114,13 @@ d_char *local_list(snac *snac, int max);
|
||||||
|
|
||||||
int following_add(snac *snac, char *actor, char *msg);
|
int following_add(snac *snac, char *actor, char *msg);
|
||||||
int following_del(snac *snac, char *actor);
|
int following_del(snac *snac, char *actor);
|
||||||
int following_check(snac *snac, char *actor);
|
int following_check(snac *snac, const char *actor);
|
||||||
int following_get(snac *snac, char *actor, d_char **data);
|
int following_get(snac *snac, char *actor, d_char **data);
|
||||||
d_char *following_list(snac *snac);
|
d_char *following_list(snac *snac);
|
||||||
|
|
||||||
void mute(snac *snac, char *actor);
|
void mute(snac *snac, const char *actor);
|
||||||
void unmute(snac *snac, char *actor);
|
void unmute(snac *snac, const char *actor);
|
||||||
int is_muted(snac *snac, char *actor);
|
int is_muted(snac *snac, const char *actor);
|
||||||
|
|
||||||
void hide(snac *snac, const char *id);
|
void hide(snac *snac, const char *id);
|
||||||
int is_hidden(snac *snac, const char *id);
|
int is_hidden(snac *snac, const char *id);
|
||||||
|
|
Loading…
Reference in a new issue