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
$totalItems = count( $following_files );
// Create a list of all the followers
// Create a list of all accounts being followed
$items = array();
foreach ( $following_files as $following_file ) {
$following = json_decode( file_get_contents( $following_file ), true );
@ -242,16 +242,33 @@
// Some servers are very chatty. They send lots of irrelevant messages.
// 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.
if ( is_array( $inbox_message["object"] ) ) {
// Messages from accounts which aren't being followed.
// 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"] ) {
"Follow", "Undo", "Dislike", "Like" => true,
default => false,
} ) {
// Discard it, no further processing.
die();
// Get a list of every account we follow
// Get all the files
$following_files = glob( $directories["following"] . "/*.json");
// Create a list of all accounts being followed
$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