De-duplicate updated messages received
rodzic
9b1c494b03
commit
3b535e12ca
25
index.php
25
index.php
|
@ -502,7 +502,7 @@
|
||||||
$following_files = glob( $directories["following"] . "/*.json");
|
$following_files = glob( $directories["following"] . "/*.json");
|
||||||
$totalFollowing = count( $following_files );
|
$totalFollowing = count( $following_files );
|
||||||
|
|
||||||
|
// Show the HTML page
|
||||||
echo <<< HTML
|
echo <<< HTML
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en-GB">
|
<html lang="en-GB">
|
||||||
|
@ -561,13 +561,32 @@ HTML;
|
||||||
// Keep the most recent 200
|
// Keep the most recent 200
|
||||||
$message_files = array_slice( $message_files, 0, 200 );
|
$message_files = array_slice( $message_files, 0, 200 );
|
||||||
|
|
||||||
// Sometimes messages are received out of order.
|
// Loop through the messages:
|
||||||
// This sorts them by their published time or, if there is none, the received time.
|
// Remove any which have been updated.
|
||||||
|
// Ensure messages are in the right order.
|
||||||
$messages_ordered = [];
|
$messages_ordered = [];
|
||||||
|
$messages_ids = [];
|
||||||
foreach ( $message_files as $message_file ) {
|
foreach ( $message_files as $message_file ) {
|
||||||
// Get the contents of the JSON
|
// Get the contents of the JSON
|
||||||
$message = json_decode( file_get_contents( $message_file ), true );
|
$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
|
// Use the timestamp of the message. If there is none, use the date in the filename
|
||||||
if ( isset( $message["published"] ) ) {
|
if ( isset( $message["published"] ) ) {
|
||||||
$published = $message["published"];
|
$published = $message["published"];
|
||||||
|
|
Ładowanie…
Reference in New Issue