Alerts overlay: show messages approved after later donations (recent mode with client-side dedupe)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
875ca42054
commit
f7ff1dc717
7 files changed
+170
-24
No files matched your search
@@ -10,7 +10,7 @@ final class OverlayService {
|
||||
|
||||
public function __construct( private OverlayDataSource $source ) {}
|
||||
|
||||
public function payload( string $widget, int $now, ?int $since = null ): ?array {
|
||||
public function payload( string $widget, int $now, ?int $since = null, bool $recent = false ): ?array {
|
||||
$goal = $this->source->activeGoal();
|
||||
$gid = $goal ? (int) $goal['id'] : 0;
|
||||
switch ( $widget ) {
|
||||
@@ -26,13 +26,22 @@ final class OverlayService {
|
||||
$c = $gid ? $this->source->counter( $gid ) : array( 'label' => '', 'value' => 0 );
|
||||
return Payloads::counter( $c['label'], $c['value'] );
|
||||
case 'alerts':
|
||||
$rows = $this->source->donations( $since, 20 );
|
||||
if ( $recent ) {
|
||||
// Newest 20 approved rows regardless of cursor. Sources that predate RecentDonationsSource
|
||||
// fall back to the oldest 20 (still correct for small installs, just not "newest").
|
||||
$rows = $this->source instanceof RecentDonationsSource
|
||||
? $this->source->recentDonations( 20 )
|
||||
: $this->source->donations( 0, 20 );
|
||||
$since = null;
|
||||
} else {
|
||||
$rows = $this->source->donations( $since, 20 );
|
||||
}
|
||||
$ids = array_values( array_filter( array_map( static fn( $r ) => (int) ( $r['id'] ?? 0 ), $rows ) ) );
|
||||
$bonuses = ( null !== $since && $ids ) ? $this->source->bonusesFor( $ids ) : array();
|
||||
$bonuses = ( ( $recent || null !== $since ) && $ids ) ? $this->source->bonusesFor( $ids ) : array();
|
||||
foreach ( $rows as $i => $r ) {
|
||||
$rows[ $i ]['bonuses'] = $bonuses[ (int) ( $r['id'] ?? 0 ) ] ?? array();
|
||||
}
|
||||
return Payloads::alerts( $rows, $since );
|
||||
return Payloads::alerts( $rows, $since, $recent ? 20 : 10, $recent );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user