Display surname for contacts without first name (#1015)

This commit is contained in:
Alexander Zinchuk 2021-04-16 14:48:24 +03:00
parent ba62d35c42
commit 41cb364b40
10 changed files with 44 additions and 44 deletions

View File

@ -7,7 +7,7 @@ import { GlobalActions } from '../../global/types';
import { selectIsChatWithSelf, selectUser } from '../../modules/selectors';
import {
isChatPrivate,
getUserFirstName,
getUserFirstOrLastName,
getPrivateChatUserId,
isChatBasicGroup,
isChatSuperGroup,
@ -37,7 +37,7 @@ type StateProps = {
isSuperGroup: boolean;
canDeleteForAll?: boolean;
chatTitle: string;
contactFirstName?: string;
contactName?: string;
};
type DispatchProps = Pick<GlobalActions, 'leaveChannel' | 'deleteHistory' | 'deleteChannel'>;
@ -52,7 +52,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
isSuperGroup,
canDeleteForAll,
chatTitle,
contactFirstName,
contactName,
onClose,
leaveChannel,
deleteHistory,
@ -129,7 +129,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
return <p>Are you sure you want to leave group <strong>{chatTitle}</strong>?</p>;
}
return <p>Are you sure you want to delete chat with <strong>{contactFirstName}</strong>?</p>;
return <p>Are you sure you want to delete chat with <strong>{contactName}</strong>?</p>;
}
function renderActionText() {
@ -157,7 +157,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
{renderMessage()}
{canDeleteForAll && (
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForAll}>
Delete for {contactFirstName ? `me and ${contactFirstName}` : 'Everyone'}
Delete for {contactName ? `me and ${contactName}` : 'Everyone'}
</Button>
)}
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteChat}>
@ -173,8 +173,8 @@ export default memo(withGlobal<OwnProps>(
const isPrivateChat = isChatPrivate(chat.id);
const isChatWithSelf = selectIsChatWithSelf(global, chat.id);
const canDeleteForAll = (isPrivateChat && !isChatWithSelf);
const contactFirstName = chat && isChatPrivate(chat.id)
? getUserFirstName(selectUser(global, getPrivateChatUserId(chat)!))
const contactName = chat && isChatPrivate(chat.id)
? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!))
: undefined;
return {
@ -185,7 +185,7 @@ export default memo(withGlobal<OwnProps>(
isSuperGroup: isChatSuperGroup(chat),
canDeleteForAll,
chatTitle: getChatTitle(chat),
contactFirstName,
contactName,
};
},
(setGlobal, actions): DispatchProps => pick(actions, ['leaveChannel', 'deleteHistory', 'deleteChannel']),

View File

@ -14,7 +14,7 @@ import {
} from '../../modules/selectors';
import {
isChatPrivate,
getUserFirstName,
getUserFirstOrLastName,
getPrivateChatUserId,
isChatBasicGroup,
isChatSuperGroup,
@ -36,7 +36,7 @@ export type OwnProps = {
type StateProps = {
canDeleteForAll?: boolean;
contactFirstName?: string;
contactName?: string;
willDeleteForCurrentUserOnly?: boolean;
willDeleteForAll?: boolean;
};
@ -49,7 +49,7 @@ const DeleteMessageModal: FC<OwnProps & StateProps & DispatchProps> = ({
message,
album,
canDeleteForAll,
contactFirstName,
contactName,
willDeleteForCurrentUserOnly,
willDeleteForAll,
onClose,
@ -98,8 +98,8 @@ const DeleteMessageModal: FC<OwnProps & StateProps & DispatchProps> = ({
)}
{canDeleteForAll && (
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForAll}>
Delete for {contactFirstName ? 'me and ' : 'Everyone'}
{contactFirstName && renderText(contactFirstName)}
Delete for {contactName ? 'me and ' : 'Everyone'}
{contactName && renderText(contactName)}
</Button>
)}
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForSelf}>
@ -115,8 +115,8 @@ export default memo(withGlobal<OwnProps>(
const { threadId } = selectCurrentMessageList(global) || {};
const { canDeleteForAll } = (threadId && selectAllowedMessageActions(global, message, threadId)) || {};
const chat = selectChat(global, message.chatId);
const contactFirstName = chat && isChatPrivate(chat.id)
? getUserFirstName(selectUser(global, getPrivateChatUserId(chat)!))
const contactName = chat && isChatPrivate(chat.id)
? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!))
: undefined;
const willDeleteForCurrentUserOnly = chat && isChatBasicGroup(chat) && !canDeleteForAll;
@ -124,7 +124,7 @@ export default memo(withGlobal<OwnProps>(
return {
canDeleteForAll: !isSchedule && canDeleteForAll,
contactFirstName,
contactName,
willDeleteForCurrentUserOnly,
willDeleteForAll,
};

View File

@ -4,7 +4,7 @@ import { withGlobal } from '../../lib/teact/teactn';
import { ApiChat, ApiUser } from '../../api/types';
import { selectChat, selectUser } from '../../modules/selectors';
import { getChatTitle, getUserFirstName, isChatPrivate } from '../../modules/helpers';
import { getChatTitle, getUserFirstOrLastName, isChatPrivate } from '../../modules/helpers';
import renderText from './helpers/renderText';
import buildClassName from '../../util/buildClassName';
import useLang from '../../hooks/useLang';
@ -64,7 +64,7 @@ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
);
const name = !chat || (user && !user.isSelf)
? getUserFirstName(user)
? getUserFirstOrLastName(user)
: getChatTitle(chat, user);
titleText = name ? renderText(name) : undefined;

View File

@ -6,7 +6,7 @@ import { GlobalActions } from '../../global/types';
import { selectChat, selectIsChatWithSelf, selectUser } from '../../modules/selectors';
import {
isChatPrivate,
getUserFirstName,
getUserFirstOrLastName,
getPrivateChatUserId,
isChatBasicGroup,
isChatSuperGroup,
@ -32,7 +32,7 @@ type StateProps = {
isGroup: boolean;
isSuperGroup: boolean;
canPinForAll: boolean;
contactFirstName?: string;
contactName?: string;
};
type DispatchProps = Pick<GlobalActions, 'pinMessage'>;
@ -45,7 +45,7 @@ const PinMessageModal: FC<OwnProps & StateProps & DispatchProps> = ({
isGroup,
isSuperGroup,
canPinForAll,
contactFirstName,
contactName,
onClose,
pinMessage,
}) => {
@ -98,7 +98,7 @@ const PinMessageModal: FC<OwnProps & StateProps & DispatchProps> = ({
</Button>
{canPinForAll && (
<Button className="confirm-dialog-button" isText onClick={handlePinMessageForAll}>
{contactFirstName ? `Pin for me and ${contactFirstName}` : 'Pin and notify all memebers'}
{contactName ? `Pin for me and ${contactName}` : 'Pin and notify all memebers'}
</Button>
)}
<Button className="confirm-dialog-button" isText onClick={onClose}>{lang('Cancel')}</Button>
@ -115,8 +115,8 @@ export default memo(withGlobal<OwnProps>(
const isGroup = !!chat && isChatBasicGroup(chat);
const isSuperGroup = !!chat && isChatSuperGroup(chat);
const canPinForAll = (isPrivateChat && !isChatWithSelf) || isSuperGroup || isGroup;
const contactFirstName = chat && isChatPrivate(chat.id)
? getUserFirstName(selectUser(global, getPrivateChatUserId(chat)!))
const contactName = chat && isChatPrivate(chat.id)
? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!))
: undefined;
return {
@ -126,7 +126,7 @@ export default memo(withGlobal<OwnProps>(
isGroup,
isSuperGroup,
canPinForAll,
contactFirstName,
contactName,
};
},
(setGlobal, actions): DispatchProps => pick(actions, ['pinMessage']),

View File

@ -4,7 +4,7 @@ import { withGlobal } from '../../lib/teact/teactn';
import { ApiUser, ApiTypingStatus } from '../../api/types';
import { selectUser } from '../../modules/selectors';
import { getUserFirstName } from '../../modules/helpers';
import { getUserFirstOrLastName } from '../../modules/helpers';
import renderText from './helpers/renderText';
import './TypingStatus.scss';
@ -18,7 +18,7 @@ type StateProps = {
};
const TypingStatus: FC<OwnProps & StateProps> = ({ typingStatus, typingUser }) => {
const typingUserName = typingUser && !typingUser.isSelf && getUserFirstName(typingUser);
const typingUserName = typingUser && !typingUser.isSelf && getUserFirstOrLastName(typingUser);
return (
<p className="typing-status">

View File

@ -6,7 +6,7 @@ import { withGlobal } from '../../../lib/teact/teactn';
import { GlobalActions } from '../../../global/types';
import { ApiUser } from '../../../api/types';
import { getUserFirstName } from '../../../modules/helpers';
import { getUserFirstOrLastName } from '../../../modules/helpers';
import renderText from '../../common/helpers/renderText';
import { throttle } from '../../../util/schedulers';
import { pick } from '../../../util/iteratees';
@ -79,7 +79,7 @@ const RecentContacts: FC<OwnProps & StateProps & DispatchProps> = ({
{topUserIds.map((userId) => (
<div className="top-peer-item" onClick={() => handleClick(userId)}>
<Avatar user={usersById[userId]} />
<div className="top-peer-name">{renderText(getUserFirstName(usersById[userId]) || NBSP)}</div>
<div className="top-peer-name">{renderText(getUserFirstOrLastName(usersById[userId]) || NBSP)}</div>
</div>
))}
</div>

View File

@ -6,7 +6,7 @@ import { GlobalActions } from '../../global/types';
import { selectCanDeleteSelectedMessages, selectCurrentChat, selectUser } from '../../modules/selectors';
import {
isChatPrivate,
getUserFirstName,
getUserFirstOrLastName,
getPrivateChatUserId,
isChatBasicGroup,
isChatSuperGroup,
@ -27,7 +27,7 @@ export type OwnProps = {
type StateProps = {
selectedMessageIds?: number[];
canDeleteForAll?: boolean;
contactFirstName?: string;
contactName?: string;
willDeleteForCurrentUserOnly?: boolean;
willDeleteForAll?: boolean;
};
@ -39,7 +39,7 @@ const DeleteSelectedMessagesModal: FC<OwnProps & StateProps & DispatchProps> = (
isSchedule,
selectedMessageIds,
canDeleteForAll,
contactFirstName,
contactName,
willDeleteForCurrentUserOnly,
willDeleteForAll,
onClose,
@ -89,8 +89,8 @@ const DeleteSelectedMessagesModal: FC<OwnProps & StateProps & DispatchProps> = (
)}
{canDeleteForAll && (
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForAll}>
Delete for {contactFirstName ? 'me and ' : 'Everyone'}
{contactFirstName && renderText(contactFirstName)}
Delete for {contactName ? 'me and ' : 'Everyone'}
{contactName && renderText(contactName)}
</Button>
)}
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForSelf}>
@ -106,8 +106,8 @@ export default memo(withGlobal<OwnProps>(
const { messageIds: selectedMessageIds } = global.selectedMessages || {};
const { canDeleteForAll } = selectCanDeleteSelectedMessages(global);
const chat = selectCurrentChat(global);
const contactFirstName = chat && isChatPrivate(chat.id)
? getUserFirstName(selectUser(global, getPrivateChatUserId(chat)!))
const contactName = chat && isChatPrivate(chat.id)
? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!))
: undefined;
const willDeleteForCurrentUserOnly = chat && isChatBasicGroup(chat) && !canDeleteForAll;
@ -116,7 +116,7 @@ export default memo(withGlobal<OwnProps>(
return {
selectedMessageIds,
canDeleteForAll: !isSchedule && canDeleteForAll,
contactFirstName,
contactName,
willDeleteForCurrentUserOnly,
willDeleteForAll,
};

View File

@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from '../../../../lib/teact/teact';
import { ApiMessageEntityTypes, ApiChatMember, ApiUser } from '../../../../api/types';
import { EDITABLE_INPUT_ID } from '../../../../config';
import { getUserFirstName } from '../../../../modules/helpers';
import { getUserFirstOrLastName } from '../../../../modules/helpers';
import searchUserName from '../helpers/searchUserName';
import { IS_MOBILE_SCREEN } from '../../../../util/environment';
import focusEditableElement from '../../../../util/focusEditableElement';
@ -62,7 +62,7 @@ export default function useMentionMenu(
}, [canSuggestMembers, html, getFilteredMembers, markIsOpen, unmarkIsOpen]);
const insertMention = useCallback((user: ApiUser, forceFocus = false) => {
if (!user.username && !getUserFirstName(user)) {
if (!user.username && !getUserFirstOrLastName(user)) {
return;
}
@ -73,7 +73,7 @@ export default function useMentionMenu(
data-entity-type="${ApiMessageEntityTypes.MentionName}"
data-user-id="${user.id}"
contenteditable="false"
>${getUserFirstName(user)}</a>`;
>${getUserFirstOrLastName(user)}</a>`;
const atIndex = html.lastIndexOf('@');
if (atIndex !== -1) {

View File

@ -9,7 +9,7 @@ import {
import { ARCHIVED_FOLDER_ID } from '../../config';
import { orderBy } from '../../util/iteratees';
import { getUserFirstName } from './users';
import { getUserFirstOrLastName } from './users';
import { getTranslation } from '../../util/langProvider';
import { LangFn } from '../../hooks/useLang';
@ -430,5 +430,5 @@ export function getMessageSenderName(chatId: number, sender?: ApiUser) {
return 'You';
}
return getUserFirstName(sender);
return getUserFirstOrLastName(sender);
}

View File

@ -7,7 +7,7 @@ import { LangFn } from '../../hooks/useLang';
const USER_COLOR_KEYS = [1, 8, 5, 2, 7, 4, 6];
export function getUserFirstName(user?: ApiUser) {
export function getUserFirstOrLastName(user?: ApiUser) {
if (!user) {
return undefined;
}
@ -15,7 +15,7 @@ export function getUserFirstName(user?: ApiUser) {
switch (user.type) {
case 'userTypeBot':
case 'userTypeRegular': {
return user.firstName;
return user.firstName || user.lastName;
}
case 'userTypeDeleted':