Sha256: 07567fd0404f3f078bc13321ec4e3908a39950362aac2042933bc09a2a6bfa04

Contents?: true

Size: 1.03 KB

Versions: 42

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Thredded
  # Delivery records for Thredded::Post notifications.
  class UserPostNotification < ActiveRecord::Base
    belongs_to :user, class_name: Thredded.user_class_name, inverse_of: :thredded_post_notifications
    belongs_to :post, class_name: 'Thredded::Post', inverse_of: :user_notifications

    # @param post [Thredded::Post]
    # @return [Array<Integer>] The IDs of users who were already notified about the given post.
    def self.notified_user_ids(post)
      where(post_id: post.id).pluck(:user_id)
    end

    # Create a user-post notification record for a given post and a user.
    # @param post [Thredded::Post]
    # @param user [Thredded.user_class]
    # @return [Boolean] true if a new record was created, false otherwise (e.g. if a record had already existed).
    def self.create_from_post_and_user(post, user)
      create(
        post_id: post.id,
        user_id: user.id,
        notified_at: Time.zone.now
      )
    rescue ActiveRecord::RecordNotUnique
      false
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
thredded-1.1.0 app/models/thredded/user_post_notification.rb
thredded-1.0.1 app/models/thredded/user_post_notification.rb
thredded-1.0.0 app/models/thredded/user_post_notification.rb
thredded-0.16.16 app/models/thredded/user_post_notification.rb
thredded-0.16.15 app/models/thredded/user_post_notification.rb
thredded-0.16.14 app/models/thredded/user_post_notification.rb
thredded-0.16.13 app/models/thredded/user_post_notification.rb
thredded-0.16.12 app/models/thredded/user_post_notification.rb
thredded-0.16.11 app/models/thredded/user_post_notification.rb
thredded-0.16.10 app/models/thredded/user_post_notification.rb
thredded-0.16.9 app/models/thredded/user_post_notification.rb
thredded-0.16.8 app/models/thredded/user_post_notification.rb
thredded-0.16.7 app/models/thredded/user_post_notification.rb
thredded-0.16.6 app/models/thredded/user_post_notification.rb
thredded-0.16.5 app/models/thredded/user_post_notification.rb
thredded-0.16.4 app/models/thredded/user_post_notification.rb
thredded-0.16.3 app/models/thredded/user_post_notification.rb
thredded-0.16.1 app/models/thredded/user_post_notification.rb
thredded-0.16.0 app/models/thredded/user_post_notification.rb
thredded-0.15.5 app/models/thredded/user_post_notification.rb