rimian
(Rimian Perkins)
13 maart 2017 om 03:29
1
Hi!
I want to create a custom notification when something happens in my plugin. I can see there is a custom notification type but I’m unsure about how to use it.
Something like:
data = {title: 'some custom event happened'}
Notification.create!(user_id: 1, notification_type: 14, data: data.to_json)
I can create them but they show ‘undefined’:
Can someone please point me in the right direction? Any help much appreciated…
joebuhlig
(Joe Buhlig)
13 maart 2017 om 12:18
2
My first guess is that you haven’t defined the Notification type and throws an undefined error somewhere:
order("notifications.created_at desc").limit(n)
}
scope :visible,
lambda {
joins("LEFT JOIN topics ON notifications.topic_id = topics.id").where(
"topics.id IS NULL OR topics.deleted_at IS NULL",
)
}
scope :unread_type, ->(user, type, limit = 30) { unread_types(user, [type], limit) }
scope :unread_types,
->(user, types, limit = 30) do
where(user_id: user.id, read: false, notification_type: types)
.visible
.includes(:topic)
.limit(limit)
end
scope :prioritized,
->(deprioritized_types = []) do
scope = order("notifications.high_priority AND NOT notifications.read DESC")
if deprioritized_types.present?
Guess #2 is that the I18n text hasn’t been defined in client.en.yml.
Depending on what you want to share with the user, I’ve found it’s sometimes better to send a PM and then spell out what happened in more detail.
PostCreator.create(
Discourse.system_user,
target_usernames: new_user.username,
archetype: Archetype.private_message,
subtype: TopicSubtype.system_message,
title: I18n.t('translations.location'}),
raw: I18n.t('translations.location'})
)
Edit: Just realized there’s a custom notification type (14) which you are using. So #1 is out.
8 likes
rimian
(Rimian Perkins)
13 maart 2017 om 23:13
3
I was thinking a private message would be a good idea also. Thanks for that!
1 like