[dev] Use more descriptive callback names (#2225)
This commit is contained in:
parent
439222f951
commit
ccc178c2fd
@ -171,7 +171,7 @@ export function buildApiPremiumPromo(promo: GramJs.help.PremiumPromo): ApiPremiu
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
statusText,
|
statusText,
|
||||||
statusEntities: statusEntities.map((l) => buildApiMessageEntity(l)),
|
statusEntities: statusEntities.map(buildApiMessageEntity),
|
||||||
videoSections,
|
videoSections,
|
||||||
videos: videos.map(buildApiDocument).filter(Boolean),
|
videos: videos.map(buildApiDocument).filter(Boolean),
|
||||||
options: periodOptions.map(buildApiPremiumSubscriptionOption),
|
options: periodOptions.map(buildApiPremiumSubscriptionOption),
|
||||||
|
|||||||
@ -771,7 +771,7 @@ export async function fetchChatFolders() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultFolderPosition = result.findIndex((l) => l instanceof GramJs.DialogFilterDefault);
|
const defaultFolderPosition = result.findIndex((folder) => folder instanceof GramJs.DialogFilterDefault);
|
||||||
const dialogFilters = result.filter((df): df is GramJs.DialogFilter => df instanceof GramJs.DialogFilter);
|
const dialogFilters = result.filter((df): df is GramJs.DialogFilter => df instanceof GramJs.DialogFilter);
|
||||||
const orderedIds = dialogFilters.map(({ id }) => id);
|
const orderedIds = dialogFilters.map(({ id }) => id);
|
||||||
if (defaultFolderPosition !== -1) {
|
if (defaultFolderPosition !== -1) {
|
||||||
|
|||||||
@ -104,7 +104,7 @@ export async function fetchExportedChatInvites({
|
|||||||
addEntitiesWithPhotosToLocalDb(exportedInvites.users);
|
addEntitiesWithPhotosToLocalDb(exportedInvites.users);
|
||||||
// TODO Verify Exported Invite logic
|
// TODO Verify Exported Invite logic
|
||||||
return (exportedInvites.invites
|
return (exportedInvites.invites
|
||||||
.filter((l) => l instanceof GramJs.ChatInviteExported) as GramJs.ChatInviteExported[])
|
.filter((invite): invite is GramJs.ChatInviteExported => invite instanceof GramJs.ChatInviteExported))
|
||||||
.map(buildApiExportedInvite);
|
.map(buildApiExportedInvite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ const GroupCall: FC<OwnProps & StateProps> = ({
|
|||||||
const [isLeaving, setIsLeaving] = useState(false);
|
const [isLeaving, setIsLeaving] = useState(false);
|
||||||
const [isFullscreen, openFullscreen, closeFullscreen] = useFlag();
|
const [isFullscreen, openFullscreen, closeFullscreen] = useFlag();
|
||||||
const [isSidebarOpen, openSidebar, closeSidebar] = useFlag(true);
|
const [isSidebarOpen, openSidebar, closeSidebar] = useFlag(true);
|
||||||
const hasVideoParticipants = participants && Object.values(participants).some((l) => l.video || l.presentation);
|
const hasVideoParticipants = Object.values(participants).some(({ video, presentation }) => video || presentation);
|
||||||
const isLandscape = isFullscreen && !IS_SINGLE_COLUMN_LAYOUT && hasVideoParticipants;
|
const isLandscape = isFullscreen && !IS_SINGLE_COLUMN_LAYOUT && hasVideoParticipants;
|
||||||
|
|
||||||
const [participantMenu, setParticipantMenu] = useState<{
|
const [participantMenu, setParticipantMenu] = useState<{
|
||||||
|
|||||||
@ -27,10 +27,10 @@ const GroupCallParticipantStreams: FC<OwnProps & StateProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [selectedVideo, setSelectedVideo] = useState<SelectedVideo | undefined>(undefined);
|
const [selectedVideo, setSelectedVideo] = useState<SelectedVideo | undefined>(undefined);
|
||||||
const presentationParticipants = useMemo(() => {
|
const presentationParticipants = useMemo(() => {
|
||||||
return Object.values(participants || {}).filter((l) => l.hasPresentationStream);
|
return Object.values(participants || {}).filter((participant) => participant.hasPresentationStream);
|
||||||
}, [participants]);
|
}, [participants]);
|
||||||
const videoParticipants = useMemo(() => {
|
const videoParticipants = useMemo(() => {
|
||||||
return Object.values(participants || {}).filter((l) => l.hasVideoStream);
|
return Object.values(participants || {}).filter((participant) => participant.hasVideoStream);
|
||||||
}, [participants]);
|
}, [participants]);
|
||||||
|
|
||||||
const totalVideoCount = videoParticipants.length + presentationParticipants.length;
|
const totalVideoCount = videoParticipants.length + presentationParticipants.length;
|
||||||
|
|||||||
@ -33,9 +33,9 @@ const AttachBotIcon: FC<OwnProps> = ({
|
|||||||
|
|
||||||
const mediaDataWithReplacedColors = mediaData.replace(COLOR_REPLACE_PATTERN, color);
|
const mediaDataWithReplacedColors = mediaData.replace(COLOR_REPLACE_PATTERN, color);
|
||||||
const doc = new DOMParser().parseFromString(mediaDataWithReplacedColors, 'image/svg+xml');
|
const doc = new DOMParser().parseFromString(mediaDataWithReplacedColors, 'image/svg+xml');
|
||||||
doc.querySelectorAll('path').forEach((l) => {
|
doc.querySelectorAll('path').forEach((path) => {
|
||||||
l.style.stroke = color;
|
path.style.stroke = color;
|
||||||
l.style.strokeWidth = ADDITIONAL_STROKE_WIDTH;
|
path.style.strokeWidth = ADDITIONAL_STROKE_WIDTH;
|
||||||
});
|
});
|
||||||
|
|
||||||
return `data:image/svg+xml;utf8,${doc.documentElement.outerHTML}`;
|
return `data:image/svg+xml;utf8,${doc.documentElement.outerHTML}`;
|
||||||
|
|||||||
@ -358,7 +358,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
const handleSetAttachments = useCallback(
|
const handleSetAttachments = useCallback(
|
||||||
(newValue: ApiAttachment[] | ((current: ApiAttachment[]) => ApiAttachment[])) => {
|
(newValue: ApiAttachment[] | ((current: ApiAttachment[]) => ApiAttachment[])) => {
|
||||||
const newAttachments = typeof newValue === 'function' ? newValue(attachments) : newValue;
|
const newAttachments = typeof newValue === 'function' ? newValue(attachments) : newValue;
|
||||||
if (newAttachments && newAttachments.some((l) => l.size > fileSizeLimit)) {
|
if (newAttachments.some(({ size }) => size > fileSizeLimit)) {
|
||||||
openLimitReachedModal({
|
openLimitReachedModal({
|
||||||
limit: 'uploadMaxFileparts',
|
limit: 'uploadMaxFileparts',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -111,7 +111,7 @@ const StickerSet: FC<OwnProps> = ({
|
|||||||
}, [isCurrentUserPremium, isPremiumSet, openPremiumModal, stickerSet, toggleStickerSet]);
|
}, [isCurrentUserPremium, isPremiumSet, openPremiumModal, stickerSet, toggleStickerSet]);
|
||||||
|
|
||||||
const isLocked = !isSavedMessages && !isRecent && isEmoji && !isCurrentUserPremium
|
const isLocked = !isSavedMessages && !isRecent && isEmoji && !isCurrentUserPremium
|
||||||
&& stickerSet.stickers?.some((l) => !l.isFree);
|
&& stickerSet.stickers?.some(({ isFree }) => !isFree);
|
||||||
const itemSize = isEmoji ? EMOJI_SIZE_PICKER : STICKER_SIZE_PICKER;
|
const itemSize = isEmoji ? EMOJI_SIZE_PICKER : STICKER_SIZE_PICKER;
|
||||||
const itemsPerRow = isEmoji ? EMOJI_PER_ROW_ON_DESKTOP : STICKERS_PER_ROW_ON_DESKTOP;
|
const itemsPerRow = isEmoji ? EMOJI_PER_ROW_ON_DESKTOP : STICKERS_PER_ROW_ON_DESKTOP;
|
||||||
const margin = isEmoji ? EMOJI_MARGIN : STICKER_MARGIN;
|
const margin = isEmoji ? EMOJI_MARGIN : STICKER_MARGIN;
|
||||||
|
|||||||
@ -109,7 +109,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const handleOptionChange = useCallback((value: string, e: ChangeEvent<HTMLInputElement>) => {
|
const handleOptionChange = useCallback((value: string, e: ChangeEvent<HTMLInputElement>) => {
|
||||||
const myChats = Object.values(getGlobal().chats.byId)
|
const myChats = Object.values(getGlobal().chats.byId)
|
||||||
.filter((l) => l.isCreator && l.usernames?.some((c) => c.isActive));
|
.filter(({ isCreator, usernames }) => isCreator && usernames?.some((c) => c.isActive));
|
||||||
|
|
||||||
if (myChats.length >= maxPublicLinks && value === 'public') {
|
if (myChats.length >= maxPublicLinks && value === 'public') {
|
||||||
openLimitReachedModal({ limit: 'channelsPublic' });
|
openLimitReachedModal({ limit: 'channelsPublic' });
|
||||||
|
|||||||
@ -617,7 +617,7 @@ addActionHandler('openTelegramLink', (global, actions, payload) => {
|
|||||||
const hostParts = uri.hostname.split('.');
|
const hostParts = uri.hostname.split('.');
|
||||||
if (hostParts.length > 3) return;
|
if (hostParts.length > 3) return;
|
||||||
const pathname = hostParts.length === 3 ? `${hostParts[0]}/${uri.pathname}` : uri.pathname;
|
const pathname = hostParts.length === 3 ? `${hostParts[0]}/${uri.pathname}` : uri.pathname;
|
||||||
const [part1, part2, part3] = pathname.split('/').filter(Boolean).map((l) => decodeURI(l));
|
const [part1, part2, part3] = pathname.split('/').filter(Boolean).map((part) => decodeURI(part));
|
||||||
const params = Object.fromEntries(uri.searchParams);
|
const params = Object.fromEntries(uri.searchParams);
|
||||||
|
|
||||||
let hash: string | undefined;
|
let hash: string | undefined;
|
||||||
|
|||||||
@ -265,7 +265,8 @@ addActionHandler('sendWatchingEmojiInteraction', (global, actions, payload) => {
|
|||||||
|
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
|
|
||||||
if (!chat || !global.activeEmojiInteractions?.some((l) => l.id === id) || chatId === global.currentUserId) {
|
if (!chat || !global.activeEmojiInteractions?.some((interaction) => interaction.id === id)
|
||||||
|
|| chatId === global.currentUserId) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,14 +53,14 @@ export const initializeSoundsForSafari = () => {
|
|||||||
ringing: ringingAudio,
|
ringing: ringingAudio,
|
||||||
};
|
};
|
||||||
|
|
||||||
initializationPromise = Promise.all(Object.values(sounds).map((l) => {
|
initializationPromise = Promise.all(Object.values(sounds).map((sound) => {
|
||||||
l.muted = true;
|
sound.muted = true;
|
||||||
l.volume = 0.0001;
|
sound.volume = 0.0001;
|
||||||
return l.play().then(() => {
|
return sound.play().then(() => {
|
||||||
l.pause();
|
sound.pause();
|
||||||
l.volume = 1;
|
sound.volume = 1;
|
||||||
l.currentTime = 0;
|
sound.currentTime = 0;
|
||||||
l.muted = false;
|
sound.muted = false;
|
||||||
});
|
});
|
||||||
})).then(() => {
|
})).then(() => {
|
||||||
initializationPromise = undefined;
|
initializationPromise = undefined;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export function checkIfHasUnreadReactions(global: GlobalState, reactions: ApiRea
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function areReactionsEmpty(reactions: ApiReactions) {
|
export function areReactionsEmpty(reactions: ApiReactions) {
|
||||||
return !reactions.results.some((l) => l.count > 0);
|
return !reactions.results.some(({ count }) => count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isSameReaction(first?: ApiReaction, second?: ApiReaction) {
|
export function isSameReaction(first?: ApiReaction, second?: ApiReaction) {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export function updateGroupCall(
|
|||||||
...global.groupCalls.byId[groupCallId]?.participants,
|
...global.groupCalls.byId[groupCallId]?.participants,
|
||||||
...groupCallUpdate.participants,
|
...groupCallUpdate.participants,
|
||||||
});
|
});
|
||||||
const filtered = unfiltered.filter((l) => !l.isLeft);
|
const filtered = unfiltered.filter(({ isLeft }) => isLeft);
|
||||||
const participants = filtered.reduce((acc: Record<string, GroupCallParticipant>, el) => {
|
const participants = filtered.reduce((acc: Record<string, GroupCallParticipant>, el) => {
|
||||||
acc[el.id] = el;
|
acc[el.id] = el;
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
@ -328,7 +328,7 @@ class TelegramClient {
|
|||||||
|
|
||||||
if (!id) return undefined;
|
if (!id) return undefined;
|
||||||
|
|
||||||
return this.peers.findIndex((l) => l.peer.id.toString() === id.toString());
|
return this.peers.findIndex((localPeer) => localPeer.peer.id.toString() === id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPeer(peer: Api.TypeInputPeer) {
|
private getPeer(peer: Api.TypeInputPeer) {
|
||||||
@ -346,11 +346,11 @@ class TelegramClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getChats() {
|
private getChats() {
|
||||||
return this.peers.filter((l) => !(l.peer instanceof Api.User)).map((l) => l.peer);
|
return this.peers.filter(({ peer }) => !(peer instanceof Api.User)).map(({ peer }) => peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getUsers() {
|
private getUsers() {
|
||||||
return this.peers.filter((l) => l.peer instanceof Api.User).map((l) => l.peer);
|
return this.peers.filter(({ peer }) => peer instanceof Api.User).map(({ peer }) => peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -159,7 +159,7 @@ async function downloadFile2(
|
|||||||
// Pick the least busy foreman
|
// Pick the least busy foreman
|
||||||
// For some reason, fresh connections give out a higher speed for the first couple of seconds
|
// For some reason, fresh connections give out a higher speed for the first couple of seconds
|
||||||
// I have no idea why, but this may speed up the download of small files
|
// I have no idea why, but this may speed up the download of small files
|
||||||
const activeCounts = foremans.map((l) => l.activeWorkers);
|
const activeCounts = foremans.map(({ activeWorkers }) => activeWorkers);
|
||||||
let currentForemanIndex = activeCounts.indexOf(Math.min(...activeCounts));
|
let currentForemanIndex = activeCounts.indexOf(Math.min(...activeCounts));
|
||||||
// Used for files with unknown size and for manual cancellations
|
// Used for files with unknown size and for manual cancellations
|
||||||
let hasEnded = false;
|
let hasEnded = false;
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export async function uploadFile(
|
|||||||
// Pick the least busy foreman
|
// Pick the least busy foreman
|
||||||
// For some reason, fresh connections give out a higher speed for the first couple of seconds
|
// For some reason, fresh connections give out a higher speed for the first couple of seconds
|
||||||
// I have no idea why, but this may speed up the download of small files
|
// I have no idea why, but this may speed up the download of small files
|
||||||
const activeCounts = foremans.map((l) => l.activeWorkers);
|
const activeCounts = foremans.map(({ activeWorkers }) => activeWorkers);
|
||||||
let currentForemanIndex = activeCounts.indexOf(Math.min(...activeCounts));
|
let currentForemanIndex = activeCounts.indexOf(Math.min(...activeCounts));
|
||||||
|
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
|
|||||||
@ -159,7 +159,7 @@ export function formatTimeDuration(lang: LangFn, duration: number, showLast = 2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO In arabic we don't use "," as delimiter rather we use "and" each time
|
// TODO In arabic we don't use "," as delimiter rather we use "and" each time
|
||||||
return out.map((l) => lang(l.type, l.duration, 'i')).join(', ');
|
return out.map((part) => lang(part.type, part.duration, 'i')).join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatHumanDate(
|
export function formatHumanDate(
|
||||||
|
|||||||
@ -161,7 +161,7 @@ export async function setLanguage(langCode: LangCode, callback?: NoneToVoidFunct
|
|||||||
document.documentElement.lang = langCode;
|
document.documentElement.lang = langCode;
|
||||||
|
|
||||||
const { languages, timeFormat } = getGlobal().settings.byKey;
|
const { languages, timeFormat } = getGlobal().settings.byKey;
|
||||||
const langInfo = languages?.find((l) => l.langCode === langCode);
|
const langInfo = languages?.find((lang) => lang.langCode === langCode);
|
||||||
getTranslation.isRtl = Boolean(langInfo?.rtl);
|
getTranslation.isRtl = Boolean(langInfo?.rtl);
|
||||||
getTranslation.code = langCode.replace('-raw', '') as LangCode;
|
getTranslation.code = langCode.replace('-raw', '') as LangCode;
|
||||||
getTranslation.langName = langInfo?.nativeName;
|
getTranslation.langName = langInfo?.nativeName;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user