Skip to content

Commit 6e309a4

Browse files
musalegavinbarron
andauthored
feat: add support for blocked messages (#2664)
* Add blocked message types for DLP violated messages Signed-off-by: Musale Martin <[email protected]> * Add link to the DLP and communication compliance policy Co-authored-by: Gavin Barron <[email protected]> * Change to use broad Message type and fix type errors Signed-off-by: Martin Musale <[email protected]> --------- Signed-off-by: Musale Martin <[email protected]> Signed-off-by: Martin Musale <[email protected]> Co-authored-by: Gavin Barron <[email protected]>
1 parent d73db51 commit 6e309a4

File tree

3 files changed

+278
-352
lines changed

3 files changed

+278
-352
lines changed

packages/mgt-chat/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
"typescript": "^4.9.5"
4242
},
4343
"dependencies": {
44-
"@azure/communication-calling": "1.10.1",
45-
"@azure/communication-chat": "1.3.0",
46-
"@azure/communication-common": "2.2.0",
44+
"@azure/communication-calling": "1.15.2",
45+
"@azure/communication-chat": "1.3.1",
46+
"@azure/communication-common": "2.2.1",
4747
"@azure/communication-identity": "1.2.0",
48-
"@azure/communication-react": "1.5.0",
48+
"@azure/communication-react": "1.7.0-beta.2",
49+
"@azure/communication-calling-effects": "1.0.1",
4950
"@azure/msal-browser": "2.33.0",
5051
"@fluentui/react": "~8.106.1",
5152
"@fluentui/react-northstar": "^0.66.4",

packages/mgt-chat/src/statefulClient/StatefulGraphChatClient.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
ChatMessage as AcsChatMessage,
1212
ErrorBarProps,
1313
SystemMessage,
14-
ContentSystemMessage
14+
ContentSystemMessage,
15+
Message
1516
} from '@azure/communication-react';
1617
import {
1718
AadUserConversationMember,
@@ -150,8 +151,8 @@ type MessageEventType =
150151
* Some messages do not have a future value and will be added immediately.
151152
*/
152153
type 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

Comments
 (0)