@mtcute/core 0.25.8 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/client.cjs +18 -12
  2. package/client.js +21 -15
  3. package/highlevel/client.d.cts +78 -72
  4. package/highlevel/client.d.ts +78 -72
  5. package/highlevel/methods/forums/toggle-forum.cjs +0 -10
  6. package/highlevel/methods/forums/toggle-forum.d.cts +0 -10
  7. package/highlevel/methods/forums/toggle-forum.d.ts +0 -10
  8. package/highlevel/methods/forums/toggle-forum.js +0 -10
  9. package/highlevel/methods/premium/get-resale-star-gifts.cjs +0 -4
  10. package/highlevel/methods/premium/get-resale-star-gifts.d.cts +0 -6
  11. package/highlevel/methods/premium/get-resale-star-gifts.d.ts +0 -6
  12. package/highlevel/methods/premium/get-resale-star-gifts.js +0 -4
  13. package/highlevel/methods/premium/get-saved-star-gifts.cjs +2 -1
  14. package/highlevel/methods/premium/get-saved-star-gifts.d.cts +4 -2
  15. package/highlevel/methods/premium/get-saved-star-gifts.d.ts +4 -2
  16. package/highlevel/methods/premium/get-saved-star-gifts.js +2 -1
  17. package/highlevel/methods/{auth/run.cjs → premium/get-star-gift-value.cjs} +8 -5
  18. package/highlevel/methods/premium/get-star-gift-value.d.cts +9 -0
  19. package/highlevel/methods/premium/get-star-gift-value.d.ts +9 -0
  20. package/highlevel/methods/premium/get-star-gift-value.js +11 -0
  21. package/highlevel/methods/premium/get-stars-transactions.cjs +3 -2
  22. package/highlevel/methods/premium/get-stars-transactions.d.cts +2 -0
  23. package/highlevel/methods/premium/get-stars-transactions.d.ts +2 -0
  24. package/highlevel/methods/premium/get-stars-transactions.js +3 -2
  25. package/highlevel/methods/premium/iter-saved-star-gifts.cjs +15 -10
  26. package/highlevel/methods/premium/iter-saved-star-gifts.d.cts +13 -19
  27. package/highlevel/methods/premium/iter-saved-star-gifts.d.ts +13 -19
  28. package/highlevel/methods/premium/iter-saved-star-gifts.js +15 -10
  29. package/highlevel/methods/premium/prepay-star-gift-upgrade.cjs +30 -0
  30. package/highlevel/methods/premium/prepay-star-gift-upgrade.d.cts +23 -0
  31. package/highlevel/methods/premium/prepay-star-gift-upgrade.d.ts +23 -0
  32. package/highlevel/methods/premium/prepay-star-gift-upgrade.js +25 -0
  33. package/highlevel/methods/stickers/delete-sticker-from-set.d.cts +2 -4
  34. package/highlevel/methods/stickers/delete-sticker-from-set.d.ts +2 -4
  35. package/highlevel/methods/stickers/move-sticker-in-set.d.cts +2 -4
  36. package/highlevel/methods/stickers/move-sticker-in-set.d.ts +2 -4
  37. package/highlevel/methods/stickers/replace-sticker-in-set.d.cts +2 -4
  38. package/highlevel/methods/stickers/replace-sticker-in-set.d.ts +2 -4
  39. package/highlevel/methods/users/get-saved-music.cjs +38 -0
  40. package/highlevel/methods/users/get-saved-music.d.cts +13 -0
  41. package/highlevel/methods/users/get-saved-music.d.ts +13 -0
  42. package/highlevel/methods/users/get-saved-music.js +33 -0
  43. package/highlevel/methods/users/save-music-to-profile.cjs +57 -0
  44. package/highlevel/methods/users/save-music-to-profile.d.cts +19 -0
  45. package/highlevel/methods/users/save-music-to-profile.d.ts +19 -0
  46. package/highlevel/methods/users/save-music-to-profile.js +52 -0
  47. package/highlevel/methods/users/set-emoji-status.cjs +0 -8
  48. package/highlevel/methods/users/set-emoji-status.d.cts +0 -11
  49. package/highlevel/methods/users/set-emoji-status.d.ts +0 -11
  50. package/highlevel/methods/users/set-emoji-status.js +1 -9
  51. package/highlevel/methods.d.cts +5 -4
  52. package/highlevel/methods.d.ts +5 -4
  53. package/highlevel/storage/service/current-user.cjs +5 -4
  54. package/highlevel/storage/service/current-user.js +5 -4
  55. package/highlevel/types/files/utils.d.cts +7 -0
  56. package/highlevel/types/files/utils.d.ts +7 -0
  57. package/highlevel/types/media/document.d.cts +1 -1
  58. package/highlevel/types/media/document.d.ts +1 -1
  59. package/highlevel/types/messages/message-action.cjs +43 -21
  60. package/highlevel/types/messages/message-action.d.cts +58 -17
  61. package/highlevel/types/messages/message-action.d.ts +58 -17
  62. package/highlevel/types/messages/message-action.js +43 -21
  63. package/highlevel/types/peers/full-user.cjs +10 -1
  64. package/highlevel/types/peers/full-user.d.cts +3 -0
  65. package/highlevel/types/peers/full-user.d.ts +3 -0
  66. package/highlevel/types/peers/full-user.js +10 -1
  67. package/highlevel/types/premium/index.d.cts +1 -0
  68. package/highlevel/types/premium/index.d.ts +1 -0
  69. package/highlevel/types/premium/saved-star-gift.cjs +6 -0
  70. package/highlevel/types/premium/saved-star-gift.d.cts +4 -0
  71. package/highlevel/types/premium/saved-star-gift.d.ts +4 -0
  72. package/highlevel/types/premium/saved-star-gift.js +6 -0
  73. package/highlevel/types/premium/star-gift-value.cjs +65 -0
  74. package/highlevel/types/premium/star-gift-value.d.cts +41 -0
  75. package/highlevel/types/premium/star-gift-value.d.ts +41 -0
  76. package/highlevel/types/premium/star-gift-value.js +60 -0
  77. package/highlevel/types/premium/stars-gift-unique.cjs +10 -3
  78. package/highlevel/types/premium/stars-gift-unique.d.cts +1 -1
  79. package/highlevel/types/premium/stars-gift-unique.d.ts +1 -1
  80. package/highlevel/types/premium/stars-gift-unique.js +10 -3
  81. package/highlevel/types/premium/stars-transaction.cjs +9 -0
  82. package/highlevel/types/premium/stars-transaction.d.cts +10 -0
  83. package/highlevel/types/premium/stars-transaction.d.ts +10 -0
  84. package/highlevel/types/premium/stars-transaction.js +9 -0
  85. package/index.cjs +2 -0
  86. package/index.js +2 -0
  87. package/methods.cjs +9 -5
  88. package/methods.js +12 -8
  89. package/network/network-manager.cjs +1 -1
  90. package/network/network-manager.js +1 -1
  91. package/package.json +2 -2
  92. package/utils/binary/compat.cjs +35 -4
  93. package/utils/binary/compat.js +35 -4
  94. package/highlevel/methods/auth/run.d.cts +0 -16
  95. package/highlevel/methods/auth/run.d.ts +0 -16
  96. package/highlevel/methods/auth/run.js +0 -8
