Class: Decidim::Messaging::Receipt

Inherits:
ApplicationRecord show all
Defined in:
decidim-core/app/models/decidim/messaging/receipt.rb

Overview

Represents the reception of a message by a user. This model is supposed to hold any information about a message that is specific to each user, for example, the read/unread status, the deleted/undeleted status, and so on.

Class Method Summary collapse

Class Method Details

.mark_as_read(user) ⇒ Object

rubocop:disable Rails/SkipsModelValidations


23
24
25
# File 'decidim-core/app/models/decidim/messaging/receipt.rb', line 23

def self.mark_as_read(user)
  recipient(user).update_all(read_at: Time.current)
end

.unread_count(user) ⇒ Integer

The number of messages unread by a user

Returns:

  • (Integer)

32
33
34
# File 'decidim-core/app/models/decidim/messaging/receipt.rb', line 32

def self.unread_count(user)
  unread_by(user).count
end