FEATURE: automatically sync "move to inbox" / "archive" state on messages
This commit is contained in:
parent
d456150bb2
commit
b0567f9c62
|
@ -632,6 +632,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||
}
|
||||
return;
|
||||
}
|
||||
case "move_to_inbox": {
|
||||
topic.set("message_archived",false);
|
||||
return;
|
||||
}
|
||||
case "archived": {
|
||||
topic.set("message_archived",true);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
Em.Logger.warn("unknown topic bus message type", data);
|
||||
}
|
||||
|
|
|
@ -289,20 +289,20 @@ class TopicsController < ApplicationController
|
|||
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.archive!(id, topic.id)
|
||||
group_id = id
|
||||
GroupArchivedMessage.create!(group_id: id, topic_id: topic.id)
|
||||
else
|
||||
GroupArchivedMessage.move_to_inbox!(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)
|
||||
UserArchivedMessage.archive!(current_user.id, topic.id)
|
||||
else
|
||||
UserArchivedMessage.move_to_inbox!(current_user.id, topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
class GroupArchivedMessage < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :topic
|
||||
|
||||
def self.move_to_inbox!(group_id, topic_id)
|
||||
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, group_ids: [group_id])
|
||||
end
|
||||
|
||||
def self.archive!(group_id, topic_id)
|
||||
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
||||
GroupArchivedMessage.create!(group_id: group_id, topic_id: topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "archived"}, group_ids: [group_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
class UserArchivedMessage < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :topic
|
||||
|
||||
def self.move_to_inbox!(user_id, topic_id)
|
||||
UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, user_ids: [user_id])
|
||||
end
|
||||
|
||||
def self.archive!(user_id, topic_id)
|
||||
UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all
|
||||
UserArchivedMessage.create!(user_id: user_id, topic_id: topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "archived"}, user_ids: [user_id])
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue