How do notifications work with Mailboxer?

I am trying to figure out how to set up a notification system using Mailboxer.

I already used it to configure the messaging system in place so that users can communicate with each other. Now, I would like to use it to send notifications from the site, notify users of changes in their reputation points, or remind them of the actions that they must take. Something like Facebook or Stackoverflow notification dropdowns.

As an example, it may contain these types of notifications:

  • The user receives points for completing the action:
    • "You received 50 points for helping #{user.name} with #{request.title}.
  • Reminder that the user must complete an action:
    • "You must review #{user.name} help with #{request.title}!
    • There will be a link to the page to complete this action.
  • The user receives a response to the message sent to them:
    • "You've received a message from #{sender.name}"
    • There will be a link to the message.

Here are a few details:

  • I do not want all notifications to send an email. Most of them will need to be seen only in the notification menu. Is there an option in Mailboxer to control what is sent by email, or do I need to bypass Mailboxer mail programs?

  • I want to format each type of notification differently in the drop-down list. Add, for example, a specific glyphicon. Can I use the type notification field for this (using it to set the conditional)? How does type work? Can I just set it to a string, such as "reputation", depending on the notification?

  • Objects can be passed to the notify method. I am confused by this purpose. How can I use this object? What objects do I want to send?


Feel free to leave some general information about Mailboxer notifications, and not specifically answer all questions.

I had a rather unsuccessful find of documentation for the notification functions, so it would be appreciated if someone with some knowledge of Mailboxer could call this back. Thanks in advance.

+6
source share
1 answer

This is a late answer, but in case someone comes across this question as me, this is what I ended up with.

There is a user authentication method, which is defined as https://github.com/mailboxer/mailboxer#user-identities

If he returns the email, an email will be sent. If it returns zero, no email will be sent.

There is a notification method in the mailbox, and you can use it to send notifications like,

 alice.notify("Hi","Bob has just viewed your profile!") 

And in mailboxer_email check if the object is a notification or not. If so, do not send an email.

 def mailboxer_email(object) if object.class==Mailboxer::Notification return nil else email end end 

Here you can define more complex logic, for example, disable email for a specific type of user, etc.

+9
source

Source: https://habr.com/ru/post/973394/


All Articles