Conversation
Optional `uniqueId` option: resending it while the notification is still on screen only refreshes title/description/icon instead of stacking a new toast, without restarting duration/progress. Without it, behavior is unchanged. Also fixes two bugs found along the way: the id was always overwritten with a random value (a caller-provided one was silently dropped), and the NUI used parseInt() on it, breaking non-numeric ids. Adds /bln_notify_flood as an example.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
I built this for my own RedM server: some of my scripts could resend the
same notification many times in a short window (a warning that re-checks
every tick, a chamado list refresh, etc.), and it just stacked toast after
toast on screen. I ended up adding an opt-in
uniqueIdto fix it, anddecided to share it here in case it helps someone else's server too.
What it does
Pass an optional
uniqueIdin the notification options. While anotification with that same
uniqueIdis still on screen, resending itonly refreshes the visible title/description/icon instead of stacking a
new toast — duration and progress keep running untouched, so a resend
can't restart the bar or extend the toast's life indefinitely. A new
toast only shows up once the current one has naturally ended.
Without
uniqueId, behavior is unchanged — fully backward compatible.Also fixes
Found two bugs while building this:
notificationIdwas always overwritten with a random value, so acaller-provided
idwas silently dropped — it never actually worked.parseInt(options.id)to key notifications, which brokeany non-numeric id.
Demo
Same test command spammed 10x in a row, first without
uniqueIdthenwith it (console log at the bottom shows every attempt actually firing
either way):
uniqueId): stacks a toast per call.uniqueIdset): stays a single toast even though thecommand still fires 10 times.
Testing
Added
/bln_notify_floodas a usage example. Tested in-game on my ownserver: without
uniqueIda burst of sends stacks N toasts (the bug);with it, only one toast stays on screen and its content updates live.