@mtcute/core 0.16.14 → 0.17.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.
@@ -8,7 +8,7 @@ const platform = require("./j7rWn_1y.js");
8
8
  const tl = require("@mtcute/tl");
9
9
  const conditionVariable = require("./eX3zeDAz.js");
10
10
  const controllablePromise = require("./CZAB54t2.js");
11
- const storyViewer = require("./chPq0GcA.js");
11
+ const storyViewer = require("./CSfUPcui.js");
12
12
  const Long = require("long");
13
13
  const peersIndex = require("./ija5tZ1t.js");
14
14
  const fileId = require("@mtcute/file-id");
@@ -1987,16 +1987,15 @@ async function findDialogs(client, peers) {
1987
1987
  foundInputPeers.push(resolvedPeer);
1988
1988
  foundIdxToOriginalIdx.set(foundInputPeers.length - 1, i);
1989
1989
  }
1990
- if (foundInputPeers.length === 0) {
1991
- throw new controllablePromise.MtPeerNotFoundError(`Could not find dialogs with peers: ${peers.join(", ")}`);
1992
- }
1993
- const dialogs = await storyViewer.getPeerDialogs(client, foundInputPeers);
1994
- if (foundInputPeers.length === peers.length) {
1995
- return dialogs;
1996
- }
1997
1990
  const ret = Array.from({ length: peers.length });
