Sha256: 8dcd7a73b180bf1112006575cd68e89da2a5795835d5b4b866b27e3ba9741d79
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require_dependency 'thredded/content_formatter' 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(id: :asc) } after_commit :update_parent_last_user_and_timestamp, on: [:create, :destroy] end def avatar_url Thredded.avatar_url.call(user) 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) Thredded::ContentFormatter.new( view_context, users_provider: -> (names) { readers_from_user_names(names) } ).format_content(content) end private def update_parent_last_user_and_timestamp return if postable.destroyed? last_post = if destroyed? postable.posts.order_oldest_first.select(:user_id, :created_at).last else self end postable.update!(last_user_id: last_post.user_id, updated_at: last_post.created_at) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
thredded-0.5.1 | app/models/concerns/thredded/post_common.rb |
thredded-0.5.0 | app/models/concerns/thredded/post_common.rb |