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