return only active conversation messages

fixes VICE-2206
flag=react_inbox

Test Plan:
- Make sure you have a conversation with a deleted conversation
  message
- Enable the react inbox FF
- Navigate to the inbox
- Select the converesation with the deleted conversation message
- The deleted conversation message should not be present

Change-Id: Ia76c54d39b605d3d59b562d329bd12b6cb0631cb
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/276913
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Chawn Neal <chawn.neal@instructure.com>
QA-Review: Chawn Neal <chawn.neal@instructure.com>
Product-Review: Chawn Neal <chawn.neal@instructure.com>
This commit is contained in:
Matthew Lemon 2021-10-27 09:41:15 -06:00
parent 51e5cb10c8
commit ba59372e41
2 changed files with 8 additions and 1 deletions

View File

@ -38,7 +38,7 @@ module Types
def conversation_messages_connection(participants: nil, created_before: nil)
load_association(:conversation_messages).then do |messages|
Loaders::AssociationLoader.for(ConversationMessage, :conversation_message_participants).load_many(messages).then do
messages = messages.select { |message| message.conversation_message_participants.pluck(:user_id).include?(current_user.id) }
messages = messages.select { |message| message.conversation_message_participants.pluck(:user_id, :workflow_state).include?([current_user.id, 'active']) }
if participants
messages = messages.select { |message| (participants - message.conversation_message_participants.pluck(:user_id).map(&:to_s)).empty? }
end

View File

@ -90,6 +90,13 @@ describe Types::ConversationType do
result = conversation_type.resolve(%|conversationMessagesConnection(createdBefore: "#{Time.zone.at(float_time).iso8601}") { nodes { body } }|)
expect(result).to include(@conversation.conversation.conversation_messages[0].body)
end
it 'does not return deleted messages' do
message = @conversation.conversation.add_message(@student, 'delete me')
message.conversation_message_participants.where(user_id: @teacher.id).first.update!(workflow_state: 'deleted')
result = conversation_type.resolve('conversationMessagesConnection { nodes { body } }')
expect(result).to match_array(@conversation.conversation.conversation_messages.where.not(id: message).pluck(:body))
end
end
context 'conversationPaticipants' do