mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +01:00
[Refactoring] API: Ignore redundant updates from fetchNotificationExceptions
This commit is contained in:
parent
417941f5f3
commit
77cdea4f75
@ -169,12 +169,14 @@ export async function invokeRequest<T extends GramJs.AnyRequest>(
|
||||
request: T,
|
||||
shouldReturnTrue?: boolean,
|
||||
shouldThrow?: boolean,
|
||||
shouldIgnoreUpdates?: boolean,
|
||||
): Promise<T['__response'] | undefined>;
|
||||
|
||||
export async function invokeRequest<T extends GramJs.AnyRequest>(
|
||||
request: T,
|
||||
shouldReturnTrue = false,
|
||||
shouldThrow = false,
|
||||
shouldIgnoreUpdates = false,
|
||||
) {
|
||||
if (!isConnected) {
|
||||
if (DEBUG) {
|
||||
@ -198,7 +200,9 @@ export async function invokeRequest<T extends GramJs.AnyRequest>(
|
||||
console.log(`[GramJs/client] INVOKE RESPONSE ${request.className}`, result);
|
||||
}
|
||||
|
||||
handleUpdatesFromRequest(request, result);
|
||||
if (!shouldIgnoreUpdates) {
|
||||
handleUpdatesFromRequest(request, result);
|
||||
}
|
||||
|
||||
return shouldReturnTrue ? result && true : result;
|
||||
} catch (err) {
|
||||
|
@ -61,7 +61,7 @@ import {
|
||||
} from '../helpers';
|
||||
import { interpolateArray } from '../../../util/waveform';
|
||||
import { requestChatUpdate } from './chats';
|
||||
import { buildApiPeerId, getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
|
||||
const FAST_SEND_TIMEOUT = 1000;
|
||||
const INPUT_WAVEFORM_LENGTH = 63;
|
||||
@ -1172,17 +1172,8 @@ function updateLocalDb(result: (
|
||||
GramJs.messages.MessagesSlice | GramJs.messages.Messages | GramJs.messages.ChannelMessages |
|
||||
GramJs.messages.DiscussionMessage | GramJs.messages.SponsoredMessages
|
||||
)) {
|
||||
result.users.forEach((user) => {
|
||||
if (user instanceof GramJs.User) {
|
||||
localDb.users[buildApiPeerId(user.id, 'user')] = user;
|
||||
}
|
||||
});
|
||||
|
||||
result.chats.forEach((chat) => {
|
||||
if (chat instanceof GramJs.Chat || chat instanceof GramJs.Channel) {
|
||||
localDb.chats[buildApiPeerId(chat.id, chat instanceof GramJs.Chat ? 'chat' : 'channel')] = chat;
|
||||
}
|
||||
});
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
|
||||
result.messages.forEach((message) => {
|
||||
if ((message instanceof GramJs.Message && isMessageWithMedia(message))
|
||||
|
@ -28,9 +28,10 @@ import { getClient, invokeRequest, uploadFile } from './client';
|
||||
import { omitVirtualClassFields } from '../apiBuilders/helpers';
|
||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||
import { getServerTime } from '../../../util/serverTime';
|
||||
import { buildApiPeerId, getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
import localDb from '../localDb';
|
||||
import { buildApiConfig } from '../apiBuilders/appConfig';
|
||||
import { addEntitiesWithPhotosToLocalDb } from '../helpers';
|
||||
|
||||
const MAX_INT_32 = 2 ** 31 - 1;
|
||||
const BETA_LANG_CODES = ['ar', 'fa', 'id', 'ko', 'uz'];
|
||||
@ -173,7 +174,9 @@ export function terminateAllAuthorizations() {
|
||||
export async function fetchNotificationExceptions({
|
||||
serverTimeOffset,
|
||||
}: { serverTimeOffset: number }) {
|
||||
const result = await invokeRequest(new GramJs.account.GetNotifyExceptions({ compareSound: true }));
|
||||
const result = await invokeRequest(new GramJs.account.GetNotifyExceptions({
|
||||
compareSound: true,
|
||||
}), undefined, undefined, true);
|
||||
|
||||
if (!(result instanceof GramJs.Updates || result instanceof GramJs.UpdatesCombined)) {
|
||||
return undefined;
|
||||
@ -453,17 +456,8 @@ function updateLocalDb(
|
||||
GramJs.Updates | GramJs.UpdatesCombined
|
||||
),
|
||||
) {
|
||||
result.users.forEach((user) => {
|
||||
if (user instanceof GramJs.User) {
|
||||
localDb.users[buildApiPeerId(user.id, 'user')] = user;
|
||||
}
|
||||
});
|
||||
|
||||
result.chats.forEach((chat) => {
|
||||
if (chat instanceof GramJs.Chat || chat instanceof GramJs.Channel) {
|
||||
localDb.chats[buildApiPeerId(chat.id, chat instanceof GramJs.Chat ? 'chat' : 'channel')] = chat;
|
||||
}
|
||||
});
|
||||
addEntitiesWithPhotosToLocalDb(result.users);
|
||||
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||
}
|
||||
|
||||
export async function fetchCountryList({ langCode = 'en' }: { langCode?: LangCode }) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user