FEATURE: allow users to archive messages from message page

This commit is contained in:
Sam
2015-12-30 13:26:21 +11:00
parent 6c9f646e34
commit a4587b18f5
11 changed files with 147 additions and 3 deletions

View File

@ -25,6 +25,8 @@ class TopicsController < ApplicationController
:reset_new,
:change_post_owners,
:change_timestamps,
:archive_message,
:move_to_inbox,
:bookmark]
before_filter :consider_user_for_promotion, only: :show
@ -269,6 +271,40 @@ class TopicsController < ApplicationController
render nothing: true
end
def archive_message
toggle_archive_message(true)
end
def move_to_inbox
toggle_archive_message(false)
end
def toggle_archive_message(archive)
topic = Topic.find(params[:id].to_i)
group_ids = current_user.groups.pluck(:id)
if group_ids.present?
allowed_groups = topic.allowed_groups
.where('topic_allowed_groups.group_id IN (?)', group_ids).pluck(:id)
allowed_groups.each do |id|
GroupArchivedMessage.where(group_id: id, topic_id: topic.id).destroy_all
if archive
GroupArchivedMessage.create!(group_id: id, topic_id: topic.id)
end
end
end
if topic.allowed_users.include?(current_user)
UserArchivedMessage.where(user_id: current_user.id, topic_id: topic.id).destroy_all
if archive
UserArchivedMessage.create!(user_id: current_user.id, topic_id: topic.id)
end
end
render nothing: true
end
def bookmark
topic = Topic.find(params[:topic_id].to_i)
first_post = topic.ordered_posts.first