Skip to content

Add uniqueId option to prevent duplicate/flooding notifications - #1

Open
sorambr wants to merge 1 commit into
blnStudio:mainfrom
sorambr:feat/unique-id
Open

sorambr wants to merge 1 commit into
blnStudio:mainfrom
sorambr:feat/unique-id

Conversation

@sorambr

@sorambr sorambr commented Aug 30, 2026

Copy link
Copy Markdown

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 uniqueId to fix it, and
decided to share it here in case it helps someone else's server too.

What it does

Pass an optional uniqueId in the notification options. While a
notification with that same uniqueId is still on screen, resending it
only 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:

  • notificationId was always overwritten with a random value, so a
    caller-provided id was silently dropped — it never actually worked.
  • the NUI used parseInt(options.id) to key notifications, which broke
    any non-numeric id.

Demo

Same test command spammed 10x in a row, first without uniqueId then
with it (console log at the bottom shows every attempt actually firing
either way):

demo

  • First half (no uniqueId): stacks a toast per call.
  • Second half (uniqueId set): stays a single toast even though the
    command still fires 10 times.

Testing

Added /bln_notify_flood as a usage example. Tested in-game on my own
server: without uniqueId a burst of sends stacks N toasts (the bug);
with it, only one toast stays on screen and its content updates live.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant