Skip to content

Commit

Permalink
fix: address unavailable user display issues [FS-1684, FS-1570] (#15159)
Browse files Browse the repository at this point in the history
* fix: address unavailable user display issues

* add users with id stored in conversation but no session initiated to the failed array

* use user's display name instead of handle in warning
  • Loading branch information
V-Gira authored May 12, 2023
1 parent 5ef8235 commit b660bb0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ setStrings({en});
function generateUsers(nbUsers: number, domain: string) {
const users: User[] = [];
for (let i = 0; i < nbUsers; i++) {
users.push({qualifiedId: {id: createUuid(), domain}, username: () => `User ${i}`});
users.push({qualifiedId: {id: createUuid(), domain}, name: () => `User ${i}`});
}
return users;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('PartialFailureToSendWarning', () => {
);

expect(queryByText('Show details')).toBeNull();
expect(container.textContent).toContain(`${users[0].username()} will get your message later`);
expect(container.textContent).toContain(`${users[0].name()} will get your message later`);
});

it('does not show the extra info toggle if there is only a single unreachable user', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {matchQualifiedIds} from 'Util/QualifiedId';

import {warning} from '../Warnings.styles';

export type User = {qualifiedId: QualifiedId; username: () => string};
export type User = {qualifiedId: QualifiedId; name: () => string};
type Props = {
failedToSend: {queued?: QualifiedUserClients; failed?: QualifiedId[]};
knownUsers: User[];
Expand All @@ -44,7 +44,7 @@ function generateNamedUsers(users: User[], userClients: QualifiedUserClients): P
const domainNamedUsers = Object.keys(domainUsers).reduce<ParsedUsers>(
(domainNamedUsers, userId) => {
const user = users.find(user => matchQualifiedIds(user.qualifiedId, {id: userId, domain}));
if (user) {
if (user && user.name()) {
domainNamedUsers.namedUsers.push(user);
} else {
domainNamedUsers.unknownUsers.push({id: userId, domain});
Expand Down Expand Up @@ -81,7 +81,9 @@ export const PartialFailureToSendWarning = ({failedToSend, knownUsers}: Props) =

const showToggle = userCount > 1;

const {namedUsers} = generateNamedUsers(knownUsers, queued);
const {namedUsers, unknownUsers} = generateNamedUsers(knownUsers, queued);

failed.push(...unknownUsers);

const unreachableUsers = generateUnreachableUsers(failed);

Expand All @@ -90,7 +92,7 @@ export const PartialFailureToSendWarning = ({failedToSend, knownUsers}: Props) =
message.head = t('messageFailedToSendParticipants', {count: userCount.toString()});
message.rest = t('messageFailedToSendPlural');
} else if (namedUsers.length === 1) {
message.head = namedUsers[0].username();
message.head = namedUsers[0].name();
message.rest = t('messageFailedToSendWillReceiveSingular');
} else if (unreachableUsers.length === 1) {
message.head = t('messageFailedToSendParticipantsFromDomainSingular', {domain: unreachableUsers[0].domain});
Expand Down Expand Up @@ -118,7 +120,7 @@ export const PartialFailureToSendWarning = ({failedToSend, knownUsers}: Props) =
data-uie-value={user.qualifiedId.id}
key={user.qualifiedId.id}
>
{user.username()}
{user.name()}
</Bold>
)),
', ',
Expand Down
4 changes: 2 additions & 2 deletions src/script/entity/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,11 @@ describe('Conversation', () => {
it('displays a fallback if no user name has been set', () => {
conversation_et.type(CONVERSATION_TYPE.ONE_TO_ONE);

expect(conversation_et.display_name()).toBe('');
expect(conversation_et.display_name()).toBe('Name not available');

conversation_et.type(CONVERSATION_TYPE.CONNECT);

expect(conversation_et.display_name()).toBe('');
expect(conversation_et.display_name()).toBe('Name not available');
});

it('displays a group conversation name with names from the participants', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/script/entity/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ export class Conversation {
*
* - Name of the other participant
* - Name of the other user of the associated connection
* - "..." if neither of those has been attached yet
* - "Name not available" if neither of those has been attached yet
*
* 'Group Conversation':
* - Conversation name received from backend
* - If unnamed, we will create a name from the participant names
* - Join the user's first names to a comma separated list or uses the user's first name if only one user participating
* - "..." if the user entities have not yet been attached yet
* - "..." if the user entities have not yet been attached
*/
this.display_name = ko.pureComputed(() => {
if (this.isRequest() || this.is1to1()) {
const [userEntity] = this.participating_user_ets();
const userName = userEntity?.name();
return userName || '…';
return userName || t('unavailableUser');
}

if (this.isGroup()) {
Expand Down
4 changes: 2 additions & 2 deletions src/script/notification/NotificationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('NotificationRepository', () => {

notification_content.title = truncate(titleText, titleLength, false);
} else {
notification_content.title = '';
notification_content.title = 'Name not available';
}

const [firstResultArgs] = showNotificationSpy.mock.calls[0];
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('NotificationRepository', () => {

describe('shows a well-formed request notification', () => {
let connectionEntity: ConnectionEntity;
const expected_title = '';
const expected_title = 'Name not available';
let memberMessage: MemberMessage;

beforeEach(() => {
Expand Down

0 comments on commit b660bb0

Please sign in to comment.