Profile: Fix forum username display (#2644)
This commit is contained in:
parent
e789e56295
commit
8ab16593cc
@ -8,6 +8,7 @@ import type { GlobalState } from '../../global/types';
|
|||||||
import type {
|
import type {
|
||||||
ApiChat, ApiCountryCode, ApiUser, ApiUsername,
|
ApiChat, ApiCountryCode, ApiUser, ApiUsername,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
|
import { MAIN_THREAD_ID } from '../../api/types';
|
||||||
|
|
||||||
import { TME_LINK_PREFIX } from '../../config';
|
import { TME_LINK_PREFIX } from '../../config';
|
||||||
import {
|
import {
|
||||||
@ -45,7 +46,6 @@ type StateProps =
|
|||||||
canInviteUsers?: boolean;
|
canInviteUsers?: boolean;
|
||||||
isMuted?: boolean;
|
isMuted?: boolean;
|
||||||
phoneCodeList: ApiCountryCode[];
|
phoneCodeList: ApiCountryCode[];
|
||||||
isForum?: boolean;
|
|
||||||
topicId?: number;
|
topicId?: number;
|
||||||
}
|
}
|
||||||
& Pick<GlobalState, 'lastSyncTime'>;
|
& Pick<GlobalState, 'lastSyncTime'>;
|
||||||
@ -60,7 +60,6 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
isMuted,
|
isMuted,
|
||||||
phoneCodeList,
|
phoneCodeList,
|
||||||
isForum,
|
|
||||||
topicId,
|
topicId,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
@ -81,40 +80,46 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
|
|
||||||
const [areNotificationsEnabled, setAreNotificationsEnabled] = useState(!isMuted);
|
const [areNotificationsEnabled, setAreNotificationsEnabled] = useState(!isMuted);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (lastSyncTime && userId) {
|
if (lastSyncTime && userId) {
|
||||||
loadFullUser({ userId });
|
loadFullUser({ userId });
|
||||||
}
|
}
|
||||||
}, [loadFullUser, userId, lastSyncTime]);
|
}, [loadFullUser, userId, lastSyncTime]);
|
||||||
|
|
||||||
|
const isTopicInfo = Boolean(topicId && topicId !== MAIN_THREAD_ID);
|
||||||
|
|
||||||
const activeUsernames = useMemo(() => {
|
const activeUsernames = useMemo(() => {
|
||||||
const result = usernames?.filter((u) => u.isActive);
|
const result = usernames?.filter((u) => u.isActive);
|
||||||
|
|
||||||
return result?.length ? result : undefined;
|
return result?.length ? result : undefined;
|
||||||
}, [usernames]);
|
}, [usernames]);
|
||||||
|
|
||||||
const activeChatUsernames = useMemo(() => {
|
const activeChatUsernames = useMemo(() => {
|
||||||
const result = !user ? chatUsernames?.filter((u) => u.isActive) : undefined;
|
const result = !user ? chatUsernames?.filter((u) => u.isActive) : undefined;
|
||||||
|
|
||||||
return result?.length ? result : undefined;
|
return result?.length ? result : undefined;
|
||||||
}, [chatUsernames, user]);
|
}, [chatUsernames, user]);
|
||||||
|
|
||||||
const link = useMemo(() => {
|
const link = useMemo(() => {
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isForum
|
return isTopicInfo
|
||||||
? getTopicLink(chat.id, activeChatUsernames?.[0].username, topicId)
|
? getTopicLink(chat.id, activeChatUsernames?.[0].username, topicId)
|
||||||
: getChatLink(chat);
|
: getChatLink(chat);
|
||||||
}, [chat, isForum, activeChatUsernames, topicId]);
|
}, [chat, isTopicInfo, activeChatUsernames, topicId]);
|
||||||
|
|
||||||
const handleNotificationChange = useCallback(() => {
|
const handleNotificationChange = useCallback(() => {
|
||||||
setAreNotificationsEnabled((current) => {
|
setAreNotificationsEnabled((current) => {
|
||||||
const newAreNotificationsEnabled = !current;
|
const newAreNotificationsEnabled = !current;
|
||||||
|
|
||||||
runDebounced(() => {
|
runDebounced(() => {
|
||||||
if (topicId) {
|
if (isTopicInfo) {
|
||||||
updateTopicMutedState({
|
updateTopicMutedState({
|
||||||
chatId: chatId!,
|
chatId: chatId!,
|
||||||
topicId,
|
topicId: topicId!,
|
||||||
isMuted: !newAreNotificationsEnabled,
|
isMuted: !newAreNotificationsEnabled,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -124,7 +129,7 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
return newAreNotificationsEnabled;
|
return newAreNotificationsEnabled;
|
||||||
});
|
});
|
||||||
}, [chatId, topicId, updateChatMutedState, updateTopicMutedState]);
|
}, [chatId, isTopicInfo, topicId, updateChatMutedState, updateTopicMutedState]);
|
||||||
|
|
||||||
if (!chat || chat.isRestricted || (isSelf && !forceShowSelf)) {
|
if (!chat || chat.isRestricted || (isSelf && !forceShowSelf)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -147,41 +152,43 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
.map((s) => {
|
.map((s) => {
|
||||||
return (s === 'USERNAMES' ? (
|
return (s === 'USERNAMES' ? (
|
||||||
<>
|
<>
|
||||||
{otherUsernames.map(({ username: nick }, idx) => (
|
{otherUsernames.map(({ username: nick }, idx) => {
|
||||||
<>
|
const textToCopy = isChat ? `${TME_LINK_PREFIX}${nick}` : `@${nick}`;
|
||||||
{idx > 0 ? ', ' : ''}
|
return (
|
||||||
<a
|
<>
|
||||||
key={nick}
|
{idx > 0 ? ', ' : ''}
|
||||||
href={`${TME_LINK_PREFIX}${nick}`}
|
<a
|
||||||
onClick={(e) => {
|
key={nick}
|
||||||
stopEvent(e);
|
href={`${TME_LINK_PREFIX}${nick}`}
|
||||||
copy(`@${nick}`, lang(isChat ? 'Link' : 'Username'));
|
onClick={(e) => {
|
||||||
}}
|
stopEvent(e);
|
||||||
className="text-entity-link username-link"
|
copy(textToCopy, lang(isChat ? 'Link' : 'Username'));
|
||||||
>
|
}}
|
||||||
{`@${nick}`}
|
className="text-entity-link username-link"
|
||||||
</a>
|
>
|
||||||
</>
|
{`@${nick}`}
|
||||||
))}
|
</a>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</>
|
</>
|
||||||
) : s);
|
) : s);
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const publicLink = isForum
|
const username = isChat ? `t.me/${mainUsername.username}` : mainUsername.username;
|
||||||
? getTopicLink('', mainUsername.username, topicId)
|
const textToCopy = isChat ? `${TME_LINK_PREFIX}${mainUsername.username}` : `@${mainUsername.username}`;
|
||||||
: `@${mainUsername.username}`;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
icon="mention"
|
icon={isChat ? 'link' : 'mention'}
|
||||||
multiline
|
multiline
|
||||||
narrow
|
narrow
|
||||||
ripple
|
ripple
|
||||||
// eslint-disable-next-line react/jsx-no-bind
|
// eslint-disable-next-line react/jsx-no-bind
|
||||||
onClick={() => copy(publicLink, lang(isChat ? 'Link' : 'Username'))}
|
onClick={() => copy(textToCopy, lang(isChat ? 'Link' : 'Username'))}
|
||||||
>
|
>
|
||||||
<span className="title" dir="auto">{publicLink}</span>
|
<span className="title" dir="auto">{username}</span>
|
||||||
<span className="subtitle">
|
<span className="subtitle">
|
||||||
{usernameLinks && <span className="other-usernames">{usernameLinks}</span>}
|
{usernameLinks && <span className="other-usernames">{usernameLinks}</span>}
|
||||||
{lang(isChat ? 'Link' : 'Username')}
|
{lang(isChat ? 'Link' : 'Username')}
|
||||||
@ -213,8 +220,8 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
<span className="subtitle">{lang(userId ? 'UserBio' : 'Info')}</span>
|
<span className="subtitle">{lang(userId ? 'UserBio' : 'Info')}</span>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
)}
|
)}
|
||||||
{activeChatUsernames && renderUsernames(activeChatUsernames, true)}
|
{activeChatUsernames && !isTopicInfo && renderUsernames(activeChatUsernames, true)}
|
||||||
{!activeChatUsernames && canInviteUsers && link && (
|
{((!activeChatUsernames && canInviteUsers) || isTopicInfo) && link && (
|
||||||
<ListItem
|
<ListItem
|
||||||
icon="link"
|
icon="link"
|
||||||
multiline
|
multiline
|
||||||
@ -265,7 +272,6 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
user,
|
user,
|
||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
isMuted,
|
isMuted,
|
||||||
isForum,
|
|
||||||
topicId,
|
topicId,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user