Implement Undo(Like) and Undo(EmojiRact)

master
teknomunk 1 year ago
parent e4c6c42975
commit 1215ebfe4e

@ -59,12 +59,46 @@ static bool route_undo_Announce( struct ap_object* act )
}
static bool route_undo_Like( struct ap_object* act )
{
bool result = false;
struct status* s = NULL;
struct account* a = NULL;
s = status_from_uri( act->object.ptr->id );
if( !s ) { return true; } // Satus not local, discard
if( !s ) { goto discard; } // Satus not local, discard
a = account_from_uri( act->actor );
if( !a )
status_remove_like( s, a );
goto cleanup;
cleanup:
status_free(s);
return false;
account_free(a);
return result;
discard:
result = true;
goto cleanup;
}
static bool route_undo_EmojiReact( struct ap_object* act )
{
bool result = false;
struct status* s = NULL;
struct account* a = NULL;
s = status_from_uri( act->object.ptr->id );
if( !s ) { goto discard; }
a = account_from_uri( act->object.ptr->actor );
if( !a ) { goto discard; }
status_remove_react( s, act->object.ptr->content.content, a );
goto discard;
cleanup:
account_free(a);
status_free(s);
return result;
discard:
result = true;
goto cleanup;
}
static bool route_undo_activity( struct ap_object* act )
@ -81,7 +115,8 @@ static bool route_undo_activity( struct ap_object* act )
switch( act->object.ptr->type ) {
case ap_Follow: return route_undo_follow( act );
case ap_Announce: return route_undo_Announce( act );
case ap_Like: return route_undo_Like( act );
case ap_Like: return route_undo_Like( act );
case pleroma_EmojiReact: return route_undo_EmojiReact(act);
default:
printf( "Unhandled object activity type %d in undo\n", act->object.ptr->type );
return false;

@ -772,6 +772,28 @@ void status_add_like( struct status* s, struct account* a )
status_save(s);
}
void status_remove_like( struct status* s, struct account* a )
{
for( int i = 0; i < s->likes.count; ++i ) {
if( s->likes.items[i] == a->id ) {
// Swap with last element
s->likes.items[i] = s->likes.items[ s->likes.count-1 ];
// Then discard the last element
s->likes.count -= 1;
break;
}
}
if( !s->stub ) {
if( a->id == owner_account_id ) {
// TODO: undo activity
// activity_like( s );
}
}
status_save(s);
}
void status_set_bookmark( struct status* s )
{
s->bookmarked = true;

Loading…
Cancel
Save