Support "Fake" and "Scam" badges (#1819)

This commit is contained in:
Alexander Zinchuk 2022-04-08 20:59:37 +02:00
parent 8d9ae4b134
commit 97b778be22
11 changed files with 55 additions and 1 deletions

View File

@ -34,6 +34,8 @@ function buildApiChatFieldsFromPeerEntity(
const avatarHash = ('photo' in peerEntity) && peerEntity.photo && buildAvatarHash(peerEntity.photo);
const isSignaturesShown = Boolean('signatures' in peerEntity && peerEntity.signatures);
const hasPrivateLink = Boolean('hasLink' in peerEntity && peerEntity.hasLink);
const isScam = Boolean('scam' in peerEntity && peerEntity.scam);
const isFake = Boolean('fake' in peerEntity && peerEntity.fake);
return {
isMin,
@ -60,6 +62,7 @@ function buildApiChatFieldsFromPeerEntity(
...(('creator' in peerEntity) && { isCreator: peerEntity.creator }),
...buildApiChatRestrictions(peerEntity),
...buildApiChatMigrationInfo(peerEntity),
fakeType: isScam ? 'scam' : (isFake ? 'fake' : undefined),
};
}

View File

@ -32,7 +32,9 @@ export function buildApiUser(mtpUser: GramJs.TypeUser): ApiUser | undefined {
return undefined;
}
const { id, firstName, lastName } = mtpUser;
const {
id, firstName, lastName, fake, scam,
} = mtpUser;
const avatarHash = mtpUser.photo instanceof GramJs.UserProfilePhoto
? String(mtpUser.photo.photoId)
: undefined;
@ -41,6 +43,7 @@ export function buildApiUser(mtpUser: GramJs.TypeUser): ApiUser | undefined {
return {
id: buildApiPeerId(id, 'user'),
isMin: Boolean(mtpUser.min),
fakeType: scam ? 'scam' : (fake ? 'fake' : undefined),
...(mtpUser.self && { isSelf: true }),
...(mtpUser.verified && { isVerified: true }),
...((mtpUser.contact || mtpUser.mutualContact) && { isContact: true }),

View File

@ -1,6 +1,7 @@
import { ApiMessage, ApiPhoto } from './messages';
import { ApiBotCommand } from './bots';
import { ApiChatInviteImporter } from './misc';
import { ApiFakeType } from './users';
type ApiChatType = (
'chatTypePrivate' | 'chatTypeSecret' |
@ -33,6 +34,7 @@ export interface ApiChat {
photos?: ApiPhoto[];
draftDate?: number;
isProtected?: boolean;
fakeType?: ApiFakeType;
// Calls
isCallActive?: boolean;

View File

@ -23,6 +23,7 @@ export interface ApiUser {
maxId: string;
isFullyLoaded: boolean;
};
fakeType?: ApiFakeType;
// Obtained from GetFullUser / UserFullInfo
fullInfo?: ApiUserFullInfo;
@ -37,6 +38,8 @@ export interface ApiUserFullInfo {
botCommands?: ApiBotCommand[];
}
export type ApiFakeType = 'fake' | 'scam';
export type ApiUserType = 'userTypeBot' | 'userTypeRegular' | 'userTypeDeleted' | 'userTypeUnknown';
export interface ApiUserStatus {

View File

@ -0,0 +1,11 @@
.FakeIcon {
border: 1px solid var(--color-error);
border-radius: 0.375rem;
color: var(--color-error);
font-size: 0.625rem;
padding: 0.125rem 0.25rem;
line-height: initial;
margin-inline: 0.25rem;
font-weight: 500;
text-transform: capitalize;
}

View File

@ -0,0 +1,21 @@
import React, { FC, memo } from '../../lib/teact/teact';
import { ApiFakeType } from '../../api/types';
import useLang from '../../hooks/useLang';
import './FakeIcon.scss';
type OwnProps = {
fakeType: ApiFakeType;
};
const FakeIcon: FC<OwnProps> = ({
fakeType,
}) => {
const lang = useLang();
return <span className="FakeIcon">{lang(fakeType === 'fake' ? 'FakeMessage' : 'ScamMessage')}</span>;
};
export default memo(FakeIcon);

View File

@ -21,6 +21,7 @@ import Avatar from './Avatar';
import VerifiedIcon from './VerifiedIcon';
import TypingStatus from './TypingStatus';
import DotAnimation from './DotAnimation';
import FakeIcon from './FakeIcon';
type OwnProps = {
chatId: string;
@ -144,6 +145,7 @@ const GroupChatInfo: FC<OwnProps & StateProps> = ({
<div className="title">
<h3 dir="auto">{renderText(getChatTitle(lang, chat))}</h3>
{chat.isVerified && <VerifiedIcon />}
{chat.fakeType && <FakeIcon fakeType={chat.fakeType} />}
</div>
{renderStatusOrTyping()}
</div>

View File

@ -17,6 +17,7 @@ import Avatar from './Avatar';
import VerifiedIcon from './VerifiedIcon';
import TypingStatus from './TypingStatus';
import DotAnimation from './DotAnimation';
import FakeIcon from './FakeIcon';
type OwnProps = {
userId: string;
@ -140,6 +141,7 @@ const PrivateChatInfo: FC<OwnProps & StateProps> = ({
<div className="title">
<h3 dir="auto">{fullName && renderText(fullName)}</h3>
{user?.isVerified && <VerifiedIcon />}
{user.fakeType && <FakeIcon fakeType={user.fakeType} />}
</div>
)}
{(status || (!isSavedMessages && !noStatusOrTyping)) && renderStatusOrTyping()}

View File

@ -21,6 +21,7 @@ import useLang from '../../hooks/useLang';
import VerifiedIcon from './VerifiedIcon';
import ProfilePhoto from './ProfilePhoto';
import Transition from '../ui/Transition';
import FakeIcon from './FakeIcon';
import './ProfileInfo.scss';
@ -185,6 +186,7 @@ const ProfileInfo: FC<OwnProps & StateProps> = ({
}
const isVerifiedIconShown = (user || chat)?.isVerified;
const fakeType = (user || chat)?.fakeType;
return (
<div className={buildClassName('ProfileInfo', forceShowSelf && 'self')} dir={lang.isRtl ? 'rtl' : undefined}>
@ -221,6 +223,7 @@ const ProfileInfo: FC<OwnProps & StateProps> = ({
<div className="title">
<h3 dir="auto">{fullName && renderText(fullName)}</h3>
{isVerifiedIconShown && <VerifiedIcon />}
{fakeType && <FakeIcon fakeType={fakeType} />}
</div>
)}
{!isSavedMessages && renderStatus()}

View File

@ -50,6 +50,7 @@ import ListItem from '../../ui/ListItem';
import Badge from './Badge';
import ChatFolderModal from '../ChatFolderModal.async';
import ChatCallStatus from './ChatCallStatus';
import FakeIcon from '../../common/FakeIcon';
import './Chat.scss';
@ -299,6 +300,7 @@ const Chat: FC<OwnProps & StateProps> = ({
<div className="title">
<h3>{renderText(getChatTitle(lang, chat, user))}</h3>
{chat.isVerified && <VerifiedIcon />}
{chat.fakeType && <FakeIcon fakeType={chat.fakeType} />}
{isMuted && <i className="icon-muted" />}
{chat.lastMessage && (
<LastMessageMeta

View File

@ -30,6 +30,7 @@ import Avatar from '../../common/Avatar';
import VerifiedIcon from '../../common/VerifiedIcon';
import ListItem from '../../ui/ListItem';
import Link from '../../ui/Link';
import FakeIcon from '../../common/FakeIcon';
import './ChatMessage.scss';
@ -90,6 +91,7 @@ const ChatMessage: FC<OwnProps & StateProps> = ({
<div className="title">
<h3 dir="auto">{renderText(getChatTitle(lang, chat, privateChatUser))}</h3>
{chat.isVerified && <VerifiedIcon />}
{chat.fakeType && <FakeIcon fakeType={chat.fakeType} />}
</div>
<div className="message-date">
<Link className="date">