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