1998
- for (const [idx, origIdx] of foundIdxToOriginalIdx) {
1999
- ret[origIdx] = dialogs[idx];
1991
+ if (foundInputPeers.length !== 0) {
1992
+ const dialogs = await storyViewer.getPeerDialogs(client, foundInputPeers);
1993
+ if (foundInputPeers.length === peers.length) {
1994
+ return dialogs;
1995
+ }
1996
+ for (const [idx, origIdx] of foundIdxToOriginalIdx) {
1997
+ ret[origIdx] = dialogs[idx];
1998
+ }
2000
1999
  }
2001
2000
  for await (const dialog of iterDialogs(client, {
2002
2001
  archived: "keep"
@@ -3861,6 +3860,23 @@ async function removeCloudPassword(client, password) {
3861
3860
  }
3862
3861
  });
3863
3862
  }
3863
+ async function acceptStarGift(client, params) {
3864
+ const { action } = params;
3865
+ const { chatId, message } = storyViewer.normalizeInputMessageId(params);
3866
+ const userId = await storyViewer.resolveUser(client, chatId);
3867
+ return client.call(
3868
+ action === "convert" ? {
3869
+ _: "payments.convertStarGift",
3870
+ userId,
3871
+ msgId: message
3872
+ } : {
3873
+ _: "payments.saveStarGift",
3874
+ unsave: action === "hide",
3875
+ userId,
3876
+ msgId: message
3877
+ }
3878
+ );
3879
+ }
3864
3880
  async function applyBoost(client, peerId) {
3865
3881
  await client.call({
3866
3882
  _: "premium.applyBoost",
@@ -3949,6 +3965,26 @@ async function getBusinessChatLinks(client) {
3949
3965
  const res = await client.call({ _: "account.getBusinessChatLinks" });
3950
3966
  return res.links.map((x) => new storyViewer.BusinessChatLink$2(x));
3951
3967
  }
3968
+ async function getStarGiftOptions(client) {
3969
+ const res = await client.call({
3970
+ _: "payments.getStarGifts",
3971
+ hash: 0
3972
+ });
3973
+ controllablePromise.assertTypeIsNot("payments.getStarGifts", res, "payments.starGiftsNotModified");
3974
+ return res.gifts.map((gift) => new storyViewer.StarGift$2(gift));
3975
+ }
3976
+ async function getStarGifts(client, userId, params) {
3977
+ const { offset = "", limit = 100 } = params ?? {};
3978
+ const res = await client.call({
3979
+ _: "payments.getUserStarGifts",
3980
+ userId: await storyViewer.resolveUser(client, userId),
3981
+ offset,
3982
+ limit
3983
+ });
3984
+ const peers = peersIndex.PeersIndex.from(res);
3985
+ const gifts = res.gifts.map((gift) => new storyViewer.UserStarGift$2(gift, peers));
3986
+ return conditionVariable.makeArrayPaginated(gifts, res.count, offset);
3987
+ }
3952
3988
  async function getStarsTransactions(client, peerId, params) {
3953
3989
  const { direction, sort, subscriptionId, offset = "", limit = 100 } = params ?? {};
3954
3990
  const res = await client.call({
@@ -3982,6 +4018,25 @@ async function* iterBoosters(client, peerId, params) {
3982
4018
  offset = res.next;
3983
4019
  }
3984
4020
  }
4021
+ async function* iterStarGifts(client, peerId, params) {
4022
+ if (!params) params = {};
4023
+ const { limit = Infinity, chunkSize = 100 } = params;
4024
+ let { offset } = params;
4025
+ let current = 0;
4026
+ const peer = await storyViewer.resolvePeer(client, peerId);
4027
+ for (; ; ) {
4028
+ const res = await getStarGifts(client, peer, {
4029
+ offset,
4030
+ limit: Math.min(limit - current, chunkSize)
4031
+ });
4032
+ for (const gift of res) {
4033
+ yield gift;
4034
+ if (++current >= limit) return;
4035
+ }
4036
+ if (!res.next) return;
4037
+ offset = res.next;
4038
+ }
4039
+ }
3985
4040
  async function* iterStarsTransactions(client, peerId, params) {
3986
4041
  if (!params) params = {};
3987
4042
  const { limit = Infinity, chunkSize = 100 } = params;
@@ -4001,6 +4056,27 @@ async function* iterStarsTransactions(client, peerId, params) {
4001
4056
  offset = res.transactionsNextOffset;
4002
4057
  }
4003
4058
  }
4059
+ async function sendStarGift(client, params) {
4060
+ const { userId, gift, anonymous, message, shouldDispatch } = params;
4061
+ const invoice = {
4062
+ _: "inputInvoiceStarGift",
4063
+ hideName: anonymous,
4064
+ userId: await storyViewer.resolveUser(client, userId),
4065
+ giftId: Long.isLong(gift) ? gift : gift.id,
4066
+ message: message ? storyViewer.inputTextToTl(message) : void 0
4067
+ };
4068
+ const form = await client.call({
4069
+ _: "payments.getPaymentForm",
4070
+ invoice
4071
+ });
4072
+ const res = await client.call({
4073
+ _: "payments.sendStarsForm",
4074
+ invoice,
4075
+ formId: form.formId
4076
+ });
4077
+ controllablePromise.assertTypeIs("payments.sendStarsForm", res, "payments.paymentResult");
4078
+ return storyViewer._findMessageInUpdate(client, res.updates, false, !shouldDispatch);
4079
+ }
4004
4080
  async function _normalizeFileToDocument(client, file, params) {
4005
4081
  if (typeof file === "object" && tl.tl.isAnyInputDocument(file)) {
4006
4082
  return file;
@@ -4101,8 +4177,6 @@ async function createStickerSet(client, params) {
4101
4177
  }
4102
4178
  const res = await client.call({
4103
4179
  _: "stickers.createStickerSet",
4104
- animated: params.sourceType === "animated",
4105
- videos: params.sourceType === "video",
4106
4180
  masks: params.type === "mask",
4107
4181
  emojis: params.type === "emoji",
4108
4182
  textColor: params.adaptive,
@@ -4455,17 +4529,6 @@ async function readStories(client, peerId, maxId) {
4455
4529
  maxId
4456
4530
  });
4457
4531
  }
4458
- async function reportStory(client, peerId, storyIds, params) {
4459
- const { reason = { _: "inputReportReasonSpam" }, message = "" } = params ?? {};
4460
- const r = await client.call({
4461
- _: "stories.report",
4462
- peer: await storyViewer.resolvePeer(client, peerId),
4463
- id: Array.isArray(storyIds) ? storyIds : [storyIds],
4464
- message,
4465
- reason
4466
- });
4467
- controllablePromise.assertTrue("stories.report", r);
4468
- }
4469
4532
  async function sendStoryReaction(client, params) {
4470
4533
  const { peerId, storyId, reaction, addToRecent } = params;
4471
4534
  const res = await client.call({
@@ -4767,6 +4830,7 @@ async function updateProfile(client, params) {
4767
4830
  return new storyViewer.User$2(res);
4768
4831
  }
4769
4832
  exports._normalizePrivacyRules = _normalizePrivacyRules;
4833
+ exports.acceptStarGift = acceptStarGift;
4770
4834
  exports.addChatMembers = addChatMembers;
4771
4835
  exports.addContact = addContact;
4772
4836
  exports.addStickerToSet = addStickerToSet;
@@ -4888,6 +4952,8 @@ exports.getReactionUsers = getReactionUsers;
4888
4952
  exports.getReplyTo = getReplyTo;
4889
4953
  exports.getScheduledMessages = getScheduledMessages;
4890
4954
  exports.getSimilarChannels = getSimilarChannels;
4955
+ exports.getStarGiftOptions = getStarGiftOptions;
4956
+ exports.getStarGifts = getStarGifts;
4891
4957
  exports.getStarsTransactions = getStarsTransactions;
4892
4958
  exports.getStickerSet = getStickerSet;
4893
4959
  exports.getStoriesById = getStoriesById;
@@ -4918,6 +4984,7 @@ exports.iterReactionUsers = iterReactionUsers;
4918
4984
  exports.iterSearchGlobal = iterSearchGlobal;
4919
4985
  exports.iterSearchHashtag = iterSearchHashtag;
4920
4986
  exports.iterSearchMessages = iterSearchMessages;
4987
+ exports.iterStarGifts = iterStarGifts;
4921
4988
  exports.iterStarsTransactions = iterStarsTransactions;
4922
4989
  exports.iterStoryViewers = iterStoryViewers;
4923
4990
  exports.joinChat = joinChat;
@@ -4942,7 +5009,6 @@ exports.replaceStickerInSet = replaceStickerInSet;
4942
5009
  exports.replyMedia = replyMedia;
4943
5010
  exports.replyMediaGroup = replyMediaGroup;
4944
5011
  exports.replyText = replyText;
4945
- exports.reportStory = reportStory;
4946
5012
  exports.resendCode = resendCode;
4947
5013
  exports.resendPasswordEmail = resendPasswordEmail;
4948
5014
  exports.restrictChatMember = restrictChatMember;
@@ -4959,6 +5025,7 @@ exports.sendPaidReaction = sendPaidReaction;
4959
5025
  exports.sendReaction = sendReaction;
4960
5026
  exports.sendRecoveryCode = sendRecoveryCode;
4961
5027
  exports.sendScheduled = sendScheduled;
5028
+ exports.sendStarGift = sendStarGift;
4962
5029
  exports.sendStory = sendStory;
4963
5030
  exports.sendStoryReaction = sendStoryReaction;
4964
5031
  exports.sendTyping = sendTyping;