Discard useless inbox messages

merge-requests/5/head
Terence Eden 2024-03-05 21:13:10 +00:00
rodzic 2454dbdda4
commit bc445fd7e6
1 zmienionych plików z 27 dodań i 10 usunięć

Wyświetl plik

@ -182,7 +182,7 @@
// Number of users // Number of users
$totalItems = count( $following_files ); $totalItems = count( $following_files );
// Create a list of all the followers // Create a list of all accounts being followed
$items = array(); $items = array();
foreach ( $following_files as $following_file ) { foreach ( $following_files as $following_file ) {
$following = json_decode( file_get_contents( $following_file ), true ); $following = json_decode( file_get_contents( $following_file ), true );
@ -242,16 +242,33 @@
// Some servers are very chatty. They send lots of irrelevant messages. // Some servers are very chatty. They send lots of irrelevant messages.
// Before even bothering to validate them, we can delete them. // Before even bothering to validate them, we can delete them.
// Lemmy sends lots of announce messages. The object contains details of what the message is. // Messages from accounts which aren't being followed.
if ( is_array( $inbox_message["object"] ) ) { // Some servers send delete messages about users we don't follow.
// Lemmy sends messages even after unfollowing or blocking a channel
if ( match( $inbox_message["object"]["type"] ) { // Get a list of every account we follow
"Follow", "Undo", "Dislike", "Like" => true, // Get all the files
default => false, $following_files = glob( $directories["following"] . "/*.json");
} ) {
// Discard it, no further processing. // Create a list of all accounts being followed
die(); $following_ids = array();
} foreach ( $following_files as $following_file ) {
$following = json_decode( file_get_contents( $following_file ), true );
$following_ids[] = $following["id"];
}
// Is this from someone we follow?
in_array( $inbox_message["actor"], $following_ids ) ? $from_following = true: $from_following = false;
// Has the user has been specifically CC'd?
if ( isset( $inbox_message["cc"] ) ) {
$reply = in_array( "https://{$server}/{$username}", $inbox_message["cc"] );
} else {
$reply = false;
}
if ( !$reply && !$from_following ) {
die();
} }
// Save any Follow, Create, Update, Announce, Like messages // Save any Follow, Create, Update, Announce, Like messages