app/controllers/thredded/posts_controller.rb in thredded-0.10.0 vs app/controllers/thredded/posts_controller.rb in thredded-0.10.1

- old
+ new

@@ -1,9 +1,8 @@ # frozen_string_literal: true module Thredded - # This currently handles both {Post}s and {PrivatePost}s. - # TODO: split up the PrivatePost functionality into a separate controller. + # A controller for managing {Post}s. class PostsController < Thredded::ApplicationController include ActionView::RecordIdentifier helper_method :topic after_action :update_user_activity @@ -35,43 +34,41 @@ redirect_back fallback_location: topic_url(topic), notice: I18n.t('thredded.posts.deleted_notice') end + def mark_as_unread + authorize post, :read? + page = post.page(user: thredded_current_user) + post.mark_as_unread(thredded_current_user, page) + after_mark_as_unread # customization hook + end + private + def after_mark_as_unread + redirect_to messageboard_topics_path(messageboard) + end + def topic post.postable end def post_params - p = params.require(:post) + params.require(:post) .permit(:content) - .merge(user: thredded_current_user, ip: request.remote_ip) - p = p.merge(messageboard: messageboard) unless for_a_private_topic? - p + .merge(user: thredded_current_user, ip: request.remote_ip, messageboard: messageboard) end def parent_topic - if for_a_private_topic? - PrivateTopic - .includes(:private_users) - .friendly - .find(params[:private_topic_id]) - else - Topic - .where(messageboard: messageboard) - .friendly - .find(params[:topic_id]) - end + Topic + .where(messageboard: messageboard) + .friendly + .find(params[:topic_id]) end - def for_a_private_topic? - params[:private_topic_id].present? - end - def post - @post ||= (for_a_private_topic? ? Thredded::PrivatePost : Thredded::Post).find(params[:id]) + @post ||= Thredded::Post.find(params[:id]) end def current_page params[:page].nil? ? 1 : params[:page].to_i end