@@ -1,27 +1,21 @@
1
1
  import { ITelegramClient } from '../../client.types.js';
2
- import { InputPeerLike } from '../../types/index.js';
2
+ import { getSavedStarGifts } from './get-saved-star-gifts.js';
3
3
  import { SavedStarGift } from '../../types/premium/saved-star-gift.js';
4
4
  /**
5
5
  * Iterate over saved star gifts of a user,
6
6
  * wrapper over {@link getSavedStarGifts}
7
7
  */
8
- export declare function iterSavedStarGifts(client: ITelegramClient, params: {
9
- /** Peer to get saved gifts from */
10
- owner: InputPeerLike;
11
- /** Whether to exclude unsaved gifts */
12
- excludeUnsaved?: boolean;
13
- /** Whether to exclude saved gifts */
14
- excludeSaved?: boolean;
15
- /** Whether to exclude gifts with unlimited availability */
16
- excludeUnlimited?: boolean;
17
- /** Whether to exclude gifts with limited availability */
18
- excludeLimited?: boolean;
19
- /** Whether to exclude unique gifts */
20
- excludeUnique?: boolean;
21
- /** Whether to sort by value */
22
- sortByValue?: boolean;
23
- /** Offset for pagination */
24
- offset?: string;
25
- /** Limit for pagination */
8
+ export declare function iterSavedStarGifts(client: ITelegramClient, params: Parameters<typeof getSavedStarGifts>[1] & {
9
+ /**
10
+ * Number of gifts to fetch per request
11
+ *
12
+ * @default 100
13
+ */
14
+ chunkSize?: number;
15
+ /**
16
+ * Total number of gifts to fetch
17
+ *
18
+ * @default Infinity
19
+ */
26
20
  limit?: number;
27
21
  }): AsyncIterableIterator<SavedStarGift>;
@@ -2,25 +2,30 @@ import { SavedStarGift as SavedStarGift$2 } from "../../types/premium/saved-star
2
2
  import { resolvePeer } from "../users/resolve-peer.js";
3
3
  import { PeersIndex } from "../../types/peers/peers-index.js";
4
4
  async function* iterSavedStarGifts(client, params) {
5
- const owner = await resolvePeer(client, params.owner);
6
- let offset = "";
5
+ const {
6
+ owner,
7
+ offset: offsetInitial = "",
8
+ chunkSize = 100,
9
+ limit = Infinity,
10
+ ...rest
11
+ } = params;
12
+ const ownerPeer = await resolvePeer(client, owner);
13
+ let offset = offsetInitial;
14
+ let current = 0;
7
15
  while (true) {
8
16
  const res = await client.call({
9
17
  _: "payments.getSavedStarGifts",
10
- peer: owner,
11
- excludeUnsaved: params.excludeUnsaved,
12
- excludeSaved: params.excludeSaved,
13
- excludeUnlimited: params.excludeUnlimited,
14
- excludeLimited: params.excludeLimited,
15
- excludeUnique: params.excludeUnique,
16
- sortByValue: params.sortByValue,
18
+ peer: ownerPeer,
17
19
  offset,
18
- limit: params.limit ?? 100
20
+ limit: Math.min(chunkSize, limit - current),
21
+ ...rest
19
22
  });
20
23
  const peers = PeersIndex.from(res);
21
24
  yield* res.gifts.map((it) => new SavedStarGift$2(it, peers));
22
25
  if (!res.nextOffset) break;
23
26
  offset = res.nextOffset;
27
+ current += res.gifts.length;
28
+ if (current >= limit) break;
24
29
  }
25
30
  }
26
31
  export {
@@ -0,0 +1,30 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const typeAssertions = require("../../../utils/type-assertions.cjs");
9
+ const findInUpdate = require("../messages/find-in-update.cjs");
10
+ const resolvePeer = require("../users/resolve-peer.cjs");
11
+ async function prepayStarGiftUpgrade(client, params) {
12
+ const { peer, hash, shouldDispatch } = params;
13
+ const invoice = {
14
+ _: "inputInvoiceStarGiftPrepaidUpgrade",
15
+ peer: await resolvePeer.resolvePeer(client, peer),
16
+ hash
17
+ };
18
+ const form = await client.call({
19
+ _: "payments.getPaymentForm",
20
+ invoice
21
+ });
22
+ const res = await client.call({
23
+ _: "payments.sendStarsForm",
24
+ invoice,
25
+ formId: form.formId
26
+ });
27
+ typeAssertions.assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
28
+ return findInUpdate._findMessageInUpdate(client, res.updates, false, !shouldDispatch, true);
29
+ }
30
+ exports.prepayStarGiftUpgrade = prepayStarGiftUpgrade;
@@ -0,0 +1,23 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputPeerLike } from '../../types/index.js';
3
+ import { Message } from '../../types/messages/message.js';
4
+ /**
5
+ * Pay for other user's star gift upgrade.
6
+ *
7
+ * > **Note**: this method is not indended to be used by full-fledged clients,
8
+ * > as this method hides the actual invoice and payment form from the user.
9
+ * > For GUI clients, you should refer to the method's source code and
10
+ * > present the payment form to the user.
11
+ *
12
+ * @returns Service message about the payment for the upgrade, if one was generated.
13
+ */
14
+ export declare function prepayStarGiftUpgrade(client: ITelegramClient, params: {
15
+ peer: InputPeerLike;
16
+ /** Prepaid upgrade hash, taken from `SavedStarGift.prepaidUpgradeHash` */
17
+ hash: string;
18
+ /**
19
+ * Whether to dispatch the new message event
20
+ * to the client's update handler.
21
+ */
22
+ shouldDispatch?: true;
23
+ }): Promise<Message | null>;
@@ -0,0 +1,23 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputPeerLike } from '../../types/index.js';
3
+ import { Message } from '../../types/messages/message.js';
4
+ /**
5
+ * Pay for other user's star gift upgrade.
6
+ *
7
+ * > **Note**: this method is not indended to be used by full-fledged clients,
8
+ * > as this method hides the actual invoice and payment form from the user.
9
+ * > For GUI clients, you should refer to the method's source code and
10
+ * > present the payment form to the user.
11
+ *
12
+ * @returns Service message about the payment for the upgrade, if one was generated.
13
+ */
14
+ export declare function prepayStarGiftUpgrade(client: ITelegramClient, params: {
15
+ peer: InputPeerLike;
16
+ /** Prepaid upgrade hash, taken from `SavedStarGift.prepaidUpgradeHash` */
17
+ hash: string;
18
+ /**
19
+ * Whether to dispatch the new message event
20
+ * to the client's update handler.
21
+ */
22
+ shouldDispatch?: true;
23
+ }): Promise<Message | null>;
@@ -0,0 +1,25 @@
1
+ import { assertTypeIs } from "../../../utils/type-assertions.js";
2
+ import { _findMessageInUpdate } from "../messages/find-in-update.js";
3
+ import { resolvePeer } from "../users/resolve-peer.js";
4
+ async function prepayStarGiftUpgrade(client, params) {
5
+ const { peer, hash, shouldDispatch } = params;
6
+ const invoice = {
7
+ _: "inputInvoiceStarGiftPrepaidUpgrade",
8
+ peer: await resolvePeer(client, peer),
9
+ hash
10
+ };
11
+ const form = await client.call({
12
+ _: "payments.getPaymentForm",
13
+ invoice
14
+ });
15
+ const res = await client.call({
16
+ _: "payments.sendStarsForm",
17
+ invoice,
18
+ formId: form.formId
19
+ });
20
+ assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
21
+ return _findMessageInUpdate(client, res.updates, false, !shouldDispatch, true);
22
+ }
23
+ export {
24
+ prepayStarGiftUpgrade
25
+ };
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Delete a sticker from a sticker set
7
5
  *
@@ -12,4 +10,4 @@ import { StickerSet } from '../../types/index.js';
12
10
  * TL object representing a sticker to be removed
13
11
  * @returns Modfiied sticker set
14
12
  */
15
- export declare function deleteStickerFromSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument): Promise<StickerSet>;
13
+ export declare function deleteStickerFromSet(client: ITelegramClient, sticker: InputDocumentId): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Delete a sticker from a sticker set
7
5
  *
