diff --git a/plugin-hrm-form/src/___tests__/maskIdentifiers/index.test.ts b/plugin-hrm-form/src/___tests__/maskIdentifiers/index.test.ts index ab573c64f4..72ab68a3b9 100644 --- a/plugin-hrm-form/src/___tests__/maskIdentifiers/index.test.ts +++ b/plugin-hrm-form/src/___tests__/maskIdentifiers/index.test.ts @@ -43,6 +43,9 @@ describe('maskConversationServiceUserNames', () => { strings: { MaskIdentifiers: 'MASKED', }, + user: { + identity: 'current-user-identity', + }, store: { subscribe: jest.fn((callback: () => void) => { storeSubscribeCallback = callback; @@ -56,10 +59,11 @@ describe('maskConversationServiceUserNames', () => { jest.clearAllMocks(); }); - const createParticipant = (sid: string, attributes: Record = {}) => ({ + const createParticipant = (sid: string, attributes: Record = {}, identity?: string) => ({ source: { sid, attributes, + ...(identity && { identity }), }, friendlyName: 'Original Name', }); @@ -78,6 +82,27 @@ describe('maskConversationServiceUserNames', () => { }); each([ + { + testCase: 'identity matches manager user identity, regardless of other checks', + participantAttributes: {}, + participantIdentity: 'current-user-identity', + flexParticipants: {}, + expectedName: 'Original Name', + }, + { + testCase: 'identity matches manager user identity, even with guest member_type', + participantAttributes: { member_type: 'guest' }, + participantIdentity: 'current-user-identity', + flexParticipants: {}, + expectedName: 'Original Name', + }, + { + testCase: 'identity matches manager user identity, even when not in flex store', + participantAttributes: {}, + participantIdentity: 'current-user-identity', + flexParticipants: { participant1: { type: 'customer', sid: 'MB999' } }, + expectedName: 'Original Name', + }, { testCase: 'no member_type attribute and not in flex store as agent', participantAttributes: {}, @@ -122,10 +147,10 @@ describe('maskConversationServiceUserNames', () => { }, ]).test( 'participant should have correct masking when $testCase', - ({ participantAttributes, flexParticipants, expectedName }) => { + ({ participantAttributes, participantIdentity, flexParticipants, expectedName }) => { const conversationSid = 'CH123'; const participantSid = 'MB456'; - const participant = createParticipant(participantSid, participantAttributes); + const participant = createParticipant(participantSid, participantAttributes, participantIdentity); const bySid: Record> = {}; Object.entries(flexParticipants).forEach(([key, value]) => { diff --git a/plugin-hrm-form/src/maskIdentifiers/index.ts b/plugin-hrm-form/src/maskIdentifiers/index.ts index f077673246..8ac975795c 100644 --- a/plugin-hrm-form/src/maskIdentifiers/index.ts +++ b/plugin-hrm-form/src/maskIdentifiers/index.ts @@ -110,7 +110,10 @@ export const maskConversationServiceUserNames = (manager: Manager) => { for (const [conversationSid, conversation] of Object.entries(chat.conversations)) { for (const participant of conversation.participants.values()) { let isAgent: boolean; - if (participant.source.attributes['member_type']) { + if (participant.source.identity && participant.source.identity === manager.user.identity) { + // Identity matches logged in user's identity, it's the current user + isAgent = true; + } else if (participant.source.attributes['member_type']) { // Webchat 2 over programmable chat, check if participant is a guest // Programmable Chat conversation participants are not listed in the 'participants' redux store, so checking that store does not work for them // However they do have a member_type attribute set on the participant in the conversation, so we can use that