FEATURE: automatically sync "move to inbox" / "archive" state on messages

This commit is contained in:
Sam Saffron
2016-02-07 23:39:07 +11:00
parent d456150bb2
commit b0567f9c62
6 changed files with 48 additions and 12 deletions

View File

@@ -276,8 +276,13 @@ class PostCreator
def unarchive_message
return unless @topic.private_message? && @topic.id
UserArchivedMessage.where(topic_id: @topic.id).destroy_all
GroupArchivedMessage.where(topic_id: @topic.id).destroy_all
UserArchivedMessage.where(topic_id: @topic.id).pluck(:user_id).each do |user_id|
UserArchivedMessage.move_to_inbox!(user_id, @topic.id)
end
GroupArchivedMessage.where(topic_id: @topic.id).pluck(:group_id).each do |group_id|
GroupArchivedMessage.move_to_inbox!(group_id, @topic.id)
end
end
private

View File

@@ -43,9 +43,9 @@ class TopicsBulkAction
topics.each do |t|
if guardian.can_see?(t) && t.private_message?
if group
GroupArchivedMessage.where(group_id: group.id, topic_id: t.id).destroy_all
GroupArchivedMessage.move_to_inbox!(group.id, t.id)
else
UserArchivedMessage.where(user_id: @user.id, topic_id: t.id).destroy_all
UserArchivedMessage.move_to_inbox!(@user.id,t.id)
end
end
end
@@ -56,9 +56,9 @@ class TopicsBulkAction
topics.each do |t|
if guardian.can_see?(t) && t.private_message?
if group
GroupArchivedMessage.create!(group_id: group.id, topic_id: t.id)
GroupArchivedMessage.archive!(group.id, t.id)
else
UserArchivedMessage.create!(user_id: @user.id, topic_id: t.id)
UserArchivedMessage.archive!(@user.id, t.id)
end
end
end