forked from krille-chan/fluffychat
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: new centralized chat banner controller #5919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ggurdin
merged 2 commits into
main
from
5911-if-grammar-improvement-popup-stack-is-more-than-2-3-ignore-others
Mar 6, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 0 additions & 191 deletions
191
lib/pangea/analytics_misc/level_up/level_up_banner.dart
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import 'dart:async'; | ||
| import 'dart:collection'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import 'package:fluffychat/pangea/common/utils/error_handler.dart'; | ||
| import 'package:fluffychat/widgets/matrix.dart'; | ||
|
|
||
| typedef BannerExecutor = void Function(Completer<void> completer); | ||
|
|
||
| class BannerQueueEntry { | ||
| final BannerExecutor show; | ||
| final String overlayKey; | ||
| final Duration timeout; | ||
|
|
||
| BannerQueueEntry({ | ||
| required this.show, | ||
| required this.overlayKey, | ||
| this.timeout = const Duration(seconds: 10), | ||
| }); | ||
| } | ||
|
|
||
| class ChatBannerController { | ||
| ChatBannerController(); | ||
|
|
||
| Completer<void>? _currentBannerCompleter; | ||
| final Queue<BannerQueueEntry> _bannerQueue = Queue(); | ||
|
|
||
| int get queueLength => _bannerQueue.length; | ||
|
|
||
| void dispose() { | ||
| // Complete the current banner completer to allow any showing banner to close | ||
| if (_currentBannerCompleter != null && | ||
| !_currentBannerCompleter!.isCompleted) { | ||
| _currentBannerCompleter!.complete(); | ||
| } | ||
|
|
||
| _currentBannerCompleter = null; | ||
| _bannerQueue.clear(); // Clear any pending banners in the queue | ||
| } | ||
|
|
||
| // The banner widget created by showBanner should call complete on the provided | ||
| // Completer when it is dismissed or if it fails to show to allow the next banner to show | ||
| void addBanner( | ||
| BannerExecutor showBanner, { | ||
| required String overlayKey, | ||
| Duration timeout = const Duration(seconds: 30), | ||
| }) { | ||
| if (_bannerQueue.any((b) => b.overlayKey == overlayKey)) return; | ||
|
|
||
| _bannerQueue.add( | ||
| BannerQueueEntry( | ||
| show: showBanner, | ||
| overlayKey: overlayKey, | ||
| timeout: timeout, | ||
| ), | ||
| ); | ||
|
|
||
| if (_currentBannerCompleter == null) { | ||
| showNextBanner(); | ||
| } | ||
| } | ||
|
|
||
| Future<void> showNextBanner() async { | ||
| if (_currentBannerCompleter != null || _bannerQueue.isEmpty) { | ||
| return; // A banner is currently showing or no banners to show | ||
| } | ||
|
|
||
| final completer = Completer<void>(); | ||
| _currentBannerCompleter = completer; | ||
| final bannerQueueEntry = _bannerQueue.removeFirst(); | ||
| final show = bannerQueueEntry.show; | ||
| final timeout = bannerQueueEntry.timeout; | ||
| final overlayKey = bannerQueueEntry.overlayKey; | ||
|
|
||
| try { | ||
| show(completer); | ||
|
|
||
| await completer.future.timeout( | ||
| timeout, | ||
| onTimeout: () { | ||
| debugPrint( | ||
| "Banner '$overlayKey' timed out after ${timeout.inSeconds}s", | ||
| ); | ||
| MatrixState.pAnyState.closeOverlay(overlayKey); | ||
| if (!completer.isCompleted) completer.complete(); | ||
| }, | ||
| ); | ||
| } catch (e, s) { | ||
| ErrorHandler.logError(e: e, s: s, data: {"overlayKey": overlayKey}); | ||
| } finally { | ||
| _currentBannerCompleter = null; | ||
| showNextBanner(); // Show the next banner in the queue | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addBannerdedupes only against_bannerQueue, so the sameoverlayKeycan be enqueued again while it is currently showing (since the active banner isn't part of the queue). Track the currently showingoverlayKey(or maintain a Set of queued+active keys) to prevent duplicate banners from showing back-to-back.