@@ -12,4 +10,4 @@ import { StickerSet } from '../../types/index.js';
12
10
  * TL object representing a sticker to be removed
13
11
  * @returns Modfiied sticker set
14
12
  */
15
- export declare function deleteStickerFromSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument): Promise<StickerSet>;
13
+ export declare function deleteStickerFromSet(client: ITelegramClient, sticker: InputDocumentId): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Move a sticker in a sticker set
7
5
  * to another position
@@ -14,4 +12,4 @@ import { StickerSet } from '../../types/index.js';
14
12
  * @param position New sticker position (starting from 0)
15
13
  * @returns Modified sticker set
16
14
  */
17
- export declare function moveStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, position: number): Promise<StickerSet>;
15
+ export declare function moveStickerInSet(client: ITelegramClient, sticker: InputDocumentId, position: number): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { tdFileId } from '@mtcute/file-id';
4
- import { StickerSet } from '../../types/index.js';
2
+ import { InputDocumentId, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Move a sticker in a sticker set
7
5
  * to another position
@@ -14,4 +12,4 @@ import { StickerSet } from '../../types/index.js';
14
12
  * @param position New sticker position (starting from 0)
15
13
  * @returns Modified sticker set
16
14
  */
17
- export declare function moveStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, position: number): Promise<StickerSet>;
15
+ export declare function moveStickerInSet(client: ITelegramClient, sticker: InputDocumentId, position: number): Promise<StickerSet>;
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { InputStickerSetItem, StickerSet } from '../../types/index.js';
4
- import { tdFileId } from '@mtcute/file-id';
2
+ import { InputDocumentId, InputStickerSetItem, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Replace a sticker in a sticker set with another sticker
7
5
  *
@@ -13,7 +11,7 @@ import { tdFileId } from '@mtcute/file-id';
13
11
  * @param newSticker New sticker to replace the old one with
14
12
  * @returns Modfiied sticker set
15
13
  */
16
- export declare function replaceStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, newSticker: InputStickerSetItem, params?: {
14
+ export declare function replaceStickerInSet(client: ITelegramClient, sticker: InputDocumentId, newSticker: InputStickerSetItem, params?: {
17
15
  /**
18
16
  * Upload progress callback
19
17
  *
@@ -1,7 +1,5 @@
1
- import { tl } from '@mtcute/tl';
2
1
  import { ITelegramClient } from '../../client.types.js';
3
- import { InputStickerSetItem, StickerSet } from '../../types/index.js';
4
- import { tdFileId } from '@mtcute/file-id';
2
+ import { InputDocumentId, InputStickerSetItem, StickerSet } from '../../types/index.js';
5
3
  /**
6
4
  * Replace a sticker in a sticker set with another sticker
7
5
  *
@@ -13,7 +11,7 @@ import { tdFileId } from '@mtcute/file-id';
13
11
  * @param newSticker New sticker to replace the old one with
14
12
  * @returns Modfiied sticker set
15
13
  */
16
- export declare function replaceStickerInSet(client: ITelegramClient, sticker: string | tdFileId.RawFullRemoteFileLocation | tl.TypeInputDocument, newSticker: InputStickerSetItem, params?: {
14
+ export declare function replaceStickerInSet(client: ITelegramClient, sticker: InputDocumentId, newSticker: InputStickerSetItem, params?: {
17
15
  /**
18
16
  * Upload progress callback
19
17
  *
@@ -0,0 +1,38 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const utils = require("@fuman/utils");
9
+ const Long = require("long");
10
+ const typeAssertions = require("../../../utils/type-assertions.cjs");
11
+ const documentUtils = require("../../types/media/document-utils.cjs");
12
+ const resolvePeer = require("./resolve-peer.cjs");
13
+ const miscUtils = require("../../utils/misc-utils.cjs");
14
+ async function getSavedMusic(client, params) {
15
+ const res = await client.call({
16
+ _: "users.getSavedMusic",
17
+ id: await resolvePeer.resolveUser(client, params.userId),
18
+ offset: params.offset ?? 0,
19
+ limit: params.limit ?? 100,
20
+ hash: Long.ZERO
21
+ });
22
+ typeAssertions.assertTypeIsNot("getSavedMusic", res, "users.savedMusicNotModified");
23
+ const files = [];
24
+ for (const file of res.documents) {
25
+ typeAssertions.assertTypeIs("getSavedMusic", file, "document");
26
+ const doc = documentUtils.parseDocument(file);
27
+ utils.assert(doc.type === "audio");
28
+ files.push(doc);
29
+ }
30
+ let nextOffset = (params.offset ?? 0) + files.length;
31
+ if (nextOffset >= res.count) nextOffset = void 0;
32
+ return miscUtils.makeArrayPaginated(
33
+ files,
34
+ res.count ?? files.length,
35
+ nextOffset
36
+ );
37
+ }
38
+ exports.getSavedMusic = getSavedMusic;
@@ -0,0 +1,13 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { ArrayPaginated, Audio, InputPeerLike } from '../../types/index.js';
3
+ /**
4
+ * Get music files saved to the user's profile
5
+ */
6
+ export declare function getSavedMusic(client: ITelegramClient, params: {
7
+ /** User ID, username, phone number, `"me"` or `"self"` */
8
+ userId: InputPeerLike;
9
+ /** Offset for pagination */
10
+ offset?: number;
11
+ /** Limit for pagination */
12
+ limit?: number;
13
+ }): Promise<ArrayPaginated<Audio, number>>;
@@ -0,0 +1,13 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { ArrayPaginated, Audio, InputPeerLike } from '../../types/index.js';
3
+ /**
4
+ * Get music files saved to the user's profile
5
+ */
6
+ export declare function getSavedMusic(client: ITelegramClient, params: {
7
+ /** User ID, username, phone number, `"me"` or `"self"` */
8
+ userId: InputPeerLike;
9
+ /** Offset for pagination */
10
+ offset?: number;
11
+ /** Limit for pagination */
12
+ limit?: number;
13
+ }): Promise<ArrayPaginated<Audio, number>>;
@@ -0,0 +1,33 @@
1
+ import { assert } from "@fuman/utils";
2
+ import Long from "long";
3
+ import { assertTypeIsNot, assertTypeIs } from "../../../utils/type-assertions.js";
4
+ import { parseDocument } from "../../types/media/document-utils.js";
5
+ import { resolveUser } from "./resolve-peer.js";
6
+ import { makeArrayPaginated } from "../../utils/misc-utils.js";
7
+ async function getSavedMusic(client, params) {
8
+ const res = await client.call({
9
+ _: "users.getSavedMusic",
10
+ id: await resolveUser(client, params.userId),
11
+ offset: params.offset ?? 0,
12
+ limit: params.limit ?? 100,
13
+ hash: Long.ZERO
14
+ });
15
+ assertTypeIsNot("getSavedMusic", res, "users.savedMusicNotModified");
16
+ const files = [];
17
+ for (const file of res.documents) {
18
+ assertTypeIs("getSavedMusic", file, "document");
19
+ const doc = parseDocument(file);
20
+ assert(doc.type === "audio");
21
+ files.push(doc);
22
+ }
23
+ let nextOffset = (params.offset ?? 0) + files.length;
24
+ if (nextOffset >= res.count) nextOffset = void 0;
25
+ return makeArrayPaginated(
26
+ files,
27
+ res.count ?? files.length,
28
+ nextOffset
29
+ );
30
+ }
31
+ export {
32
+ getSavedMusic
33
+ };
@@ -0,0 +1,57 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const utils = require("@fuman/utils");
9
+ const fileId = require("@mtcute/file-id");
10
+ const tl = require("@mtcute/tl");
11
+ const typeAssertions = require("../../../utils/type-assertions.cjs");
12
+ const convertFileId = require("../../utils/convert-file-id.cjs");
13
+ const normalizeInputMedia = require("../files/normalize-input-media.cjs");
14
+ async function saveMusicToProfile(client, params) {
15
+ let after = params.after;
16
+ if (fileId.tdFileId.isFileIdLike(after)) {
17
+ after = convertFileId.fileIdToInputDocument(after);
18
+ }
19
+ let audio = params.audio;
20
+ if (fileId.tdFileId.isFileIdLike(audio)) {
21
+ audio = {
22
+ type: "audio",
23
+ file: audio
24
+ };
25
+ }
26
+ let audioId;
27
+ if (tl.tl.isAnyInputDocument(audio)) {
28
+ audioId = audio;
29
+ } else {
30
+ const media = await normalizeInputMedia._normalizeInputMedia(client, audio, {
31
+ progressCallback: params.progressCallback,
32
+ uploadPeer: { _: "inputPeerSelf" }
33
+ }, true);
34
+ utils.assert(media._ === "inputMediaDocument");
35
+ audioId = media.id;
36
+ }
37
+ const res = await client.call({
38
+ _: "account.saveMusic",
39
+ id: audioId,
40
+ afterId: after
41
+ });
42
+ typeAssertions.assertTrue("account.saveMusic", res);
43
+ }
44
+ async function unsaveMusicFromProfile(client, params) {
45
+ let audio = params.audio;
46
+ if (fileId.tdFileId.isFileIdLike(audio)) {
47
+ audio = convertFileId.fileIdToInputDocument(audio);
48
+ }
49
+ const res = await client.call({
50
+ _: "account.saveMusic",
51
+ id: audio,
52
+ unsave: true
53
+ });
54
+ typeAssertions.assertTrue("account.saveMusic", res);
55
+ }
56
+ exports.saveMusicToProfile = saveMusicToProfile;
57
+ exports.unsaveMusicFromProfile = unsaveMusicFromProfile;
@@ -0,0 +1,19 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputDocumentId, InputMediaAudio } from '../../types/index.js';
3
+ export declare function saveMusicToProfile(client: ITelegramClient, params: {
4
+ /** Audio file to save (or its ID) */
5
+ audio: InputMediaAudio | InputDocumentId;
6
+ /** Optionally, document ID after which we should insert the music */
7
+ after?: InputDocumentId;
8
+ /**
9
+ * Upload progress callback
10
+ *
11
+ * @param uploaded Number of bytes uploaded
12
+ * @param total Total file size
13
+ */
14
+ progressCallback?: (uploaded: number, total: number) => void;
15
+ }): Promise<void>;
16
+ export declare function unsaveMusicFromProfile(client: ITelegramClient, params: {
17
+ /** ID of the Audio file to unsave */
18
+ audio: InputDocumentId;
19
+ }): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { ITelegramClient } from '../../client.types.js';
2
+ import { InputDocumentId, InputMediaAudio } from '../../types/index.js';
3
+ export declare function saveMusicToProfile(client: ITelegramClient, params: {
4
+ /** Audio file to save (or its ID) */
5
+ audio: InputMediaAudio | InputDocumentId;
6
+ /** Optionally, document ID after which we should insert the music */
7
+ after?: InputDocumentId;
8
+ /**
9
+ * Upload progress callback
10
+ *
11
+ * @param uploaded Number of bytes uploaded
12
+ * @param total Total file size
13
+ */
14
+ progressCallback?: (uploaded: number, total: number) => void;
15
+ }): Promise<void>;
16
+ export declare function unsaveMusicFromProfile(client: ITelegramClient, params: {
17
+ /** ID of the Audio file to unsave */
18
+ audio: InputDocumentId;
19
+ }): Promise<void>;
@@ -0,0 +1,52 @@
1
+ import { assert } from "@fuman/utils";
2
+ import { tdFileId } from "@mtcute/file-id";
3
+ import { tl } from "@mtcute/tl";
4
+ import { assertTrue } from "../../../utils/type-assertions.js";
5
+ import { fileIdToInputDocument } from "../../utils/convert-file-id.js";
6
+ import { _normalizeInputMedia } from "../files/normalize-input-media.js";
7
+ async function saveMusicToProfile(client, params) {
8
+ let after = params.after;
9
+ if (tdFileId.isFileIdLike(after)) {
10
+ after = fileIdToInputDocument(after);
11
+ }
12
+ let audio = params.audio;
13
+ if (tdFileId.isFileIdLike(audio)) {
14
+ audio = {
15
+ type: "audio",
16
+ file: audio
17
+ };
18
+ }
19
+ let audioId;
20
+ if (tl.isAnyInputDocument(audio)) {
21
+ audioId = audio;
22
+ } else {
23
+ const media = await _normalizeInputMedia(client, audio, {
24
+ progressCallback: params.progressCallback,
25
+ uploadPeer: { _: "inputPeerSelf" }
26
+ }, true);
27
+ assert(media._ === "inputMediaDocument");
28
+ audioId = media.id;
29
+ }
30
+ const res = await client.call({
31
+ _: "account.saveMusic",
32
+ id: audioId,
33
+ afterId: after
34
+ });
35
+ assertTrue("account.saveMusic", res);
36
+ }
37
+ async function unsaveMusicFromProfile(client, params) {
38
+ let audio = params.audio;
39
+ if (tdFileId.isFileIdLike(audio)) {
40
+ audio = fileIdToInputDocument(audio);
41
+ }
42
+ const res = await client.call({
43
+ _: "account.saveMusic",
44
+ id: audio,
45
+ unsave: true
46
+ });
47
+ assertTrue("account.saveMusic", res);
48
+ }
49
+ export {
50
+ saveMusicToProfile,
51
+ unsaveMusicFromProfile
52
+ };
@@ -11,13 +11,6 @@ const utils = require("../auth/utils.cjs");
11
11
  const resolvePeer = require("./resolve-peer.cjs");
12
12
  const miscUtils = require("../../utils/misc-utils.cjs");
13
13
  const peerUtils = require("../../utils/peer-utils.cjs");
14
- async function setMyEmojiStatus(client, emoji, params) {
15
- return setEmojiStatus(client, {
16
- peerId: "self",
17
- emoji,
18
- until: params?.until
19
- });
20
- }
21
14
  async function setEmojiStatus(client, params) {
22
15
  const {
23
16
  peerId,
@@ -72,4 +65,3 @@ async function setEmojiStatus(client, params) {
72
65
  }
73
66
  }
74
67
  exports.setEmojiStatus = setEmojiStatus;
75
- exports.setMyEmojiStatus = setMyEmojiStatus;
@@ -1,17 +1,6 @@
1
1
  import { tl } from '@mtcute/tl';
2
2
  import { ITelegramClient } from '../../client.types.js';
3
3
  import { InputPeerLike } from '../../types/peers/peer.js';
4
- /**
5
- * Set an emoji status for the current user
6
- *
7
- * @deprecated – use {@link setEmojiStatus} with `self` instead
8
- */
9
- export declare function setMyEmojiStatus(client: ITelegramClient, emoji: tl.Long | null, params?: {
10
- /**
11
- * Date when the emoji status should expire (only if `emoji` is not `null`)
12
- */
13
- until?: number | Date;
14
- }): Promise<void>;
15
4
  /**
16
5
  * Set an emoji status for the given user/chat
17
6
  *
@@ -1,17 +1,6 @@
1
1
  import { tl } from '@mtcute/tl';
2
2
  import { ITelegramClient } from '../../client.types.js';
3
3
  import { InputPeerLike } from '../../types/peers/peer.js';
4
- /**
5
- * Set an emoji status for the current user
6
- *
7
- * @deprecated – use {@link setEmojiStatus} with `self` instead
8
- */
9
- export declare function setMyEmojiStatus(client: ITelegramClient, emoji: tl.Long | null, params?: {
10
- /**
11
- * Date when the emoji status should expire (only if `emoji` is not `null`)
12
- */
13
- until?: number | Date;
14
- }): Promise<void>;
15
4
  /**
16
5
  * Set an emoji status for the given user/chat
17
6
  *
@@ -4,13 +4,6 @@ import { isSelfPeer } from "../auth/utils.js";
4
4
  import { resolvePeer } from "./resolve-peer.js";
5
5
  import { normalizeDate } from "../../utils/misc-utils.js";
6
6
  import { isInputPeerChannel, toInputChannel, isInputPeerUser, toInputUser } from "../../utils/peer-utils.js";
7
- async function setMyEmojiStatus(client, emoji, params) {
8
- return setEmojiStatus(client, {
9
- peerId: "self",
10
- emoji,
11
- until: params?.until
12
- });
13
- }
14
7
  async function setEmojiStatus(client, params) {
15
8
  const {
16
9
  peerId,
@@ -65,6 +58,5 @@ async function setEmojiStatus(client, params) {
65
58
  }
66
59
  }
67
60
  export {
68
- setEmojiStatus,
69
- setMyEmojiStatus
61
+ setEmojiStatus
70
62
  };