I'm developing a trader feedback extension for Flarum 1.8 and facing issues with the notification system. While the notifications are being created in the database, they're not being delivered to users properly.
@Sami (SychO) @clarkwinkelmann
Extension Details:
The Problem:
- I have three notification types:
newFeedback, feedbackApproved, and feedbackRejected
- Notifications ARE being created in the database with correct data
- The
newFeedback notification sometimes works, but feedbackApproved and feedbackRejected never appear in the UI
- No errors in logs, no JavaScript console errors
Current Implementation:
extend.php:
// Notification registration
(new Extend\Notification())
->type(NewFeedbackBlueprint::class, BasicUserSerializer::class, ['alert'])
->type(FeedbackApprovedBlueprint::class, BasicUserSerializer::class, ['alert'])
->type(FeedbackRejectedBlueprint::class, BasicUserSerializer::class, ['alert']),
// Notification data serialization
(new Extend\ApiSerializer(NotificationSerializer::class))
->attributes(function (NotificationSerializer $serializer, Notification $notification) {
if (in_array($notification->type, [
'newFeedback',
'feedbackApproved',
'feedbackRejected'
])) {
return ['content' => $notification->data ?: []];
}
return [];
}),
// User preferences
(new Extend\User())
->registerPreference('notify_newFeedback_alert', 'boolval', true)
->registerPreference('notify_feedbackApproved_alert', 'boolval', true)
->registerPreference('notify_feedbackRejected_alert', 'boolval', true),
Blueprint Example (FeedbackApprovedBlueprint.php):
class FeedbackApprovedBlueprint implements BlueprintInterface
{
public function getSubject()
{
return User::find($this->feedback->from_user_id);
}
public function getFromUser()
{
return User::find($this->feedback->approved_by_id);
}
public function getData()
{
return [
'feedbackId' => $this->feedback->id,
'feedbackType' => $this->feedback->type,
'toUsername' => $this->feedback->toUser->username
];
}
public static function getType()
{
return 'feedbackApproved';
}
public static function getSubjectModel()
{
return User::class;
}
}
Frontend (notifications.js):
app.notificationComponents.feedbackApproved = class extends Notification {
icon() {
return 'fas fa-check-circle';
}
href() {
const data = this.attrs.notification.content() || {};
return app.route('user.feedbacks', {
username: data.toUsername || app.session.user?.slug()
});
}
content() {
const data = this.attrs.notification.content() || {};
return app.translator.trans('huseyinfiliz-traderfeedback.forum.notifications.feedback_approved_title', {
username: data.toUsername || 'a user'
});
}
};
What I've Tried:
- ✅ Database shows notifications are created with correct data structure
- ✅ User preferences are set correctly (
notify_feedbackApproved_alert = 1)
- ✅ Frontend components are registered in
app.notificationComponents
- ✅ Cleared cache multiple times
- ✅ Used both Event/Listener pattern and direct NotificationSyncer
- ✅ Verified that
notification.content() returns the data
Database Evidence:
-- Notification exists in DB:
id: 123
type: feedbackApproved
from_user_id: 1
subject_id: 2
data: {"feedbackId":68,"feedbackType":"positive","toUsername":"testuser"}
created_at: 2025-01-18 10:56:58
is_deleted: 0
-- User preference exists:
user_id: 2
key: notify_feedbackApproved_alert
value: 1
Questions:
- Is there something special about notification handling in Flarum 1.8 that I'm missing?
- Do I need to implement
MailableInterface even if I only use alerts?
- Is there a specific order for registering notification components?
- Could there be a conflict with notification type names?
Any help would be greatly appreciated! I can provide more code samples if needed.
Repository:
huseyinfiliz/traderfeedback
Thank you in advance for your help! 🙏