De-duplicate updated messages received

merge-requests/5/head
Terence Eden 2024-03-03 15:00:01 +00:00
rodzic 9b1c494b03
commit 3b535e12ca
1 zmienionych plików z 23 dodań i 4 usunięć

Wyświetl plik

@ -502,7 +502,7 @@
$following_files = glob( $directories["following"] . "/*.json");
$totalFollowing = count( $following_files );
// Show the HTML page
echo <<< HTML
<!DOCTYPE html>
<html lang="en-GB">
@ -561,13 +561,32 @@ HTML;
// Keep the most recent 200
$message_files = array_slice( $message_files, 0, 200 );
// Sometimes messages are received out of order.
// This sorts them by their published time or, if there is none, the received time.
// Loop through the messages:
// Remove any which have been updated.
// Ensure messages are in the right order.
$messages_ordered = [];
$messages_ids = [];
foreach ( $message_files as $message_file ) {
// Get the contents of the JSON
$message = json_decode( file_get_contents( $message_file ), true );
// Get the ID
if ( isset( $message["object"]["id"] ) ) {
$id = $message["object"]["id"];
} else if ( isset( $message["id"] ) ) {
$id = $message["id"];
}
// Has this message ID already been seen?
// If so, it's an older update. Skip displaying it
if ( !in_array( $id, $messages_ids ) ) {
$messages_ids[] = $id;
} else {
continue;
}
// Sometimes messages are received out of order.
// This sorts them by their published time or, if there is none, the received time.
// Use the timestamp of the message. If there is none, use the date in the filename
if ( isset( $message["published"] ) ) {
$published = $message["published"];