Sha256: 4f3244169cd3f6ad0bf54d0278452f824e889c6af6cff4a6e6ce48f9256c376e

Contents?: true

Size: 1010 Bytes

Versions: 21

Compression:

Stored size: 1010 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.zone.now)
      end
      # rubocop:enable Rails/SkipsModelValidations
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-core-0.13.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.12.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.13.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.12.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.13.0.pre1 app/models/decidim/messaging/receipt.rb
decidim-core-0.12.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.11.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.12.0.pre app/models/decidim/messaging/receipt.rb
decidim-core-0.11.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.11.0.pre1 app/models/decidim/messaging/receipt.rb
decidim-core-0.10.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.10.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.9.3 app/models/decidim/messaging/receipt.rb
decidim-core-0.9.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.9.1 app/models/decidim/messaging/receipt.rb
decidim-core-0.9.0 app/models/decidim/messaging/receipt.rb
decidim-core-0.8.4 app/models/decidim/messaging/receipt.rb
decidim-core-0.8.3 app/models/decidim/messaging/receipt.rb
decidim-core-0.8.2 app/models/decidim/messaging/receipt.rb
decidim-core-0.8.1 app/models/decidim/messaging/receipt.rb