Sha256: 04b86ae6fa788d1ea470333e2d55e606cc1917fe9096681f6480ab7d99cfe478
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true module Thredded module PostCommon extend ActiveSupport::Concern included do paginates_per 50 delegate :email, to: :user, prefix: true, allow_nil: true has_many :post_notifications, as: :post, dependent: :destroy validates :content, presence: true scope :order_oldest_first, -> { order(created_at: :asc, id: :asc) } scope :order_newest_first, -> { order(created_at: :desc, id: :desc) } before_validation :ensure_user_detail, on: :create end def avatar_url Thredded.avatar_url.call(user) end def calculate_page(postable_posts, per_page) 1 + postable_posts.where(postable_posts.arel_table[:created_at].lt(created_at)).count / per_page end # @param view_context [Object] the context of the rendering view. # @return [String] formatted and sanitized html-safe post content. def filtered_content(view_context, users_provider: ->(names) { readers_from_user_names(names) }) Thredded::ContentFormatter.new(view_context, users_provider: users_provider).format_content(content) end def first_post_in_topic? postable.first_post == self end private def ensure_user_detail build_user_detail if user && !user_detail end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
thredded-0.9.3 | app/models/concerns/thredded/post_common.rb |
thredded-0.9.2 | app/models/concerns/thredded/post_common.rb |
thredded-0.9.1 | app/models/concerns/thredded/post_common.rb |