mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-11 08:39:59 +01:00
Composer: Show translated ban due date (#1286)
This commit is contained in:
parent
08a27a98b8
commit
b44792afab
@ -135,6 +135,7 @@ export interface ApiChatBannedRights {
|
|||||||
changeInfo?: true;
|
changeInfo?: true;
|
||||||
inviteUsers?: true;
|
inviteUsers?: true;
|
||||||
pinMessages?: true;
|
pinMessages?: true;
|
||||||
|
untilDate?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiRestrictionReason {
|
export interface ApiRestrictionReason {
|
||||||
|
@ -3,7 +3,7 @@ import React, {
|
|||||||
} from '../../lib/teact/teact';
|
} from '../../lib/teact/teact';
|
||||||
import { withGlobal } from '../../lib/teact/teactn';
|
import { withGlobal } from '../../lib/teact/teactn';
|
||||||
|
|
||||||
import { MAIN_THREAD_ID } from '../../api/types';
|
import { ApiChatBannedRights, MAIN_THREAD_ID } from '../../api/types';
|
||||||
import { GlobalActions, MessageListType } from '../../global/types';
|
import { GlobalActions, MessageListType } from '../../global/types';
|
||||||
import { ThemeKey } from '../../types';
|
import { ThemeKey } from '../../types';
|
||||||
|
|
||||||
@ -69,7 +69,8 @@ type StateProps = {
|
|||||||
isPinnedMessageList?: boolean;
|
isPinnedMessageList?: boolean;
|
||||||
isScheduledMessageList?: boolean;
|
isScheduledMessageList?: boolean;
|
||||||
canPost?: boolean;
|
canPost?: boolean;
|
||||||
messageSendingRestrictionReason?: string;
|
currentUserBannedRights?: ApiChatBannedRights;
|
||||||
|
defaultBannedRights?: ApiChatBannedRights;
|
||||||
hasPinnedOrAudioMessage?: boolean;
|
hasPinnedOrAudioMessage?: boolean;
|
||||||
pinnedMessagesCount?: number;
|
pinnedMessagesCount?: number;
|
||||||
theme: ThemeKey;
|
theme: ThemeKey;
|
||||||
@ -104,7 +105,8 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
isPinnedMessageList,
|
isPinnedMessageList,
|
||||||
isScheduledMessageList,
|
isScheduledMessageList,
|
||||||
canPost,
|
canPost,
|
||||||
messageSendingRestrictionReason,
|
currentUserBannedRights,
|
||||||
|
defaultBannedRights,
|
||||||
hasPinnedOrAudioMessage,
|
hasPinnedOrAudioMessage,
|
||||||
pinnedMessagesCount,
|
pinnedMessagesCount,
|
||||||
customBackground,
|
customBackground,
|
||||||
@ -127,6 +129,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { width: windowWidth } = useWindowSize();
|
const { width: windowWidth } = useWindowSize();
|
||||||
|
|
||||||
|
const lang = useLang();
|
||||||
const [dropAreaState, setDropAreaState] = useState(DropAreaState.None);
|
const [dropAreaState, setDropAreaState] = useState(DropAreaState.None);
|
||||||
const [isFabShown, setIsFabShown] = useState<boolean | undefined>();
|
const [isFabShown, setIsFabShown] = useState<boolean | undefined>();
|
||||||
const [isNotchShown, setIsNotchShown] = useState<boolean | undefined>();
|
const [isNotchShown, setIsNotchShown] = useState<boolean | undefined>();
|
||||||
@ -235,6 +238,11 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
!isSelectModeActive && 'shown',
|
!isSelectModeActive && 'shown',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const messageSendingRestrictionReason = getMessageSendingRestrictionReason(
|
||||||
|
lang, currentUserBannedRights, defaultBannedRights,
|
||||||
|
);
|
||||||
|
|
||||||
// CSS Variables calculation doesn't work properly with transforms, so we calculate transform values in JS
|
// CSS Variables calculation doesn't work properly with transforms, so we calculate transform values in JS
|
||||||
const {
|
const {
|
||||||
composerHiddenScale, toolbarHiddenScale,
|
composerHiddenScale, toolbarHiddenScale,
|
||||||
@ -245,8 +253,6 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
[renderingCanPost, windowWidth],
|
[renderingCanPost, windowWidth],
|
||||||
);
|
);
|
||||||
|
|
||||||
const lang = useLang();
|
|
||||||
|
|
||||||
const footerClassName = buildClassName(
|
const footerClassName = buildClassName(
|
||||||
'middle-column-footer',
|
'middle-column-footer',
|
||||||
!renderingCanPost && 'no-composer',
|
!renderingCanPost && 'no-composer',
|
||||||
@ -443,7 +449,8 @@ export default memo(withGlobal(
|
|||||||
canPost: !isPinnedMessageList && (!chat || canPost) && (!isBotNotStarted || IS_SINGLE_COLUMN_LAYOUT),
|
canPost: !isPinnedMessageList && (!chat || canPost) && (!isBotNotStarted || IS_SINGLE_COLUMN_LAYOUT),
|
||||||
isPinnedMessageList,
|
isPinnedMessageList,
|
||||||
isScheduledMessageList,
|
isScheduledMessageList,
|
||||||
messageSendingRestrictionReason: chat && getMessageSendingRestrictionReason(chat),
|
currentUserBannedRights: chat && chat.currentUserBannedRights,
|
||||||
|
defaultBannedRights: chat && chat.defaultBannedRights,
|
||||||
hasPinnedOrAudioMessage: (
|
hasPinnedOrAudioMessage: (
|
||||||
threadId !== MAIN_THREAD_ID
|
threadId !== MAIN_THREAD_ID
|
||||||
|| Boolean(pinnedIds && pinnedIds.length)
|
|| Boolean(pinnedIds && pinnedIds.length)
|
||||||
|
@ -104,7 +104,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
setPermissions((p) => ({
|
setPermissions((p) => ({
|
||||||
...p,
|
...p,
|
||||||
[name]: getUpdatedPermissionValue(p[name as keyof ApiChatBannedRights]),
|
[name]: getUpdatedPermissionValue(p[name as Exclude<keyof ApiChatBannedRights, 'untilDate'>]),
|
||||||
...(name === 'sendStickers' && {
|
...(name === 'sendStickers' && {
|
||||||
sendGifs: getUpdatedPermissionValue(p[name]),
|
sendGifs: getUpdatedPermissionValue(p[name]),
|
||||||
}),
|
}),
|
||||||
|
@ -82,7 +82,7 @@ const ManageGroupUserPermissions: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
setPermissions((p) => ({
|
setPermissions((p) => ({
|
||||||
...p,
|
...p,
|
||||||
[name]: getUpdatedPermissionValue(p[name as keyof ApiChatBannedRights]),
|
[name]: getUpdatedPermissionValue(p[name as Exclude<keyof ApiChatBannedRights, 'untilDate'>]),
|
||||||
...(name === 'sendStickers' && {
|
...(name === 'sendStickers' && {
|
||||||
sendGifs: getUpdatedPermissionValue(p[name]),
|
sendGifs: getUpdatedPermissionValue(p[name]),
|
||||||
}),
|
}),
|
||||||
@ -117,7 +117,7 @@ const ManageGroupUserPermissions: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
});
|
});
|
||||||
}, [chat, selectedChatMemberId, updateChatMemberBannedRights]);
|
}, [chat, selectedChatMemberId, updateChatMemberBannedRights]);
|
||||||
|
|
||||||
const getControlIsDisabled = useCallback((key: keyof ApiChatBannedRights) => {
|
const getControlIsDisabled = useCallback((key: Exclude<keyof ApiChatBannedRights, 'untilDate'>) => {
|
||||||
if (isFormFullyDisabled) {
|
if (isFormFullyDisabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,16 @@ import {
|
|||||||
ApiChatFolder,
|
ApiChatFolder,
|
||||||
MAIN_THREAD_ID,
|
MAIN_THREAD_ID,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
|
|
||||||
import { NotifyException, NotifySettings } from '../../types';
|
import { NotifyException, NotifySettings } from '../../types';
|
||||||
|
import { LangFn } from '../../hooks/useLang';
|
||||||
|
|
||||||
import { ARCHIVED_FOLDER_ID } from '../../config';
|
import { ARCHIVED_FOLDER_ID } from '../../config';
|
||||||
import { orderBy } from '../../util/iteratees';
|
import { orderBy } from '../../util/iteratees';
|
||||||
import { getUserFirstOrLastName } from './users';
|
import { getUserFirstOrLastName } from './users';
|
||||||
import { LangFn } from '../../hooks/useLang';
|
import { formatDateToString, formatTime } from '../../util/dateFormat';
|
||||||
|
|
||||||
|
const FOREVER_BANNED_DATE = Date.now() / 1000 + 31622400; // 366 days
|
||||||
|
|
||||||
const VEIFIED_PRIORITY_BASE = 3e9;
|
const VEIFIED_PRIORITY_BASE = 3e9;
|
||||||
const PINNED_PRIORITY_BASE = 3e8;
|
const PINNED_PRIORITY_BASE = 3e8;
|
||||||
@ -176,12 +180,24 @@ export function getAllowedAttachmentOptions(chat?: ApiChat, isChatWithBot = fals
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMessageSendingRestrictionReason(chat: ApiChat) {
|
export function getMessageSendingRestrictionReason(
|
||||||
if (chat.currentUserBannedRights && chat.currentUserBannedRights.sendMessages) {
|
lang: LangFn, currentUserBannedRights?: ApiChatBannedRights, defaultBannedRights?: ApiChatBannedRights,
|
||||||
return 'You are not allowed to send messages in this chat.';
|
) {
|
||||||
|
if (currentUserBannedRights && currentUserBannedRights.sendMessages) {
|
||||||
|
const { untilDate } = currentUserBannedRights;
|
||||||
|
return untilDate && untilDate < FOREVER_BANNED_DATE
|
||||||
|
? lang(
|
||||||
|
'Channel.Persmission.Denied.SendMessages.Until',
|
||||||
|
lang(
|
||||||
|
'formatDateAtTime',
|
||||||
|
[formatDateToString(new Date(untilDate * 1000), lang.code), formatTime(untilDate * 1000)],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: lang('Channel.Persmission.Denied.SendMessages.Forever');
|
||||||
}
|
}
|
||||||
if (chat.defaultBannedRights && chat.defaultBannedRights.sendMessages) {
|
|
||||||
return 'Sending messages is not allowed in this chat.';
|
if (defaultBannedRights && defaultBannedRights.sendMessages) {
|
||||||
|
return lang('Channel.Persmission.Denied.SendMessages.DefaultRestrictedText');
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -176,9 +176,9 @@ export function formatVoiceRecordDuration(durationInMs: number) {
|
|||||||
return `${parts.join(':')},${String(milliseconds).padStart(2, '0')}`;
|
return `${parts.join(':')},${String(milliseconds).padStart(2, '0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDateToString(date: Date) {
|
export function formatDateToString(date: Date, locale = 'en-US') {
|
||||||
return date.toLocaleString(
|
return date.toLocaleString(
|
||||||
'en-US',
|
locale,
|
||||||
{
|
{
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
|
@ -11,6 +11,7 @@ interface LangFn {
|
|||||||
(key: string, value?: any, format?: 'i'): any;
|
(key: string, value?: any, format?: 'i'): any;
|
||||||
|
|
||||||
isRtl?: boolean;
|
isRtl?: boolean;
|
||||||
|
code?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FALLBACK_LANG_CODE = 'en';
|
const FALLBACK_LANG_CODE = 'en';
|
||||||
@ -124,6 +125,7 @@ export async function setLanguage(langCode: string, callback?: NoneToVoidFunctio
|
|||||||
const { languages } = getGlobal().settings.byKey;
|
const { languages } = getGlobal().settings.byKey;
|
||||||
const langInfo = languages ? languages.find((l) => l.langCode === langCode) : undefined;
|
const langInfo = languages ? languages.find((l) => l.langCode === langCode) : undefined;
|
||||||
getTranslation.isRtl = Boolean(langInfo && langInfo.rtl);
|
getTranslation.isRtl = Boolean(langInfo && langInfo.rtl);
|
||||||
|
getTranslation.code = langCode;
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
Loading…
Reference in New Issue
Block a user