diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 0a8e2cd..94e7776 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -6,7 +6,7 @@ en: unassign_creates_tracking_post: "If you unassign a topic a whisper or small action will be created to track change" assign_self_regex: "Regex that needs to pass for self assign. Example 'my list'" assign_other_regex: "Regex that needs to pass for assigning topics to others via mention. Example 'your list'." - unassign_on_group_archive: "When a message is archived by a group, unassign message" + unassign_on_group_archive: "When a message is archived by a group, unassign message (reassign if moved back to inbox)" unassign_on_close: "When a topic is closed unassign topic" discourse_assign: assigned_to: "Topic assigned to @%{username}" diff --git a/plugin.rb b/plugin.rb index e5b3d56..7bddb6c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -348,11 +348,30 @@ SQL ::TopicAssigner.auto_assign(post, force: true) end + on(:move_to_inbox) do |info| + if SiteSetting.unassign_on_group_archive && info[:group] + if topic = info[:topic] + if user_id = topic.custom_fields["prev_assigned_to_id"] + if user = User.find_by(id: user_id.to_i) + assigner = TopicAssigner.new(topic, Discourse.system_user) + assigner.assign(user, silent: true) + end + end + end + end + end + on(:archive_message) do |info| if SiteSetting.unassign_on_group_archive && info[:group] - assigner = TopicAssigner.new(info[:topic], Discourse.system_user) - # not forcing silent cause archive leaves no trace - assigner.unassign + topic = info[:topic] + if user_id = topic.custom_fields["assigned_to_id"] + if user = User.find_by(id: user_id.to_i) + topic.custom_fields["prev_assigned_to_id"] = user.id + topic.save + assigner = TopicAssigner.new(topic, Discourse.system_user) + assigner.unassign(silent: true) + end + end end end