@@ -11,7 +11,8 @@ import {
1111 ChatMessage as AcsChatMessage ,
1212 ErrorBarProps ,
1313 SystemMessage ,
14- ContentSystemMessage
14+ ContentSystemMessage ,
15+ Message
1516} from '@azure/communication-react' ;
1617import {
1718 AadUserConversationMember ,
@@ -150,8 +151,8 @@ type MessageEventType =
150151 * Some messages do not have a future value and will be added immediately.
151152 */
152153type MessageConversion = {
153- currentValue ?: AcsChatMessage | SystemMessage ;
154- futureValue ?: Promise < AcsChatMessage | SystemMessage > ;
154+ currentValue ?: Message ;
155+ futureValue ?: Promise < Message > ;
155156} ;
156157
157158/**
@@ -448,7 +449,7 @@ class StatefulGraphChatClient implements StatefulClient<GraphChatClient> {
448449 this . notifyStateChange ( ( draft : GraphChatClient ) => {
449450 draft . participants = this . _chat ?. members || [ ] ;
450451 draft . participantCount = draft . participants . length ;
451- const initialMessages : ( AcsChatMessage | SystemMessage ) [ ] = [ ] ;
452+ const initialMessages : Message [ ] = [ ] ;
452453 draft . messages = draft . messages . concat (
453454 messageConversions
454455 . map ( m => m . currentValue )
@@ -601,7 +602,7 @@ detail: ${JSON.stringify(eventDetail)}`);
601602
602603 // add a pending message to the state.
603604 this . notifyStateChange ( ( draft : GraphChatClient ) => {
604- const pendingMessage : AcsChatMessage = {
605+ const pendingMessage : Message = {
605606 clientMessageId : pendingId ,
606607 messageId : pendingId ,
607608 contentType : 'text' ,
@@ -754,12 +755,13 @@ detail: ${JSON.stringify(eventDetail)}`);
754755 // trying to filter out messages on the graph request causes a 400
755756 // deleted messages are returned as messages with no content, which we can't filter on the graph request
756757 // so we filter them out here
757- . filter ( m => m . body ?. content )
758+ // Violating DLP returns content as empty BUT with policyViolation set
759+ . filter ( m => m . body ?. content || ( ! m . body ?. content && m ?. policyViolation ) )
758760 // This gives us both current and eventual values for each message
759761 . map ( m => this . convertChatMessage ( m ) ) ;
760762
761763 // update the state with the current values
762- const currentValueMessages : ( AcsChatMessage | SystemMessage ) [ ] = [ ] ;
764+ const currentValueMessages : Message [ ] = [ ] ;
763765 messageConversions
764766 . map ( m => m . currentValue )
765767 // need to use a reduce here to filter out undefined values in a way that TypeScript understands
@@ -817,11 +819,11 @@ detail: ${JSON.stringify(eventDetail)}`);
817819 * Update the state with given message either replacing an existing message matching on the id or adding to the list
818820 *
819821 * @private
820- * @param {(AcsChatMessage | SystemMessage ) } [message]
822+ * @param {(Message ) } [message]
821823 * @return {* }
822824 * @memberof StatefulGraphChatClient
823825 */
824- private updateMessages ( message ?: AcsChatMessage | SystemMessage ) {
826+ private updateMessages ( message ?: Message ) {
825827 if ( ! message ) return ;
826828 this . notifyStateChange ( ( draft : GraphChatClient ) => {
827829 const index = draft . messages . findIndex ( m => m . messageId === message . messageId ) ;
@@ -904,7 +906,12 @@ detail: ${JSON.stringify(eventDetail)}`);
904906 index ++ ;
905907 match = this . graphImageMatch ( messageResult ) ;
906908 }
907- let placeholderMessage = this . buildAcsMessage ( graphMessage , currentUser , messageId , messageResult ) ;
909+ let placeholderMessage = this . buildAcsMessage (
910+ graphMessage ,
911+ currentUser ,
912+ messageId ,
913+ messageResult
914+ ) as AcsChatMessage ;
908915 conversion . currentValue = placeholderMessage ;
909916 // local function to update the message with data from each of the resolved image requests
910917 const updateMessage = async ( ) => {
@@ -947,14 +954,9 @@ detail: ${JSON.stringify(eventDetail)}`);
947954 return result ;
948955 }
949956
950- private buildAcsMessage (
951- graphMessage : ChatMessage ,
952- currentUser : string ,
953- messageId : string ,
954- content : string
955- ) : AcsChatMessage {
957+ private buildAcsMessage ( graphMessage : ChatMessage , currentUser : string , messageId : string , content : string ) : Message {
956958 const senderId = graphMessage . from ?. user ?. id || undefined ;
957- return {
959+ let messageData : Message = {
958960 messageId,
959961 contentType : graphMessage . body ?. contentType ?? 'text' ,
960962 messageType : 'chat' ,
@@ -967,6 +969,13 @@ detail: ${JSON.stringify(eventDetail)}`);
967969 status : 'seen' ,
968970 attached : 'top'
969971 } ;
972+ if ( graphMessage ?. policyViolation ) {
973+ messageData = Object . assign ( messageData , {
974+ messageType : 'blocked' ,
975+ link : 'https://go.microsoft.com/fwlink/?LinkId=2132837'
976+ } ) ;
977+ }
978+ return messageData ;
970979 }
971980
972981 private readonly renameChat = async ( topic : string | null ) : Promise < void > => {
0 commit comments