conversations: update unread count only for recipients
fixes CNVS-13639 test plan: * as user A, send a message to B and C * as user B, mark the conversation as read * as user C, reply privately to A * as user B, verify that your unread message count does not change Change-Id: I9fbf9b7bfea507d51a95231568ec33211ddd14da Reviewed-on: https://gerrit.instructure.com/36519 Reviewed-by: Drew Bowman <dbowman@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Braden Anderson <braden@instructure.com> Tested-by: Bryan Madsen <bryan@instructure.com>
This commit is contained in:
parent
21d8f43f85
commit
f2d4d287f0
|
@ -427,15 +427,23 @@ class Conversation < ActiveRecord::Base
|
|||
(options[:only_users]).map(&:id)) if options[:only_users]
|
||||
|
||||
skip_ids = options[:skip_users].try(:map, &:id) || [message.author_id]
|
||||
skip_ids = [0] if skip_ids.empty?
|
||||
update_for_skips = options[:update_for_skips] != false
|
||||
|
||||
# make sure this jumps to the top of the inbox and is marked as unread for anyone who's subscribed
|
||||
cp_conditions = sanitize_sql([
|
||||
"cp.conversation_id = ? AND cp.workflow_state <> 'unread' AND (cp.last_message_at IS NULL OR cp.subscribed) AND cp.user_id NOT IN (?)",
|
||||
sql = "cp.conversation_id = ? AND cp.workflow_state <> 'unread' AND (cp.last_message_at IS NULL OR cp.subscribed)"
|
||||
params = [
|
||||
self.id,
|
||||
skip_ids
|
||||
])
|
||||
]
|
||||
if skip_ids.present?
|
||||
sql += " AND cp.user_id NOT IN (?)"
|
||||
params << skip_ids
|
||||
end
|
||||
if options[:only_users]
|
||||
sql += " AND cp.user_id IN (?)"
|
||||
params << (options[:only_users]).map(&:id)
|
||||
end
|
||||
cp_conditions = sanitize_sql(params.unshift(sql))
|
||||
|
||||
if %w{MySQL Mysql2}.include?(connection.adapter_name)
|
||||
connection.execute <<-SQL
|
||||
UPDATE users, conversation_participants cp
|
||||
|
|
|
@ -283,6 +283,20 @@ describe Conversation do
|
|||
@unsubscribed_guy.conversations.unread.size.should eql 0
|
||||
end
|
||||
|
||||
it "should increment only for message participants" do
|
||||
root_convo = Conversation.initiate([@sender, @recipient, @subscribed_guy], false)
|
||||
root_convo.add_message(@sender, 'test')
|
||||
|
||||
@subscribed_guy.conversations.first.update_attribute(:workflow_state, "read")
|
||||
@subscribed_guy.reload.unread_conversations_count.should eql 0
|
||||
@subscribed_guy.conversations.unread.size.should eql 0
|
||||
|
||||
root_convo.add_message(@sender, 'test2', :only_users => [@recipient])
|
||||
|
||||
@subscribed_guy.reload.unread_conversations_count.should eql 0
|
||||
@subscribed_guy.conversations.unread.size.should eql 0
|
||||
end
|
||||
|
||||
it "should decrement when deleting an unread conversation" do
|
||||
root_convo = Conversation.initiate([@sender, @unread_guy], false)
|
||||
root_convo.add_message(@sender, 'test')
|
||||
|
|
Loading…
Reference in New Issue