mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
New function timeline_request().
This commit is contained in:
parent
bb70101fec
commit
6169932733
@ -75,6 +75,33 @@ int actor_request(snac *snac, char *actor, d_char **data)
|
||||
}
|
||||
|
||||
|
||||
void timeline_request(snac *snac, char *id)
|
||||
/* ensures that an entry and its ancestors are in the timeline */
|
||||
{
|
||||
if (!xs_is_null(id)) {
|
||||
/* is the admired object already there? */
|
||||
if (!timeline_here(snac, id)) {
|
||||
int status;
|
||||
xs *object = NULL;
|
||||
|
||||
/* no; download it */
|
||||
status = activitypub_request(snac, id, &object);
|
||||
|
||||
if (valid_status(status)) {
|
||||
/* does it have an ancestor? */
|
||||
char *in_reply_to = xs_dict_get(object, "inReplyTo");
|
||||
|
||||
/* recurse! */
|
||||
timeline_request(snac, in_reply_to);
|
||||
|
||||
/* finally store */
|
||||
timeline_add(snac, id, object, in_reply_to);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size)
|
||||
/* sends a message to an Inbox */
|
||||
{
|
||||
@ -204,10 +231,7 @@ void process_message(snac *snac, char *msg, char *req)
|
||||
char *id = xs_dict_get(object, "id");
|
||||
char *in_reply_to = xs_dict_get(object, "inReplyTo");
|
||||
|
||||
if (xs_is_null(in_reply_to)) {
|
||||
/* recursively download ancestors */
|
||||
/* ... */
|
||||
}
|
||||
timeline_request(snac, in_reply_to);
|
||||
|
||||
snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
|
||||
timeline_add(snac, id, msg, in_reply_to);
|
||||
@ -229,17 +253,24 @@ void process_message(snac *snac, char *msg, char *req)
|
||||
snac_debug(snac, 2, xs_fmt("xs_type for 'Like' object not string"));
|
||||
}
|
||||
else
|
||||
/*
|
||||
|| strcmp(type, "Announce") == 0) {
|
||||
if (strcmp(type, "Announce") == 0) {
|
||||
if (xs_type(object) == XSTYPE_STRING) {
|
||||
timeline_request(snac, object);
|
||||
|
||||
timeline_admire(snac, object, actor, 0);
|
||||
}
|
||||
else
|
||||
snac_debug(snac, 2, xs_fmt("xs_type for 'Announce' object not string"));
|
||||
}
|
||||
/*
|
||||
else
|
||||
if (strcmp(type, "Update") == 0) {
|
||||
}
|
||||
else
|
||||
if (strcmp(type, "Delete") == 0) {
|
||||
}
|
||||
else
|
||||
*/
|
||||
else
|
||||
snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type));
|
||||
}
|
||||
|
||||
|
14
data.c
14
data.c
@ -290,6 +290,15 @@ d_char *_timeline_find_fn(snac *snac, char *id)
|
||||
}
|
||||
|
||||
|
||||
int timeline_here(snac *snac, char *id)
|
||||
/* checks if an object is already downloaded */
|
||||
{
|
||||
xs *fn = _timeline_find_fn(snac, id);
|
||||
|
||||
return fn != NULL;
|
||||
}
|
||||
|
||||
|
||||
d_char *timeline_find(snac *snac, char *id)
|
||||
/* gets a message from the timeline by id */
|
||||
{
|
||||
@ -549,6 +558,8 @@ void timeline_add(snac *snac, char *id, char *o_msg, char *parent)
|
||||
msg = xs_dict_set(msg, "_snac", md);
|
||||
|
||||
_timeline_write(snac, id, msg, parent);
|
||||
|
||||
snac_log(snac, xs_fmt("timeline_add %s", id));
|
||||
}
|
||||
|
||||
|
||||
@ -593,6 +604,9 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like)
|
||||
unlink(ofn);
|
||||
|
||||
_timeline_write(snac, id, msg, xs_dict_get(meta, "parent"));
|
||||
|
||||
snac_log(snac, xs_fmt("timeline_admire (%s) %s %s",
|
||||
like ? "Like" : "Announce", id, admirer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
snac.h
1
snac.h
@ -51,6 +51,7 @@ int follower_del(snac *snac, char *actor);
|
||||
int follower_check(snac *snac, char *actor);
|
||||
d_char *follower_list(snac *snac);
|
||||
|
||||
int timeline_here(snac *snac, char *id);
|
||||
d_char *timeline_find(snac *snac, char *id);
|
||||
void timeline_del(snac *snac, char *id);
|
||||
d_char *timeline_get(snac *snac, char *fn);
|
||||
|
Loading…
Reference in New Issue
Block a user