mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Some fixes to timeline_add().
This commit is contained in:
parent
5792ef5d24
commit
4f328eec1f
4 changed files with 68 additions and 23 deletions
|
@ -204,7 +204,7 @@ void process_message(snac *snac, char *msg, char *req)
|
||||||
char *id = xs_dict_get(object, "id");
|
char *id = xs_dict_get(object, "id");
|
||||||
char *in_reply_to = xs_dict_get(object, "inReplyTo");
|
char *in_reply_to = xs_dict_get(object, "inReplyTo");
|
||||||
|
|
||||||
if (in_reply_to != NULL) {
|
if (xs_is_null(in_reply_to)) {
|
||||||
/* recursively download ancestors */
|
/* recursively download ancestors */
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
|
|
13
data.c
13
data.c
|
@ -391,7 +391,7 @@ d_char *_timeline_new_fn(snac *snac, char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
void timeline_add(snac *snac, char *id, char *o_msg, char *parent)
|
||||||
/* adds a message to the timeline */
|
/* adds a message to the timeline */
|
||||||
{
|
{
|
||||||
xs *pfn = _timeline_find_fn(snac, id);
|
xs *pfn = _timeline_find_fn(snac, id);
|
||||||
|
@ -404,6 +404,7 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||||
|
|
||||||
/* build the new filename */
|
/* build the new filename */
|
||||||
xs *fn = _timeline_new_fn(snac, id);
|
xs *fn = _timeline_new_fn(snac, id);
|
||||||
|
xs *msg = xs_dup(o_msg);
|
||||||
xs *md;
|
xs *md;
|
||||||
|
|
||||||
/* add metadata */
|
/* add metadata */
|
||||||
|
@ -414,7 +415,7 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||||
"\"parent\": null"
|
"\"parent\": null"
|
||||||
"}");
|
"}");
|
||||||
|
|
||||||
if (parent != NULL)
|
if (!xs_is_null(parent))
|
||||||
md = xs_dict_set(md, "parent", parent);
|
md = xs_dict_set(md, "parent", parent);
|
||||||
|
|
||||||
msg = xs_dict_set(msg, "_snac", md);
|
msg = xs_dict_set(msg, "_snac", md);
|
||||||
|
@ -430,14 +431,14 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||||
|
|
||||||
/* related to this user? link to local timeline */
|
/* related to this user? link to local timeline */
|
||||||
if (xs_startswith(id, snac->actor) ||
|
if (xs_startswith(id, snac->actor) ||
|
||||||
(parent != NULL && xs_startswith(parent, snac->actor))) {
|
(!xs_is_null(parent) && xs_startswith(parent, snac->actor))) {
|
||||||
xs *lfn = xs_replace(fn, "/timeline/", "/local/");
|
xs *lfn = xs_replace(fn, "/timeline/", "/local/");
|
||||||
link(fn, lfn);
|
link(fn, lfn);
|
||||||
|
|
||||||
snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn));
|
snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent != NULL) {
|
if (!xs_is_null(parent)) {
|
||||||
/* update the parent, adding this id to its children list */
|
/* update the parent, adding this id to its children list */
|
||||||
xs *pfn = _timeline_find_fn(snac, parent);
|
xs *pfn = _timeline_find_fn(snac, parent);
|
||||||
xs *p_msg = NULL;
|
xs *p_msg = NULL;
|
||||||
|
@ -493,7 +494,7 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||||
/* now iterate all parents up, just renaming the files */
|
/* now iterate all parents up, just renaming the files */
|
||||||
xs *grampa = xs_dup(xs_dict_get(meta, "parent"));
|
xs *grampa = xs_dup(xs_dict_get(meta, "parent"));
|
||||||
|
|
||||||
while (grampa != NULL) {
|
while (!xs_is_null(grampa)) {
|
||||||
xs *gofn = _timeline_find_fn(snac, grampa);
|
xs *gofn = _timeline_find_fn(snac, grampa);
|
||||||
|
|
||||||
if (gofn == NULL)
|
if (gofn == NULL)
|
||||||
|
@ -528,7 +529,7 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent)
|
||||||
|
|
||||||
free(grampa);
|
free(grampa);
|
||||||
|
|
||||||
if (p != NULL)
|
if (!xs_is_null(p))
|
||||||
p = xs_dup(p);
|
p = xs_dup(p);
|
||||||
|
|
||||||
grampa = p;
|
grampa = p;
|
||||||
|
|
68
main.c
68
main.c
|
@ -9,11 +9,47 @@
|
||||||
|
|
||||||
int usage(void)
|
int usage(void)
|
||||||
{
|
{
|
||||||
printf("usage:\n");
|
printf("snac - A simple, minimalistic ActivityPub instance\n");
|
||||||
|
printf("Copyright (c) 2022 grunfink - MIT license\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Commands:\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("init [{basedir}] Initializes the database\n");
|
||||||
|
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
||||||
|
printf("webfinger {basedir} {user} Queries about a @user@host or actor\n");
|
||||||
|
printf("queue {basedir} {uid} Processes a user queue\n");
|
||||||
|
// printf("check {basedir} [{uid}] Checks the database\n");
|
||||||
|
// printf("purge {basedir} [{uid}] Purges old data\n");
|
||||||
|
// printf("adduser {basedir} [{uid}] Adds a new user\n");
|
||||||
|
|
||||||
|
// printf("update {basedir} {uid} Sends a user update to followers\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("mute {basedir} {uid} {actor} Mutes an actor\n");
|
||||||
|
// printf("unmute {basedir} {uid} {actor} Unmutes an actor\n");
|
||||||
|
// printf("like {basedir} {uid} {url} Likes an url\n");
|
||||||
|
// printf("announce {basedir} {uid} {url} Announces (boosts) an url\n");
|
||||||
|
// printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
|
||||||
|
|
||||||
|
printf("request {basedir} {uid} {url} Requests an object\n");
|
||||||
|
printf("actor {basedir} {uid} {url} Requests an actor\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *get_argv(int *argi, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (*argi < argc)
|
||||||
|
return argv[(*argi)++];
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define GET_ARGV() get_argv(&argi, argc, argv)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *cmd;
|
char *cmd;
|
||||||
|
@ -23,21 +59,20 @@ int main(int argc, char *argv[])
|
||||||
int argi = 1;
|
int argi = 1;
|
||||||
snac snac;
|
snac snac;
|
||||||
|
|
||||||
argc--;
|
if ((cmd = GET_ARGV()) == NULL)
|
||||||
if (argc < argi)
|
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
cmd = argv[argi++];
|
|
||||||
|
|
||||||
if (strcmp(cmd, "init") == 0) {
|
if (strcmp(cmd, "init") == 0) {
|
||||||
|
/* initialize the database */
|
||||||
|
/* ... */
|
||||||
|
basedir = GET_ARGV();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < argi)
|
if ((basedir = GET_ARGV()) == NULL)
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
basedir = argv[argi++];
|
|
||||||
|
|
||||||
if (!srv_open(basedir)) {
|
if (!srv_open(basedir)) {
|
||||||
srv_log(xs_fmt("error opening database at %s", basedir));
|
srv_log(xs_fmt("error opening database at %s", basedir));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -48,11 +83,9 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < argi)
|
if ((user = GET_ARGV()) == NULL)
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
user = argv[argi++];
|
|
||||||
|
|
||||||
if (strcmp(cmd, "webfinger") == 0) {
|
if (strcmp(cmd, "webfinger") == 0) {
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
xs *uid = NULL;
|
xs *uid = NULL;
|
||||||
|
@ -69,16 +102,19 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < argi)
|
|
||||||
return usage();
|
|
||||||
|
|
||||||
url = argv[argi++];
|
|
||||||
|
|
||||||
if (!user_open(&snac, user)) {
|
if (!user_open(&snac, user)) {
|
||||||
printf("error in user '%s'\n", user);
|
printf("error in user '%s'\n", user);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(cmd, "queue") == 0) {
|
||||||
|
process_queue(&snac);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((url = GET_ARGV()) == NULL)
|
||||||
|
return usage();
|
||||||
|
|
||||||
if (strcmp(cmd, "request") == 0) {
|
if (strcmp(cmd, "request") == 0) {
|
||||||
int status;
|
int status;
|
||||||
xs *data = NULL;
|
xs *data = NULL;
|
||||||
|
|
8
xs.h
8
xs.h
|
@ -41,6 +41,7 @@ void _xs_destroy(char **var);
|
||||||
#define xs_debug() kill(getpid(), 5)
|
#define xs_debug() kill(getpid(), 5)
|
||||||
xstype xs_type(const char *data);
|
xstype xs_type(const char *data);
|
||||||
int xs_size(const char *data);
|
int xs_size(const char *data);
|
||||||
|
int xs_is_null(char *data);
|
||||||
d_char *xs_dup(const char *data);
|
d_char *xs_dup(const char *data);
|
||||||
d_char *xs_expand(d_char *data, int offset, int size);
|
d_char *xs_expand(d_char *data, int offset, int size);
|
||||||
d_char *xs_collapse(d_char *data, int offset, int size);
|
d_char *xs_collapse(d_char *data, int offset, int size);
|
||||||
|
@ -185,6 +186,13 @@ int xs_size(const char *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int xs_is_null(char *data)
|
||||||
|
/* checks for null */
|
||||||
|
{
|
||||||
|
return !!(data == NULL || xs_type(data) == XSTYPE_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *xs_dup(const char *data)
|
d_char *xs_dup(const char *data)
|
||||||
/* creates a duplicate of data */
|
/* creates a duplicate of data */
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue