Channels: Fix error after posting (#2224)

This commit is contained in:
Alexander Zinchuk 2022-12-27 02:46:10 +01:00
parent f1a82ff079
commit 7a908c702a
5 changed files with 14 additions and 12 deletions

View File

@ -16,7 +16,7 @@ import type {
} from '../../types'; } from '../../types';
import { import {
DEBUG, ARCHIVED_FOLDER_ID, MEMBERS_LOAD_SLICE, SERVICE_NOTIFICATIONS_USER_ID, ALL_FOLDER_ID, DEBUG, ARCHIVED_FOLDER_ID, MEMBERS_LOAD_SLICE, SERVICE_NOTIFICATIONS_USER_ID, ALL_FOLDER_ID, MAX_INT_32,
} from '../../../config'; } from '../../../config';
import { invokeRequest, uploadFile } from './client'; import { invokeRequest, uploadFile } from './client';
import { import {
@ -57,7 +57,6 @@ type FullChatData = {
membersCount?: number; membersCount?: number;
}; };
const MAX_INT_32 = 2 ** 31 - 1;
let onUpdate: OnApiUpdate; let onUpdate: OnApiUpdate;
export function init(_onUpdate: OnApiUpdate) { export function init(_onUpdate: OnApiUpdate) {

View File

@ -24,7 +24,7 @@ import {
import { import {
ALL_FOLDER_ID, ALL_FOLDER_ID,
DEBUG, MENTION_UNREAD_SLICE, DEBUG, MAX_INT_32, MENTION_UNREAD_SLICE,
PINNED_MESSAGES_LIMIT, REACTION_UNREAD_SLICE, PINNED_MESSAGES_LIMIT, REACTION_UNREAD_SLICE,
SUPPORTED_IMAGE_CONTENT_TYPES, SUPPORTED_IMAGE_CONTENT_TYPES,
SUPPORTED_VIDEO_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES,
@ -97,7 +97,7 @@ export async function fetchMessages({
}), }),
...(offsetId && { ...(offsetId && {
// Workaround for local message IDs overflowing some internal `Buffer` range check // Workaround for local message IDs overflowing some internal `Buffer` range check
offsetId: Math.min(offsetId, 2 ** (32 - 1) - 1), offsetId: Math.min(offsetId, MAX_INT_32),
}), }),
...pagination, ...pagination,
}), undefined, true); }), undefined, true);
@ -763,27 +763,29 @@ export async function sendMessageAction({
} }
export async function markMessageListRead({ export async function markMessageListRead({
chat, threadId, maxId, serverTimeOffset, chat, threadId, maxId = -1, serverTimeOffset,
}: { }: {
chat: ApiChat; threadId: number; maxId?: number; serverTimeOffset: number; chat: ApiChat; threadId: number; maxId?: number; serverTimeOffset: number;
}) { }) {
const isChannel = getEntityTypeById(chat.id) === 'channel'; const isChannel = getEntityTypeById(chat.id) === 'channel';
// Workaround for local message IDs overflowing some internal `Buffer` range check
const fixedMaxId = Math.min(maxId, MAX_INT_32);
if (isChannel && threadId === MAIN_THREAD_ID) { if (isChannel && threadId === MAIN_THREAD_ID) {
await invokeRequest(new GramJs.channels.ReadHistory({ await invokeRequest(new GramJs.channels.ReadHistory({
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel, channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
maxId, maxId: fixedMaxId,
})); }));
} else if (isChannel) { } else if (isChannel) {
await invokeRequest(new GramJs.messages.ReadDiscussion({ await invokeRequest(new GramJs.messages.ReadDiscussion({
peer: buildInputPeer(chat.id, chat.accessHash), peer: buildInputPeer(chat.id, chat.accessHash),
msgId: threadId, msgId: threadId,
readMaxId: maxId, readMaxId: fixedMaxId,
})); }));
} else { } else {
await invokeRequest(new GramJs.messages.ReadHistory({ await invokeRequest(new GramJs.messages.ReadHistory({
peer: buildInputPeer(chat.id, chat.accessHash), peer: buildInputPeer(chat.id, chat.accessHash),
maxId, maxId: fixedMaxId,
})); }));
} }

View File

@ -10,9 +10,9 @@ import type {
ApiNotifyException, ApiPhoto, ApiNotifyException, ApiPhoto,
} from '../../types'; } from '../../types';
import type { ApiPrivacyKey, InputPrivacyRules, LangCode } from '../../../types'; import type { ApiPrivacyKey, InputPrivacyRules, LangCode } from '../../../types';
import type { LANG_PACKS } from '../../../config'; import type { LANG_PACKS } from '../../../config';
import { BLOCKED_LIST_LIMIT, DEFAULT_LANG_PACK } from '../../../config';
import { BLOCKED_LIST_LIMIT, DEFAULT_LANG_PACK, MAX_INT_32 } from '../../../config';
import { ACCEPTABLE_USERNAME_ERRORS } from './management'; import { ACCEPTABLE_USERNAME_ERRORS } from './management';
import { import {
buildApiConfig, buildApiConfig,
@ -39,7 +39,6 @@ import { getServerTime } from '../../../util/serverTime';
import { addEntitiesWithPhotosToLocalDb, addPhotoToLocalDb } from '../helpers'; import { addEntitiesWithPhotosToLocalDb, addPhotoToLocalDb } from '../helpers';
import localDb from '../localDb'; import localDb from '../localDb';
const MAX_INT_32 = 2 ** 31 - 1;
const BETA_LANG_CODES = ['ar', 'fa', 'id', 'ko', 'uz', 'en']; const BETA_LANG_CODES = ['ar', 'fa', 'id', 'ko', 'uz', 'en'];
export function updateProfile({ export function updateProfile({

View File

@ -3,6 +3,7 @@ import React, {
memo, useState, useEffect, useMemo, useCallback, memo, useState, useEffect, useMemo, useCallback,
} from '../../lib/teact/teact'; } from '../../lib/teact/teact';
import { MAX_INT_32 } from '../../config';
import buildClassName from '../../util/buildClassName'; import buildClassName from '../../util/buildClassName';
import { formatTime, formatDateToString, getDayStart } from '../../util/dateFormat'; import { formatTime, formatDateToString, getDayStart } from '../../util/dateFormat';
import type { LangFn } from '../../hooks/useLang'; import type { LangFn } from '../../hooks/useLang';
@ -15,7 +16,7 @@ import Button from '../ui/Button';
import './CalendarModal.scss'; import './CalendarModal.scss';
const MAX_SAFE_DATE = 2147483647 * 1000; // API has int for dates const MAX_SAFE_DATE = MAX_INT_32 * 1000;
const MIN_SAFE_DATE = 0; const MIN_SAFE_DATE = 0;
export type OwnProps = { export type OwnProps = {

View File

@ -120,6 +120,7 @@ export const MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH = 950; // px
export const MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT = 450; // px export const MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT = 450; // px
export const LOCAL_MESSAGE_MIN_ID = 1e11; // `Date.now()` is always used as base export const LOCAL_MESSAGE_MIN_ID = 1e11; // `Date.now()` is always used as base
export const MAX_INT_32 = 2 ** 31 - 1;
export const TMP_CHAT_ID = '0'; export const TMP_CHAT_ID = '0';
export const ANIMATION_END_DELAY = 100; export const ANIMATION_END_DELAY = 100;