Skip to content

Hide chat messages for student if teacher flags#72264

Open
fisher-alice wants to merge 14 commits intostagingfrom
alice/teacher-flagged-hide
Open

Hide chat messages for student if teacher flags#72264
fisher-alice wants to merge 14 commits intostagingfrom
alice/teacher-flagged-hide

Conversation

@fisher-alice
Copy link
Copy Markdown
Contributor

@fisher-alice fisher-alice commented Apr 21, 2026

The feature to allow teachers to flag messages in the teacher view of their student's chat history was added in #62797.
This PR updates student view of the the student chat history so that if a message is flagged by the teacher, the message is hidden from the student.

There were 5,561,438 chat events from the last 90 days (as of April 21), and only 47 of them included teacher feedback spreadsheet. Here's a graph of the breakdown of teacher feedback of these events:

Screenshot 2026-04-21 at 9 41 15 PM

For both user and assistant messages that are flagged with 'clean_disagree', the following is now displayed: 'This message has been flagged as inappropriate by the teacher.' Note that if a message is text + image or just an image, the same message is displayed.

This PR includes computing teacherFlaggedHidden to determine the display and corresponding UI for teacher-flagged message. I added a couple helper functions (getHeader and getFooter) in ChatMessageView to help readability.

Links

Testing story

Tested locally on a teacher account and a student account who's in the teacher's section.

Screencast of teacher flagging/unflagging messages in Web Lab 2's AI Tutor:

weblab2.mp4

Screencast of teacher flagging/unflagging messages in AI

aichat.mp4

Chat Lab:

Deployment notes

Privacy and security

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-side hiding of teacher-flagged chat messages for students by deriving a teacherFlaggedHidden state from teacher feedback and using it to alter message display, styling, and UI chrome.

Changes:

  • Compute teacherFlaggedHidden in ChatEventView based on teacherFeedback === CLEAN_DISAGREE and !isTeacherView, and pass it through to message rendering.
  • Update ChatMessageView to accept isTeacherView + teacherFlaggedHidden, hide assets/footers when hidden, and adjust message style accordingly.
  • Refactor footer selection logic into a helper (getFooter) and extend getChatMessageDisplayText/getMessageStyle to account for hidden messages.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
apps/src/aichat/views/ChatMessageView.tsx Uses teacherFlaggedHidden to suppress visibility-dependent UI and change the rendered message text/style; refactors footer logic.
apps/src/aichat/views/ChatEventView.tsx Derives teacherFlaggedHidden from teacher feedback and supplies it to aria-label + ChatMessageView.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/src/aichat/views/ChatMessageView.tsx
Comment thread apps/src/aichat/views/ChatMessageView.tsx Outdated
Comment thread apps/src/aichat/views/ChatMessageView.tsx
Comment thread apps/src/aichat/views/ChatEventView.tsx
@fisher-alice fisher-alice marked this pull request as ready for review April 21, 2026 21:08
@fisher-alice fisher-alice requested review from a team, cnbrenci and sanchitmalhotra126 April 22, 2026 13:05
if (status === Status.PROFANITY_VIOLATION && !showProfaneUserMessage) {
return commonI18n.aiChatInappropriateUserMessage();
}
if (teacherFlaggedHidden) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to put this at the beginning of the function so we don't need to duplicate it in both branches of logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it at the end so that other errors would be displayed. but teacherFlaggedHidden can only be true if the message was considered 'clean'. So yes! I think putting at the beginning makes sense to de-dup. I'll add a comment explaining why also.

displayText === intendedDisplayText &&
chatMessage.status !== Status.PROFANITY_VIOLATION;
chatMessage.status !== Status.PROFANITY_VIOLATION &&
!teacherFlaggedHidden;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think displayText === intendedDisplayText would already give us the right messageVisible value without adding the extra !teacherFlaggedHidden check; is my thinking correct here? Since getChatMessageDisplayText will override displayText?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! related to comment above and below. Will remove unnecessary check.

chatMessage.role === Role.USER &&
chatMessage.status === Status.PROFANITY_VIOLATION;
chatMessage.status === Status.PROFANITY_VIOLATION &&
!teacherFlaggedHidden;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a similar question here- do we need to add the extra clause here at all? because it won't ever be teacherFlaggedHidden unless it was clean and the teacher disagreed?

Comment on lines +98 to +100
const teacherFlagged = isCompletedChatMessage(event)
? event.teacherFeedback === TeacherFeedback.CLEAN_DISAGREE
: false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove ternary? isCompletedChatMessage(event) && event.teacherFeedback === TeacherFeedback.CLEAN_DISAGREE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update

teacherFlaggedHidden: boolean;
}

function getHeader({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well make this (and the footer) functional components?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense - this file is getting pretty long.

@fisher-alice fisher-alice requested a review from dju90 April 22, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants