Class: UserMailbox
- Inherits:
-
Object
- Object
- UserMailbox
- Defined in:
- app/models/user_mailbox.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #delete_all ⇒ Object
- #destroy(message_id) ⇒ Object
- #inbox ⇒ Object
-
#initialize(user) ⇒ UserMailbox
constructor
A new instance of UserMailbox.
- #label(locale_from_params = nil) ⇒ Object
- #unread_count ⇒ Object
Constructor Details
#initialize(user) ⇒ UserMailbox
Returns a new instance of UserMailbox.
5 6 7 |
# File 'app/models/user_mailbox.rb', line 5 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/models/user_mailbox.rb', line 3 def user @user end |
Instance Method Details
#delete_all ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/user_mailbox.rb', line 29 def delete_all user.mailbox.inbox.each do |msg| (msg) end empty_trash(user) end |
#destroy(message_id) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/user_mailbox.rb', line 36 def destroy() msg = Mailboxer::Conversation.find() return "You do not have privileges to delete the notification..." unless msg.participants.include? user (msg) empty_trash(msg.participants[0]) nil end |
#inbox ⇒ Object
9 10 11 12 |
# File 'app/models/user_mailbox.rb', line 9 def inbox = user.mailbox.inbox .each { |m| m.mark_as_read(user) } end |
#label(locale_from_params = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/user_mailbox.rb', line 18 def label(locale_from_params = nil) case unread_count when 0 I18n.t("hyrax.toolbar.notifications.zero", locale: locale_from_params || preferred_locale) when 1 I18n.t("hyrax.toolbar.notifications.one", locale: locale_from_params || preferred_locale) else I18n.t("hyrax.toolbar.notifications.many", count: unread_count, locale: locale_from_params || preferred_locale) end end |
#unread_count ⇒ Object
14 15 16 |
# File 'app/models/user_mailbox.rb', line 14 def unread_count user.mailbox.inbox(unread: true).count end |