GramJS: Fix incorrect TS typings (#5855)
This commit is contained in:
parent
a72abc5cbc
commit
a63d4b7687
@ -1,5 +1,6 @@
|
||||
import type BigInt from 'big-integer';
|
||||
import { Api as GramJs } from '../../../lib/gramjs';
|
||||
import type { Entity } from '../../../lib/gramjs/types';
|
||||
|
||||
import type {
|
||||
ApiBotCommand,
|
||||
@ -49,7 +50,7 @@ type PeerEntityApiChatFields = Omit<ApiChat, (
|
||||
)>;
|
||||
|
||||
function buildApiChatFieldsFromPeerEntity(
|
||||
peerEntity: GramJs.TypeUser | GramJs.TypeChat,
|
||||
peerEntity: Entity,
|
||||
isSupport = false,
|
||||
): PeerEntityApiChatFields {
|
||||
const isMin = Boolean('min' in peerEntity && peerEntity.min);
|
||||
@ -225,7 +226,7 @@ function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat)
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
function buildApiChatMigrationInfo(peerEntity: GramJs.TypeChat): {
|
||||
function buildApiChatMigrationInfo(peerEntity: Entity): {
|
||||
migratedTo?: {
|
||||
chatId: string;
|
||||
accessHash?: string;
|
||||
@ -305,7 +306,7 @@ export function getPeerKey(peer: GramJs.TypePeer) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getApiChatTitleFromMtpPeer(peer: GramJs.TypePeer, peerEntity: GramJs.User | GramJs.Chat) {
|
||||
export function getApiChatTitleFromMtpPeer(peer: GramJs.TypePeer, peerEntity: Entity) {
|
||||
if (isMtpPeerUser(peer)) {
|
||||
return getUserName(peerEntity as GramJs.User);
|
||||
} else {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Api as GramJs } from '../../../lib/gramjs';
|
||||
import type { Entity } from '../../../lib/gramjs/types';
|
||||
import { strippedPhotoToJpg } from '../../../lib/gramjs/Utils';
|
||||
|
||||
import type {
|
||||
@ -68,7 +69,7 @@ export function buildApiThumbnailFromCached(photoSize: GramJs.PhotoCachedSize):
|
||||
|
||||
export function buildApiThumbnailFromPath(
|
||||
photoSize: GramJs.PhotoPathSize,
|
||||
sizeAttribute: GramJs.DocumentAttributeImageSize | GramJs.DocumentAttributeVideo,
|
||||
sizeAttribute: GramJs.DocumentAttributeImageSize | GramJs.DocumentAttributeVideo | GramJs.PhotoSize,
|
||||
): ApiThumbnail | undefined {
|
||||
const { w, h } = sizeAttribute;
|
||||
const dataUri = `data:image/svg+xml;utf8,${pathBytesToSvg(photoSize.bytes, w, h)}`;
|
||||
@ -130,8 +131,8 @@ export function buildApiPhotoSize(photoSize: GramJs.PhotoSize): ApiPhotoSize {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildApiUsernames(mtpPeer: GramJs.User | GramJs.Channel | GramJs.UpdateUserName) {
|
||||
if (!mtpPeer.usernames && !('username' in mtpPeer && mtpPeer.username)) {
|
||||
export function buildApiUsernames(mtpPeer: Entity | GramJs.UpdateUserName) {
|
||||
if (!('usernames' in mtpPeer && mtpPeer.usernames) && !('username' in mtpPeer && mtpPeer.username)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,7 @@ import {
|
||||
buildApiFormattedText,
|
||||
buildApiPhoto,
|
||||
} from './common';
|
||||
import { type OmitVirtualFields } from './helpers';
|
||||
import { buildApiMessageAction } from './messageActions';
|
||||
import { buildMessageContent, buildMessageMediaContent, buildMessageTextContent } from './messageContent';
|
||||
import { buildApiPeerColor, buildApiPeerId, getApiChatIdFromMtpPeer } from './peers';
|
||||
@ -168,9 +169,10 @@ export function buildApiMessageFromNotification(
|
||||
};
|
||||
}
|
||||
|
||||
type TypeMessageWithContent = OmitVirtualFields<GramJs.Message> & OmitVirtualFields<GramJs.MessageService>;
|
||||
export type UniversalMessage = (
|
||||
Pick<GramJs.Message & GramJs.MessageService, ('id' | 'date' | 'peerId')>
|
||||
& Partial<GramJs.Message & GramJs.MessageService>
|
||||
Pick<TypeMessageWithContent, ('id' | 'date' | 'peerId')>
|
||||
& Partial<TypeMessageWithContent>
|
||||
);
|
||||
|
||||
export function buildApiMessageWithChatId(
|
||||
|
||||
@ -6,15 +6,17 @@ import type { ApiEmojiStatusType, ApiPeerColor } from '../../types';
|
||||
import { CHANNEL_ID_LENGTH } from '../../../config';
|
||||
import { numberToHexColor } from '../../../util/colors';
|
||||
|
||||
export function isMtpPeerUser(peer: GramJs.TypePeer | GramJs.TypeInputPeer): peer is GramJs.PeerUser {
|
||||
type TypePeerOrInput = GramJs.TypePeer | GramJs.TypeInputPeer | GramJs.TypeInputUser | GramJs.TypeInputChannel;
|
||||
|
||||
export function isMtpPeerUser(peer: TypePeerOrInput): peer is GramJs.PeerUser {
|
||||
return peer.hasOwnProperty('userId');
|
||||
}
|
||||
|
||||
export function isMtpPeerChat(peer: GramJs.TypePeer | GramJs.TypeInputPeer): peer is GramJs.PeerChat {
|
||||
export function isMtpPeerChat(peer: TypePeerOrInput): peer is GramJs.PeerChat {
|
||||
return peer.hasOwnProperty('chatId');
|
||||
}
|
||||
|
||||
export function isMtpPeerChannel(peer: GramJs.TypePeer | GramJs.TypeInputPeer): peer is GramJs.PeerChannel {
|
||||
export function isMtpPeerChannel(peer: TypePeerOrInput): peer is GramJs.PeerChannel {
|
||||
return peer.hasOwnProperty('channelId');
|
||||
}
|
||||
|
||||
@ -33,7 +35,7 @@ export function buildApiPeerId(id: BigInt.BigInteger, type: 'user' | 'chat' | 'c
|
||||
return `-${id}`;
|
||||
}
|
||||
|
||||
export function getApiChatIdFromMtpPeer(peer: GramJs.TypePeer | GramJs.TypeInputPeer) {
|
||||
export function getApiChatIdFromMtpPeer(peer: TypePeerOrInput) {
|
||||
if (isMtpPeerUser(peer)) {
|
||||
return buildApiPeerId(peer.userId, 'user');
|
||||
} else if (isMtpPeerChat(peer)) {
|
||||
|
||||
@ -112,7 +112,7 @@ export function buildGroupStatistics(stats: GramJs.stats.MegagroupStats): ApiGro
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPostsStatistics(stats: GramJs.stats.MessageStats): ApiPostStatistics {
|
||||
export function buildPostsStatistics(stats: GramJs.stats.MessageStats | GramJs.stats.StoryStats): ApiPostStatistics {
|
||||
return {
|
||||
viewsGraph: buildGraph(stats.viewsGraph),
|
||||
reactionsGraph: buildGraph(stats.reactionsByEmotionGraph),
|
||||
@ -120,13 +120,16 @@ export function buildPostsStatistics(stats: GramJs.stats.MessageStats): ApiPostS
|
||||
}
|
||||
|
||||
export function buildMessagePublicForwards(
|
||||
result: GramJs.messages.TypeMessages,
|
||||
result: GramJs.stats.PublicForwards,
|
||||
): ApiMessagePublicForward[] | undefined {
|
||||
if (!result || !('messages' in result)) {
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return result.messages.map((message) => buildApiMessagePublicForward(message, result.chats));
|
||||
return result.forwards.map((forward) => {
|
||||
if (forward instanceof GramJs.PublicForwardStory) return undefined;
|
||||
return buildApiMessagePublicForward(forward.message, result.chats);
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
export function buildStoryPublicForwards(
|
||||
@ -243,7 +246,7 @@ function getOverviewPeriod(data: GramJs.StatsDateRangeDays): StatisticsOverviewP
|
||||
function buildApiMessagePublicForward(message: GramJs.TypeMessage, chats: GramJs.TypeChat[]): ApiMessagePublicForward {
|
||||
const peerId = getApiChatIdFromMtpPeer(message.peerId!);
|
||||
const channel = chats.find((c) => buildApiPeerId(c.id, 'channel') === peerId);
|
||||
const channelProfilePhoto = channel && 'photo' in channel && channel.photo instanceof GramJs.Photo
|
||||
const channelProfilePhoto = channel && 'photo' in channel && channel.photo instanceof GramJs.ChatPhoto
|
||||
? channel.photo : undefined;
|
||||
|
||||
return {
|
||||
@ -256,7 +259,7 @@ function buildApiMessagePublicForward(message: GramJs.TypeMessage, chats: GramJs
|
||||
title: (channel as GramJs.Channel).title,
|
||||
usernames: buildApiUsernames(channel as GramJs.Channel),
|
||||
avatarPhotoId: channelProfilePhoto && buildAvatarPhotoId(channelProfilePhoto),
|
||||
hasVideoAvatar: Boolean(channelProfilePhoto?.videoSizes),
|
||||
hasVideoAvatar: Boolean(channelProfilePhoto?.hasVideo),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -94,7 +94,33 @@ export function buildInputPeer(chatOrUserId: string, accessHash?: string): GramJ
|
||||
}
|
||||
}
|
||||
|
||||
export function buildInputPaidReactionPrivacy(isPrivate?: boolean, peerId?: string): GramJs.TypeInputPeer {
|
||||
export function buildInputUser(userId: string, accessHash?: string): GramJs.TypeInputUser {
|
||||
if (!accessHash) {
|
||||
return new GramJs.InputUserEmpty();
|
||||
}
|
||||
|
||||
return new GramJs.InputUser({
|
||||
userId: buildMtpPeerId(userId, 'user'),
|
||||
accessHash: BigInt(accessHash),
|
||||
});
|
||||
}
|
||||
|
||||
export function buildInputChannel(channelId: string, accessHash?: string): GramJs.TypeInputChannel {
|
||||
if (!accessHash) {
|
||||
return new GramJs.InputChannelEmpty();
|
||||
}
|
||||
|
||||
return new GramJs.InputChannel({
|
||||
channelId: buildMtpPeerId(channelId, 'channel'),
|
||||
accessHash: BigInt(accessHash),
|
||||
});
|
||||
}
|
||||
|
||||
export function buildInputChat(chatId: string) {
|
||||
return BigInt(chatId);
|
||||
}
|
||||
|
||||
export function buildInputPaidReactionPrivacy(isPrivate?: boolean, peerId?: string): GramJs.TypePaidReactionPrivacy {
|
||||
if (isPrivate) return new GramJs.PaidReactionPrivacyAnonymous();
|
||||
if (peerId) {
|
||||
const peer = buildInputPeerFromLocalDb(peerId);
|
||||
@ -126,22 +152,14 @@ export function buildInputPeerFromLocalDb(chatOrUserId: string): GramJs.TypeInpu
|
||||
return buildInputPeer(chatOrUserId, String(accessHash));
|
||||
}
|
||||
|
||||
export function buildInputEntity(chatOrUserId: string, accessHash?: string) {
|
||||
const type = getEntityTypeById(chatOrUserId);
|
||||
export function buildInputChannelFromLocalDb(channelId: string): GramJs.TypeInputChannel | undefined {
|
||||
const channel = localDb.chats[channelId];
|
||||
|
||||
if (type === 'user') {
|
||||
return new GramJs.InputUser({
|
||||
userId: buildMtpPeerId(chatOrUserId, 'user'),
|
||||
accessHash: BigInt(accessHash!),
|
||||
});
|
||||
} else if (type === 'channel') {
|
||||
return new GramJs.InputChannel({
|
||||
channelId: buildMtpPeerId(chatOrUserId, 'channel'),
|
||||
accessHash: BigInt(accessHash!),
|
||||
});
|
||||
} else {
|
||||
return buildMtpPeerId(chatOrUserId, 'chat');
|
||||
if (!channel || !(channel instanceof GramJs.Channel)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return buildInputChannel(channelId, String(channel.accessHash));
|
||||
}
|
||||
|
||||
export function buildInputStickerSet(id: string, accessHash: string) {
|
||||
@ -584,7 +602,7 @@ GramJs.TypeInputStorePaymentPurpose {
|
||||
|
||||
if (purpose.type === 'starsgift') {
|
||||
return new GramJs.InputStorePaymentStarsGift({
|
||||
userId: buildInputEntity(purpose.user.id, purpose.user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(purpose.user.id, purpose.user.accessHash),
|
||||
stars: BigInt(purpose.stars),
|
||||
currency: purpose.currency,
|
||||
amount: BigInt(purpose.amount),
|
||||
@ -593,7 +611,7 @@ GramJs.TypeInputStorePaymentPurpose {
|
||||
|
||||
if (purpose.type === 'giftcode') {
|
||||
return new GramJs.InputStorePaymentPremiumGiftCode({
|
||||
users: purpose.users.map((user) => buildInputEntity(user.id, user.accessHash) as GramJs.InputUser),
|
||||
users: purpose.users.map((user) => buildInputUser(user.id, user.accessHash)),
|
||||
boostPeer: purpose.boostChannel
|
||||
? buildInputPeer(purpose.boostChannel.id, purpose.boostChannel.accessHash)
|
||||
: undefined,
|
||||
@ -695,7 +713,7 @@ export function buildInputInvoice(invoice: ApiRequestInputInvoice) {
|
||||
} = invoice;
|
||||
return new GramJs.InputInvoicePremiumGiftStars({
|
||||
months,
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
message: message && buildInputTextWithEntities(message),
|
||||
});
|
||||
}
|
||||
@ -837,7 +855,7 @@ export function buildInputPrivacyRules(
|
||||
|
||||
if (rules.allowedUsers?.length) {
|
||||
privacyRules.push(new GramJs.InputPrivacyValueAllowUsers({
|
||||
users: rules.allowedUsers.map(({ id, accessHash }) => buildInputEntity(id, accessHash) as GramJs.InputUser),
|
||||
users: rules.allowedUsers.map(({ id, accessHash }) => buildInputUser(id, accessHash)),
|
||||
}));
|
||||
}
|
||||
if (rules.allowedChats?.length) {
|
||||
@ -849,7 +867,7 @@ export function buildInputPrivacyRules(
|
||||
}
|
||||
if (rules.blockedUsers?.length) {
|
||||
privacyRules.push(new GramJs.InputPrivacyValueDisallowUsers({
|
||||
users: rules.blockedUsers.map(({ id, accessHash }) => buildInputEntity(id, accessHash) as GramJs.InputUser),
|
||||
users: rules.blockedUsers.map(({ id, accessHash }) => buildInputUser(id, accessHash)),
|
||||
}));
|
||||
}
|
||||
if (rules.blockedChats?.length) {
|
||||
|
||||
@ -157,7 +157,8 @@ export function addChatToLocalDb(chat: GramJs.Chat | GramJs.Channel) {
|
||||
localDb.chats[id] = chat;
|
||||
}
|
||||
|
||||
export function addUserToLocalDb(user: GramJs.User) {
|
||||
export function addUserToLocalDb(user: GramJs.TypeUser) {
|
||||
if (user instanceof GramJs.UserEmpty) return;
|
||||
const id = buildApiPeerId(user.id, 'user');
|
||||
const storedUser = localDb.users[id];
|
||||
|
||||
|
||||
@ -28,10 +28,10 @@ import { buildApiUrlAuthResult } from '../apiBuilders/misc';
|
||||
import { buildApiUser } from '../apiBuilders/users';
|
||||
import {
|
||||
buildInputBotApp,
|
||||
buildInputEntity,
|
||||
buildInputPeer,
|
||||
buildInputReplyTo,
|
||||
buildInputThemeParams,
|
||||
buildInputUser,
|
||||
generateRandomBigInt,
|
||||
} from '../gramjsBuilders';
|
||||
import {
|
||||
@ -121,7 +121,7 @@ export async function fetchInlineBotResults({
|
||||
bot: ApiUser; chat: ApiChat; query: string; offset?: string;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetInlineBotResults({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
query,
|
||||
offset,
|
||||
@ -179,7 +179,7 @@ export async function startBot({
|
||||
const randomId = generateRandomBigInt();
|
||||
|
||||
await invokeRequest(new GramJs.messages.StartBot({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
peer: buildInputPeer(bot.id, bot.accessHash),
|
||||
randomId,
|
||||
startParam,
|
||||
@ -212,7 +212,7 @@ export async function requestWebView({
|
||||
const result = await invokeRequest(new GramJs.messages.RequestWebView({
|
||||
silent: isSilent || undefined,
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
url,
|
||||
startParam,
|
||||
themeParams: theme ? buildInputThemeParams(theme) : undefined,
|
||||
@ -249,7 +249,7 @@ export async function requestMainWebView({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.RequestMainWebView({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
startParam,
|
||||
fullscreen: mode === 'fullscreen' || undefined,
|
||||
themeParams: theme ? buildInputThemeParams(theme) : undefined,
|
||||
@ -284,7 +284,7 @@ export async function requestSimpleWebView({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.RequestSimpleWebView({
|
||||
url,
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
themeParams: theme ? buildInputThemeParams(theme) : undefined,
|
||||
platform: WEB_APP_PLATFORM,
|
||||
startParam,
|
||||
@ -304,7 +304,7 @@ export async function fetchBotApp({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetBotApp({
|
||||
app: new GramJs.InputBotAppShortName({
|
||||
botId: buildInputEntity(bot.id, bot.accessHash) as GramJs.InputUser,
|
||||
botId: buildInputUser(bot.id, bot.accessHash),
|
||||
shortName: appName,
|
||||
}),
|
||||
}));
|
||||
@ -362,7 +362,7 @@ export function prolongWebView({
|
||||
return invokeRequest(new GramJs.messages.ProlongWebView({
|
||||
silent: isSilent || undefined,
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
queryId: BigInt(queryId),
|
||||
replyTo: replyInfo && buildInputReplyTo(replyInfo),
|
||||
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
|
||||
@ -378,7 +378,7 @@ export async function sendWebViewData({
|
||||
}) {
|
||||
const randomId = generateRandomBigInt();
|
||||
await invokeRequest(new GramJs.messages.SendWebViewData({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
buttonText,
|
||||
data,
|
||||
randomId,
|
||||
@ -409,7 +409,7 @@ export async function loadAttachBot({
|
||||
bot: ApiUser;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetAttachMenuBot({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
}));
|
||||
|
||||
if (result instanceof GramJs.AttachMenuBotsBot) {
|
||||
@ -430,7 +430,7 @@ export function toggleAttachBot({
|
||||
isEnabled: boolean;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.ToggleBotInAttachMenu({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
writeAllowed: isWriteAllowed || undefined,
|
||||
enabled: isEnabled,
|
||||
}));
|
||||
@ -532,13 +532,13 @@ export async function acceptLinkUrlAuth({ url, isWriteAllowed }: { url: string;
|
||||
|
||||
export function fetchBotCanSendMessage({ bot } : { bot: ApiUser }) {
|
||||
return invokeRequest(new GramJs.bots.CanSendMessage({
|
||||
bot: buildInputEntity(bot.id, bot.accessHash) as GramJs.InputUser,
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
}));
|
||||
}
|
||||
|
||||
export function allowBotSendMessages({ bot } : { bot: ApiUser }) {
|
||||
return invokeRequest(new GramJs.bots.AllowSendMessage({
|
||||
bot: buildInputEntity(bot.id, bot.accessHash) as GramJs.InputUser,
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -559,7 +559,7 @@ export async function invokeWebViewCustomMethod({
|
||||
}> {
|
||||
try {
|
||||
const result = await invokeRequest(new GramJs.bots.InvokeWebViewCustomMethod({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
params: new GramJs.DataJSON({
|
||||
data: parameters,
|
||||
}),
|
||||
@ -581,7 +581,7 @@ export async function invokeWebViewCustomMethod({
|
||||
|
||||
export async function fetchPreviewMedias({ bot } : { bot: ApiUser }) {
|
||||
const result = await invokeRequest(new GramJs.bots.GetPreviewMedias({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
}));
|
||||
|
||||
if (!result) return undefined;
|
||||
@ -605,7 +605,7 @@ export function checkBotDownloadFileParams({
|
||||
url: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.bots.CheckDownloadFileParams({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
fileName,
|
||||
url,
|
||||
}), {
|
||||
@ -615,7 +615,7 @@ export function checkBotDownloadFileParams({
|
||||
|
||||
export function toggleUserEmojiStatusPermission({ bot, isEnabled } : { bot: ApiUser; isEnabled: boolean }) {
|
||||
return invokeRequest(new GramJs.bots.ToggleUserEmojiStatusPermission({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -662,7 +662,7 @@ export function setBotInfo({
|
||||
description?: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.bots.SetBotInfo({
|
||||
bot: buildInputPeer(bot.id, bot.accessHash),
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
langCode,
|
||||
name: name || '',
|
||||
about: about || '',
|
||||
@ -698,7 +698,7 @@ export async function fetchPopularAppBots({
|
||||
|
||||
export async function fetchBotsRecommendations({ user }: { user: ApiChat }) {
|
||||
if (!user) return undefined;
|
||||
const inputUser = buildInputEntity(user.id, user.accessHash) as GramJs.InputUser;
|
||||
const inputUser = buildInputUser(user.id, user.accessHash);
|
||||
const result = await invokeRequest(new GramJs.bots.GetBotRecommendations({
|
||||
bot: inputUser,
|
||||
}));
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
buildPhoneCall,
|
||||
} from '../apiBuilders/calls';
|
||||
import {
|
||||
buildInputGroupCall, buildInputPeer, buildInputPhoneCall, generateRandomInt,
|
||||
buildInputGroupCall, buildInputPeer, buildInputPhoneCall, buildInputUser, generateRandomInt,
|
||||
} from '../gramjsBuilders';
|
||||
import { sendApiUpdate } from '../updates/apiUpdateEmitter';
|
||||
import { invokeRequest, invokeRequestBeacon } from './client';
|
||||
@ -277,7 +277,7 @@ export async function requestCall({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.phone.RequestCall({
|
||||
randomId: generateRandomInt(),
|
||||
userId: buildInputPeer(user.id, user.accessHash),
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
gAHash: Buffer.from(gAHash),
|
||||
...(isVideo && { video: true }),
|
||||
protocol: buildCallProtocol(),
|
||||
|
||||
@ -61,13 +61,16 @@ import {
|
||||
buildChatAdminRights,
|
||||
buildChatBannedRights,
|
||||
buildFilterFromApiFolder,
|
||||
buildInputChannel,
|
||||
buildInputChat,
|
||||
buildInputChatReactions,
|
||||
buildInputEntity,
|
||||
buildInputPeer,
|
||||
buildInputPhoto,
|
||||
buildInputReplyTo,
|
||||
buildInputUser,
|
||||
buildMtpMessageEntity,
|
||||
generateRandomBigInt,
|
||||
getEntityTypeById,
|
||||
} from '../gramjsBuilders';
|
||||
import {
|
||||
addPhotoToLocalDb,
|
||||
@ -345,11 +348,11 @@ export async function fetchSavedChats({
|
||||
}
|
||||
|
||||
export function fetchFullChat(chat: ApiChat) {
|
||||
const { id, accessHash } = chat;
|
||||
const { id } = chat;
|
||||
|
||||
const input = buildInputEntity(id, accessHash);
|
||||
const type = getEntityTypeById(chat.id);
|
||||
|
||||
return input instanceof GramJs.InputChannel
|
||||
return type === 'channel'
|
||||
? getFullChannelInfo(chat)
|
||||
: getFullChatInfo(id);
|
||||
}
|
||||
@ -393,13 +396,13 @@ export async function fetchChat({
|
||||
}: {
|
||||
type: 'user' | 'self' | 'support'; user?: ApiUser;
|
||||
}) {
|
||||
let mtpUser: GramJs.User | undefined;
|
||||
let mtpUser: GramJs.TypeUser | undefined;
|
||||
|
||||
if (type === 'self' || type === 'user') {
|
||||
const result = await invokeRequest(new GramJs.users.GetUsers({
|
||||
id: [
|
||||
type === 'user' && user
|
||||
? buildInputEntity(user.id, user.accessHash) as GramJs.InputUser
|
||||
? buildInputUser(user.id, user.accessHash)
|
||||
: new GramJs.InputUserSelf(),
|
||||
],
|
||||
}));
|
||||
@ -507,7 +510,7 @@ export function saveDraft({
|
||||
|
||||
async function getFullChatInfo(chatId: string): Promise<FullChatData | undefined> {
|
||||
const result = await invokeRequest(new GramJs.messages.GetFullChat({
|
||||
chatId: buildInputEntity(chatId) as BigInt.BigInteger,
|
||||
chatId: buildInputChat(chatId),
|
||||
}));
|
||||
|
||||
if (!result || !(result.fullChat instanceof GramJs.ChatFull)) {
|
||||
@ -580,7 +583,7 @@ async function getFullChannelInfo(
|
||||
const { id, adminRights } = chat;
|
||||
const accessHash = chat.accessHash!;
|
||||
const result = await invokeRequest(new GramJs.channels.GetFullChannel({
|
||||
channel: buildInputEntity(id, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
}));
|
||||
|
||||
if (!result || !(result.fullChat instanceof GramJs.ChannelFull)) {
|
||||
@ -832,8 +835,8 @@ export async function createChannel({
|
||||
|
||||
if (users?.length) {
|
||||
const invitedUsers = await invokeRequest(new GramJs.channels.InviteToChannel({
|
||||
channel: buildInputEntity(channel.id, channel.accessHash) as GramJs.InputChannel,
|
||||
users: users.map(({ id, accessHash }) => buildInputEntity(id, accessHash)) as GramJs.InputUser[],
|
||||
channel: buildInputChannel(channel.id, channel.accessHash),
|
||||
users: users.map(({ id, accessHash }) => buildInputUser(id, accessHash)),
|
||||
}));
|
||||
if (!invitedUsers) return undefined;
|
||||
|
||||
@ -850,7 +853,7 @@ export function joinChannel({
|
||||
channelId: string; accessHash: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.JoinChannel({
|
||||
channel: buildInputEntity(channelId, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(channelId, accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
shouldThrow: true,
|
||||
@ -864,8 +867,8 @@ export function deleteChatUser({
|
||||
}) {
|
||||
if (chat.type !== 'chatTypeBasicGroup') return undefined;
|
||||
return invokeRequest(new GramJs.messages.DeleteChatUser({
|
||||
chatId: buildInputEntity(chat.id, chat.accessHash) as BigInt.BigInteger,
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
chatId: buildInputChat(chat.id),
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
revokeHistory: shouldRevokeHistory || undefined,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -878,7 +881,7 @@ export function deleteChat({
|
||||
chatId: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.DeleteChat({
|
||||
chatId: buildInputEntity(chatId) as BigInt.BigInteger,
|
||||
chatId: buildInputChat(chatId),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -890,7 +893,7 @@ export function leaveChannel({
|
||||
channelId: string; accessHash: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.LeaveChannel({
|
||||
channel: buildInputEntity(channelId, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(channelId, accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -902,7 +905,7 @@ export function deleteChannel({
|
||||
channelId: string; accessHash: string;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.DeleteChannel({
|
||||
channel: buildInputEntity(channelId, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(channelId, accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -915,7 +918,7 @@ export async function createGroupChat({
|
||||
}) {
|
||||
const invitedUsers = await invokeRequest(new GramJs.messages.CreateChat({
|
||||
title,
|
||||
users: users.map(({ id, accessHash }) => buildInputEntity(id, accessHash)) as GramJs.InputUser[],
|
||||
users: users.map(({ id, accessHash }) => buildInputUser(id, accessHash)),
|
||||
}));
|
||||
if (!invitedUsers) return undefined;
|
||||
|
||||
@ -939,7 +942,7 @@ export async function editChatPhoto({
|
||||
}: {
|
||||
chatId: string; accessHash?: string; photo?: File | ApiPhoto;
|
||||
}) {
|
||||
const inputEntity = buildInputEntity(chatId, accessHash);
|
||||
const chatType = getEntityTypeById(chatId);
|
||||
let inputPhoto: GramJs.TypeInputChatPhoto;
|
||||
if (photo instanceof File) {
|
||||
const uploadedPhoto = await uploadFile(photo);
|
||||
@ -956,13 +959,13 @@ export async function editChatPhoto({
|
||||
inputPhoto = new GramJs.InputChatPhotoEmpty();
|
||||
}
|
||||
return invokeRequest(
|
||||
inputEntity instanceof GramJs.InputChannel
|
||||
chatType === 'channel'
|
||||
? new GramJs.channels.EditPhoto({
|
||||
channel: inputEntity as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chatId, accessHash!),
|
||||
photo: inputPhoto,
|
||||
})
|
||||
: new GramJs.messages.EditChatPhoto({
|
||||
chatId: inputEntity as BigInt.BigInteger,
|
||||
chatId: buildInputChat(chatId),
|
||||
photo: inputPhoto,
|
||||
}),
|
||||
{
|
||||
@ -1191,10 +1194,10 @@ export function togglePreHistoryHidden({
|
||||
chat, isEnabled,
|
||||
}: { chat: ApiChat; isEnabled: boolean }) {
|
||||
const { id, accessHash } = chat;
|
||||
const channel = buildInputEntity(id, accessHash);
|
||||
const channel = buildInputChannel(id, accessHash);
|
||||
|
||||
return invokeRequest(new GramJs.channels.TogglePreHistoryHidden({
|
||||
channel: channel as GramJs.InputChannel,
|
||||
channel,
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -1218,8 +1221,8 @@ export function updateChatDefaultBannedRights({
|
||||
export function updateChatMemberBannedRights({
|
||||
chat, user, bannedRights, untilDate,
|
||||
}: { chat: ApiChat; user: ApiUser; bannedRights: ApiChatBannedRights; untilDate?: number }) {
|
||||
const channel = buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel;
|
||||
const participant = buildInputPeer(user.id, user.accessHash) as GramJs.InputUser;
|
||||
const channel = buildInputChannel(chat.id, chat.accessHash);
|
||||
const participant = buildInputPeer(user.id, user.accessHash);
|
||||
|
||||
return invokeRequest(new GramJs.channels.EditBanned({
|
||||
channel,
|
||||
@ -1233,8 +1236,8 @@ export function updateChatMemberBannedRights({
|
||||
export function updateChatAdmin({
|
||||
chat, user, adminRights, customTitle = '',
|
||||
}: { chat: ApiChat; user: ApiUser; adminRights: ApiChatAdminRights; customTitle?: string }) {
|
||||
const channel = buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel;
|
||||
const userId = buildInputEntity(user.id, user.accessHash) as GramJs.InputUser;
|
||||
const channel = buildInputChannel(chat.id, chat.accessHash);
|
||||
const userId = buildInputUser(user.id, user.accessHash);
|
||||
|
||||
return invokeRequest(new GramJs.channels.EditAdmin({
|
||||
channel,
|
||||
@ -1247,14 +1250,14 @@ export function updateChatAdmin({
|
||||
}
|
||||
|
||||
export async function updateChatTitle(chat: ApiChat, title: string) {
|
||||
const inputEntity = buildInputEntity(chat.id, chat.accessHash);
|
||||
const type = getEntityTypeById(chat.id);
|
||||
await invokeRequest(
|
||||
inputEntity instanceof GramJs.InputChannel
|
||||
type === 'channel'
|
||||
? new GramJs.channels.EditTitle({
|
||||
channel: inputEntity as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
title,
|
||||
}) : new GramJs.messages.EditChatTitle({
|
||||
chatId: inputEntity as BigInt.BigInteger,
|
||||
chatId: buildInputChat(chat.id),
|
||||
title,
|
||||
}),
|
||||
{
|
||||
@ -1290,10 +1293,10 @@ export function toggleSignatures({
|
||||
areProfilesEnabled: boolean;
|
||||
}) {
|
||||
const { id, accessHash } = chat;
|
||||
const channel = buildInputEntity(id, accessHash);
|
||||
const channel = buildInputChannel(id, accessHash);
|
||||
|
||||
return invokeRequest(new GramJs.channels.ToggleSignatures({
|
||||
channel: channel as GramJs.InputChannel,
|
||||
channel,
|
||||
signaturesEnabled: areSignaturesEnabled || undefined,
|
||||
profilesEnabled: areProfilesEnabled || undefined,
|
||||
}), {
|
||||
@ -1336,7 +1339,7 @@ export async function fetchMembers({
|
||||
}
|
||||
|
||||
const result = await invokeRequest(new GramJs.channels.GetParticipants({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
filter,
|
||||
offset,
|
||||
limit: MEMBERS_LOAD_SLICE,
|
||||
@ -1366,7 +1369,7 @@ export async function fetchMember({
|
||||
const participant = peer ? buildInputPeer(peer.id, peer.accessHash) : new GramJs.InputPeerSelf();
|
||||
|
||||
const result = await invokeRequest(new GramJs.channels.GetParticipant({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
participant,
|
||||
}), {
|
||||
abortControllerChatId: chat.id,
|
||||
@ -1407,8 +1410,8 @@ export function setDiscussionGroup({
|
||||
chat?: ApiChat;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.SetDiscussionGroup({
|
||||
broadcast: buildInputPeer(channel.id, channel.accessHash),
|
||||
group: chat ? buildInputPeer(chat.id, chat.accessHash) : new GramJs.InputChannelEmpty(),
|
||||
broadcast: buildInputChannel(channel.id, channel.accessHash),
|
||||
group: chat ? buildInputChannel(chat.id, chat.accessHash) : new GramJs.InputChannelEmpty(),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -1416,7 +1419,7 @@ export function setDiscussionGroup({
|
||||
|
||||
export async function migrateChat(chat: ApiChat) {
|
||||
const result = await invokeRequest(
|
||||
new GramJs.messages.MigrateChat({ chatId: buildInputEntity(chat.id) as BigInt.BigInteger }),
|
||||
new GramJs.messages.MigrateChat({ chatId: buildInputChat(chat.id) }),
|
||||
{
|
||||
shouldThrow: true,
|
||||
},
|
||||
@ -1471,8 +1474,8 @@ export async function addChatMembers(chat: ApiChat, users: ApiUser[]) {
|
||||
try {
|
||||
if (chat.type === 'chatTypeChannel' || chat.type === 'chatTypeSuperGroup') {
|
||||
const invitedUsers = await invokeRequest(new GramJs.channels.InviteToChannel({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
users: users.map((user) => buildInputEntity(user.id, user.accessHash)) as GramJs.InputUser[],
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
users: users.map((user) => buildInputUser(user.id, user.accessHash)),
|
||||
}));
|
||||
if (!invitedUsers) return undefined;
|
||||
handleGramJsUpdate(invitedUsers.updates);
|
||||
@ -1482,8 +1485,8 @@ export async function addChatMembers(chat: ApiChat, users: ApiUser[]) {
|
||||
const addChatUsersResult = await Promise.all(
|
||||
users.map(async (user) => {
|
||||
const invitedUsers = await invokeRequest(new GramJs.messages.AddChatUser({
|
||||
chatId: buildInputEntity(chat.id) as BigInt.BigInteger,
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
chatId: buildInputChat(chat.id),
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
}));
|
||||
if (!invitedUsers) return undefined;
|
||||
handleGramJsUpdate(invitedUsers.updates);
|
||||
@ -1536,8 +1539,8 @@ export function deleteChatMember(chat: ApiChat, user: ApiUser) {
|
||||
});
|
||||
} else {
|
||||
return invokeRequest(new GramJs.messages.DeleteChatUser({
|
||||
chatId: buildInputEntity(chat.id) as BigInt.BigInteger,
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
chatId: buildInputChat(chat.id),
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
});
|
||||
@ -1546,7 +1549,7 @@ export function deleteChatMember(chat: ApiChat, user: ApiUser) {
|
||||
|
||||
export function toggleJoinToSend(chat: ApiChat, isEnabled: boolean) {
|
||||
return invokeRequest(new GramJs.channels.ToggleJoinToSend({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -1555,7 +1558,7 @@ export function toggleJoinToSend(chat: ApiChat, isEnabled: boolean) {
|
||||
|
||||
export function toggleJoinRequest(chat: ApiChat, isEnabled: boolean) {
|
||||
return invokeRequest(new GramJs.channels.ToggleJoinRequest({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -1634,7 +1637,7 @@ export function toggleParticipantsHidden({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
return invokeRequest(new GramJs.channels.ToggleParticipantsHidden({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -1647,7 +1650,7 @@ export function toggleForum({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
return invokeRequest(new GramJs.channels.ToggleForum({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
enabled: isEnabled,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -1667,7 +1670,7 @@ export async function createTopic({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
const updates = await invokeRequest(new GramJs.channels.CreateForumTopic({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
title,
|
||||
iconColor,
|
||||
iconEmojiId: iconEmojiId ? BigInt(iconEmojiId) : undefined,
|
||||
@ -1705,7 +1708,7 @@ export async function fetchTopics({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
const result = await invokeRequest(new GramJs.channels.GetForumTopics({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
limit,
|
||||
q: query,
|
||||
offsetTopic: offsetTopicId,
|
||||
@ -1755,7 +1758,7 @@ export async function fetchTopicById({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
const result = await invokeRequest(new GramJs.channels.GetForumTopicsByID({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
topics: [topicId],
|
||||
}));
|
||||
|
||||
@ -1780,7 +1783,7 @@ export async function deleteTopic({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
const result = await invokeRequest(new GramJs.channels.DeleteTopicHistory({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
topMsgId: topicId,
|
||||
}));
|
||||
|
||||
@ -1803,7 +1806,7 @@ export function togglePinnedTopic({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
return invokeRequest(new GramJs.channels.UpdatePinnedForumTopic({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
topicId,
|
||||
pinned: isPinned,
|
||||
}), {
|
||||
@ -1824,7 +1827,7 @@ export function editTopic({
|
||||
const { id, accessHash } = chat;
|
||||
|
||||
return invokeRequest(new GramJs.channels.EditForumTopic({
|
||||
channel: buildInputPeer(id, accessHash),
|
||||
channel: buildInputChannel(id, accessHash),
|
||||
topicId,
|
||||
title,
|
||||
iconEmojiId: topicId !== GENERAL_TOPIC_ID && iconEmojiId ? BigInt(iconEmojiId) : undefined,
|
||||
@ -1996,10 +1999,10 @@ export function togglePeerTranslations({
|
||||
|
||||
export function setViewForumAsMessages({ chat, isEnabled }: { chat: ApiChat; isEnabled: boolean }) {
|
||||
const { id, accessHash } = chat;
|
||||
const channel = buildInputEntity(id, accessHash);
|
||||
const channel = buildInputChannel(id, accessHash);
|
||||
|
||||
return invokeRequest(new GramJs.channels.ToggleViewForumAsMessages({
|
||||
channel: channel as GramJs.InputChannel,
|
||||
channel,
|
||||
enabled: Boolean(isEnabled),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
@ -2008,7 +2011,7 @@ export function setViewForumAsMessages({ chat, isEnabled }: { chat: ApiChat; isE
|
||||
|
||||
export async function fetchChannelRecommendations({ chat }: { chat?: ApiChat }) {
|
||||
const result = await invokeRequest(new GramJs.channels.GetChannelRecommendations({
|
||||
channel: chat && buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: chat && buildInputChannel(chat.id, chat.accessHash),
|
||||
}));
|
||||
if (!result) {
|
||||
return undefined;
|
||||
|
||||
@ -28,7 +28,7 @@ import {
|
||||
import { buildApiPeerId } from '../apiBuilders/peers';
|
||||
import { buildApiStory } from '../apiBuilders/stories';
|
||||
import { buildApiUser, buildApiUserFullInfo } from '../apiBuilders/users';
|
||||
import { buildInputPeerFromLocalDb, getEntityTypeById } from '../gramjsBuilders';
|
||||
import { buildInputChannelFromLocalDb, buildInputPeerFromLocalDb, getEntityTypeById } from '../gramjsBuilders';
|
||||
import {
|
||||
addStoryToLocalDb, addUserToLocalDb,
|
||||
} from '../helpers/localDb';
|
||||
@ -523,12 +523,12 @@ export async function repairFileReference({
|
||||
|
||||
async function repairMessageMedia(peerId: string, messageId: number) {
|
||||
const type = getEntityTypeById(peerId);
|
||||
const peer = buildInputPeerFromLocalDb(peerId);
|
||||
if (!peer) return false;
|
||||
const inputChannel = buildInputChannelFromLocalDb(peerId);
|
||||
if (!inputChannel) return false;
|
||||
const result = await invokeRequest(
|
||||
type === 'channel'
|
||||
? new GramJs.channels.GetMessages({
|
||||
channel: peer,
|
||||
channel: inputChannel,
|
||||
id: [new GramJs.InputMessageID({ id: messageId })],
|
||||
})
|
||||
: new GramJs.messages.GetMessages({
|
||||
@ -541,7 +541,7 @@ async function repairMessageMedia(peerId: string, messageId: number) {
|
||||
|
||||
if (!result || result instanceof GramJs.messages.MessagesNotModified) return false;
|
||||
|
||||
if (peer && 'pts' in result) {
|
||||
if (inputChannel && 'pts' in result) {
|
||||
updateChannelState(peerId, result.pts);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import type {
|
||||
|
||||
import { ACCEPTABLE_USERNAME_ERRORS } from '../../../config';
|
||||
import { buildApiExportedInvite, buildChatInviteImporter } from '../apiBuilders/chats';
|
||||
import { buildInputEntity, buildInputPeer } from '../gramjsBuilders';
|
||||
import { buildInputChannel, buildInputPeer, buildInputUser } from '../gramjsBuilders';
|
||||
import { sendApiUpdate } from '../updates/apiUpdateEmitter';
|
||||
import { invokeRequest } from './client';
|
||||
|
||||
@ -38,7 +38,7 @@ export async function setChatUsername(
|
||||
{ chat, username }: { chat: ApiChat; username: string },
|
||||
) {
|
||||
const result = await invokeRequest(new GramJs.channels.UpdateUsername({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
username,
|
||||
}));
|
||||
|
||||
@ -61,7 +61,7 @@ export async function setChatUsername(
|
||||
|
||||
export async function deactivateAllUsernames({ chat }: { chat: ApiChat }) {
|
||||
const result = await invokeRequest(new GramJs.channels.DeactivateAllUsernames({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
}));
|
||||
|
||||
if (result) {
|
||||
@ -111,7 +111,7 @@ export async function fetchExportedChatInvites({
|
||||
}: { peer: ApiChat; admin: ApiUser; limit?: number; isRevoked?: boolean }) {
|
||||
const exportedInvites = await invokeRequest(new GramJs.messages.GetExportedChatInvites({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
adminId: buildInputEntity(admin.id, admin.accessHash) as GramJs.InputUser,
|
||||
adminId: buildInputUser(admin.id, admin.accessHash),
|
||||
limit,
|
||||
revoked: isRevoked || undefined,
|
||||
}), {
|
||||
@ -214,7 +214,7 @@ export async function deleteRevokedExportedChatInvites({
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.DeleteRevokedExportedChatInvites({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
adminId: buildInputEntity(admin.id, admin.accessHash) as GramJs.InputUser,
|
||||
adminId: buildInputUser(admin.id, admin.accessHash),
|
||||
}));
|
||||
|
||||
return result;
|
||||
@ -229,8 +229,7 @@ export async function fetchChatInviteImporters({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
link,
|
||||
offsetDate,
|
||||
offsetUser: offsetUser
|
||||
? buildInputEntity(offsetUser.id, offsetUser.accessHash) as GramJs.InputUser : new GramJs.InputUserEmpty(),
|
||||
offsetUser: offsetUser ? buildInputUser(offsetUser.id, offsetUser.accessHash) : new GramJs.InputUserEmpty(),
|
||||
limit,
|
||||
requested: isRequested || undefined,
|
||||
}), {
|
||||
@ -255,7 +254,7 @@ export function hideChatJoinRequest({
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.HideChatJoinRequest({
|
||||
peer: buildInputPeer(peer.id, peer.accessHash),
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
approved: isApproved || undefined,
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
|
||||
@ -142,7 +142,10 @@ async function download(
|
||||
}
|
||||
|
||||
if (MEDIA_ENTITY_TYPES.has(entityType)) {
|
||||
const data = await client.downloadMedia(entity, {
|
||||
const entityWithType = entity as (
|
||||
GramJs.Photo | GramJs.Document | GramJs.WebDocument
|
||||
);
|
||||
const data = await client.downloadMedia(entityWithType, {
|
||||
sizeType, start, end, progressCallback: onProgress, workers: DOWNLOAD_WORKERS,
|
||||
});
|
||||
let mimeType;
|
||||
|
||||
@ -73,7 +73,7 @@ import {
|
||||
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
import { buildApiUser, buildApiUserStatuses } from '../apiBuilders/users';
|
||||
import {
|
||||
buildInputEntity,
|
||||
buildInputChannel,
|
||||
buildInputMediaDocument,
|
||||
buildInputPeer,
|
||||
buildInputPoll,
|
||||
@ -82,6 +82,7 @@ import {
|
||||
buildInputReplyTo,
|
||||
buildInputStory,
|
||||
buildInputTextWithEntities,
|
||||
buildInputUser,
|
||||
buildMessageFromUpdate,
|
||||
buildMtpMessageEntity,
|
||||
buildPeer,
|
||||
@ -196,7 +197,7 @@ export async function fetchMessage({ chat, messageId }: { chat: ApiChat; message
|
||||
result = await invokeRequest(
|
||||
isChannel
|
||||
? new GramJs.channels.GetMessages({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
id: [new GramJs.InputMessageID({ id: messageId })],
|
||||
})
|
||||
: new GramJs.messages.GetMessages({
|
||||
@ -805,7 +806,7 @@ export async function deleteMessages({
|
||||
const result = await invokeRequest(
|
||||
isChannel
|
||||
? new GramJs.channels.DeleteMessages({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
id: messageIds,
|
||||
})
|
||||
: new GramJs.messages.DeleteMessages({
|
||||
@ -834,7 +835,7 @@ export async function deleteParticipantHistory({
|
||||
}) {
|
||||
const result = await invokeRequest(
|
||||
new GramJs.channels.DeleteParticipantHistory({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
participant: buildInputPeer(peer.id, peer.accessHash),
|
||||
}),
|
||||
);
|
||||
@ -878,7 +879,7 @@ export async function deleteHistory({
|
||||
const result = await invokeRequest(
|
||||
isChannel
|
||||
? new GramJs.channels.DeleteHistory({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
})
|
||||
: new GramJs.messages.DeleteHistory({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
@ -969,7 +970,7 @@ export function reportChannelSpam({
|
||||
}) {
|
||||
return invokeRequest(new GramJs.channels.ReportSpam({
|
||||
participant: buildInputPeer(peer.id, peer.accessHash),
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
id: messageIds,
|
||||
}));
|
||||
}
|
||||
@ -1016,7 +1017,7 @@ export async function markMessageListRead({
|
||||
const fixedMaxId = Math.min(maxId, MAX_INT_32);
|
||||
if (isChannel && threadId === MAIN_THREAD_ID) {
|
||||
await invokeRequest(new GramJs.channels.ReadHistory({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
maxId: fixedMaxId,
|
||||
}));
|
||||
} else if (isChannel) {
|
||||
@ -1057,7 +1058,7 @@ export async function markMessagesRead({
|
||||
const result = await invokeRequest(
|
||||
isChannel
|
||||
? new GramJs.channels.ReadMessageContents({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
id: messageIds,
|
||||
})
|
||||
: new GramJs.messages.ReadMessageContents({
|
||||
@ -2027,7 +2028,9 @@ function handleMultipleLocalMessagesUpdate(
|
||||
}
|
||||
|
||||
function handleLocalMessageUpdate(
|
||||
localMessage: ApiMessage, update: GramJs.TypeUpdates, scheduledMessageUpdate?: GramJs.UpdateNewScheduledMessage,
|
||||
localMessage: ApiMessage,
|
||||
update: GramJs.TypeUpdates | GramJs.UpdateMessageID,
|
||||
scheduledMessageUpdate?: GramJs.UpdateNewScheduledMessage,
|
||||
) {
|
||||
let messageUpdate;
|
||||
if (update instanceof GramJs.UpdateShortSentMessage || update instanceof GramJs.UpdateMessageID) {
|
||||
@ -2180,7 +2183,7 @@ export async function exportMessageLink({
|
||||
shouldIncludeGrouped?: boolean;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.channels.ExportMessageLink({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
id,
|
||||
thread: shouldIncludeThread || undefined,
|
||||
grouped: shouldIncludeGrouped || undefined,
|
||||
@ -2196,7 +2199,7 @@ export async function fetchPreparedInlineMessage({
|
||||
id: string;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetPreparedInlineMessage({
|
||||
bot: buildInputEntity(bot.id, bot.accessHash) as GramJs.InputUser,
|
||||
bot: buildInputUser(bot.id, bot.accessHash),
|
||||
id,
|
||||
}));
|
||||
if (!result) return undefined;
|
||||
|
||||
@ -42,9 +42,11 @@ import {
|
||||
import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers';
|
||||
import {
|
||||
buildDisallowedGiftsSettings,
|
||||
buildInputEntity, buildInputPeer, buildInputPhoto,
|
||||
buildInputChannel,
|
||||
buildInputPeer, buildInputPhoto,
|
||||
buildInputPrivacyKey,
|
||||
buildInputPrivacyRules,
|
||||
buildInputUser,
|
||||
} from '../gramjsBuilders';
|
||||
import { addPhotoToLocalDb } from '../helpers/localDb';
|
||||
import localDb from '../localDb';
|
||||
@ -119,7 +121,7 @@ export async function uploadProfilePhoto(
|
||||
) {
|
||||
const inputFile = await uploadFile(file);
|
||||
const result = await invokeRequest(new GramJs.photos.UploadProfilePhoto({
|
||||
...(bot ? { bot: buildInputPeer(bot.id, bot.accessHash) } : undefined),
|
||||
...(bot ? { bot: buildInputUser(bot.id, bot.accessHash) } : undefined),
|
||||
...(isVideo ? { video: inputFile, videoStartTs: videoTs } : { file: inputFile }),
|
||||
...(isFallback ? { fallback: true } : undefined),
|
||||
}));
|
||||
@ -144,7 +146,7 @@ export async function uploadContactProfilePhoto({
|
||||
}) {
|
||||
const inputFile = file ? await uploadFile(file) : undefined;
|
||||
const result = await invokeRequest(new GramJs.photos.UploadContactProfilePhoto({
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
file: inputFile,
|
||||
...(isSuggest ? { suggest: true } : { save: true }),
|
||||
}));
|
||||
@ -715,7 +717,7 @@ export function toggleUsername({
|
||||
}) {
|
||||
if (chatId) {
|
||||
return invokeRequest(new GramJs.channels.ToggleUsername({
|
||||
channel: buildInputEntity(chatId, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chatId, accessHash),
|
||||
username,
|
||||
active: isActive,
|
||||
}));
|
||||
@ -734,7 +736,7 @@ export function reorderUsernames({ chatId, accessHash, usernames }: {
|
||||
}) {
|
||||
if (chatId) {
|
||||
return invokeRequest(new GramJs.channels.ReorderUsernames({
|
||||
channel: buildInputEntity(chatId, accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chatId, accessHash),
|
||||
order: usernames,
|
||||
}));
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import {
|
||||
buildApiStarsTransaction,
|
||||
buildApiStarTopupOption,
|
||||
} from '../apiBuilders/payments';
|
||||
import { buildInputPeer, buildInputSavedStarGift } from '../gramjsBuilders';
|
||||
import { buildInputPeer, buildInputSavedStarGift, buildInputUser } from '../gramjsBuilders';
|
||||
import { checkErrorType, wrapError } from '../helpers/misc';
|
||||
import { invokeRequest } from './client';
|
||||
import { getPassword } from './twoFaSettings';
|
||||
@ -114,7 +114,7 @@ export async function getStarsGiftOptions({
|
||||
chat?: ApiChat;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.payments.GetStarsGiftOptions({
|
||||
userId: chat && buildInputPeer(chat.id, chat.accessHash),
|
||||
userId: chat && buildInputUser(chat.id, chat.accessHash),
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
buildPostsStatistics,
|
||||
buildStoryPublicForwards,
|
||||
} from '../apiBuilders/statistics';
|
||||
import { buildInputEntity, buildInputPeer } from '../gramjsBuilders';
|
||||
import { buildInputChannel, buildInputPeer } from '../gramjsBuilders';
|
||||
import { checkErrorType, wrapError } from '../helpers/misc';
|
||||
import { invokeRequest } from './client';
|
||||
import { getPassword } from './twoFaSettings';
|
||||
@ -24,7 +24,7 @@ export async function fetchChannelStatistics({
|
||||
chat, dcId,
|
||||
}: { chat: ApiChat; dcId?: number }) {
|
||||
const result = await invokeRequest(new GramJs.stats.GetBroadcastStats({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
}), {
|
||||
dcId,
|
||||
});
|
||||
@ -62,7 +62,7 @@ export async function fetchGroupStatistics({
|
||||
chat, dcId,
|
||||
}: { chat: ApiChat; dcId?: number }) {
|
||||
const result = await invokeRequest(new GramJs.stats.GetMegagroupStats({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
}), {
|
||||
dcId,
|
||||
});
|
||||
@ -86,7 +86,7 @@ export async function fetchMessageStatistics({
|
||||
dcId?: number;
|
||||
}): Promise<ApiPostStatistics | undefined> {
|
||||
const result = await invokeRequest(new GramJs.stats.GetMessageStats({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
msgId: messageId,
|
||||
}), {
|
||||
dcId,
|
||||
@ -115,7 +115,7 @@ export async function fetchMessagePublicForwards({
|
||||
nextOffset?: string;
|
||||
} | undefined> {
|
||||
const result = await invokeRequest(new GramJs.stats.GetMessagePublicForwards({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(chat.id, chat.accessHash),
|
||||
msgId: messageId,
|
||||
offset,
|
||||
limit: STATISTICS_PUBLIC_FORWARDS_LIMIT,
|
||||
|
||||
@ -12,8 +12,8 @@ import { buildApiUser, buildApiUserFullInfo, buildApiUserStatuses } from '../api
|
||||
import {
|
||||
buildInputContact,
|
||||
buildInputEmojiStatus,
|
||||
buildInputEntity,
|
||||
buildInputPeer,
|
||||
buildInputUser,
|
||||
buildMtpPeerId,
|
||||
getEntityTypeById,
|
||||
} from '../gramjsBuilders';
|
||||
@ -30,7 +30,7 @@ export async function fetchFullUser({
|
||||
id: string;
|
||||
accessHash?: string;
|
||||
}) {
|
||||
const input = buildInputEntity(id, accessHash);
|
||||
const input = buildInputUser(id, accessHash);
|
||||
if (!(input instanceof GramJs.InputUser)) {
|
||||
return undefined;
|
||||
}
|
||||
@ -88,7 +88,7 @@ export async function fetchFullUser({
|
||||
|
||||
export async function fetchCommonChats(user: ApiUser, maxId?: string) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetCommonChats({
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
maxId: maxId ? buildMtpPeerId(maxId, getEntityTypeById(maxId)) : undefined,
|
||||
}));
|
||||
|
||||
@ -105,7 +105,7 @@ export async function fetchCommonChats(user: ApiUser, maxId?: string) {
|
||||
|
||||
export async function fetchPaidMessagesStarsAmount(user: ApiUser) {
|
||||
const result = await invokeRequest(new GramJs.users.GetRequirementsToContact({
|
||||
id: [buildInputEntity(user.id, user.accessHash) as GramJs.InputUser],
|
||||
id: [buildInputUser(user.id, user.accessHash)],
|
||||
}));
|
||||
|
||||
if (!result) {
|
||||
@ -158,7 +158,7 @@ export async function fetchContactList() {
|
||||
|
||||
export async function fetchUsers({ users }: { users: ApiUser[] }) {
|
||||
const result = await invokeRequest(new GramJs.users.GetUsers({
|
||||
id: users.map(({ id, accessHash }) => buildInputPeer(id, accessHash)),
|
||||
id: users.map(({ id, accessHash }) => buildInputUser(id, accessHash)),
|
||||
}));
|
||||
if (!result || !result.length) {
|
||||
return undefined;
|
||||
@ -213,7 +213,7 @@ export function updateContact({
|
||||
shouldSharePhoneNumber?: boolean;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.contacts.AddContact({
|
||||
id: buildInputEntity(id, accessHash) as GramJs.InputUser,
|
||||
id: buildInputUser(id, accessHash),
|
||||
firstName,
|
||||
lastName,
|
||||
phone: phoneNumber,
|
||||
@ -230,7 +230,7 @@ export async function deleteContact({
|
||||
id: string;
|
||||
accessHash?: string;
|
||||
}) {
|
||||
const input = buildInputEntity(id, accessHash);
|
||||
const input = buildInputUser(id, accessHash);
|
||||
if (!(input instanceof GramJs.InputUser)) {
|
||||
return;
|
||||
}
|
||||
@ -253,7 +253,7 @@ export async function addNoPaidMessagesException({ user, shouldRefundCharged }:
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.account.AddNoPaidMessagesException({
|
||||
refundCharged: shouldRefundCharged ? true : undefined,
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
@ -263,7 +263,7 @@ export async function fetchPaidMessagesRevenue({ user }: {
|
||||
shouldRefundCharged?: boolean;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.account.GetPaidMessagesRevenue({
|
||||
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(user.id, user.accessHash),
|
||||
}));
|
||||
if (!result) return undefined;
|
||||
return result.starsAmount.toJSNumber();
|
||||
@ -284,7 +284,7 @@ export async function fetchProfilePhotos({
|
||||
const { id, accessHash } = user;
|
||||
|
||||
const result = await invokeRequest(new GramJs.photos.GetUserPhotos({
|
||||
userId: buildInputEntity(id, accessHash) as GramJs.InputUser,
|
||||
userId: buildInputUser(id, accessHash),
|
||||
limit,
|
||||
offset,
|
||||
maxId: BigInt('0'),
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Api as GramJs, type Update } from '../../../lib/gramjs';
|
||||
import { UpdateConnectionState, UpdateServerTimeOffset } from '../../../lib/gramjs/network';
|
||||
import type { Entity } from '../../../lib/gramjs/types';
|
||||
|
||||
import type { ApiChat } from '../../types';
|
||||
import type { invokeRequest } from '../methods/client';
|
||||
@ -7,7 +8,7 @@ import type { invokeRequest } from '../methods/client';
|
||||
import { DEBUG } from '../../../config';
|
||||
import SortedQueue from '../../../util/SortedQueue';
|
||||
import { buildApiPeerId } from '../apiBuilders/peers';
|
||||
import { buildInputEntity, buildMtpPeerId } from '../gramjsBuilders';
|
||||
import { buildInputChannel, buildMtpPeerId } from '../gramjsBuilders';
|
||||
import localDb from '../localDb';
|
||||
import { sendApiUpdate } from './apiUpdateEmitter';
|
||||
import { processAndUpdateEntities } from './entityProcessor';
|
||||
@ -140,7 +141,7 @@ function applyUpdate(updateObject: SeqUpdate | PtsUpdate) {
|
||||
|
||||
if (updateObject instanceof GramJs.UpdatesCombined || updateObject instanceof GramJs.Updates) {
|
||||
processAndUpdateEntities(updateObject);
|
||||
const entities = updateObject.users.concat(updateObject.chats);
|
||||
const entities = (updateObject.users as Entity[]).concat(updateObject.chats);
|
||||
|
||||
updateObject.updates.forEach((update) => {
|
||||
if (entities) {
|
||||
@ -331,7 +332,7 @@ async function getChannelDifference(channelId: string) {
|
||||
}
|
||||
|
||||
const response = await invoke(new GramJs.updates.GetChannelDifference({
|
||||
channel: buildInputEntity(channelId, channel.accessHash.toString()) as GramJs.InputChannel,
|
||||
channel: buildInputChannel(channelId, channel.accessHash.toString()),
|
||||
pts: localDb.channelPtsById[channelId],
|
||||
filter: new GramJs.ChannelMessagesFilterEmpty(),
|
||||
limit: CHANNEL_DIFFERENCE_LIMIT,
|
||||
|
||||
@ -24,7 +24,6 @@ import {
|
||||
isUserRightBanned,
|
||||
} from '../../global/helpers';
|
||||
import { getIsChatMuted } from '../../global/helpers/notifications';
|
||||
import { getPeerFullTitle } from '../../global/helpers/peers';
|
||||
import {
|
||||
selectBot,
|
||||
selectCanGift,
|
||||
|
||||
@ -28,11 +28,9 @@ function _raiseCastFail(entity: any, target: string) {
|
||||
* @param allowSelf
|
||||
* @param checkHash
|
||||
*/
|
||||
export function getInputPeer(entity: Entity, allowSelf = true, checkHash = true): Api.TypeInputPeer {
|
||||
if (entity.SUBCLASS_OF_ID === 0xc91c90b6) { // crc32(b'InputPeer')
|
||||
return entity;
|
||||
}
|
||||
|
||||
export function getInputPeer(
|
||||
entity: Entity, allowSelf = true, checkHash = true,
|
||||
): Api.TypeInputPeer {
|
||||
if (entity instanceof Api.User) {
|
||||
if (entity.self && allowSelf) {
|
||||
return new Api.InputPeerSelf();
|
||||
@ -68,18 +66,6 @@ export function getInputPeer(entity: Entity, allowSelf = true, checkHash = true)
|
||||
});
|
||||
}
|
||||
|
||||
if (entity instanceof Api.InputUser) {
|
||||
return new Api.InputPeerUser({
|
||||
userId: entity.userId,
|
||||
accessHash: entity.accessHash,
|
||||
});
|
||||
}
|
||||
if (entity instanceof Api.InputChannel) {
|
||||
return new Api.InputPeerChannel({
|
||||
channelId: entity.channelId,
|
||||
accessHash: entity.accessHash,
|
||||
});
|
||||
}
|
||||
if (entity instanceof Api.UserEmpty) {
|
||||
return new Api.InputPeerEmpty();
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ class TelegramClient {
|
||||
return downloadFile(this as any, inputLocation, args);
|
||||
}
|
||||
|
||||
_downloadPhoto(photo: Api.MessageMediaPhoto | Api.Photo | undefined, args: any) {
|
||||
_downloadPhoto(photo: Api.MessageMediaPhoto | Api.TypePhoto | undefined, args: any) {
|
||||
if (photo instanceof Api.MessageMediaPhoto) {
|
||||
photo = photo.photo;
|
||||
}
|
||||
|
||||
@ -776,7 +776,8 @@ class TelegramClient {
|
||||
}
|
||||
|
||||
downloadMedia(
|
||||
entityOrMedia: Api.Message | Api.TypeMessageMedia, args: DownloadMediaParams & Partial<DownloadFileParams>,
|
||||
entityOrMedia: Api.TypeMessage | Api.TypeMessageMedia | Api.TypePhoto | Api.TypeDocument | Api.TypeWebDocument,
|
||||
args: DownloadMediaParams & Partial<DownloadFileParams>,
|
||||
) {
|
||||
let media;
|
||||
if (entityOrMedia instanceof Api.Message || entityOrMedia instanceof Api.StoryItem) {
|
||||
|
||||
5844
src/lib/gramjs/tl/api.d.ts
vendored
5844
src/lib/gramjs/tl/api.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -41,11 +41,15 @@ const generate = ({
|
||||
}
|
||||
|
||||
function renderConstructors(arr: GenerationEntryConfig[], indent: string) {
|
||||
return arr.map(({ name, argsConfig }) => {
|
||||
return arr.map(({ name, subclassOfId, constructorId, argsConfig }) => {
|
||||
const argKeys = Object.keys(argsConfig);
|
||||
const defaultHead = `${indent} CONSTRUCTOR_ID: ${constructorId};
|
||||
${indent} SUBCLASS_OF_ID: ${subclassOfId};
|
||||
${indent} className: '${name}';\n`;
|
||||
|
||||
if (!argKeys.length) {
|
||||
return `export class ${upperFirst(name)} extends VirtualClass<void> {
|
||||
${defaultHead}
|
||||
${indent} static fromReader(reader: Reader): ${upperFirst(name)};
|
||||
${indent}}`;
|
||||
}
|
||||
@ -65,6 +69,7 @@ ${indent} ${Object.keys(argsConfig)
|
||||
${renderArg(argName, argsConfig[argName])};
|
||||
`.trim())
|
||||
.join(`\n${indent} `)}
|
||||
${defaultHead}
|
||||
${indent} static fromReader(reader: Reader): ${upperFirst(name)};
|
||||
${indent}}`.trim();
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user