Skip to content

Commit 03ec8fb

Browse files
committed
added participating_user_ids to conversation_message_json
fixes CNVS-7130 test plan - retrieve conversations via the api - ensure that the participating_user_ids field for each message lists the messages participating user ids Change-Id: I3d7a579d610e70f06dd646d3089c8568db9bc10d Reviewed-on: https://gerrit.instructure.com/22720 Reviewed-by: Braden Anderson <banderson@instructure.com> QA-Review: Braden Anderson <banderson@instructure.com> QA-Review: Cam Theriault <cam@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Joel Hough <joel@instructure.com>
1 parent bfb4e5c commit 03ec8fb

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

lib/api/v1/conversation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def conversation_json(conversation, current_user, session, options = {})
4646

4747
def conversation_message_json(message, current_user, session)
4848
result = message.as_json
49+
result['participating_user_ids'] = message.conversation_message_participants.pluck(:user_id)
4950
result['media_comment'] = media_comment_json(result['media_comment']) if result['media_comment']
5051
result['attachments'] = result['attachments'].map{ |attachment| attachment_json(attachment, current_user) }
5152
result['forwarded_messages'] = result['forwarded_messages'].map{ |m| conversation_message_json(m, current_user, session) }

spec/apis/v1/conversations_api_spec.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ def verify_filter(filter)
395395
p.delete("avatar_url")
396396
}
397397
}
398+
json.each {|c| c["messages"].each {|m| m["participating_user_ids"].sort!}}
398399
conversation = @me.all_conversations.order("conversation_id DESC").first
399400
json.should eql [
400401
{
@@ -420,7 +421,7 @@ def verify_filter(filter)
420421
{"id" => @bob.id, "name" => @bob.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
421422
],
422423
"messages" => [
423-
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
424+
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @bob.id].sort}
424425
]
425426
}
426427
]
@@ -436,6 +437,7 @@ def verify_filter(filter)
436437
p.delete("avatar_url")
437438
}
438439
}
440+
json.each {|c| c["messages"].each {|m| m["participating_user_ids"].sort!}}
439441
conversation = @me.all_conversations.order("conversation_id DESC").first
440442
json.should eql [
441443
{
@@ -462,7 +464,7 @@ def verify_filter(filter)
462464
{"id" => @bob.id, "name" => @bob.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
463465
],
464466
"messages" => [
465-
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
467+
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @billy.id, @bob.id].sort}
466468
]
467469
}
468470
]
@@ -482,6 +484,7 @@ def verify_filter(filter)
482484
p.delete("avatar_url")
483485
}
484486
}
487+
json.each {|c| c["messages"].each {|m| m["participating_user_ids"].sort!}}
485488
json.should eql [
486489
{
487490
"id" => conversation.conversation_id,
@@ -506,7 +509,7 @@ def verify_filter(filter)
506509
{"id" => @bob.id, "name" => @bob.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
507510
],
508511
"messages" => [
509-
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
512+
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @bob.id].sort}
510513
]
511514
}
512515
]
@@ -568,6 +571,7 @@ def verify_filter(filter)
568571
p.delete("avatar_url")
569572
}
570573
}
574+
json.each {|c| c["messages"].each {|m| m["participating_user_ids"].sort!}}
571575
conversation = @me.all_conversations.order("last_message_at DESC, conversation_id DESC").first
572576
json.should eql [
573577
{
@@ -595,7 +599,7 @@ def verify_filter(filter)
595599
],
596600
"messages" => [
597601
{
598-
"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "attachments" => [],
602+
"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "attachments" => [], "participating_user_ids" => [@me.id, @billy.id].sort,
599603
"forwarded_messages" => [
600604
{
601605
"id" => forwarded_message.id, "created_at" => forwarded_message.created_at.to_json[1, 20], "body" => "test", "author_id" => @bob.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [],
@@ -608,7 +612,7 @@ def verify_filter(filter)
608612
'hidden_for_user' => false,
609613
'created_at' => attachment.created_at.as_json,
610614
'updated_at' => attachment.updated_at.as_json,
611-
'thumbnail_url' => attachment.thumbnail_url }]
615+
'thumbnail_url' => attachment.thumbnail_url }], "participating_user_ids" => [@me.id, @bob.id].sort
612616
}
613617
]
614618
}
@@ -640,6 +644,7 @@ def verify_filter(filter)
640644
json["participants"].each{ |p|
641645
p.delete("avatar_url")
642646
}
647+
json["messages"].each {|m| m["participating_user_ids"].sort!}
643648
json.should eql({
644649
"id" => conversation.conversation_id,
645650
"workflow_state" => "read",
@@ -695,9 +700,10 @@ def verify_filter(filter)
695700
'updated_at' => attachment.updated_at.as_json,
696701
'thumbnail_url' => attachment.thumbnail_url
697702
}
698-
]
703+
],
704+
"participating_user_ids" => [@me.id, @bob.id].sort
699705
},
700-
{"id" => conversation.messages.last.id, "created_at" => conversation.messages.last.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
706+
{"id" => conversation.messages.last.id, "created_at" => conversation.messages.last.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @bob.id].sort}
701707
],
702708
"submissions" => []
703709
})
@@ -724,6 +730,7 @@ def check_conversation
724730
json["participants"].each{ |p|
725731
p.delete("avatar_url")
726732
}
733+
json["messages"].each {|m| m["participating_user_ids"].sort!}
727734
expected = {
728735
"id" => @conversation.conversation_id,
729736
"workflow_state" => "read",
@@ -747,7 +754,7 @@ def check_conversation
747754
{"id" => @bob.id, "name" => @bob.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
748755
],
749756
"messages" => [
750-
{"id" => @conversation.messages.last.id, "created_at" => @conversation.messages.last.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
757+
{"id" => @conversation.messages.last.id, "created_at" => @conversation.messages.last.created_at.to_json[1, 20], "body" => "test", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @bob.id].sort}
751758
],
752759
"submissions" => []
753760
}
@@ -865,6 +872,7 @@ def check_conversation
865872
json["participants"].each{ |p|
866873
p.delete("avatar_url")
867874
}
875+
json["messages"].each {|m| m["participating_user_ids"].sort!}
868876
json.should eql({
869877
"id" => conversation.conversation_id,
870878
"workflow_state" => "read",
@@ -888,7 +896,7 @@ def check_conversation
888896
{"id" => @bob.id, "name" => @bob.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
889897
],
890898
"messages" => [
891-
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "another", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
899+
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "another", "author_id" => @me.id, "generated" => false, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @bob.id].sort}
892900
]
893901
})
894902
end
@@ -920,6 +928,7 @@ def check_conversation
920928
json["participants"].each{ |p|
921929
p.delete("avatar_url")
922930
}
931+
json["messages"].each {|m| m["participating_user_ids"].sort!}
923932
json.should eql({
924933
"id" => conversation.conversation_id,
925934
"workflow_state" => "read",
@@ -947,7 +956,7 @@ def check_conversation
947956
{"id" => @tommy.id, "name" => @tommy.name, "common_courses" => {@course.id.to_s => ["StudentEnrollment"]}, "common_groups" => {}}
948957
],
949958
"messages" => [
950-
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "jane, joe, and tommy were added to the conversation by nobody@example.com", "author_id" => @me.id, "generated" => true, "media_comment" => nil, "forwarded_messages" => [], "attachments" => []}
959+
{"id" => conversation.messages.first.id, "created_at" => conversation.messages.first.created_at.to_json[1, 20], "body" => "jane, joe, and tommy were added to the conversation by nobody@example.com", "author_id" => @me.id, "generated" => true, "media_comment" => nil, "forwarded_messages" => [], "attachments" => [], "participating_user_ids" => [@me.id, @billy.id, @bob.id, @jane.id, @joe.id, @tommy.id].sort}
951960
]
952961
})
953962
end

0 commit comments

Comments
 (0)