Browse Source

Fix downloads again

master
Eduard Kuzmenko 2 years ago
parent
commit
02ac2c189a
  1. 4
      src/components/chat/commandsHelper.ts
  2. 2
      src/components/popups/payment.ts
  3. 177
      src/layer.d.ts
  4. 65
      src/lib/appManagers/appDownloadManager.ts
  5. 1
      src/lib/files/downloadStorage.ts
  6. 8
      src/lib/mtproto/apiFileManager.ts
  7. 31
      src/lib/mtproto/mtprotoworker.ts
  8. 3
      src/lib/mtproto/schema.ts
  9. 6
      src/lib/serviceWorker/download.ts
  10. 5
      src/lib/serviceWorker/index.service.ts
  11. 4
      src/scripts/in/schema.json
  12. 2
      src/scripts/out/schema.json

4
src/components/chat/commandsHelper.ts

@ -24,6 +24,10 @@ export function processPeerFullForCommands(peerId: PeerId, full: ChatFull.chatFu
type T = {peerId: PeerId, name: string, description: string, index: number, command: string}; type T = {peerId: PeerId, name: string, description: string, index: number, command: string};
const commands: Map<string, T> = new Map(); const commands: Map<string, T> = new Map();
botInfos.forEach((botInfo) => { botInfos.forEach((botInfo) => {
if(!botInfo.commands) {
return;
}
botInfo.commands.forEach(({command, description}, idx) => { botInfo.commands.forEach(({command, description}, idx) => {
const c = '/' + command; const c = '/' + command;
commands.set(command, { commands.set(command, {

2
src/components/popups/payment.ts

@ -221,7 +221,7 @@ export default class PopupPayment extends PopupElement {
} }
let savedInfo = (paymentForm as PaymentsPaymentForm).saved_info || (paymentForm as PaymentsPaymentReceipt).info; let savedInfo = (paymentForm as PaymentsPaymentForm).saved_info || (paymentForm as PaymentsPaymentReceipt).info;
const savedCredentials = (paymentForm as PaymentsPaymentForm).saved_credentials; const savedCredentials = (paymentForm as PaymentsPaymentForm).saved_credentials?.[0];
let [lastRequestedInfo, passwordState, providerPeerTitle] = await Promise.all([ let [lastRequestedInfo, passwordState, providerPeerTitle] = await Promise.all([
!isReceipt && savedInfo && this.managers.appPaymentsManager.validateRequestedInfo(inputInvoice, savedInfo), !isReceipt && savedInfo && this.managers.appPaymentsManager.validateRequestedInfo(inputInvoice, savedInfo),
savedCredentials && this.managers.passwordManager.getState(), savedCredentials && this.managers.passwordManager.getState(),

177
src/layer.d.ts vendored

@ -1039,7 +1039,7 @@ export namespace MessageMedia {
/** /**
* @link https://core.telegram.org/type/MessageAction * @link https://core.telegram.org/type/MessageAction
*/ */
export type MessageAction = MessageAction.messageActionEmpty | MessageAction.messageActionChatCreate | MessageAction.messageActionChatEditTitle | MessageAction.messageActionChatEditPhoto | MessageAction.messageActionChatDeletePhoto | MessageAction.messageActionChatAddUser | MessageAction.messageActionChatDeleteUser | MessageAction.messageActionChatJoinedByLink | MessageAction.messageActionChannelCreate | MessageAction.messageActionChatMigrateTo | MessageAction.messageActionChannelMigrateFrom | MessageAction.messageActionPinMessage | MessageAction.messageActionHistoryClear | MessageAction.messageActionGameScore | MessageAction.messageActionPaymentSentMe | MessageAction.messageActionPaymentSent | MessageAction.messageActionPhoneCall | MessageAction.messageActionScreenshotTaken | MessageAction.messageActionCustomAction | MessageAction.messageActionBotAllowed | MessageAction.messageActionSecureValuesSentMe | MessageAction.messageActionSecureValuesSent | MessageAction.messageActionContactSignUp | MessageAction.messageActionGeoProximityReached | MessageAction.messageActionGroupCall | MessageAction.messageActionInviteToGroupCall | MessageAction.messageActionSetMessagesTTL | MessageAction.messageActionGroupCallScheduled | MessageAction.messageActionSetChatTheme | MessageAction.messageActionChatJoinedByRequest | MessageAction.messageActionWebViewDataSentMe | MessageAction.messageActionWebViewDataSent | MessageAction.messageActionDiscussionStarted | MessageAction.messageActionChatLeave | MessageAction.messageActionChannelDeletePhoto | MessageAction.messageActionChannelEditTitle | MessageAction.messageActionChannelEditPhoto | MessageAction.messageActionChannelEditVideo | MessageAction.messageActionChatEditVideo | MessageAction.messageActionChatAddUsers | MessageAction.messageActionChatJoined | MessageAction.messageActionChatReturn | MessageAction.messageActionChatJoinedYou | MessageAction.messageActionChatReturnYou; export type MessageAction = MessageAction.messageActionEmpty | MessageAction.messageActionChatCreate | MessageAction.messageActionChatEditTitle | MessageAction.messageActionChatEditPhoto | MessageAction.messageActionChatDeletePhoto | MessageAction.messageActionChatAddUser | MessageAction.messageActionChatDeleteUser | MessageAction.messageActionChatJoinedByLink | MessageAction.messageActionChannelCreate | MessageAction.messageActionChatMigrateTo | MessageAction.messageActionChannelMigrateFrom | MessageAction.messageActionPinMessage | MessageAction.messageActionHistoryClear | MessageAction.messageActionGameScore | MessageAction.messageActionPaymentSentMe | MessageAction.messageActionPaymentSent | MessageAction.messageActionPhoneCall | MessageAction.messageActionScreenshotTaken | MessageAction.messageActionCustomAction | MessageAction.messageActionBotAllowed | MessageAction.messageActionSecureValuesSentMe | MessageAction.messageActionSecureValuesSent | MessageAction.messageActionContactSignUp | MessageAction.messageActionGeoProximityReached | MessageAction.messageActionGroupCall | MessageAction.messageActionInviteToGroupCall | MessageAction.messageActionSetMessagesTTL | MessageAction.messageActionGroupCallScheduled | MessageAction.messageActionSetChatTheme | MessageAction.messageActionChatJoinedByRequest | MessageAction.messageActionWebViewDataSentMe | MessageAction.messageActionWebViewDataSent | MessageAction.messageActionGiftPremium | MessageAction.messageActionDiscussionStarted | MessageAction.messageActionChatLeave | MessageAction.messageActionChannelDeletePhoto | MessageAction.messageActionChannelEditTitle | MessageAction.messageActionChannelEditPhoto | MessageAction.messageActionChannelEditVideo | MessageAction.messageActionChatEditVideo | MessageAction.messageActionChatAddUsers | MessageAction.messageActionChatJoined | MessageAction.messageActionChatReturn | MessageAction.messageActionChatJoinedYou | MessageAction.messageActionChatReturnYou;
export namespace MessageAction { export namespace MessageAction {
export type messageActionEmpty = { export type messageActionEmpty = {
@ -1229,6 +1229,13 @@ export namespace MessageAction {
text: string text: string
}; };
export type messageActionGiftPremium = {
_: 'messageActionGiftPremium',
currency: string,
amount: string | number,
months: number
};
export type messageActionDiscussionStarted = { export type messageActionDiscussionStarted = {
_: 'messageActionDiscussionStarted' _: 'messageActionDiscussionStarted'
}; };
@ -1689,6 +1696,7 @@ export namespace UserFull {
can_pin_message?: true, can_pin_message?: true,
has_scheduled?: true, has_scheduled?: true,
video_calls_available?: true, video_calls_available?: true,
voice_messages_forbidden?: true,
}>, }>,
id: string | number, id: string | number,
about?: string, about?: string,
@ -1703,7 +1711,8 @@ export namespace UserFull {
theme_emoticon?: string, theme_emoticon?: string,
private_forward_name?: string, private_forward_name?: string,
bot_group_admin_rights?: ChatAdminRights, bot_group_admin_rights?: ChatAdminRights,
bot_broadcast_admin_rights?: ChatAdminRights bot_broadcast_admin_rights?: ChatAdminRights,
premium_gifts?: Array<PremiumGiftOption>
}; };
} }
@ -2005,7 +2014,7 @@ export namespace MessagesFilter {
/** /**
* @link https://core.telegram.org/type/Update * @link https://core.telegram.org/type/Update
*/ */
export type Update = Update.updateNewMessage | Update.updateMessageID | Update.updateDeleteMessages | Update.updateUserTyping | Update.updateChatUserTyping | Update.updateChatParticipants | Update.updateUserStatus | Update.updateUserName | Update.updateUserPhoto | Update.updateNewEncryptedMessage | Update.updateEncryptedChatTyping | Update.updateEncryption | Update.updateEncryptedMessagesRead | Update.updateChatParticipantAdd | Update.updateChatParticipantDelete | Update.updateDcOptions | Update.updateNotifySettings | Update.updateServiceNotification | Update.updatePrivacy | Update.updateUserPhone | Update.updateReadHistoryInbox | Update.updateReadHistoryOutbox | Update.updateWebPage | Update.updateReadMessagesContents | Update.updateChannelTooLong | Update.updateChannel | Update.updateNewChannelMessage | Update.updateReadChannelInbox | Update.updateDeleteChannelMessages | Update.updateChannelMessageViews | Update.updateChatParticipantAdmin | Update.updateNewStickerSet | Update.updateStickerSetsOrder | Update.updateStickerSets | Update.updateSavedGifs | Update.updateBotInlineQuery | Update.updateBotInlineSend | Update.updateEditChannelMessage | Update.updateBotCallbackQuery | Update.updateEditMessage | Update.updateInlineBotCallbackQuery | Update.updateReadChannelOutbox | Update.updateDraftMessage | Update.updateReadFeaturedStickers | Update.updateRecentStickers | Update.updateConfig | Update.updatePtsChanged | Update.updateChannelWebPage | Update.updateDialogPinned | Update.updatePinnedDialogs | Update.updateBotWebhookJSON | Update.updateBotWebhookJSONQuery | Update.updateBotShippingQuery | Update.updateBotPrecheckoutQuery | Update.updatePhoneCall | Update.updateLangPackTooLong | Update.updateLangPack | Update.updateFavedStickers | Update.updateChannelReadMessagesContents | Update.updateContactsReset | Update.updateChannelAvailableMessages | Update.updateDialogUnreadMark | Update.updateMessagePoll | Update.updateChatDefaultBannedRights | Update.updateFolderPeers | Update.updatePeerSettings | Update.updatePeerLocated | Update.updateNewScheduledMessage | Update.updateDeleteScheduledMessages | Update.updateTheme | Update.updateGeoLiveViewed | Update.updateLoginToken | Update.updateMessagePollVote | Update.updateDialogFilter | Update.updateDialogFilterOrder | Update.updateDialogFilters | Update.updatePhoneCallSignalingData | Update.updateChannelMessageForwards | Update.updateReadChannelDiscussionInbox | Update.updateReadChannelDiscussionOutbox | Update.updatePeerBlocked | Update.updateChannelUserTyping | Update.updatePinnedMessages | Update.updatePinnedChannelMessages | Update.updateChat | Update.updateGroupCallParticipants | Update.updateGroupCall | Update.updatePeerHistoryTTL | Update.updateChatParticipant | Update.updateChannelParticipant | Update.updateBotStopped | Update.updateGroupCallConnection | Update.updateBotCommands | Update.updatePendingJoinRequests | Update.updateBotChatInviteRequester | Update.updateMessageReactions | Update.updateAttachMenuBots | Update.updateWebViewResultSent | Update.updateBotMenuButton | Update.updateSavedRingtones | Update.updateTranscribedAudio | Update.updateNewDiscussionMessage | Update.updateDeleteDiscussionMessages | Update.updateChannelReload; export type Update = Update.updateNewMessage | Update.updateMessageID | Update.updateDeleteMessages | Update.updateUserTyping | Update.updateChatUserTyping | Update.updateChatParticipants | Update.updateUserStatus | Update.updateUserName | Update.updateUserPhoto | Update.updateNewEncryptedMessage | Update.updateEncryptedChatTyping | Update.updateEncryption | Update.updateEncryptedMessagesRead | Update.updateChatParticipantAdd | Update.updateChatParticipantDelete | Update.updateDcOptions | Update.updateNotifySettings | Update.updateServiceNotification | Update.updatePrivacy | Update.updateUserPhone | Update.updateReadHistoryInbox | Update.updateReadHistoryOutbox | Update.updateWebPage | Update.updateReadMessagesContents | Update.updateChannelTooLong | Update.updateChannel | Update.updateNewChannelMessage | Update.updateReadChannelInbox | Update.updateDeleteChannelMessages | Update.updateChannelMessageViews | Update.updateChatParticipantAdmin | Update.updateNewStickerSet | Update.updateStickerSetsOrder | Update.updateStickerSets | Update.updateSavedGifs | Update.updateBotInlineQuery | Update.updateBotInlineSend | Update.updateEditChannelMessage | Update.updateBotCallbackQuery | Update.updateEditMessage | Update.updateInlineBotCallbackQuery | Update.updateReadChannelOutbox | Update.updateDraftMessage | Update.updateReadFeaturedStickers | Update.updateRecentStickers | Update.updateConfig | Update.updatePtsChanged | Update.updateChannelWebPage | Update.updateDialogPinned | Update.updatePinnedDialogs | Update.updateBotWebhookJSON | Update.updateBotWebhookJSONQuery | Update.updateBotShippingQuery | Update.updateBotPrecheckoutQuery | Update.updatePhoneCall | Update.updateLangPackTooLong | Update.updateLangPack | Update.updateFavedStickers | Update.updateChannelReadMessagesContents | Update.updateContactsReset | Update.updateChannelAvailableMessages | Update.updateDialogUnreadMark | Update.updateMessagePoll | Update.updateChatDefaultBannedRights | Update.updateFolderPeers | Update.updatePeerSettings | Update.updatePeerLocated | Update.updateNewScheduledMessage | Update.updateDeleteScheduledMessages | Update.updateTheme | Update.updateGeoLiveViewed | Update.updateLoginToken | Update.updateMessagePollVote | Update.updateDialogFilter | Update.updateDialogFilterOrder | Update.updateDialogFilters | Update.updatePhoneCallSignalingData | Update.updateChannelMessageForwards | Update.updateReadChannelDiscussionInbox | Update.updateReadChannelDiscussionOutbox | Update.updatePeerBlocked | Update.updateChannelUserTyping | Update.updatePinnedMessages | Update.updatePinnedChannelMessages | Update.updateChat | Update.updateGroupCallParticipants | Update.updateGroupCall | Update.updatePeerHistoryTTL | Update.updateChatParticipant | Update.updateChannelParticipant | Update.updateBotStopped | Update.updateGroupCallConnection | Update.updateBotCommands | Update.updatePendingJoinRequests | Update.updateBotChatInviteRequester | Update.updateMessageReactions | Update.updateAttachMenuBots | Update.updateWebViewResultSent | Update.updateBotMenuButton | Update.updateSavedRingtones | Update.updateTranscribedAudio | Update.updateReadFeaturedEmojiStickers | Update.updateNewDiscussionMessage | Update.updateDeleteDiscussionMessages | Update.updateChannelReload;
export namespace Update { export namespace Update {
export type updateNewMessage = { export type updateNewMessage = {
@ -2726,6 +2735,10 @@ export namespace Update {
text: string text: string
}; };
export type updateReadFeaturedEmojiStickers = {
_: 'updateReadFeaturedEmojiStickers'
};
export type updateNewDiscussionMessage = { export type updateNewDiscussionMessage = {
_: 'updateNewDiscussionMessage', _: 'updateNewDiscussionMessage',
message?: Message message?: Message
@ -3474,7 +3487,7 @@ export namespace ContactsFound {
/** /**
* @link https://core.telegram.org/type/InputPrivacyKey * @link https://core.telegram.org/type/InputPrivacyKey
*/ */
export type InputPrivacyKey = InputPrivacyKey.inputPrivacyKeyStatusTimestamp | InputPrivacyKey.inputPrivacyKeyChatInvite | InputPrivacyKey.inputPrivacyKeyPhoneCall | InputPrivacyKey.inputPrivacyKeyPhoneP2P | InputPrivacyKey.inputPrivacyKeyForwards | InputPrivacyKey.inputPrivacyKeyProfilePhoto | InputPrivacyKey.inputPrivacyKeyPhoneNumber | InputPrivacyKey.inputPrivacyKeyAddedByPhone; export type InputPrivacyKey = InputPrivacyKey.inputPrivacyKeyStatusTimestamp | InputPrivacyKey.inputPrivacyKeyChatInvite | InputPrivacyKey.inputPrivacyKeyPhoneCall | InputPrivacyKey.inputPrivacyKeyPhoneP2P | InputPrivacyKey.inputPrivacyKeyForwards | InputPrivacyKey.inputPrivacyKeyProfilePhoto | InputPrivacyKey.inputPrivacyKeyPhoneNumber | InputPrivacyKey.inputPrivacyKeyAddedByPhone | InputPrivacyKey.inputPrivacyKeyVoiceMessages;
export namespace InputPrivacyKey { export namespace InputPrivacyKey {
export type inputPrivacyKeyStatusTimestamp = { export type inputPrivacyKeyStatusTimestamp = {
@ -3508,12 +3521,16 @@ export namespace InputPrivacyKey {
export type inputPrivacyKeyAddedByPhone = { export type inputPrivacyKeyAddedByPhone = {
_: 'inputPrivacyKeyAddedByPhone' _: 'inputPrivacyKeyAddedByPhone'
}; };
export type inputPrivacyKeyVoiceMessages = {
_: 'inputPrivacyKeyVoiceMessages'
};
} }
/** /**
* @link https://core.telegram.org/type/PrivacyKey * @link https://core.telegram.org/type/PrivacyKey
*/ */
export type PrivacyKey = PrivacyKey.privacyKeyStatusTimestamp | PrivacyKey.privacyKeyChatInvite | PrivacyKey.privacyKeyPhoneCall | PrivacyKey.privacyKeyPhoneP2P | PrivacyKey.privacyKeyForwards | PrivacyKey.privacyKeyProfilePhoto | PrivacyKey.privacyKeyPhoneNumber | PrivacyKey.privacyKeyAddedByPhone; export type PrivacyKey = PrivacyKey.privacyKeyStatusTimestamp | PrivacyKey.privacyKeyChatInvite | PrivacyKey.privacyKeyPhoneCall | PrivacyKey.privacyKeyPhoneP2P | PrivacyKey.privacyKeyForwards | PrivacyKey.privacyKeyProfilePhoto | PrivacyKey.privacyKeyPhoneNumber | PrivacyKey.privacyKeyAddedByPhone | PrivacyKey.privacyKeyVoiceMessages;
export namespace PrivacyKey { export namespace PrivacyKey {
export type privacyKeyStatusTimestamp = { export type privacyKeyStatusTimestamp = {
@ -3547,6 +3564,10 @@ export namespace PrivacyKey {
export type privacyKeyAddedByPhone = { export type privacyKeyAddedByPhone = {
_: 'privacyKeyAddedByPhone' _: 'privacyKeyAddedByPhone'
}; };
export type privacyKeyVoiceMessages = {
_: 'privacyKeyVoiceMessages'
};
} }
/** /**
@ -3664,7 +3685,7 @@ export namespace AccountDaysTTL {
/** /**
* @link https://core.telegram.org/type/DocumentAttribute * @link https://core.telegram.org/type/DocumentAttribute
*/ */
export type DocumentAttribute = DocumentAttribute.documentAttributeImageSize | DocumentAttribute.documentAttributeAnimated | DocumentAttribute.documentAttributeSticker | DocumentAttribute.documentAttributeVideo | DocumentAttribute.documentAttributeAudio | DocumentAttribute.documentAttributeFilename | DocumentAttribute.documentAttributeHasStickers; export type DocumentAttribute = DocumentAttribute.documentAttributeImageSize | DocumentAttribute.documentAttributeAnimated | DocumentAttribute.documentAttributeSticker | DocumentAttribute.documentAttributeVideo | DocumentAttribute.documentAttributeAudio | DocumentAttribute.documentAttributeFilename | DocumentAttribute.documentAttributeHasStickers | DocumentAttribute.documentAttributeCustomEmoji;
export namespace DocumentAttribute { export namespace DocumentAttribute {
export type documentAttributeImageSize = { export type documentAttributeImageSize = {
@ -3720,6 +3741,16 @@ export namespace DocumentAttribute {
export type documentAttributeHasStickers = { export type documentAttributeHasStickers = {
_: 'documentAttributeHasStickers' _: 'documentAttributeHasStickers'
}; };
export type documentAttributeCustomEmoji = {
_: 'documentAttributeCustomEmoji',
flags?: number,
pFlags?: Partial<{
free?: true,
}>,
alt: string,
stickerset: InputStickerSet
};
} }
/** /**
@ -4023,7 +4054,7 @@ export namespace ChatInvite {
/** /**
* @link https://core.telegram.org/type/InputStickerSet * @link https://core.telegram.org/type/InputStickerSet
*/ */
export type InputStickerSet = InputStickerSet.inputStickerSetEmpty | InputStickerSet.inputStickerSetID | InputStickerSet.inputStickerSetShortName | InputStickerSet.inputStickerSetAnimatedEmoji | InputStickerSet.inputStickerSetDice | InputStickerSet.inputStickerSetAnimatedEmojiAnimations; export type InputStickerSet = InputStickerSet.inputStickerSetEmpty | InputStickerSet.inputStickerSetID | InputStickerSet.inputStickerSetShortName | InputStickerSet.inputStickerSetAnimatedEmoji | InputStickerSet.inputStickerSetDice | InputStickerSet.inputStickerSetAnimatedEmojiAnimations | InputStickerSet.inputStickerSetPremiumGifts;
export namespace InputStickerSet { export namespace InputStickerSet {
export type inputStickerSetEmpty = { export type inputStickerSetEmpty = {
@ -4053,6 +4084,10 @@ export namespace InputStickerSet {
export type inputStickerSetAnimatedEmojiAnimations = { export type inputStickerSetAnimatedEmojiAnimations = {
_: 'inputStickerSetAnimatedEmojiAnimations' _: 'inputStickerSetAnimatedEmojiAnimations'
}; };
export type inputStickerSetPremiumGifts = {
_: 'inputStickerSetPremiumGifts'
};
} }
/** /**
@ -4080,6 +4115,7 @@ export namespace StickerSet {
thumbs?: Array<PhotoSize>, thumbs?: Array<PhotoSize>,
thumb_dc_id?: number, thumb_dc_id?: number,
thumb_version?: number, thumb_version?: number,
thumb_document_id?: string | number,
count: number, count: number,
hash: number hash: number
}; };
@ -4310,7 +4346,7 @@ export namespace ReplyMarkup {
/** /**
* @link https://core.telegram.org/type/MessageEntity * @link https://core.telegram.org/type/MessageEntity
*/ */
export type MessageEntity = MessageEntity.messageEntityUnknown | MessageEntity.messageEntityMention | MessageEntity.messageEntityHashtag | MessageEntity.messageEntityBotCommand | MessageEntity.messageEntityUrl | MessageEntity.messageEntityEmail | MessageEntity.messageEntityBold | MessageEntity.messageEntityItalic | MessageEntity.messageEntityCode | MessageEntity.messageEntityPre | MessageEntity.messageEntityTextUrl | MessageEntity.messageEntityMentionName | MessageEntity.inputMessageEntityMentionName | MessageEntity.messageEntityPhone | MessageEntity.messageEntityCashtag | MessageEntity.messageEntityUnderline | MessageEntity.messageEntityStrike | MessageEntity.messageEntityBlockquote | MessageEntity.messageEntityBankCard | MessageEntity.messageEntitySpoiler | MessageEntity.messageEntityEmoji | MessageEntity.messageEntityHighlight | MessageEntity.messageEntityLinebreak | MessageEntity.messageEntityCaret; export type MessageEntity = MessageEntity.messageEntityUnknown | MessageEntity.messageEntityMention | MessageEntity.messageEntityHashtag | MessageEntity.messageEntityBotCommand | MessageEntity.messageEntityUrl | MessageEntity.messageEntityEmail | MessageEntity.messageEntityBold | MessageEntity.messageEntityItalic | MessageEntity.messageEntityCode | MessageEntity.messageEntityPre | MessageEntity.messageEntityTextUrl | MessageEntity.messageEntityMentionName | MessageEntity.inputMessageEntityMentionName | MessageEntity.messageEntityPhone | MessageEntity.messageEntityCashtag | MessageEntity.messageEntityUnderline | MessageEntity.messageEntityStrike | MessageEntity.messageEntityBlockquote | MessageEntity.messageEntityBankCard | MessageEntity.messageEntitySpoiler | MessageEntity.messageEntityCustomEmoji | MessageEntity.messageEntityEmoji | MessageEntity.messageEntityHighlight | MessageEntity.messageEntityLinebreak | MessageEntity.messageEntityCaret;
export namespace MessageEntity { export namespace MessageEntity {
export type messageEntityUnknown = { export type messageEntityUnknown = {
@ -4438,6 +4474,13 @@ export namespace MessageEntity {
length: number length: number
}; };
export type messageEntityCustomEmoji = {
_: 'messageEntityCustomEmoji',
offset: number,
length: number,
document_id: string | number
};
export type messageEntityEmoji = { export type messageEntityEmoji = {
_: 'messageEntityEmoji', _: 'messageEntityEmoji',
offset?: number, offset?: number,
@ -5373,7 +5416,7 @@ export namespace MessagesStickerSetInstallResult {
/** /**
* @link https://core.telegram.org/type/StickerSetCovered * @link https://core.telegram.org/type/StickerSetCovered
*/ */
export type StickerSetCovered = StickerSetCovered.stickerSetCovered | StickerSetCovered.stickerSetMultiCovered; export type StickerSetCovered = StickerSetCovered.stickerSetCovered | StickerSetCovered.stickerSetMultiCovered | StickerSetCovered.stickerSetFullCovered;
export namespace StickerSetCovered { export namespace StickerSetCovered {
export type stickerSetCovered = { export type stickerSetCovered = {
@ -5387,6 +5430,13 @@ export namespace StickerSetCovered {
set: StickerSet, set: StickerSet,
covers: Array<Document> covers: Array<Document>
}; };
export type stickerSetFullCovered = {
_: 'stickerSetFullCovered',
set: StickerSet,
packs: Array<StickerPack>,
documents: Array<Document>
};
} }
/** /**
@ -5959,7 +6009,7 @@ export namespace InputWebDocument {
/** /**
* @link https://core.telegram.org/type/InputWebFileLocation * @link https://core.telegram.org/type/InputWebFileLocation
*/ */
export type InputWebFileLocation = InputWebFileLocation.inputWebFileLocation | InputWebFileLocation.inputWebFileGeoPointLocation; export type InputWebFileLocation = InputWebFileLocation.inputWebFileLocation | InputWebFileLocation.inputWebFileGeoPointLocation | InputWebFileLocation.inputWebFileAudioAlbumThumbLocation;
export namespace InputWebFileLocation { export namespace InputWebFileLocation {
export type inputWebFileLocation = { export type inputWebFileLocation = {
@ -5977,6 +6027,17 @@ export namespace InputWebFileLocation {
zoom: number, zoom: number,
scale: number scale: number
}; };
export type inputWebFileAudioAlbumThumbLocation = {
_: 'inputWebFileAudioAlbumThumbLocation',
flags?: number,
pFlags?: Partial<{
small?: true,
}>,
document?: InputDocument,
title?: string,
performer?: string
};
} }
/** /**
@ -6018,8 +6079,9 @@ export namespace PaymentsPaymentForm {
url: string, url: string,
native_provider?: string, native_provider?: string,
native_params?: DataJSON, native_params?: DataJSON,
additional_methods?: Array<PaymentFormMethod>,
saved_info?: PaymentRequestedInfo, saved_info?: PaymentRequestedInfo,
saved_credentials?: PaymentSavedCredentials, saved_credentials?: Array<PaymentSavedCredentials>,
users: Array<User> users: Array<User>
}; };
} }
@ -9861,6 +9923,58 @@ export namespace HelpPremiumPromo {
}; };
} }
/**
* @link https://core.telegram.org/type/InputStorePaymentPurpose
*/
export type InputStorePaymentPurpose = InputStorePaymentPurpose.inputStorePaymentPremiumSubscription | InputStorePaymentPurpose.inputStorePaymentGiftPremium;
export namespace InputStorePaymentPurpose {
export type inputStorePaymentPremiumSubscription = {
_: 'inputStorePaymentPremiumSubscription',
flags?: number,
pFlags?: Partial<{
restore?: true,
}>
};
export type inputStorePaymentGiftPremium = {
_: 'inputStorePaymentGiftPremium',
user_id: InputUser,
currency: string,
amount: string | number
};
}
/**
* @link https://core.telegram.org/type/PremiumGiftOption
*/
export type PremiumGiftOption = PremiumGiftOption.premiumGiftOption;
export namespace PremiumGiftOption {
export type premiumGiftOption = {
_: 'premiumGiftOption',
flags?: number,
months: number,
currency: string,
amount: string | number,
bot_url: string,
store_product?: string
};
}
/**
* @link https://core.telegram.org/type/PaymentFormMethod
*/
export type PaymentFormMethod = PaymentFormMethod.paymentFormMethod;
export namespace PaymentFormMethod {
export type paymentFormMethod = {
_: 'paymentFormMethod',
url: string,
title: string
};
}
export interface ConstructorDeclMap { export interface ConstructorDeclMap {
'error': Error.error, 'error': Error.error,
'inputPeerEmpty': InputPeer.inputPeerEmpty, 'inputPeerEmpty': InputPeer.inputPeerEmpty,
@ -10857,6 +10971,19 @@ export interface ConstructorDeclMap {
'messages.transcribedAudio': MessagesTranscribedAudio.messagesTranscribedAudio, 'messages.transcribedAudio': MessagesTranscribedAudio.messagesTranscribedAudio,
'dialogFilterDefault': DialogFilter.dialogFilterDefault, 'dialogFilterDefault': DialogFilter.dialogFilterDefault,
'help.premiumPromo': HelpPremiumPromo.helpPremiumPromo, 'help.premiumPromo': HelpPremiumPromo.helpPremiumPromo,
'messageEntityCustomEmoji': MessageEntity.messageEntityCustomEmoji,
'documentAttributeCustomEmoji': DocumentAttribute.documentAttributeCustomEmoji,
'stickerSetFullCovered': StickerSetCovered.stickerSetFullCovered,
'inputStorePaymentPremiumSubscription': InputStorePaymentPurpose.inputStorePaymentPremiumSubscription,
'inputStorePaymentGiftPremium': InputStorePaymentPurpose.inputStorePaymentGiftPremium,
'messageActionGiftPremium': MessageAction.messageActionGiftPremium,
'premiumGiftOption': PremiumGiftOption.premiumGiftOption,
'inputStickerSetPremiumGifts': InputStickerSet.inputStickerSetPremiumGifts,
'updateReadFeaturedEmojiStickers': Update.updateReadFeaturedEmojiStickers,
'inputPrivacyKeyVoiceMessages': InputPrivacyKey.inputPrivacyKeyVoiceMessages,
'privacyKeyVoiceMessages': PrivacyKey.privacyKeyVoiceMessages,
'paymentFormMethod': PaymentFormMethod.paymentFormMethod,
'inputWebFileAudioAlbumThumbLocation': InputWebFileLocation.inputWebFileAudioAlbumThumbLocation,
'messageEntityEmoji': MessageEntity.messageEntityEmoji, 'messageEntityEmoji': MessageEntity.messageEntityEmoji,
'messageEntityHighlight': MessageEntity.messageEntityHighlight, 'messageEntityHighlight': MessageEntity.messageEntityHighlight,
'messageEntityLinebreak': MessageEntity.messageEntityLinebreak, 'messageEntityLinebreak': MessageEntity.messageEntityLinebreak,
@ -13403,27 +13530,33 @@ export type MessagesRateTranscribedAudio = {
}; };
export type PaymentsAssignAppStoreTransaction = { export type PaymentsAssignAppStoreTransaction = {
flags?: number, receipt: Uint8Array,
restore?: boolean, purpose: InputStorePaymentPurpose
receipt: Uint8Array
}; };
export type PaymentsAssignPlayMarketTransaction = { export type PaymentsAssignPlayMarketTransaction = {
purchase_token: string receipt: DataJSON,
purpose: InputStorePaymentPurpose
}; };
export type PaymentsCanPurchasePremium = { export type PaymentsCanPurchasePremium = {
purpose: InputStorePaymentPurpose
}; };
export type HelpGetPremiumPromo = { export type HelpGetPremiumPromo = {
}; };
export type PaymentsRequestRecurringPayment = { export type MessagesGetCustomEmojiDocuments = {
user_id: InputUser, document_id: Array<string | number>
recurring_init_charge: string, };
invoice_media: InputMedia
export type MessagesGetEmojiStickers = {
hash: string | number
};
export type MessagesGetFeaturedEmojiStickers = {
hash: string | number
}; };
export interface MethodDeclMap { export interface MethodDeclMap {
@ -13871,6 +14004,8 @@ export interface MethodDeclMap {
'payments.assignPlayMarketTransaction': {req: PaymentsAssignPlayMarketTransaction, res: Updates}, 'payments.assignPlayMarketTransaction': {req: PaymentsAssignPlayMarketTransaction, res: Updates},
'payments.canPurchasePremium': {req: PaymentsCanPurchasePremium, res: boolean}, 'payments.canPurchasePremium': {req: PaymentsCanPurchasePremium, res: boolean},
'help.getPremiumPromo': {req: HelpGetPremiumPromo, res: HelpPremiumPromo}, 'help.getPremiumPromo': {req: HelpGetPremiumPromo, res: HelpPremiumPromo},
'payments.requestRecurringPayment': {req: PaymentsRequestRecurringPayment, res: Updates}, 'messages.getCustomEmojiDocuments': {req: MessagesGetCustomEmojiDocuments, res: Array<Document>},
'messages.getEmojiStickers': {req: MessagesGetEmojiStickers, res: MessagesAllStickers},
'messages.getFeaturedEmojiStickers': {req: MessagesGetFeaturedEmojiStickers, res: MessagesFeaturedStickers},
} }

65
src/lib/appManagers/appDownloadManager.ts

@ -6,6 +6,7 @@
import type {DownloadMediaOptions, DownloadOptions} from '../mtproto/apiFileManager'; import type {DownloadMediaOptions, DownloadOptions} from '../mtproto/apiFileManager';
import type {AppMessagesManager} from './appMessagesManager'; import type {AppMessagesManager} from './appMessagesManager';
import type {MyDocument} from './appDocsManager';
import deferredPromise, {CancellablePromise} from '../../helpers/cancellablePromise'; import deferredPromise, {CancellablePromise} from '../../helpers/cancellablePromise';
import {InputFile, Photo, PhotoSize} from '../../layer'; import {InputFile, Photo, PhotoSize} from '../../layer';
import getFileNameForUpload from '../../helpers/getFileNameForUpload'; import getFileNameForUpload from '../../helpers/getFileNameForUpload';
@ -17,6 +18,11 @@ import getDownloadMediaDetails from './utils/download/getDownloadMediaDetails';
import getDownloadFileNameFromOptions from './utils/download/getDownloadFileNameFromOptions'; import getDownloadFileNameFromOptions from './utils/download/getDownloadFileNameFromOptions';
import indexOfAndSplice from '../../helpers/array/indexOfAndSplice'; import indexOfAndSplice from '../../helpers/array/indexOfAndSplice';
import makeError from '../../helpers/makeError'; import makeError from '../../helpers/makeError';
import createDownloadAnchor from '../../helpers/dom/createDownloadAnchor';
import {getFileNameByLocation} from '../../helpers/fileName';
import getDocumentDownloadOptions from './utils/docs/getDocumentDownloadOptions';
import getPhotoDownloadOptions from './utils/photos/getPhotoDownloadOptions';
import apiManagerProxy from '../mtproto/mtprotoworker';
export type ResponseMethodBlob = 'blob'; export type ResponseMethodBlob = 'blob';
export type ResponseMethodJson = 'json'; export type ResponseMethodJson = 'json';
@ -167,19 +173,23 @@ export class AppDownloadManager {
return this.d(fileName, () => this.managers.apiFileManager.download(options), 'blob') as any; return this.d(fileName, () => this.managers.apiFileManager.download(options), 'blob') as any;
} }
public downloadMedia(options: DownloadMediaOptions, type: DownloadType = 'blob'): DownloadBlob { public downloadMedia(options: DownloadMediaOptions, type: DownloadType = 'blob', promiseBefore?: Promise<any>): DownloadBlob {
const {downloadOptions, fileName} = getDownloadMediaDetails(options); const {downloadOptions, fileName} = getDownloadMediaDetails(options);
return this.d(fileName, () => { return this.d(fileName, () => {
let cb: any; let cb: any;
if(type === 'url') { if(type === 'url') {
cb = this.managers.apiFileManager.downloadMediaURL; cb = this.managers.apiFileManager.downloadMediaURL;
} else if(type === 'void' || type === 'disc') { } else if(type === 'void'/* || type === 'disc' */) {
cb = this.managers.apiFileManager.downloadMediaVoid; cb = this.managers.apiFileManager.downloadMediaVoid;
} else if(type === 'blob') { } else /* if(type === 'blob') */ {
cb = this.managers.apiFileManager.downloadMedia; cb = this.managers.apiFileManager.downloadMedia;
} }
if(promiseBefore) {
return promiseBefore.then(() => cb(options));
}
return cb(options); return cb(options);
}, type) as any; }, type) as any;
} }
@ -241,19 +251,23 @@ export class AppDownloadManager {
const url = `download/${id}`; const url = `download/${id}`;
options.downloadId = id; options.downloadId = id;
const promise = this.downloadMedia(options, 'disc'); const pingPromise = apiManagerProxy.pingServiceWorkerWithIframe();
const promise = this.downloadMedia(options, 'disc', pingPromise);
// this.downloadsToDisc[cacheFileName] = promise; // this.downloadsToDisc[cacheFileName] = promise;
if(justAttach) { if(justAttach) {
// * force SW to keep alive
fetch(url, {headers: {'Cache-Control': 'no-cache'}}).then((response) => response.status);
return promise; return promise;
} }
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
iframe.hidden = true; iframe.hidden = true;
pingPromise.then(() => {
iframe.src = url; iframe.src = url;
document.body.append(iframe); document.body.append(iframe);
});
// createDownloadAnchor(url, 'asd.txt'); // createDownloadAnchor(url, 'asd.txt');
// const events = [ // const events = [
@ -282,7 +296,20 @@ export class AppDownloadManager {
}; };
promise.addNotifyListener(onProgress); promise.addNotifyListener(onProgress);
promise.catch(noop).finally(() => { promise.then((blob) => {
if(!blob) {
return;
}
const url = URL.createObjectURL(blob);
const downloadOptions = isDocument ?
getDocumentDownloadOptions(media) :
getPhotoDownloadOptions(media as any, options.thumb as PhotoSize.photoSize);
const fileName = (options.media as MyDocument).file_name || getFileNameByLocation(downloadOptions.location);
createDownloadAnchor(url, downloadOptions.fileName || fileName, () => {
URL.revokeObjectURL(url);
});
}).catch(noop).finally(() => {
if(!hadProgress) { if(!hadProgress) {
onProgress(); onProgress();
} }
@ -297,30 +324,6 @@ export class AppDownloadManager {
}); });
return promise; return promise;
// } else {
// const promise = this.downloadMedia(options, 'blob');
// promise.then((blob) => {
// const url = URL.createObjectURL(blob);
// createDownloadAnchor(url, downloadOptions.fileName || fileName, () => {
// URL.revokeObjectURL(url);
// });
// });
// return promise;
// }
// const promise = this.downloadMedia(options);
// promise.then((blob) => {
// const url = URL.createObjectURL(blob);
// const downloadOptions = isDocument ?
// getDocumentDownloadOptions(media) :
// getPhotoDownloadOptions(media as any, options.thumb);
// const fileName = (options.media as Document.document).file_name || getFileNameByLocation(downloadOptions.location);
// createDownloadAnchor(url, fileName, () => {
// URL.revokeObjectURL(url);
// });
// }, noop);
// return promise;
} }
} }

1
src/lib/files/downloadStorage.ts

@ -10,7 +10,6 @@ import fileNameRFC from '../../helpers/string/fileNameRFC';
import {getServiceMessagePort} from '../mtproto/mtproto.worker'; import {getServiceMessagePort} from '../mtproto/mtproto.worker';
import DownloadWriter from './downloadWriter'; import DownloadWriter from './downloadWriter';
import FileStorage from './fileStorage'; import FileStorage from './fileStorage';
import StreamWriter from './streamWriter';
export default class DownloadStorage implements FileStorage { export default class DownloadStorage implements FileStorage {
public getFile(fileName: string): Promise<any> { public getFile(fileName: string): Promise<any> {

8
src/lib/mtproto/apiFileManager.ts

@ -41,6 +41,7 @@ import DownloadStorage from '../files/downloadStorage';
import copy from '../../helpers/object/copy'; import copy from '../../helpers/object/copy';
import indexOfAndSplice from '../../helpers/array/indexOfAndSplice'; import indexOfAndSplice from '../../helpers/array/indexOfAndSplice';
import {MIME_TYPE_EXTENSION_MAP} from '../../environment/mimeTypeMap'; import {MIME_TYPE_EXTENSION_MAP} from '../../environment/mimeTypeMap';
import {getServiceMessagePort} from './mtproto.worker';
type Delayed = { type Delayed = {
offset: number, offset: number,
@ -465,7 +466,12 @@ export class ApiFileManager extends AppManager {
public download(options: DownloadOptions): DownloadPromise { public download(options: DownloadOptions): DownloadPromise {
const size = options.size ?? 0; const size = options.size ?? 0;
const {dcId, location, downloadId} = options; const {dcId, location} = options;
let {downloadId} = options;
if(downloadId && !getServiceMessagePort()) {
this.log.error('download fallback to blob', options);
downloadId = undefined;
}
const originalMimeType = options.mimeType; const originalMimeType = options.mimeType;
const convertMethod = this.getConvertMethod(originalMimeType); const convertMethod = this.getConvertMethod(originalMimeType);

31
src/lib/mtproto/mtprotoworker.ts

@ -28,6 +28,7 @@ import toggleStorages from '../../helpers/toggleStorages';
import idleController from '../../helpers/idleController'; import idleController from '../../helpers/idleController';
import ServiceMessagePort from '../serviceWorker/serviceMessagePort'; import ServiceMessagePort from '../serviceWorker/serviceMessagePort';
import App from '../../config/app'; import App from '../../config/app';
import deferredPromise, {CancellablePromise} from '../../helpers/cancellablePromise';
export type Mirrors = { export type Mirrors = {
state: State state: State
@ -64,6 +65,8 @@ class ApiManagerProxy extends MTProtoMessagePort {
public serviceMessagePort: ServiceMessagePort<true>; public serviceMessagePort: ServiceMessagePort<true>;
private lastServiceWorker: ServiceWorker; private lastServiceWorker: ServiceWorker;
private pingServiceWorkerPromise: CancellablePromise<void>;
constructor() { constructor() {
super(); super();
@ -199,6 +202,34 @@ class ApiManagerProxy extends MTProtoMessagePort {
// this.sendState(); // this.sendState();
} }
public pingServiceWorkerWithIframe() {
if(this.pingServiceWorkerPromise) {
return this.pingServiceWorkerPromise;
}
const promise = this.pingServiceWorkerPromise = deferredPromise<void>();
const iframe = document.createElement('iframe');
iframe.hidden = true;
const onLoad = () => {
setTimeout(() => { // ping once in 10 seconds
this.pingServiceWorkerPromise = undefined;
}, 10e3);
clearTimeout(timeout);
iframe.remove();
iframe.removeEventListener('load', onLoad);
iframe.removeEventListener('error', onLoad);
promise.resolve();
};
iframe.addEventListener('load', onLoad);
iframe.addEventListener('error', onLoad);
iframe.src = 'ping/' + (Math.random() * 0xFFFFFFFF);
document.body.append(iframe);
const timeout = window.setTimeout(onLoad, 1e3);
return promise;
}
private attachServiceWorker(serviceWorker: ServiceWorker) { private attachServiceWorker(serviceWorker: ServiceWorker) {
this.lastServiceWorker && this.serviceMessagePort.detachPort(this.lastServiceWorker); this.lastServiceWorker && this.serviceMessagePort.detachPort(this.lastServiceWorker);
this.serviceMessagePort.attachSendPort(this.lastServiceWorker = serviceWorker); this.serviceMessagePort.attachSendPort(this.lastServiceWorker = serviceWorker);

3
src/lib/mtproto/schema.ts

File diff suppressed because one or more lines are too long

6
src/lib/serviceWorker/download.ts

@ -139,7 +139,7 @@ export default function handleDownload(serviceMessagePort: ServiceMessagePort<fa
} }
function onDownloadFetch(event: FetchEvent, params: string) { function onDownloadFetch(event: FetchEvent, params: string) {
event.respondWith(pause(100).then(() => { const promise = pause(100).then(() => {
const item = downloadMap.get(params); const item = downloadMap.get(params);
if(!item || (item.used && !DOWNLOAD_TEST)) { if(!item || (item.used && !DOWNLOAD_TEST)) {
return; return;
@ -149,9 +149,9 @@ function onDownloadFetch(event: FetchEvent, params: string) {
const stream = item.readableStream; const stream = item.readableStream;
const response = new Response(stream, {headers: item.headers}); const response = new Response(stream, {headers: item.headers});
return response; return response;
})); });
// event.respondWith(response); event.respondWith(promise);
} }
function cancelAllDownloads() { function cancelAllDownloads() {

5
src/lib/serviceWorker/index.service.ts

@ -132,6 +132,11 @@ const onFetch = (event: FetchEvent): void => {
onDownloadFetch(event, params); onDownloadFetch(event, params);
break; break;
} }
case 'ping': {
event.respondWith(new Response('pong'));
break;
}
} }
} catch(err) { } catch(err) {
log.error('fetch error', err); log.error('fetch error', err);

4
src/scripts/in/schema.json

File diff suppressed because one or more lines are too long

2
src/scripts/out/schema.json

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save