canvas-lms/lib/mutable.rb

85 lines
2.8 KiB
Ruby
Raw Normal View History

module Mutable
attr_accessor :recently_unmuted
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def declare_mutable_broadcast_policy(options)
policy = options[:policy]
participants = options[:participants]
policy.dispatch :assignment_unmuted
policy.to { participants }
policy.whenever do |record|
@recently_unmuted
end
end
end
def mute!
self.update_attribute(:muted, true)
clear_sent_messages
hide_stream_items
end
def unmute!
self.update_attribute(:muted, false)
broadcast_unmute_event
show_stream_items
end
def broadcast_unmute_event
@recently_unmuted = true
self.save!
@recently_unmuted = false
end
protected
def clear_sent_messages
self.clear_broadcast_messages if self.respond_to? :clear_broadcast_messages
end
def hide_stream_items
if self.respond_to? :submissions
stream_items = StreamItem.select([:id, :context_type, :context_id]).
where(:asset_type => 'Submission', :asset_id => submissions).
includes(:context).to_a
stream_item_contexts = stream_items.map { |si| [si.context_type, si.context_id] }
associated_shards = stream_items.inject([]) { |result, si| result | si.associated_shards }
Shard.with_each_shard(associated_shards) do
StreamItemInstance.where(:stream_item_id => stream_items).
update_all_with_invalidation(stream_item_contexts, :hidden => true)
end
end
end
def show_stream_items
if self.respond_to? :submissions
conversation messages for submission comments, fixes #5443 this commit makes submission first-class citizens in conversations. this means that when submission comments are added/deleted, or assignments are unmuted, conversations and messages will be updated accordingly the main impacts in the ui are: 1. submissions can be deleted from conversations. if a new comment is added, they will reappear 2. submissions factor into the message total for the conversation. each submission counts as a single message, even if there are multiple comments 3. submission messages affect unread-ness, and are reflected in the timestamp and text in the conversation preview test plan: 1. confirm submissions appear in the appropriate conversations, i.e. * submissions with no comments should not appear in any conversations * submissions where there are comments but not by instructors: * should appear in each instructor's private conversation with the submitter * should not appear in the submitter's private conversations with anyone * submissions where there are comments by instructors: * should appear in each commenting instructor's private conversation with the submitter * should appear in submitter's private conversations with each commenting instructor adding or removing submission comments should update private conversations accordingly (e.g. when one teacher comments on a submission, it should be removed from the other teachers' private conversations with the submitter). 2. for each scenario above where the submission comments are added and appear in conversations, ensure that the submission as a whole behaves like a single conversation message, i.e. * the unread conversations count is incremented and the private conversation is marked as unread (if it didn't exist or was already read) * the latest submission comment and timestamp should be reflected in the conversation pane on the left side * you can delete the submission from the conversation. if new comments are posted on the submission, the submission should reappear in the conversation (provided it still matches the criteria in 1.). note that submission can not be forwarded to other conversations. 3. submissions should differ from traditional conversation messages in that: * they should not trigger conversation notifications * they should not create/bump conversation stream items. if a conversation has non-submission messages, the submission and its comments should appear in the stream item, but they should not cause it to jump to the top migration: existing submissions/comments will be migrated in, but not necessarily through a traditional rails migration. to bring in those messages, run the following from the rails console: Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) } Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73 Reviewed-on: https://gerrit.instructure.com/8086 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
submissions = submissions(:include => {:hidden_submission_comments => :author})
stream_items = StreamItem.select([:id, :context_type, :context_id]).
where(:asset_type => 'Submission', :asset_id => submissions).
includes(:context).to_a
stream_item_contexts = stream_items.map { |si| [si.context_type, si.context_id] }
associated_shards = stream_items.inject([]) { |result, si| result | si.associated_shards }
Shard.with_each_shard(associated_shards) do
StreamItemInstance.where(:hidden => true, :stream_item_id => stream_items).
update_all_with_invalidation(stream_item_contexts, :hidden => false)
end
conversation messages for submission comments, fixes #5443 this commit makes submission first-class citizens in conversations. this means that when submission comments are added/deleted, or assignments are unmuted, conversations and messages will be updated accordingly the main impacts in the ui are: 1. submissions can be deleted from conversations. if a new comment is added, they will reappear 2. submissions factor into the message total for the conversation. each submission counts as a single message, even if there are multiple comments 3. submission messages affect unread-ness, and are reflected in the timestamp and text in the conversation preview test plan: 1. confirm submissions appear in the appropriate conversations, i.e. * submissions with no comments should not appear in any conversations * submissions where there are comments but not by instructors: * should appear in each instructor's private conversation with the submitter * should not appear in the submitter's private conversations with anyone * submissions where there are comments by instructors: * should appear in each commenting instructor's private conversation with the submitter * should appear in submitter's private conversations with each commenting instructor adding or removing submission comments should update private conversations accordingly (e.g. when one teacher comments on a submission, it should be removed from the other teachers' private conversations with the submitter). 2. for each scenario above where the submission comments are added and appear in conversations, ensure that the submission as a whole behaves like a single conversation message, i.e. * the unread conversations count is incremented and the private conversation is marked as unread (if it didn't exist or was already read) * the latest submission comment and timestamp should be reflected in the conversation pane on the left side * you can delete the submission from the conversation. if new comments are posted on the submission, the submission should reappear in the conversation (provided it still matches the criteria in 1.). note that submission can not be forwarded to other conversations. 3. submissions should differ from traditional conversation messages in that: * they should not trigger conversation notifications * they should not create/bump conversation stream items. if a conversation has non-submission messages, the submission and its comments should appear in the stream item, but they should not cause it to jump to the top migration: existing submissions/comments will be migrated in, but not necessarily through a traditional rails migration. to bring in those messages, run the following from the rails console: Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) } Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73 Reviewed-on: https://gerrit.instructure.com/8086 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
outstanding = submissions.map{ |submission|
comments = submission.hidden_submission_comments.all
next if comments.empty?
[submission, comments.map(&:author_id).uniq.size == 1 ? [comments.last.author] : []]
conversation messages for submission comments, fixes #5443 this commit makes submission first-class citizens in conversations. this means that when submission comments are added/deleted, or assignments are unmuted, conversations and messages will be updated accordingly the main impacts in the ui are: 1. submissions can be deleted from conversations. if a new comment is added, they will reappear 2. submissions factor into the message total for the conversation. each submission counts as a single message, even if there are multiple comments 3. submission messages affect unread-ness, and are reflected in the timestamp and text in the conversation preview test plan: 1. confirm submissions appear in the appropriate conversations, i.e. * submissions with no comments should not appear in any conversations * submissions where there are comments but not by instructors: * should appear in each instructor's private conversation with the submitter * should not appear in the submitter's private conversations with anyone * submissions where there are comments by instructors: * should appear in each commenting instructor's private conversation with the submitter * should appear in submitter's private conversations with each commenting instructor adding or removing submission comments should update private conversations accordingly (e.g. when one teacher comments on a submission, it should be removed from the other teachers' private conversations with the submitter). 2. for each scenario above where the submission comments are added and appear in conversations, ensure that the submission as a whole behaves like a single conversation message, i.e. * the unread conversations count is incremented and the private conversation is marked as unread (if it didn't exist or was already read) * the latest submission comment and timestamp should be reflected in the conversation pane on the left side * you can delete the submission from the conversation. if new comments are posted on the submission, the submission should reappear in the conversation (provided it still matches the criteria in 1.). note that submission can not be forwarded to other conversations. 3. submissions should differ from traditional conversation messages in that: * they should not trigger conversation notifications * they should not create/bump conversation stream items. if a conversation has non-submission messages, the submission and its comments should appear in the stream item, but they should not cause it to jump to the top migration: existing submissions/comments will be migrated in, but not necessarily through a traditional rails migration. to bring in those messages, run the following from the rails console: Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) } Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73 Reviewed-on: https://gerrit.instructure.com/8086 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
}.compact
SubmissionComment.where(:hidden => true, :submission_id => submissions).update_all(:hidden => false)
conversation messages for submission comments, fixes #5443 this commit makes submission first-class citizens in conversations. this means that when submission comments are added/deleted, or assignments are unmuted, conversations and messages will be updated accordingly the main impacts in the ui are: 1. submissions can be deleted from conversations. if a new comment is added, they will reappear 2. submissions factor into the message total for the conversation. each submission counts as a single message, even if there are multiple comments 3. submission messages affect unread-ness, and are reflected in the timestamp and text in the conversation preview test plan: 1. confirm submissions appear in the appropriate conversations, i.e. * submissions with no comments should not appear in any conversations * submissions where there are comments but not by instructors: * should appear in each instructor's private conversation with the submitter * should not appear in the submitter's private conversations with anyone * submissions where there are comments by instructors: * should appear in each commenting instructor's private conversation with the submitter * should appear in submitter's private conversations with each commenting instructor adding or removing submission comments should update private conversations accordingly (e.g. when one teacher comments on a submission, it should be removed from the other teachers' private conversations with the submitter). 2. for each scenario above where the submission comments are added and appear in conversations, ensure that the submission as a whole behaves like a single conversation message, i.e. * the unread conversations count is incremented and the private conversation is marked as unread (if it didn't exist or was already read) * the latest submission comment and timestamp should be reflected in the conversation pane on the left side * you can delete the submission from the conversation. if new comments are posted on the submission, the submission should reappear in the conversation (provided it still matches the criteria in 1.). note that submission can not be forwarded to other conversations. 3. submissions should differ from traditional conversation messages in that: * they should not trigger conversation notifications * they should not create/bump conversation stream items. if a conversation has non-submission messages, the submission and its comments should appear in the stream item, but they should not cause it to jump to the top migration: existing submissions/comments will be migrated in, but not necessarily through a traditional rails migration. to bring in those messages, run the following from the rails console: Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) } Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73 Reviewed-on: https://gerrit.instructure.com/8086 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
Submission.send(:preload_associations, outstanding.map(&:first), :visible_submission_comments)
outstanding.each do |submission, skip_users|
submission.create_or_update_conversations!(:create, :skip_users => skip_users)
conversation messages for submission comments, fixes #5443 this commit makes submission first-class citizens in conversations. this means that when submission comments are added/deleted, or assignments are unmuted, conversations and messages will be updated accordingly the main impacts in the ui are: 1. submissions can be deleted from conversations. if a new comment is added, they will reappear 2. submissions factor into the message total for the conversation. each submission counts as a single message, even if there are multiple comments 3. submission messages affect unread-ness, and are reflected in the timestamp and text in the conversation preview test plan: 1. confirm submissions appear in the appropriate conversations, i.e. * submissions with no comments should not appear in any conversations * submissions where there are comments but not by instructors: * should appear in each instructor's private conversation with the submitter * should not appear in the submitter's private conversations with anyone * submissions where there are comments by instructors: * should appear in each commenting instructor's private conversation with the submitter * should appear in submitter's private conversations with each commenting instructor adding or removing submission comments should update private conversations accordingly (e.g. when one teacher comments on a submission, it should be removed from the other teachers' private conversations with the submitter). 2. for each scenario above where the submission comments are added and appear in conversations, ensure that the submission as a whole behaves like a single conversation message, i.e. * the unread conversations count is incremented and the private conversation is marked as unread (if it didn't exist or was already read) * the latest submission comment and timestamp should be reflected in the conversation pane on the left side * you can delete the submission from the conversation. if new comments are posted on the submission, the submission should reappear in the conversation (provided it still matches the criteria in 1.). note that submission can not be forwarded to other conversations. 3. submissions should differ from traditional conversation messages in that: * they should not trigger conversation notifications * they should not create/bump conversation stream items. if a conversation has non-submission messages, the submission and its comments should appear in the stream item, but they should not cause it to jump to the top migration: existing submissions/comments will be migrated in, but not necessarily through a traditional rails migration. to bring in those messages, run the following from the rails console: Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) } Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73 Reviewed-on: https://gerrit.instructure.com/8086 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
end
end
end
end