Add system stub messages, prevent notifications from being created when a post is a stub, fix url in Status API response

master
teknomunk 1 year ago
parent afa99c1d4f
commit b83d9db75a

@ -18,6 +18,11 @@ void write_json_escaped( FILE* f, const char* str );
void api_status_write_as_json( struct status* s, FILE* f )
{
if( s->stub ) {
struct status* system_status = status_new_system_stub( s );
s = system_status;
}
struct account* account = account_from_id( s->account_id );
struct status* in_reply_to = NULL;
@ -36,6 +41,7 @@ void api_status_write_as_json( struct status* s, FILE* f )
cleanup:
account_free(account);
account_free(in_reply_to_account);
status_free(in_reply_to);
}

@ -104,7 +104,10 @@ static bool handle_command_status_sync( struct cli_request* req )
}
struct status* s = status_from_id(id);
if( !s ) { return true; }
if( !s ) {
printf( "! Status %d not found\n", id );
return true;
}
status_sync(s);
status_save(s);
@ -116,10 +119,11 @@ static bool handle_command_status( struct cli_request* req )
int res = cli_route_command( req, "status", 1, "(import|sync) ..." );
if( res != 1 ) { return !!res; }
return false
|| handle_command_status_import( req )
|| handle_command_status_sync( req )
;
if( handle_command_status_import( req ) ) { return true; }
if( handle_command_status_sync( req ) ) { return true; }
printf( "Usage: %s status (import|sync)", req->binary_name );
return true;
}
void handle_command( char** argv, int argc )

@ -3,6 +3,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
const char* format( char* buffer, int size, const char* f, ... )
{
@ -24,3 +25,9 @@ char* aformat( const char* f, ... )
return res;
}
char* safe_strdup( const char* str )
{
if( !str ) { return NULL; }
return strdup(str);
}

@ -2,4 +2,5 @@
const char* format( char* buffer, int size, const char* f, ... );
char* aformat( const char* f, ... );
char* safe_strdup( const char* str );

@ -1 +1 @@
Subproject commit 9882a630cace9308c6f7c902c722b504894de597
Subproject commit cb8b0e194daafbac2ed8d34512ee546756ac1c53

@ -1 +1 @@
Subproject commit 68edc18e9b79bd144049c0aaec5cc6fbdfc0db2c
Subproject commit a415e6a851221eabe796d89a486fca603a2af2d7

@ -17,12 +17,6 @@
#include <stdio.h>
#include <string.h>
char* safe_strdup( const char* str )
{
if( !str ) { return NULL; }
return strdup(str);
}
struct ap_activity* ap_activity_new()
{
struct ap_activity* act = malloc(sizeof(struct ap_activity));

@ -98,8 +98,9 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_activity* act )
s->account_id = a->id;
s->published = act->published;
s->remote = true;
s->stub = false;
s->source = strdup(act->source.content);
s->source = safe_strdup(act->source.content);
s->url = strdup( act->id );
// Erase existing media
@ -249,6 +250,23 @@ struct status* status_new_system_block( int account_id )
return s;
}
struct status* status_new_system_stub( struct status* stub )
{
struct status* s;
s = malloc(sizeof(*s));
memset(s,0,sizeof(*s));
s->id = -stub->id - 50;
s->account_id = -1;
s->published = time(NULL);
asprintf( &s->content, "Unable to load status #%d. View on original server at <a href='%s'>%s</a>",
stub->id,
stub->url, stub->url
);
s->sensitive = true;
return s;
}
struct status* status_from_activity( struct ap_activity* act )
{
@ -468,6 +486,7 @@ void status_remove_react( struct status* s, const char* react, struct account* a
/// Generate Undo Activity
// TODO: generate notification
/*
if( s->account_id == owner_account_id && a->id != owner_account_id ) {
// Create notification for liking the owner's post
struct notification* note = notification_new();
@ -477,7 +496,7 @@ void status_remove_react( struct status* s, const char* react, struct account* a
note->created_at = time(NULL);
notification_save( note );
notification_free( note );
}
}*/
struct status_react* re = NULL;
for( int i = 0; i < s->reacts.count; ++i ) {
@ -506,18 +525,21 @@ void status_add_like( struct status* s, struct account* a )
}
}
if( s->account_id == owner_account_id ) {
if( a->id != owner_account_id ) {
// Create notification for liking the owner's post
struct notification* note = notification_new();
note->type = nt_like;
note->account_id = a->id;
note->created_at = time(NULL);
notification_save( note );
notification_free( note );
if( !s->stub ) {
if( s->account_id == owner_account_id ) {
if( a->id != owner_account_id ) {
// Create notification for liking the owner's post
struct notification* note = notification_new();
note->type = nt_like;
note->account_id = a->id;
note->status_id = s->id;
note->created_at = time(NULL);
notification_save( note );
notification_free( note );
}
} else {
ap_activity_like( s );
}
} else {
ap_activity_like( s );
}
status_save(s);

@ -54,6 +54,7 @@ struct status
struct status* status_from_id( unsigned int id );
struct status* status_new_system_unfollow( int account_id );
struct status* status_new_system_block( int account_id );
struct status* status_new_system_stub( struct status* s );
struct status* status_from_uri( const char* uri );
struct status* status_fetch_from_uri( const char* uri );

@ -93,7 +93,7 @@
"spoiler_text": "",
"tags": [],
"text": null,
"uri": "https://poa.st/objects/0db3a913-5007-464d-9829-995d5090c976",
"url": "https://poa.st/objects/0db3a913-5007-464d-9829-995d5090c976",
"uri": "%s{s->url}",
"url": "%s{s->url}",
"visibility": "public"
}

Loading…
Cancel
Save