Sha256: d667c7bc2e0b7effa0c465a5d5b3cff69369f303c2b2e6c4e624bb1bb7e381a8

Contents?: true

Size: 1009 Bytes

Versions: 19

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Messaging
    #
    # 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 Receipt < ApplicationRecord
      belongs_to :recipient, foreign_key: "decidim_recipient_id", class_name: "Decidim::User"
      belongs_to :message, foreign_key: "decidim_message_id", class_name: "Decidim::Messaging::Message"

      validates :recipient, :message, presence: true

      scope :recipient, ->(recipient) { where(recipient: recipient) }
      scope :unread_by, ->(user) { recipient(user).unread }
      scope :unread, -> { where(read_at: nil) }

      # rubocop:disable Rails/SkipsModelValidations
      def self.mark_as_read(user)
        recipient(user).update_all(read_at: Time.current)
      end
      # rubocop:enable Rails/SkipsModelValidations
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.21.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.20.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.20.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.19.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.18.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.19.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.17.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.18.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.17.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.16.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.17.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.16.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.15.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.15.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.15.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.14.4 app/models/decidim/messaging/receipt.rb
decidim-core-0.14.3 app/models/decidim/messaging/receipt.rb
decidim-core-0.14.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.14.1 app/models/decidim/messaging/receipt.rb