GramJS: Forbid skipping required parameters (#6033)
This commit is contained in:
parent
cc597fe373
commit
05a1956ee2
@ -124,6 +124,7 @@ function buildApiChatFieldsFromPeerEntity(
|
||||
paidMessagesStars: paidMessagesStars?.toJSNumber(),
|
||||
level: channel?.level,
|
||||
hasAutoTranslation: channel?.autotranslation,
|
||||
withForumTabs: channel?.forumTabs,
|
||||
|
||||
...buildApiChatPermissions(peerEntity),
|
||||
...buildApiChatRestrictions(peerEntity),
|
||||
|
||||
@ -42,6 +42,12 @@ import { pick } from '../../../util/iteratees';
|
||||
import { deserializeBytes } from '../helpers/misc';
|
||||
import localDb from '../localDb';
|
||||
|
||||
export const DEFAULT_PRIMITIVES = {
|
||||
INT: 0,
|
||||
BIGINT: BigInt(0),
|
||||
STRING: '',
|
||||
} as const;
|
||||
|
||||
export function getEntityTypeById(peerId: string) {
|
||||
const n = Number(peerId);
|
||||
if (n > 0) {
|
||||
@ -514,7 +520,7 @@ export function buildInputPrivacyKey(privacyKey: ApiPrivacyKey) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function buildInputReportReason(reason: ApiReportReason) {
|
||||
export function buildInputReportReason(reason: ApiReportReason): GramJs.TypeReportReason {
|
||||
switch (reason) {
|
||||
case 'spam':
|
||||
return new GramJs.InputReportReasonSpam();
|
||||
@ -535,10 +541,9 @@ export function buildInputReportReason(reason: ApiReportReason) {
|
||||
case 'personalDetails':
|
||||
return new GramJs.InputReportReasonPersonalDetails();
|
||||
case 'other':
|
||||
default:
|
||||
return new GramJs.InputReportReasonOther();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function buildSendMessageAction(action: ApiSendMessageAction) {
|
||||
|
||||
@ -6,13 +6,13 @@ import type {
|
||||
} from '../../types';
|
||||
|
||||
import { buildApiChatLink } from '../apiBuilders/misc';
|
||||
import { buildInputPeer, buildInputPhoto, buildInputReportReason } from '../gramjsBuilders';
|
||||
import { buildInputPeer, buildInputPhoto, buildInputReportReason, DEFAULT_PRIMITIVES } from '../gramjsBuilders';
|
||||
import { invokeRequest } from './client';
|
||||
|
||||
export async function reportPeer({
|
||||
peer,
|
||||
reason,
|
||||
description,
|
||||
description = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
peer: ApiPeer; reason: ApiReportReason; description?: string;
|
||||
}) {
|
||||
@ -29,7 +29,7 @@ export async function reportProfilePhoto({
|
||||
peer,
|
||||
photo,
|
||||
reason,
|
||||
description,
|
||||
description = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
peer: ApiPeer; photo: ApiPhoto; reason: ApiReportReason; description?: string;
|
||||
}) {
|
||||
|
||||
@ -32,6 +32,7 @@ import {
|
||||
buildInputReplyTo,
|
||||
buildInputThemeParams,
|
||||
buildInputUser,
|
||||
DEFAULT_PRIMITIVES,
|
||||
generateRandomBigInt,
|
||||
} from '../gramjsBuilders';
|
||||
import {
|
||||
@ -62,6 +63,9 @@ export async function answerCallbackButton({
|
||||
export async function fetchTopInlineBots() {
|
||||
const topPeers = await invokeRequest(new GramJs.contacts.GetTopPeers({
|
||||
botsInline: true,
|
||||
limit: DEFAULT_PRIMITIVES.INT,
|
||||
offset: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!(topPeers instanceof GramJs.contacts.TopPeers)) {
|
||||
@ -79,6 +83,9 @@ export async function fetchTopInlineBots() {
|
||||
export async function fetchTopBotApps() {
|
||||
const topPeers = await invokeRequest(new GramJs.contacts.GetTopPeers({
|
||||
botsApp: true,
|
||||
limit: DEFAULT_PRIMITIVES.INT,
|
||||
offset: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!(topPeers instanceof GramJs.contacts.TopPeers)) {
|
||||
@ -116,7 +123,7 @@ export async function fetchInlineBot({ username }: { username: string }) {
|
||||
}
|
||||
|
||||
export async function fetchInlineBotResults({
|
||||
bot, chat, query, offset = '',
|
||||
bot, chat, query, offset = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
bot: ApiUser; chat: ApiChat; query: string; offset?: string;
|
||||
}) {
|
||||
@ -182,7 +189,7 @@ export async function startBot({
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
peer: buildInputPeer(bot.id, bot.accessHash),
|
||||
randomId,
|
||||
startParam,
|
||||
startParam: startParam ?? DEFAULT_PRIMITIVES.STRING,
|
||||
}));
|
||||
}
|
||||
|
||||
@ -307,6 +314,7 @@ export async function fetchBotApp({
|
||||
botId: buildInputUser(bot.id, bot.accessHash),
|
||||
shortName: appName,
|
||||
}),
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.BotAppNotModified) {
|
||||
@ -391,7 +399,7 @@ export async function loadAttachBots({
|
||||
hash?: string;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetAttachMenuBots({
|
||||
hash: hash ? BigInt(hash) : undefined,
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (result instanceof GramJs.AttachMenuBots) {
|
||||
@ -664,23 +672,23 @@ export function setBotInfo({
|
||||
return invokeRequest(new GramJs.bots.SetBotInfo({
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
langCode,
|
||||
name: name || '',
|
||||
about: about || '',
|
||||
description: description || '',
|
||||
name,
|
||||
about,
|
||||
description,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchPopularAppBots({
|
||||
offset = '', limit,
|
||||
offset = DEFAULT_PRIMITIVES.STRING, limit,
|
||||
}: {
|
||||
offset?: string;
|
||||
limit?: number;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.bots.GetPopularAppBots({
|
||||
offset,
|
||||
limit,
|
||||
limit: limit ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
buildPhoneCall,
|
||||
} from '../apiBuilders/calls';
|
||||
import {
|
||||
buildInputGroupCall, buildInputPeer, buildInputPhoneCall, buildInputUser, generateRandomInt,
|
||||
buildInputGroupCall, buildInputPeer, buildInputPhoneCall, buildInputUser, DEFAULT_PRIMITIVES, generateRandomInt,
|
||||
} from '../gramjsBuilders';
|
||||
import { sendApiUpdate } from '../updates/apiUpdateEmitter';
|
||||
import { invokeRequest, invokeRequestBeacon } from './client';
|
||||
@ -25,6 +25,7 @@ export async function getGroupCall({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.phone.GetGroupCall({
|
||||
call: buildInputGroupCall(call),
|
||||
limit: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -100,7 +101,8 @@ export async function exportGroupCallInvite({
|
||||
}
|
||||
|
||||
export async function fetchGroupCallParticipants({
|
||||
call, offset,
|
||||
call,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
call: ApiGroupCall; offset?: string;
|
||||
}) {
|
||||
@ -108,7 +110,7 @@ export async function fetchGroupCallParticipants({
|
||||
call: buildInputGroupCall(call),
|
||||
ids: [],
|
||||
sources: [],
|
||||
offset: offset || '',
|
||||
offset,
|
||||
limit: GROUP_CALL_PARTICIPANTS_LIMIT,
|
||||
}));
|
||||
|
||||
@ -131,6 +133,7 @@ export function leaveGroupCall({
|
||||
}) {
|
||||
const request = new GramJs.phone.LeaveGroupCall({
|
||||
call: buildInputGroupCall(call),
|
||||
source: DEFAULT_PRIMITIVES.INT,
|
||||
});
|
||||
|
||||
if (isPageUnload) {
|
||||
@ -239,7 +242,10 @@ export function leaveGroupCallPresentation({
|
||||
}
|
||||
|
||||
export async function getDhConfig() {
|
||||
const dhConfig = await invokeRequest(new GramJs.messages.GetDhConfig({}));
|
||||
const dhConfig = await invokeRequest(new GramJs.messages.GetDhConfig({
|
||||
version: DEFAULT_PRIMITIVES.INT,
|
||||
randomLength: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!dhConfig || dhConfig instanceof GramJs.messages.DhConfigNotModified) return undefined;
|
||||
|
||||
@ -258,6 +264,8 @@ export function discardCall({
|
||||
const request = new GramJs.phone.DiscardCall({
|
||||
peer: buildInputPhoneCall(call),
|
||||
reason: isBusy ? new GramJs.PhoneCallDiscardReasonBusy() : new GramJs.PhoneCallDiscardReasonHangup(),
|
||||
duration: DEFAULT_PRIMITIVES.INT,
|
||||
connectionId: DEFAULT_PRIMITIVES.BIGINT,
|
||||
});
|
||||
|
||||
if (isPageUnload) {
|
||||
|
||||
@ -70,6 +70,7 @@ import {
|
||||
buildInputReplyTo,
|
||||
buildInputUser,
|
||||
buildMtpMessageEntity,
|
||||
DEFAULT_PRIMITIVES,
|
||||
generateRandomBigInt,
|
||||
getEntityTypeById,
|
||||
} from '../gramjsBuilders';
|
||||
@ -128,16 +129,17 @@ export async function fetchChats({
|
||||
}): Promise<ChatListData | undefined> {
|
||||
const peer = (offsetPeer && buildInputPeer(offsetPeer.id, offsetPeer.accessHash)) || new GramJs.InputPeerEmpty();
|
||||
const result = await invokeRequest(new GramJs.messages.GetDialogs({
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
offsetPeer: peer,
|
||||
offsetId,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
limit,
|
||||
offsetDate,
|
||||
offsetDate: offsetDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
folderId: archived ? ARCHIVED_FOLDER_ID : undefined,
|
||||
...(withPinned && { excludePinned: true }),
|
||||
}));
|
||||
const resultPinned = withPinned
|
||||
? await invokeRequest(new GramJs.messages.GetPinnedDialogs({
|
||||
folderId: archived ? ARCHIVED_FOLDER_ID : undefined,
|
||||
folderId: archived ? ARCHIVED_FOLDER_ID : ALL_FOLDER_ID,
|
||||
}))
|
||||
: undefined;
|
||||
|
||||
@ -265,9 +267,10 @@ export async function fetchSavedChats({
|
||||
const peer = (offsetPeer && buildInputPeer(offsetPeer.id, offsetPeer.accessHash)) || new GramJs.InputPeerEmpty();
|
||||
const result = await invokeRequest(new GramJs.messages.GetSavedDialogs({
|
||||
offsetPeer: peer,
|
||||
offsetId,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
limit,
|
||||
offsetDate,
|
||||
offsetDate: offsetDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
...(withPinned && { excludePinned: true }),
|
||||
}));
|
||||
const resultPinned = withPinned
|
||||
@ -520,7 +523,7 @@ export function saveDraft({
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.SaveDraft({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
message: draft?.text?.text || '',
|
||||
message: draft?.text?.text || DEFAULT_PRIMITIVES.STRING,
|
||||
entities: draft?.text?.entities?.map(buildMtpMessageEntity),
|
||||
replyTo: draft?.replyInfo && buildInputReplyTo(draft.replyInfo),
|
||||
}));
|
||||
@ -821,7 +824,7 @@ export function updateTopicMutedState({
|
||||
}
|
||||
|
||||
export async function createChannel({
|
||||
title, about = '', users, isBroadcast, isMegagroup,
|
||||
title, about = DEFAULT_PRIMITIVES.STRING, users, isBroadcast, isMegagroup,
|
||||
}: {
|
||||
title: string; about?: string; users?: ApiUser[]; isBroadcast?: true; isMegagroup?: true;
|
||||
}) {
|
||||
@ -1094,7 +1097,7 @@ export async function fetchPinnedDialogs({
|
||||
listType: ChatListType;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetPinnedDialogs({
|
||||
folderId: listType === 'archived' ? ARCHIVED_FOLDER_ID : undefined,
|
||||
folderId: listType === 'archived' ? ARCHIVED_FOLDER_ID : ALL_FOLDER_ID,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -1282,7 +1285,7 @@ export function updateChatMemberBannedRights({
|
||||
}
|
||||
|
||||
export function updateChatAdmin({
|
||||
chat, user, adminRights, customTitle = '',
|
||||
chat, user, adminRights, customTitle = DEFAULT_PRIMITIVES.STRING,
|
||||
}: { chat: ApiChat; user: ApiUser; adminRights: ApiChatAdminRights; customTitle?: string }) {
|
||||
const channel = buildInputChannel(chat.id, chat.accessHash);
|
||||
const userId = buildInputUser(user.id, user.accessHash);
|
||||
@ -1362,7 +1365,7 @@ export async function fetchMembers({
|
||||
chat,
|
||||
memberFilter = 'recent',
|
||||
offset,
|
||||
query = '',
|
||||
query = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
memberFilter?: ChannelMembersFilter;
|
||||
@ -1389,7 +1392,8 @@ export async function fetchMembers({
|
||||
const result = await invokeRequest(new GramJs.channels.GetParticipants({
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
filter,
|
||||
offset,
|
||||
offset: offset ?? DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
limit: MEMBERS_LOAD_SLICE,
|
||||
}), {
|
||||
abortControllerChatId: chat.id,
|
||||
@ -1535,6 +1539,7 @@ export async function addChatMembers(chat: ApiChat, users: ApiUser[]) {
|
||||
const invitedUsers = await invokeRequest(new GramJs.messages.AddChatUser({
|
||||
chatId: buildInputChat(chat.id),
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
fwdLimit: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
if (!invitedUsers) return undefined;
|
||||
handleGramJsUpdate(invitedUsers.updates);
|
||||
@ -1700,6 +1705,7 @@ export function toggleForum({
|
||||
return invokeRequest(new GramJs.channels.ToggleForum({
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
enabled: isEnabled,
|
||||
tabs: Boolean(chat.withForumTabs),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
shouldThrow: true,
|
||||
@ -1759,9 +1765,9 @@ export async function fetchTopics({
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
limit,
|
||||
q: query,
|
||||
offsetTopic: offsetTopicId,
|
||||
offsetId,
|
||||
offsetDate,
|
||||
offsetTopic: offsetTopicId ?? DEFAULT_PRIMITIVES.INT,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
offsetDate: offsetDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result) return undefined;
|
||||
@ -1954,7 +1960,9 @@ export function leaveChatlist({
|
||||
}
|
||||
|
||||
export async function createChalistInvite({
|
||||
folderId, title, peers,
|
||||
folderId,
|
||||
title = DEFAULT_PRIMITIVES.STRING,
|
||||
peers,
|
||||
}: {
|
||||
folderId: number;
|
||||
title?: string;
|
||||
@ -1964,7 +1972,7 @@ export async function createChalistInvite({
|
||||
chatlist: new GramJs.InputChatlistDialogFilter({
|
||||
filterId: folderId,
|
||||
}),
|
||||
title: title || '',
|
||||
title,
|
||||
peers: peers.map((peer) => buildInputPeer(peer.id, peer.accessHash)),
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
@ -2081,7 +2089,7 @@ export function updatePaidMessagesPrice({
|
||||
chat?: ApiChat; paidMessagesStars: number;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.UpdatePaidMessagesPrice({
|
||||
channel: chat && buildInputChannel(chat.id, chat.accessHash),
|
||||
channel: chat ? buildInputChannel(chat.id, chat.accessHash) : new GramJs.InputChannelEmpty(),
|
||||
sendPaidMessagesStars: BigInt(paidMessagesStars),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
|
||||
@ -87,6 +87,7 @@ import {
|
||||
buildMtpMessageEntity,
|
||||
buildPeer,
|
||||
buildSendMessageAction,
|
||||
DEFAULT_PRIMITIVES,
|
||||
generateRandomBigInt,
|
||||
getEntityTypeById,
|
||||
} from '../gramjsBuilders';
|
||||
@ -126,7 +127,8 @@ export async function fetchMessages({
|
||||
threadId,
|
||||
offsetId,
|
||||
isSavedDialog,
|
||||
...pagination
|
||||
addOffset,
|
||||
limit,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
threadId?: ThreadId;
|
||||
@ -142,15 +144,18 @@ export async function fetchMessages({
|
||||
|
||||
try {
|
||||
result = await invokeRequest(new RequestClass({
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
maxId: DEFAULT_PRIMITIVES.INT,
|
||||
minId: DEFAULT_PRIMITIVES.INT,
|
||||
offsetDate: DEFAULT_PRIMITIVES.INT,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
...(threadId !== MAIN_THREAD_ID && !isSavedDialog && {
|
||||
msgId: Number(threadId),
|
||||
}),
|
||||
...(offsetId && {
|
||||
// Workaround for local message IDs overflowing some internal `Buffer` range check
|
||||
offsetId: Math.min(offsetId, MAX_INT_32),
|
||||
}),
|
||||
...pagination,
|
||||
// Workaround for local message IDs overflowing some internal `Buffer` range check
|
||||
offsetId: offsetId ? Math.min(offsetId, MAX_INT_32) : DEFAULT_PRIMITIVES.INT,
|
||||
addOffset: addOffset ?? DEFAULT_PRIMITIVES.INT,
|
||||
limit,
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
abortControllerChatId: chat.id,
|
||||
@ -376,33 +381,57 @@ export function sendApiMessage(
|
||||
phoneNumber: contact.phoneNumber,
|
||||
firstName: contact.firstName,
|
||||
lastName: contact.lastName,
|
||||
vcard: '',
|
||||
vcard: DEFAULT_PRIMITIVES.STRING,
|
||||
});
|
||||
}
|
||||
|
||||
const RequestClass = media ? GramJs.messages.SendMedia : GramJs.messages.SendMessage;
|
||||
type SharedKeys<T, U> = {
|
||||
[K in keyof T & keyof U]:
|
||||
T[K] extends U[K] ? (U[K] extends T[K] ? K : never) : never
|
||||
}[keyof T & keyof U];
|
||||
type SharedRecord<T, U> = Pick<T, SharedKeys<T, U>>;
|
||||
|
||||
type SendMediaArgs = ConstructorParameters<typeof GramJs.messages.SendMedia>[0];
|
||||
type SendMessageArgs = ConstructorParameters<typeof GramJs.messages.SendMessage>[0];
|
||||
|
||||
type SharedArgs = SharedRecord<SendMediaArgs, SendMessageArgs>;
|
||||
|
||||
const args: SharedArgs = {
|
||||
clearDraft: true,
|
||||
message: text || DEFAULT_PRIMITIVES.STRING,
|
||||
entities: entities ? entities.map(buildMtpMessageEntity) : undefined,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
randomId,
|
||||
replyTo: replyInfo && buildInputReplyTo(replyInfo),
|
||||
silent: isSilent || undefined,
|
||||
scheduleDate: scheduledAt,
|
||||
sendAs: sendAs && buildInputPeer(sendAs.id, sendAs.accessHash),
|
||||
updateStickersetsOrder: shouldUpdateStickerSetOrder || undefined,
|
||||
invertMedia: isInvertedMedia || undefined,
|
||||
effect: effectId ? BigInt(effectId) : undefined,
|
||||
allowPaidStars: messagePriceInStars ? BigInt(messagePriceInStars) : undefined,
|
||||
};
|
||||
|
||||
try {
|
||||
const update = await invokeRequest(new RequestClass({
|
||||
clearDraft: true,
|
||||
message: text || '',
|
||||
entities: entities ? entities.map(buildMtpMessageEntity) : undefined,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
randomId,
|
||||
replyTo: replyInfo && buildInputReplyTo(replyInfo),
|
||||
...(isSilent && { silent: isSilent }),
|
||||
...(scheduledAt && { scheduleDate: scheduledAt }),
|
||||
...(media && { media }),
|
||||
...(noWebPage && { noWebpage: noWebPage }),
|
||||
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
|
||||
...(shouldUpdateStickerSetOrder && { updateStickersetsOrder: shouldUpdateStickerSetOrder }),
|
||||
...(isInvertedMedia && { invertMedia: isInvertedMedia }),
|
||||
...(effectId && { effect: BigInt(effectId) }),
|
||||
...(messagePriceInStars && { allowPaidStars: BigInt(messagePriceInStars) }),
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
shouldIgnoreUpdates: true,
|
||||
});
|
||||
let update;
|
||||
if (media) {
|
||||
update = await invokeRequest(new GramJs.messages.SendMedia({
|
||||
...args,
|
||||
media,
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
shouldIgnoreUpdates: true,
|
||||
});
|
||||
} else {
|
||||
update = await invokeRequest(new GramJs.messages.SendMessage({
|
||||
...args,
|
||||
noWebpage: noWebPage || undefined,
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
shouldIgnoreUpdates: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (update) handleLocalMessageUpdate(localMessage, update);
|
||||
} catch (error: any) {
|
||||
if (error.errorMessage === 'PRIVACY_PREMIUM_REQUIRED') {
|
||||
@ -439,7 +468,7 @@ const groupedUploads: Record<string, {
|
||||
function sendGroupedMedia(
|
||||
{
|
||||
chat,
|
||||
text,
|
||||
text = DEFAULT_PRIMITIVES.STRING,
|
||||
entities,
|
||||
replyInfo,
|
||||
attachment,
|
||||
@ -514,7 +543,7 @@ function sendGroupedMedia(
|
||||
groupedUploads[groupedId].singleMediaByIndex[groupIndex] = new GramJs.InputSingleMedia({
|
||||
media: inputMedia,
|
||||
randomId,
|
||||
message: text || '',
|
||||
message: text,
|
||||
entities: entities ? entities.map(buildMtpMessageEntity) : undefined,
|
||||
});
|
||||
groupedUploads[groupedId].localMessages[randomId.toString()] = localMessage;
|
||||
@ -638,7 +667,7 @@ export async function editMessage({
|
||||
const mtpEntities = entities && entities.map(buildMtpMessageEntity);
|
||||
|
||||
await invokeRequest(new GramJs.messages.EditMessage({
|
||||
message: text || '',
|
||||
message: text,
|
||||
entities: mtpEntities,
|
||||
media: mediaUpdate,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
@ -871,7 +900,7 @@ export function deleteScheduledMessages({
|
||||
}
|
||||
|
||||
export async function deleteHistory({
|
||||
chat, shouldDeleteForAll,
|
||||
chat, shouldDeleteForAll, maxId,
|
||||
}: {
|
||||
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
|
||||
}) {
|
||||
@ -880,9 +909,11 @@ export async function deleteHistory({
|
||||
isChannel
|
||||
? new GramJs.channels.DeleteHistory({
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
maxId: maxId ?? DEFAULT_PRIMITIVES.INT,
|
||||
})
|
||||
: new GramJs.messages.DeleteHistory({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
maxId: maxId ?? DEFAULT_PRIMITIVES.INT,
|
||||
...(shouldDeleteForAll && { revoke: true }),
|
||||
...(!shouldDeleteForAll && { just_clear: true }),
|
||||
}),
|
||||
@ -914,6 +945,7 @@ export async function deleteSavedHistory({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.DeleteSavedHistory({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
maxId: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -1101,7 +1133,7 @@ export async function fetchMessageViews({
|
||||
invokeRequest(new GramJs.messages.GetMessagesViews({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
id: chunkIds,
|
||||
increment: shouldIncrement,
|
||||
increment: Boolean(shouldIncrement),
|
||||
}))
|
||||
)));
|
||||
|
||||
@ -1208,7 +1240,17 @@ export async function fetchDiscussionMessage({
|
||||
}
|
||||
|
||||
export async function searchMessagesInChat({
|
||||
peer, isSavedDialog, savedTag, type, query = '', threadId, minDate, maxDate, ...pagination
|
||||
peer,
|
||||
isSavedDialog,
|
||||
savedTag,
|
||||
type,
|
||||
query = DEFAULT_PRIMITIVES.STRING,
|
||||
threadId,
|
||||
minDate,
|
||||
maxDate,
|
||||
offsetId,
|
||||
addOffset,
|
||||
limit,
|
||||
}: {
|
||||
peer: ApiPeer;
|
||||
isSavedDialog?: boolean;
|
||||
@ -1257,9 +1299,14 @@ export async function searchMessagesInChat({
|
||||
topMsgId: threadId !== MAIN_THREAD_ID && !isSavedDialog ? Number(threadId) : undefined,
|
||||
filter,
|
||||
q: query,
|
||||
minDate,
|
||||
maxDate,
|
||||
...pagination,
|
||||
minDate: minDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
maxDate: maxDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
maxId: DEFAULT_PRIMITIVES.INT,
|
||||
minId: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
addOffset: addOffset ?? DEFAULT_PRIMITIVES.INT,
|
||||
limit,
|
||||
}), {
|
||||
abortControllerChatId: peer.id,
|
||||
abortControllerThreadId: threadId,
|
||||
@ -1340,14 +1387,14 @@ export async function searchMessagesGlobal({
|
||||
q: query,
|
||||
offsetRate,
|
||||
offsetPeer: peer,
|
||||
offsetId,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
broadcastsOnly: type === 'channels' || context === 'channels' || undefined,
|
||||
groupsOnly: context === 'groups' || undefined,
|
||||
usersOnly: context === 'users' || undefined,
|
||||
limit,
|
||||
filter,
|
||||
minDate,
|
||||
maxDate,
|
||||
minDate: minDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
maxDate: maxDate ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (
|
||||
@ -1395,10 +1442,10 @@ export async function searchHashtagPosts({
|
||||
const peer = (offsetPeer && buildInputPeer(offsetPeer.id, offsetPeer.accessHash)) || new GramJs.InputPeerEmpty();
|
||||
const result = await invokeRequest(new GramJs.channels.SearchPosts({
|
||||
hashtag,
|
||||
offsetRate,
|
||||
offsetId,
|
||||
offsetRate: offsetRate ?? DEFAULT_PRIMITIVES.INT,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
offsetPeer: peer,
|
||||
limit,
|
||||
limit: limit ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.MessagesNotModified) {
|
||||
@ -1491,9 +1538,9 @@ export async function loadPollOptionResults({
|
||||
const result = await invokeRequest(new GramJs.messages.GetPollVotes({
|
||||
peer: buildInputPeer(id, accessHash),
|
||||
id: messageId,
|
||||
...(option && { option: deserializeBytes(option) }),
|
||||
...(offset && { offset }),
|
||||
...(limit && { limit }),
|
||||
limit: limit ?? DEFAULT_PRIMITIVES.INT,
|
||||
option: option ? deserializeBytes(option) : undefined,
|
||||
offset,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -1635,6 +1682,10 @@ export async function findFirstMessageIdAfterDate({
|
||||
offsetDate: timestamp,
|
||||
addOffset: -1,
|
||||
limit: 1,
|
||||
offsetId: DEFAULT_PRIMITIVES.INT,
|
||||
maxId: DEFAULT_PRIMITIVES.INT,
|
||||
minId: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (
|
||||
@ -1653,6 +1704,7 @@ export async function fetchScheduledHistory({ chat }: { chat: ApiChat }) {
|
||||
|
||||
const result = await invokeRequest(new GramJs.messages.GetScheduledHistory({
|
||||
peer: buildInputPeer(id, accessHash),
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}), {
|
||||
abortControllerChatId: id,
|
||||
});
|
||||
@ -1686,9 +1738,16 @@ export async function fetchPinnedMessages({ chat, threadId }: { chat: ApiChat; t
|
||||
{
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
filter: new GramJs.InputMessagesFilterPinned(),
|
||||
q: '',
|
||||
q: DEFAULT_PRIMITIVES.STRING,
|
||||
limit: PINNED_MESSAGES_LIMIT,
|
||||
topMsgId: Number(threadId),
|
||||
minDate: DEFAULT_PRIMITIVES.INT,
|
||||
maxDate: DEFAULT_PRIMITIVES.INT,
|
||||
offsetId: DEFAULT_PRIMITIVES.INT,
|
||||
addOffset: DEFAULT_PRIMITIVES.INT,
|
||||
maxId: DEFAULT_PRIMITIVES.INT,
|
||||
minId: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
},
|
||||
), {
|
||||
abortControllerChatId: chat.id,
|
||||
@ -1871,7 +1930,7 @@ export async function readAllReactions({
|
||||
}
|
||||
|
||||
export async function fetchUnreadMentions({
|
||||
chat, threadId, ...pagination
|
||||
chat, threadId, offsetId, addOffset, maxId, minId,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
threadId?: ThreadId;
|
||||
@ -1884,7 +1943,10 @@ export async function fetchUnreadMentions({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
topMsgId: threadId ? Number(threadId) : undefined,
|
||||
limit: MENTION_UNREAD_SLICE,
|
||||
...pagination,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
addOffset: addOffset ?? DEFAULT_PRIMITIVES.INT,
|
||||
maxId: maxId ?? DEFAULT_PRIMITIVES.INT,
|
||||
minId: minId ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (
|
||||
@ -1903,7 +1965,7 @@ export async function fetchUnreadMentions({
|
||||
}
|
||||
|
||||
export async function fetchUnreadReactions({
|
||||
chat, threadId, ...pagination
|
||||
chat, threadId, offsetId, addOffset, maxId, minId,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
threadId?: ThreadId;
|
||||
@ -1916,7 +1978,10 @@ export async function fetchUnreadReactions({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
topMsgId: threadId ? Number(threadId) : undefined,
|
||||
limit: REACTION_UNREAD_SLICE,
|
||||
...pagination,
|
||||
offsetId: offsetId ?? DEFAULT_PRIMITIVES.INT,
|
||||
addOffset: addOffset ?? DEFAULT_PRIMITIVES.INT,
|
||||
maxId: maxId ?? DEFAULT_PRIMITIVES.INT,
|
||||
minId: minId ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (
|
||||
@ -2124,7 +2189,9 @@ export async function fetchOutboxReadDate({ chat, messageId }: { chat: ApiChat;
|
||||
}
|
||||
|
||||
export async function fetchQuickReplies() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetQuickReplies({}));
|
||||
const result = await invokeRequest(new GramJs.messages.GetQuickReplies({
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
if (!result || result instanceof GramJs.messages.QuickRepliesNotModified) return undefined;
|
||||
|
||||
const messages = result.messages.map(buildApiMessage).filter(Boolean);
|
||||
@ -2147,6 +2214,7 @@ export async function sendQuickReply({
|
||||
// Remove this request when the client fully supports quick replies and caches them
|
||||
const messages = await invokeRequest(new GramJs.messages.GetQuickReplyMessages({
|
||||
shortcutId,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
if (!messages || messages instanceof GramJs.messages.MessagesNotModified) return;
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ import {
|
||||
buildInputStorePaymentPurpose,
|
||||
buildInputThemeParams,
|
||||
buildShippingInfo,
|
||||
DEFAULT_PRIMITIVES,
|
||||
} from '../gramjsBuilders';
|
||||
import {
|
||||
deserializeBytes,
|
||||
@ -295,8 +296,8 @@ export async function fetchBoostStatus({
|
||||
export async function fetchBoostList({
|
||||
chat,
|
||||
isGifts,
|
||||
offset = '',
|
||||
limit,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
limit = DEFAULT_PRIMITIVES.INT,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
isGifts?: boolean;
|
||||
|
||||
@ -21,7 +21,11 @@ import {
|
||||
} from '../apiBuilders/reactions';
|
||||
import { buildStickerFromDocument } from '../apiBuilders/symbols';
|
||||
import {
|
||||
buildInputPaidReactionPrivacy, buildInputPeer, buildInputReaction, generateRandomTimestampedBigInt,
|
||||
buildInputPaidReactionPrivacy,
|
||||
buildInputPeer,
|
||||
buildInputReaction,
|
||||
DEFAULT_PRIMITIVES,
|
||||
generateRandomTimestampedBigInt,
|
||||
} from '../gramjsBuilders';
|
||||
import localDb from '../localDb';
|
||||
import { invokeRequest } from './client';
|
||||
@ -71,7 +75,9 @@ export function sendEmojiInteraction({
|
||||
}
|
||||
|
||||
export async function fetchAvailableReactions() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetAvailableReactions({}));
|
||||
const result = await invokeRequest(new GramJs.messages.GetAvailableReactions({
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.AvailableReactionsNotModified) {
|
||||
return undefined;
|
||||
@ -99,7 +105,9 @@ export async function fetchAvailableReactions() {
|
||||
}
|
||||
|
||||
export async function fetchAvailableEffects() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetAvailableEffects({}));
|
||||
const result = await invokeRequest(new GramJs.messages.GetAvailableEffects({
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.AvailableEffectsNotModified) {
|
||||
return undefined;
|
||||
@ -232,10 +240,10 @@ export function setDefaultReaction({
|
||||
}));
|
||||
}
|
||||
|
||||
export async function fetchTopReactions({ hash = '0' }: { hash?: string }) {
|
||||
export async function fetchTopReactions({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetTopReactions({
|
||||
limit: TOP_REACTIONS_LIMIT,
|
||||
hash: BigInt(hash),
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.ReactionsNotModified) {
|
||||
@ -248,10 +256,10 @@ export async function fetchTopReactions({ hash = '0' }: { hash?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchRecentReactions({ hash = '0' }: { hash?: string }) {
|
||||
export async function fetchRecentReactions({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetRecentReactions({
|
||||
limit: RECENT_REACTIONS_LIMIT,
|
||||
hash: BigInt(hash),
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.ReactionsNotModified) {
|
||||
@ -268,9 +276,9 @@ export function clearRecentReactions() {
|
||||
return invokeRequest(new GramJs.messages.ClearRecentReactions());
|
||||
}
|
||||
|
||||
export async function fetchDefaultTagReactions({ hash = '0' }: { hash?: string }) {
|
||||
export async function fetchDefaultTagReactions({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetDefaultTagReactions({
|
||||
hash: BigInt(hash),
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.ReactionsNotModified) {
|
||||
@ -283,8 +291,10 @@ export async function fetchDefaultTagReactions({ hash = '0' }: { hash?: string }
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchSavedReactionTags({ hash = '0' }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetSavedReactionTags({ hash: BigInt(hash) }));
|
||||
export async function fetchSavedReactionTags({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetSavedReactionTags({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.SavedReactionTagsNotModified) {
|
||||
return undefined;
|
||||
|
||||
@ -47,6 +47,7 @@ import {
|
||||
buildInputPrivacyKey,
|
||||
buildInputPrivacyRules,
|
||||
buildInputUser,
|
||||
DEFAULT_PRIMITIVES,
|
||||
} from '../gramjsBuilders';
|
||||
import { addPhotoToLocalDb } from '../helpers/localDb';
|
||||
import localDb from '../localDb';
|
||||
@ -64,9 +65,9 @@ export function updateProfile({
|
||||
about?: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.account.UpdateProfile({
|
||||
firstName: firstName || '',
|
||||
lastName: lastName || '',
|
||||
about: about || '',
|
||||
firstName,
|
||||
lastName,
|
||||
about,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -100,9 +101,9 @@ export function updateUsername(username: string) {
|
||||
}
|
||||
|
||||
export async function updateProfilePhoto(photo?: ApiPhoto, isFallback?: boolean) {
|
||||
const photoId = photo ? buildInputPhoto(photo) : new GramJs.InputPhotoEmpty();
|
||||
const photoId = photo && buildInputPhoto(photo);
|
||||
const result = await invokeRequest(new GramJs.photos.UpdateProfilePhoto({
|
||||
id: photoId,
|
||||
id: photoId || new GramJs.InputPhotoEmpty(),
|
||||
...(isFallback ? { fallback: true } : undefined),
|
||||
}));
|
||||
if (!result) return undefined;
|
||||
@ -235,6 +236,7 @@ export async function fetchBlockedUsers({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.contacts.GetBlocked({
|
||||
myStoriesFrom: isOnlyStories,
|
||||
offset: DEFAULT_PRIMITIVES.INT,
|
||||
limit: BLOCKED_LIST_LIMIT,
|
||||
}));
|
||||
if (!result) {
|
||||
@ -523,6 +525,8 @@ export async function oldFetchLangPack({ sourceLangPacks, langCode }: {
|
||||
|
||||
export async function fetchPrivacySettings(privacyKey: ApiPrivacyKey) {
|
||||
const key = buildInputPrivacyKey(privacyKey);
|
||||
if (!key) return undefined;
|
||||
|
||||
const result = await invokeRequest(new GramJs.account.GetPrivacy({ key }));
|
||||
|
||||
if (!result) {
|
||||
@ -536,7 +540,7 @@ export async function fetchPrivacySettings(privacyKey: ApiPrivacyKey) {
|
||||
|
||||
export function registerDevice(token: string) {
|
||||
const client = getClient();
|
||||
const secret = client.session.getAuthKey().getKey();
|
||||
const secret = client.session.getAuthKey().getKey()!;
|
||||
return invokeRequest(new GramJs.account.RegisterDevice({
|
||||
tokenType: 10,
|
||||
secret,
|
||||
@ -559,6 +563,7 @@ export async function setPrivacySettings(
|
||||
) {
|
||||
const key = buildInputPrivacyKey(privacyKey);
|
||||
const privacyRules = buildInputPrivacyRules(rules);
|
||||
if (!key) return undefined;
|
||||
|
||||
const result = await invokeRequest(new GramJs.account.SetPrivacy({ key, rules: privacyRules }));
|
||||
|
||||
@ -594,7 +599,7 @@ export function updateContentSettings(isEnabled: boolean) {
|
||||
}
|
||||
|
||||
export async function fetchAppConfig(hash?: number): Promise<ApiAppConfig | undefined> {
|
||||
const result = await invokeRequest(new GramJs.help.GetAppConfig({ hash }));
|
||||
const result = await invokeRequest(new GramJs.help.GetAppConfig({ hash: hash ?? DEFAULT_PRIMITIVES.INT }));
|
||||
if (!result || result instanceof GramJs.help.AppConfigNotModified) return undefined;
|
||||
|
||||
const { config, hash: resultHash } = result;
|
||||
@ -610,7 +615,7 @@ export async function fetchConfig(): Promise<ApiConfig | undefined> {
|
||||
|
||||
export async function fetchPeerColors(hash?: number) {
|
||||
const result = await invokeRequest(new GramJs.help.GetPeerColors({
|
||||
hash,
|
||||
hash: hash ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
if (!result) return undefined;
|
||||
|
||||
@ -627,7 +632,7 @@ export async function fetchPeerColors(hash?: number) {
|
||||
|
||||
export async function fetchTimezones(hash?: number) {
|
||||
const result = await invokeRequest(new GramJs.help.GetTimezonesList({
|
||||
hash,
|
||||
hash: hash ?? DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
if (!result || result instanceof GramJs.help.TimezonesListNotModified) return undefined;
|
||||
|
||||
@ -642,6 +647,7 @@ export async function fetchTimezones(hash?: number) {
|
||||
export async function fetchCountryList({ langCode = 'en' }: { langCode?: string }) {
|
||||
const countryList = await invokeRequest(new GramJs.help.GetCountriesList({
|
||||
langCode,
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(countryList instanceof GramJs.help.CountriesList)) {
|
||||
|
||||
@ -20,7 +20,7 @@ import {
|
||||
buildApiStarsTransaction,
|
||||
buildApiStarTopupOption,
|
||||
} from '../apiBuilders/payments';
|
||||
import { buildInputPeer, buildInputSavedStarGift, buildInputUser } from '../gramjsBuilders';
|
||||
import { buildInputPeer, buildInputSavedStarGift, buildInputUser, DEFAULT_PRIMITIVES } from '../gramjsBuilders';
|
||||
import { checkErrorType, wrapError } from '../helpers/misc';
|
||||
import { invokeRequest } from './client';
|
||||
import { getPassword } from './twoFaSettings';
|
||||
@ -36,7 +36,9 @@ export async function fetchStarsGiveawayOptions() {
|
||||
}
|
||||
|
||||
export async function fetchStarGifts() {
|
||||
const result = await invokeRequest(new GramJs.payments.GetStarGifts({}));
|
||||
const result = await invokeRequest(new GramJs.payments.GetStarGifts({
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.payments.StarGiftsNotModified) {
|
||||
return undefined;
|
||||
@ -48,9 +50,9 @@ export async function fetchStarGifts() {
|
||||
|
||||
export async function fetchResaleGifts({
|
||||
giftId,
|
||||
offset = '',
|
||||
limit,
|
||||
attributesHash = '0',
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
limit = DEFAULT_PRIMITIVES.INT,
|
||||
attributesHash,
|
||||
filter,
|
||||
}: {
|
||||
giftId: string;
|
||||
@ -71,12 +73,12 @@ export async function fetchResaleGifts({
|
||||
giftId: bigInt(giftId),
|
||||
offset,
|
||||
limit,
|
||||
attributesHash: attributesHash ? bigInt(attributesHash) : undefined,
|
||||
attributesHash: attributesHash ? bigInt(attributesHash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
attributes: buildInputResaleGiftsAttributes(attributes),
|
||||
...(filter && {
|
||||
sortByPrice: filter.sortType === 'byPrice' || undefined,
|
||||
sortByNum: filter.sortType === 'byNumber' || undefined,
|
||||
} satisfies GetResaleStarGifts),
|
||||
} satisfies Partial<GetResaleStarGifts>),
|
||||
};
|
||||
|
||||
const result = await invokeRequest(new GramJs.payments.GetResaleStarGifts(params));
|
||||
@ -90,8 +92,8 @@ export async function fetchResaleGifts({
|
||||
|
||||
export async function fetchSavedStarGifts({
|
||||
peer,
|
||||
offset = '',
|
||||
limit,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
limit = DEFAULT_PRIMITIVES.INT,
|
||||
filter,
|
||||
}: {
|
||||
peer: ApiPeer;
|
||||
@ -112,7 +114,7 @@ export async function fetchSavedStarGifts({
|
||||
excludeUnique: !filter.shouldIncludeUnique || undefined,
|
||||
excludeSaved: !filter.shouldIncludeDisplayed || undefined,
|
||||
excludeUnsaved: !filter.shouldIncludeHidden || undefined,
|
||||
} satisfies GetSavedStarGiftsParams),
|
||||
} satisfies Partial<GetSavedStarGiftsParams>),
|
||||
};
|
||||
|
||||
const result = await invokeRequest(new GramJs.payments.GetSavedStarGifts(params));
|
||||
@ -188,12 +190,14 @@ export async function fetchStarsStatus() {
|
||||
|
||||
export async function fetchStarsTransactions({
|
||||
peer,
|
||||
offset,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
limit = DEFAULT_PRIMITIVES.INT,
|
||||
isInbound,
|
||||
isOutbound,
|
||||
}: {
|
||||
peer?: ApiPeer;
|
||||
offset?: string;
|
||||
limit?: number;
|
||||
isInbound?: true;
|
||||
isOutbound?: true;
|
||||
}) {
|
||||
@ -201,6 +205,7 @@ export async function fetchStarsTransactions({
|
||||
const result = await invokeRequest(new GramJs.payments.GetStarsTransactions({
|
||||
peer: inputPeer,
|
||||
offset,
|
||||
limit,
|
||||
inbound: isInbound,
|
||||
outbound: isOutbound,
|
||||
}));
|
||||
@ -240,9 +245,10 @@ export async function fetchStarsTransactionById({
|
||||
}
|
||||
|
||||
export async function fetchStarsSubscriptions({
|
||||
offset, peer,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
peer,
|
||||
}: {
|
||||
offset?: string;
|
||||
offset?: string; limit?: number;
|
||||
peer?: ApiPeer;
|
||||
}) {
|
||||
const inputPeer = peer ? buildInputPeer(peer.id, peer.accessHash) : new GramJs.InputPeerSelf();
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
buildPostsStatistics,
|
||||
buildStoryPublicForwards,
|
||||
} from '../apiBuilders/statistics';
|
||||
import { buildInputChannel, buildInputPeer } from '../gramjsBuilders';
|
||||
import { buildInputChannel, buildInputPeer, DEFAULT_PRIMITIVES } from '../gramjsBuilders';
|
||||
import { checkErrorType, wrapError } from '../helpers/misc';
|
||||
import { invokeRequest } from './client';
|
||||
import { getPassword } from './twoFaSettings';
|
||||
@ -103,7 +103,7 @@ export async function fetchMessagePublicForwards({
|
||||
chat,
|
||||
messageId,
|
||||
dcId,
|
||||
offset,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
messageId: number;
|
||||
@ -186,7 +186,7 @@ export async function fetchStoryPublicForwards({
|
||||
chat,
|
||||
storyId,
|
||||
dcId,
|
||||
offset,
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
storyId: number;
|
||||
|
||||
@ -25,6 +25,7 @@ import {
|
||||
buildInputPeer,
|
||||
buildInputPrivacyRules,
|
||||
buildInputReaction,
|
||||
DEFAULT_PRIMITIVES,
|
||||
} from '../gramjsBuilders';
|
||||
import { addStoryToLocalDb } from '../helpers/localDb';
|
||||
import { deserializeBytes } from '../helpers/misc';
|
||||
@ -143,7 +144,8 @@ export async function fetchPeerStories({
|
||||
}
|
||||
|
||||
export function fetchPeerProfileStories({
|
||||
peer, offsetId,
|
||||
peer,
|
||||
offsetId = DEFAULT_PRIMITIVES.INT,
|
||||
}: {
|
||||
peer: ApiPeer;
|
||||
offsetId?: number;
|
||||
@ -160,7 +162,7 @@ export function fetchPeerProfileStories({
|
||||
|
||||
export function fetchStoriesArchive({
|
||||
peer,
|
||||
offsetId,
|
||||
offsetId = DEFAULT_PRIMITIVES.INT,
|
||||
}: {
|
||||
peer: ApiPeer;
|
||||
offsetId?: number;
|
||||
@ -238,7 +240,7 @@ export function toggleStoryInProfile({
|
||||
return invokeRequest(new GramJs.stories.TogglePinned({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
id: [storyId],
|
||||
pinned: isInProfile,
|
||||
pinned: Boolean(isInProfile),
|
||||
}));
|
||||
}
|
||||
|
||||
@ -260,7 +262,7 @@ export async function fetchStoryViewList({
|
||||
query,
|
||||
areReactionsFirst,
|
||||
limit = STORY_LIST_LIMIT,
|
||||
offset = '',
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
peer: ApiPeer;
|
||||
storyId: number;
|
||||
|
||||
@ -11,13 +11,20 @@ import { buildApiEmojiStatus } from '../apiBuilders/peers';
|
||||
import {
|
||||
buildStickerSet, buildStickerSetCovered, processStickerPackResult, processStickerResult,
|
||||
} from '../apiBuilders/symbols';
|
||||
import { buildInputDocument, buildInputStickerSet, buildInputStickerSetShortName } from '../gramjsBuilders';
|
||||
import {
|
||||
buildInputDocument,
|
||||
buildInputStickerSet,
|
||||
buildInputStickerSetShortName,
|
||||
DEFAULT_PRIMITIVES,
|
||||
} from '../gramjsBuilders';
|
||||
import localDb from '../localDb';
|
||||
import { sendApiUpdate } from '../updates/apiUpdateEmitter';
|
||||
import { invokeRequest } from './client';
|
||||
|
||||
export async function fetchCustomEmojiSets({ hash = '0' }: { hash?: string }) {
|
||||
const allStickers = await invokeRequest(new GramJs.messages.GetEmojiStickers({ hash: BigInt(hash) }));
|
||||
export async function fetchCustomEmojiSets({ hash }: { hash?: string }) {
|
||||
const allStickers = await invokeRequest(new GramJs.messages.GetEmojiStickers({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!allStickers || allStickers instanceof GramJs.messages.AllStickersNotModified) {
|
||||
return undefined;
|
||||
@ -35,8 +42,10 @@ export async function fetchCustomEmojiSets({ hash = '0' }: { hash?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchStickerSets({ hash = '0' }: { hash?: string }) {
|
||||
const allStickers = await invokeRequest(new GramJs.messages.GetAllStickers({ hash: BigInt(hash) }));
|
||||
export async function fetchStickerSets({ hash }: { hash?: string }) {
|
||||
const allStickers = await invokeRequest(new GramJs.messages.GetAllStickers({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!allStickers || allStickers instanceof GramJs.messages.AllStickersNotModified) {
|
||||
return undefined;
|
||||
@ -54,8 +63,10 @@ export async function fetchStickerSets({ hash = '0' }: { hash?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchRecentStickers({ hash = '0' }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetRecentStickers({ hash: BigInt(hash) }));
|
||||
export async function fetchRecentStickers({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetRecentStickers({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.RecentStickersNotModified) {
|
||||
return undefined;
|
||||
@ -67,8 +78,10 @@ export async function fetchRecentStickers({ hash = '0' }: { hash?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchFavoriteStickers({ hash = '0' }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetFavedStickers({ hash: BigInt(hash) }));
|
||||
export async function fetchFavoriteStickers({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetFavedStickers({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.FavedStickersNotModified) {
|
||||
return undefined;
|
||||
@ -80,8 +93,10 @@ export async function fetchFavoriteStickers({ hash = '0' }: { hash?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchFeaturedStickers({ hash = '0' }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetFeaturedStickers({ hash: BigInt(hash) }));
|
||||
export async function fetchFeaturedStickers({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetFeaturedStickers({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.FeaturedStickersNotModified) {
|
||||
return undefined;
|
||||
@ -120,9 +135,11 @@ export async function faveSticker({
|
||||
sticker: ApiSticker;
|
||||
unfave?: boolean;
|
||||
}) {
|
||||
const id = buildInputDocument(sticker);
|
||||
if (!id) return;
|
||||
const request = new GramJs.messages.FaveSticker({
|
||||
id: buildInputDocument(sticker),
|
||||
unfave,
|
||||
id,
|
||||
unfave: Boolean(unfave),
|
||||
});
|
||||
|
||||
const result = await invokeRequest(request);
|
||||
@ -138,8 +155,10 @@ export function removeRecentSticker({
|
||||
}: {
|
||||
sticker: ApiSticker;
|
||||
}) {
|
||||
const id = buildInputDocument(sticker);
|
||||
if (!id) return;
|
||||
const request = new GramJs.messages.SaveRecentSticker({
|
||||
id: buildInputDocument(sticker),
|
||||
id,
|
||||
unsave: true,
|
||||
});
|
||||
|
||||
@ -155,10 +174,13 @@ export async function fetchStickers(
|
||||
{ stickerSetInfo: ApiStickerSetInfo },
|
||||
) {
|
||||
if ('isMissing' in stickerSetInfo) return undefined;
|
||||
const inputStickerSet = 'id' in stickerSetInfo
|
||||
? buildInputStickerSet(stickerSetInfo.id, stickerSetInfo.accessHash)
|
||||
: buildInputStickerSetShortName(stickerSetInfo.shortName);
|
||||
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: 'id' in stickerSetInfo
|
||||
? buildInputStickerSet(stickerSetInfo.id, stickerSetInfo.accessHash)
|
||||
: buildInputStickerSetShortName(stickerSetInfo.shortName),
|
||||
stickerset: inputStickerSet,
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}), {
|
||||
shouldThrow: true,
|
||||
});
|
||||
@ -189,6 +211,7 @@ export async function fetchCustomEmoji({ documentId }: { documentId: string[] })
|
||||
export async function fetchAnimatedEmojis() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetAnimatedEmoji(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -204,6 +227,7 @@ export async function fetchAnimatedEmojis() {
|
||||
export async function fetchAnimatedEmojiEffects() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetAnimatedEmojiAnimations(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -219,6 +243,7 @@ export async function fetchAnimatedEmojiEffects() {
|
||||
export async function fetchGenericEmojiEffects() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetEmojiGenericAnimations(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -234,6 +259,7 @@ export async function fetchGenericEmojiEffects() {
|
||||
export async function fetchPremiumGifts() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetPremiumGifts(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -249,6 +275,7 @@ export async function fetchPremiumGifts() {
|
||||
export async function fetchDefaultTopicIcons() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetEmojiDefaultTopicIcons(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -264,6 +291,7 @@ export async function fetchDefaultTopicIcons() {
|
||||
export async function fetchDefaultStatusEmojis() {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickerSet({
|
||||
stickerset: new GramJs.InputStickerSetEmojiDefaultStatuses(),
|
||||
hash: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!(result instanceof GramJs.messages.StickerSet)) {
|
||||
@ -276,9 +304,9 @@ export async function fetchDefaultStatusEmojis() {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchCollectibleEmojiStatuses({ hash = '0' }: { hash?: string }) {
|
||||
export async function fetchCollectibleEmojiStatuses({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.account.GetCollectibleEmojiStatuses(
|
||||
{ hash: BigInt(hash) },
|
||||
{ hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT },
|
||||
));
|
||||
|
||||
if (!(result instanceof GramJs.account.EmojiStatuses)) {
|
||||
@ -293,10 +321,10 @@ export async function fetchCollectibleEmojiStatuses({ hash = '0' }: { hash?: str
|
||||
};
|
||||
}
|
||||
|
||||
export async function searchStickers({ query, hash = '0' }: { query: string; hash?: string }) {
|
||||
export async function searchStickers({ query, hash }: { query: string; hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.SearchStickerSets({
|
||||
q: query,
|
||||
hash: BigInt(hash),
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.FoundStickerSetsNotModified) {
|
||||
@ -309,8 +337,10 @@ export async function searchStickers({ query, hash = '0' }: { query: string; has
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchSavedGifs({ hash = '0' }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetSavedGifs({ hash: BigInt(hash) }));
|
||||
export async function fetchSavedGifs({ hash }: { hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetSavedGifs({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.SavedGifsNotModified) {
|
||||
return undefined;
|
||||
@ -323,9 +353,11 @@ export async function fetchSavedGifs({ hash = '0' }: { hash?: string }) {
|
||||
}
|
||||
|
||||
export function saveGif({ gif, shouldUnsave }: { gif: ApiVideo; shouldUnsave?: boolean }) {
|
||||
const id = buildInputDocument(gif);
|
||||
if (!id) return;
|
||||
const request = new GramJs.messages.SaveGif({
|
||||
id: buildInputDocument(gif),
|
||||
unsave: shouldUnsave,
|
||||
id,
|
||||
unsave: Boolean(shouldUnsave),
|
||||
});
|
||||
|
||||
return invokeRequest(request, { shouldReturnTrue: true });
|
||||
@ -334,6 +366,7 @@ export function saveGif({ gif, shouldUnsave }: { gif: ApiVideo; shouldUnsave?: b
|
||||
export async function installStickerSet({ stickerSetId, accessHash }: { stickerSetId: string; accessHash: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.InstallStickerSet({
|
||||
stickerset: buildInputStickerSet(stickerSetId, accessHash),
|
||||
archived: false,
|
||||
}));
|
||||
|
||||
if (result) {
|
||||
@ -363,7 +396,7 @@ let inputGifBot: GramJs.InputUser | undefined;
|
||||
|
||||
export async function searchGifs({
|
||||
query,
|
||||
offset = '',
|
||||
offset = DEFAULT_PRIMITIVES.STRING,
|
||||
username = DEFAULT_GIF_SEARCH_BOT_USERNAME,
|
||||
}: { query: string; offset?: string; username?: string }) {
|
||||
if (!inputGifBot) {
|
||||
@ -407,11 +440,11 @@ export async function searchGifs({
|
||||
}
|
||||
|
||||
export async function fetchStickersForEmoji({
|
||||
emoji, hash = '0',
|
||||
emoji, hash,
|
||||
}: { emoji: string; hash?: string }) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetStickers({
|
||||
emoticon: emoji,
|
||||
hash: BigInt(hash),
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.messages.StickersNotModified) {
|
||||
@ -424,7 +457,10 @@ export async function fetchStickersForEmoji({
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchEmojiKeywords({ language, fromVersion }: {
|
||||
export async function fetchEmojiKeywords({
|
||||
language,
|
||||
fromVersion = DEFAULT_PRIMITIVES.INT,
|
||||
}: {
|
||||
language: string;
|
||||
fromVersion?: number;
|
||||
}) {
|
||||
@ -448,8 +484,10 @@ export async function fetchEmojiKeywords({ language, fromVersion }: {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchRecentEmojiStatuses(hash = '0') {
|
||||
const result = await invokeRequest(new GramJs.account.GetRecentEmojiStatuses({ hash: BigInt(hash) }));
|
||||
export async function fetchRecentEmojiStatuses(hash?: string) {
|
||||
const result = await invokeRequest(new GramJs.account.GetRecentEmojiStatuses({
|
||||
hash: hash ? BigInt(hash) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
|
||||
if (!result || result instanceof GramJs.account.EmojiStatusesNotModified) {
|
||||
return undefined;
|
||||
|
||||
@ -14,6 +14,7 @@ import {
|
||||
buildInputPeer,
|
||||
buildInputUser,
|
||||
buildMtpPeerId,
|
||||
DEFAULT_PRIMITIVES,
|
||||
getEntityTypeById,
|
||||
} from '../gramjsBuilders';
|
||||
import { addPhotoToLocalDb, addUserToLocalDb } from '../helpers/localDb';
|
||||
@ -88,7 +89,9 @@ export async function fetchFullUser({
|
||||
export async function fetchCommonChats(user: ApiUser, maxId?: string) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetCommonChats({
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
maxId: maxId ? buildMtpPeerId(maxId, getEntityTypeById(maxId)) : undefined,
|
||||
maxId: maxId
|
||||
? buildMtpPeerId(maxId, getEntityTypeById(maxId)) : DEFAULT_PRIMITIVES.BIGINT,
|
||||
limit: DEFAULT_PRIMITIVES.INT,
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -127,6 +130,9 @@ export async function fetchNearestCountry() {
|
||||
export async function fetchTopUsers() {
|
||||
const topPeers = await invokeRequest(new GramJs.contacts.GetTopPeers({
|
||||
correspondents: true,
|
||||
offset: DEFAULT_PRIMITIVES.INT,
|
||||
limit: DEFAULT_PRIMITIVES.INT,
|
||||
hash: DEFAULT_PRIMITIVES.BIGINT,
|
||||
}));
|
||||
if (!(topPeers instanceof GramJs.contacts.TopPeers)) {
|
||||
return undefined;
|
||||
@ -173,9 +179,9 @@ export async function fetchUsers({ users }: { users: ApiUser[] }) {
|
||||
}
|
||||
|
||||
export async function importContact({
|
||||
phone,
|
||||
firstName,
|
||||
lastName,
|
||||
phone = DEFAULT_PRIMITIVES.STRING,
|
||||
firstName = DEFAULT_PRIMITIVES.STRING,
|
||||
lastName = DEFAULT_PRIMITIVES.STRING,
|
||||
}: {
|
||||
phone?: string;
|
||||
firstName?: string;
|
||||
@ -183,9 +189,9 @@ export async function importContact({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.contacts.ImportContacts({
|
||||
contacts: [buildInputContact({
|
||||
phone: phone || '',
|
||||
firstName: firstName || '',
|
||||
lastName: lastName || '',
|
||||
phone,
|
||||
firstName,
|
||||
lastName,
|
||||
})],
|
||||
}));
|
||||
|
||||
@ -199,9 +205,9 @@ export async function importContact({
|
||||
export function updateContact({
|
||||
id,
|
||||
accessHash,
|
||||
phoneNumber = '',
|
||||
firstName = '',
|
||||
lastName = '',
|
||||
phoneNumber = DEFAULT_PRIMITIVES.STRING,
|
||||
firstName = DEFAULT_PRIMITIVES.STRING,
|
||||
lastName = DEFAULT_PRIMITIVES.STRING,
|
||||
shouldSharePhoneNumber = false,
|
||||
}: {
|
||||
id: string;
|
||||
|
||||
@ -48,6 +48,7 @@ export interface ApiChat {
|
||||
isForum?: boolean;
|
||||
isForumAsMessages?: true;
|
||||
isMonoforum?: boolean;
|
||||
withForumTabs?: boolean;
|
||||
linkedMonoforumId?: string;
|
||||
areChannelMessagesAllowed?: boolean;
|
||||
boostLevel?: number;
|
||||
|
||||
@ -4,6 +4,7 @@ import type TelegramClient from './TelegramClient';
|
||||
import type { Update } from './TelegramClient';
|
||||
|
||||
import { getServerTime } from '../../../util/serverTime';
|
||||
import { DEFAULT_PRIMITIVES } from '../../../api/gramjs/gramjsBuilders';
|
||||
import { RPCError } from '../errors';
|
||||
import Api from '../tl/api';
|
||||
|
||||
@ -84,7 +85,7 @@ async function signInUserWithWebToken(
|
||||
try {
|
||||
const { apiId, apiHash } = apiCredentials;
|
||||
const sendResult = await client.invoke(new Api.auth.ImportWebTokenAuthorization({
|
||||
webAuthToken: authParams.webAuthToken,
|
||||
webAuthToken: authParams.webAuthToken!,
|
||||
apiId,
|
||||
apiHash,
|
||||
}));
|
||||
@ -208,7 +209,7 @@ async function signInUser(
|
||||
phoneNumber,
|
||||
phoneCodeHash,
|
||||
firstName,
|
||||
lastName,
|
||||
lastName: lastName || DEFAULT_PRIMITIVES.STRING,
|
||||
})) as Api.auth.Authorization;
|
||||
|
||||
if (termsOfService) {
|
||||
@ -232,6 +233,8 @@ async function signInUserWithQrCode(
|
||||
): Promise<Api.TypeUser> {
|
||||
let isScanningComplete = false;
|
||||
|
||||
const { apiId, apiHash } = apiCredentials;
|
||||
|
||||
const inputPromise = (async () => {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (1) {
|
||||
@ -240,8 +243,8 @@ async function signInUserWithQrCode(
|
||||
}
|
||||
|
||||
const result = await client.invoke(new Api.auth.ExportLoginToken({
|
||||
apiId: Number(process.env.TELEGRAM_API_ID),
|
||||
apiHash: process.env.TELEGRAM_API_HASH,
|
||||
apiId,
|
||||
apiHash,
|
||||
exceptIds: authParams.accountIds?.map((id) => bigInt(id)) || [],
|
||||
}));
|
||||
if (!(result instanceof Api.auth.LoginToken)) {
|
||||
@ -281,8 +284,8 @@ async function signInUserWithQrCode(
|
||||
|
||||
try {
|
||||
const result2 = await client.invoke(new Api.auth.ExportLoginToken({
|
||||
apiId: Number(process.env.TELEGRAM_API_ID),
|
||||
apiHash: process.env.TELEGRAM_API_HASH,
|
||||
apiId,
|
||||
apiHash,
|
||||
exceptIds: authParams.accountIds?.map((id) => bigInt(id)) || [],
|
||||
}));
|
||||
|
||||
|
||||
2614
src/lib/gramjs/tl/api.d.ts
vendored
2614
src/lib/gramjs/tl/api.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -88,12 +88,12 @@ ${indent}}`.trim();
|
||||
const hasRequiredArgs = argKeys.some((argName) => !isFlagArg(argName) && !argsConfig[argName].isFlag);
|
||||
|
||||
return `
|
||||
export class ${upperFirst(name)} extends Request<Partial<{
|
||||
export class ${upperFirst(name)} extends Request<{
|
||||
${indent} ${argKeys.map((argName) => `
|
||||
${renderArg(argName, argsConfig[argName])};
|
||||
`.trim())
|
||||
.join(`\n${indent} `)}
|
||||
${indent}}${!hasRequiredArgs ? ' | void' : ''}>, ${renderedResult}> {
|
||||
${indent}}${!hasRequiredArgs ? ' | void' : ''}, ${renderedResult}> {
|
||||
${indent} ${argKeys.map((argName) => `
|
||||
${renderArg(argName, argsConfig[argName])};
|
||||
`.trim())
|
||||
@ -200,7 +200,7 @@ namespace Api {
|
||||
constructor(args: Args);
|
||||
}
|
||||
|
||||
class Request<Args, Response> extends VirtualClass<Partial<Args>> {
|
||||
class Request<Args, Response> extends VirtualClass<Args> {
|
||||
static readResult(reader: Reader): Buffer;
|
||||
|
||||
__response: Response;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user