[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,
|
request: T,
|
||||||
shouldReturnTrue?: boolean,
|
shouldReturnTrue?: boolean,
|
||||||
shouldThrow?: boolean,
|
shouldThrow?: boolean,
|
||||||
|
shouldIgnoreUpdates?: boolean,
|
||||||
): Promise<T['__response'] | undefined>;
|
): Promise<T['__response'] | undefined>;
|
||||||
|
|
||||||
export async function invokeRequest<T extends GramJs.AnyRequest>(
|
export async function invokeRequest<T extends GramJs.AnyRequest>(
|
||||||
request: T,
|
request: T,
|
||||||
shouldReturnTrue = false,
|
shouldReturnTrue = false,
|
||||||
shouldThrow = false,
|
shouldThrow = false,
|
||||||
|
shouldIgnoreUpdates = false,
|
||||||
) {
|
) {
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -198,7 +200,9 @@ export async function invokeRequest<T extends GramJs.AnyRequest>(
|
|||||||
console.log(`[GramJs/client] INVOKE RESPONSE ${request.className}`, result);
|
console.log(`[GramJs/client] INVOKE RESPONSE ${request.className}`, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUpdatesFromRequest(request, result);
|
if (!shouldIgnoreUpdates) {
|
||||||
|
handleUpdatesFromRequest(request, result);
|
||||||
|
}
|
||||||
|
|
||||||
return shouldReturnTrue ? result && true : result;
|
return shouldReturnTrue ? result && true : result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ import {
|
|||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import { interpolateArray } from '../../../util/waveform';
|
import { interpolateArray } from '../../../util/waveform';
|
||||||
import { requestChatUpdate } from './chats';
|
import { requestChatUpdate } from './chats';
|
||||||
import { buildApiPeerId, getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||||
|
|
||||||
const FAST_SEND_TIMEOUT = 1000;
|
const FAST_SEND_TIMEOUT = 1000;
|
||||||
const INPUT_WAVEFORM_LENGTH = 63;
|
const INPUT_WAVEFORM_LENGTH = 63;
|
||||||
@ -1172,17 +1172,8 @@ function updateLocalDb(result: (
|
|||||||
GramJs.messages.MessagesSlice | GramJs.messages.Messages | GramJs.messages.ChannelMessages |
|
GramJs.messages.MessagesSlice | GramJs.messages.Messages | GramJs.messages.ChannelMessages |
|
||||||
GramJs.messages.DiscussionMessage | GramJs.messages.SponsoredMessages
|
GramJs.messages.DiscussionMessage | GramJs.messages.SponsoredMessages
|
||||||
)) {
|
)) {
|
||||||
result.users.forEach((user) => {
|
addEntitiesWithPhotosToLocalDb(result.users);
|
||||||
if (user instanceof GramJs.User) {
|
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
result.messages.forEach((message) => {
|
result.messages.forEach((message) => {
|
||||||
if ((message instanceof GramJs.Message && isMessageWithMedia(message))
|
if ((message instanceof GramJs.Message && isMessageWithMedia(message))
|
||||||
|
|||||||
@ -28,9 +28,10 @@ import { getClient, invokeRequest, uploadFile } from './client';
|
|||||||
import { omitVirtualClassFields } from '../apiBuilders/helpers';
|
import { omitVirtualClassFields } from '../apiBuilders/helpers';
|
||||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||||
import { getServerTime } from '../../../util/serverTime';
|
import { getServerTime } from '../../../util/serverTime';
|
||||||
import { buildApiPeerId, getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||||
import localDb from '../localDb';
|
import localDb from '../localDb';
|
||||||
import { buildApiConfig } from '../apiBuilders/appConfig';
|
import { buildApiConfig } from '../apiBuilders/appConfig';
|
||||||
|
import { addEntitiesWithPhotosToLocalDb } from '../helpers';
|
||||||
|
|
||||||
const MAX_INT_32 = 2 ** 31 - 1;
|
const MAX_INT_32 = 2 ** 31 - 1;
|
||||||
const BETA_LANG_CODES = ['ar', 'fa', 'id', 'ko', 'uz'];
|
const BETA_LANG_CODES = ['ar', 'fa', 'id', 'ko', 'uz'];
|
||||||
@ -173,7 +174,9 @@ export function terminateAllAuthorizations() {
|
|||||||
export async function fetchNotificationExceptions({
|
export async function fetchNotificationExceptions({
|
||||||
serverTimeOffset,
|
serverTimeOffset,
|
||||||
}: { serverTimeOffset: number }) {
|
}: { 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)) {
|
if (!(result instanceof GramJs.Updates || result instanceof GramJs.UpdatesCombined)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -453,17 +456,8 @@ function updateLocalDb(
|
|||||||
GramJs.Updates | GramJs.UpdatesCombined
|
GramJs.Updates | GramJs.UpdatesCombined
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
result.users.forEach((user) => {
|
addEntitiesWithPhotosToLocalDb(result.users);
|
||||||
if (user instanceof GramJs.User) {
|
addEntitiesWithPhotosToLocalDb(result.chats);
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchCountryList({ langCode = 'en' }: { langCode?: LangCode }) {
|
export async function fetchCountryList({ langCode = 'en' }: { langCode?: LangCode }) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user