@@ -11,6 +11,12 @@ class SettingsDropdown extends Component
1111{
1212 public $ showWhatsNewModal = false ;
1313
14+ public bool $ shouldPollChangelog = false ;
15+
16+ public bool $ changelogFetchRequested = false ;
17+
18+ public int $ changelogPollAttempts = 0 ;
19+
1420 public function getUnreadCountProperty ()
1521 {
1622 return Auth::user ()->getUnreadChangelogCount ();
@@ -31,6 +37,53 @@ public function getCurrentVersionProperty()
3137 public function openWhatsNewModal ()
3238 {
3339 $ this ->showWhatsNewModal = true ;
40+
41+ $ this ->prefetchChangelog ();
42+ }
43+
44+ public function prefetchChangelog ()
45+ {
46+ $ entries = app (ChangelogService::class)->getEntriesForUser (Auth::user ());
47+ if ($ entries ->isEmpty ()) {
48+ if (! $ this ->changelogFetchRequested ) {
49+ $ this ->changelogFetchRequested = true ;
50+ $ this ->shouldPollChangelog = true ;
51+ $ this ->changelogPollAttempts = 0 ;
52+ PullChangelog::dispatch ();
53+ }
54+
55+ return ;
56+ }
57+
58+ $ this ->dispatch ('changelog-entries ' , entries: $ entries ->values ()->all ());
59+ }
60+
61+ public function refreshChangelog ()
62+ {
63+ if (! $ this ->shouldPollChangelog ) {
64+ return ;
65+ }
66+
67+ $ this ->changelogPollAttempts ++;
68+ if ($ this ->changelogPollAttempts > 10 ) {
69+ $ this ->shouldPollChangelog = false ;
70+ $ this ->changelogFetchRequested = false ;
71+
72+ return ;
73+ }
74+
75+ $ entries = app (ChangelogService::class)->getEntriesForUser (Auth::user ());
76+ if ($ entries ->isEmpty ()) {
77+ return ;
78+ }
79+
80+ $ this ->shouldPollChangelog = false ;
81+ $ this ->changelogFetchRequested = false ;
82+ $ this ->changelogPollAttempts = 0 ;
83+ $ this ->dispatch ('changelog-entries ' , entries: $ entries ->values ()->all ());
84+
85+ cache ()->forget ('user_unread_changelog_count_ ' .Auth::id ());
86+ $ this ->dispatch ('$refresh ' );
3487 }
3588
3689 public function closeWhatsNewModal ()
0 commit comments