Winner notifications are missing from the notification center (no link to the giveaway)
Bug
Per the feature spec (README: "Winner notifications — every winner gets an in-app alert linking straight to the giveaway"), each winner should receive an in-app notification containing a direct link to the giveaway.
Actual behavior: the giveawayWon / giveawayClaimed notifications never render in the notifications dropdown. The dropdown opens with HeaderList-content empty (the unread count badge still increments), so there is no row and therefore no clickable link to the giveaway. The browser console also logs:
Pushing object of type giveaways not allowed, as type not yet registered in the store.
Reproduced on two independent environments (local phpstudy + a VPS), so it is not a cache/environment issue.
Root cause
The backend correctly registers a JSON:API resource for giveaways (src/Api/Resource/GiveawayResource.php, type() === 'giveaways') and the notification API correctly returns the giveaway as the notification subject (verified in the live /api/notifications response, including the included giveaways resource and the data.content containing slug).
The frontend, however, never registers a Model for the giveaways JSON:API type. app.store.models only contains the core types, so:
Store.pushObject() (flarum/core/js/src/common/Store.ts, lines 132-139) sees this.models['giveaways'] is not registered, drops the included subject from the store and throws the async error above.
notification.subject() therefore returns undefined.
- The core notifications list (
flarum/core/.../forum/components/NotificationList.js, page.items.forEach(...) → if (typeof subject === 'undefined') return;) silently skips the notification row, so the "you won" alert (and its href() link in js/src/forum/components/GiveawayWonNotification.tsx) is never rendered.
Steps to reproduce
- Install & enable the extension (
composer require ernestdefoe/giveaways).
- Create a giveaway, enter it, and let it be drawn (or draw manually).
- Wait for the
giveawayWon notification to be created (also stored in notifications.data with slug — confirmed).
- Open the notification center (bell icon) as the winner.
- → The list is empty / the notification row is missing; the giveaway alert never shows, so there is no direct link.
Fix
Register a frontend Model for the giveaways type so the notification subject deserializes. Local reproduction confirms this resolves it (the row renders and the existing href() correctly builds /giveaways/{slug}).
New file js/src/common/models/Giveaway.ts:
import Model from "flarum/common/Model";
export default class Giveaway extends Model {
slug() {
return Model.attribute<string>("slug").call(this);
}
title() {
return Model.attribute<string>("title").call(this);
}
prize() {
return Model.attribute<string>("prize").call(this);
}
status() {
return Model.attribute<string>("status").call(this);
}
endsAt() {
return Model.attribute<Date | null, string | null>("endsAt", Model.transformDate).call(this);
}
drawnAt() {
return Model.attribute<Date | null, string | null>("drawnAt", Model.transformDate).call(this);
}
}
Edit js/src/forum/index.ts — add the import and register the model in the initializer:
import Giveaway from "../common/models/Giveaway";
app.initializers.add("ernestdefoe-giveaways", () => {
app.store.models.giveaways = Giveaway;
// ... existing route / notification-component / nav registrations
});
Then rebuild: cd js && npm run build.
Environment
- Flarum core: 2.0
- Extension: ernestdefoe/giveaways (v1.0.0 / MVP)
- Reproduction URL/DB both verified locally and on a VPS