Skip to content

Commit

Permalink
Merge pull request #81 from ulu-telegram/master
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
ulugmer authored Nov 16, 2023
2 parents 11655b1 + 811b02d commit 2ad1c65
Show file tree
Hide file tree
Showing 75 changed files with 2,106 additions and 591 deletions.
2 changes: 1 addition & 1 deletion .patch-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
21
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telegram-t",
"version": "10.0.18",
"version": "10.0.21",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -139,6 +139,7 @@
"@june-so/analytics-next": "^2.0.0",
"async-mutex": "^0.4.0",
"big-integer": "github:painor/BigInteger.js",
"chrono-node": "^2.7.0",
"cmdk": "^0.2.0",
"croppie": "^2.6.5",
"emoji-data-ios": "git+https://github.com/korenskoy/emoji-data-ios#2886b318eae174527c4bc9fcd321940ef3a85527",
Expand Down
2 changes: 1 addition & 1 deletion public/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.0.18
10.0.21
31 changes: 30 additions & 1 deletion src/api/gramjs/apiBuilders/messageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ApiDocument,
ApiFormattedText,
ApiGame,
ApiGiveaway,
ApiInvoice,
ApiLocation,
ApiMessageExtendedMediaPreview,
Expand Down Expand Up @@ -49,7 +50,7 @@ export function buildMessageContent(
const hasUnsupportedMedia = mtpMessage.media instanceof GramJs.MessageMediaUnsupported;

if (mtpMessage.message && !hasUnsupportedMedia
&& !content.sticker && !content.poll && !content.contact && !(content.video?.isRound)) {
&& !content.sticker && !content.poll && !content.contact && !content.video?.isRound) {
content = {
...content,
text: buildMessageTextContent(mtpMessage.message, mtpMessage.entities),
Expand Down Expand Up @@ -118,6 +119,9 @@ export function buildMessageMediaContent(media: GramJs.TypeMessageMedia): MediaC
const storyData = buildMessageStoryData(media);
if (storyData) return { storyData };

const giveaway = buildGiweawayFromMedia(media);
if (giveaway) return { giveaway };

return undefined;
}

Expand Down Expand Up @@ -466,6 +470,31 @@ function buildGame(media: GramJs.MessageMediaGame): ApiGame | undefined {
};
}

function buildGiweawayFromMedia(media: GramJs.TypeMessageMedia): ApiGiveaway | undefined {
if (!(media instanceof GramJs.MessageMediaGiveaway)) {
return undefined;
}

return buildGiveaway(media);
}

function buildGiveaway(media: GramJs.MessageMediaGiveaway): ApiGiveaway | undefined {
const {
channels, months, quantity, untilDate, countriesIso2, onlyNewSubscribers,
} = media;

const channelIds = channels.map((channel) => buildApiPeerId(channel, 'channel'));

return {
channelIds,
months,
quantity,
untilDate,
countries: countriesIso2,
isOnlyForNewSubscribers: onlyNewSubscribers,
};
}

export function buildMessageStoryData(media: GramJs.TypeMessageMedia): ApiMessageStoryData | undefined {
if (!(media instanceof GramJs.MessageMediaStory)) {
return undefined;
Expand Down
18 changes: 18 additions & 0 deletions src/api/gramjs/apiBuilders/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ function buildAction(
let months: number | undefined;
let topicEmojiIconId: string | undefined;
let isTopicAction: boolean | undefined;
let slug: string | undefined;
let isGiveaway: boolean | undefined;
let isUnclaimed: boolean | undefined;

const targetUserIds = 'users' in action
? action.users && action.users.map((id) => buildApiPeerId(id, 'user'))
Expand Down Expand Up @@ -523,6 +526,18 @@ function buildAction(
translationValues.push('%target_user%');

if (targetPeerId) targetUserIds.push(targetPeerId);
} else if (action instanceof GramJs.MessageActionGiveawayLaunch) {
text = 'BoostingGiveawayJustStarted';
translationValues.push('%action_origin%');
} else if (action instanceof GramJs.MessageActionGiftCode) {
text = 'BoostingReceivedGiftNoName';
slug = action.slug;
months = action.months;
isGiveaway = Boolean(action.viaGiveaway);
isUnclaimed = Boolean(action.unclaimed);
if (action.boostPeer) {
targetChatId = getApiChatIdFromMtpPeer(action.boostPeer);
}
} else {
text = 'ChatList.UnsupportedMessage';
}
Expand All @@ -541,13 +556,16 @@ function buildAction(
amount,
currency,
giftCryptoInfo,
isGiveaway,
slug,
translationValues,
call,
phoneCall,
score,
months,
topicEmojiIconId,
isTopicAction,
isUnclaimed,
};
}

Expand Down
99 changes: 97 additions & 2 deletions src/api/gramjs/apiBuilders/payments.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { Api as GramJs } from '../../../lib/gramjs';
import { Api as GramJs } from '../../../lib/gramjs';

import type {
ApiInvoice, ApiLabeledPrice, ApiPaymentCredentials,
ApiBoostsStatus,
ApiCheckedGiftCode,
ApiGiveawayInfo,
ApiInvoice, ApiLabeledPrice, ApiMyBoost, ApiPaymentCredentials,
ApiPaymentForm, ApiPaymentSavedInfo, ApiPremiumPromo, ApiPremiumSubscriptionOption,
ApiReceipt,
} from '../../types';

import { buildApiMessageEntity } from './common';
import { omitVirtualClassFields } from './helpers';
import { buildApiDocument, buildApiWebDocument } from './messageContent';
import { buildApiPeerId, getApiChatIdFromMtpPeer } from './peers';
import { buildStatisticsPercentage } from './statistics';

export function buildShippingOptions(shippingOptions: GramJs.ShippingOption[] | undefined) {
if (!shippingOptions) {
Expand Down Expand Up @@ -197,3 +203,92 @@ function buildApiPremiumSubscriptionOption(option: GramJs.PremiumSubscriptionOpt
export function buildApiPaymentCredentials(credentials: GramJs.PaymentSavedCredentialsCard[]): ApiPaymentCredentials[] {
return credentials.map(({ id, title }) => ({ id, title }));
}

export function buildApiBoostsStatus(boostStatus: GramJs.premium.BoostsStatus): ApiBoostsStatus {
const {
level, boostUrl, boosts, myBoost, currentLevelBoosts, nextLevelBoosts, premiumAudience,
} = boostStatus;
return {
level,
currentLevelBoosts,
boosts,
hasMyBoost: Boolean(myBoost),
boostUrl,
nextLevelBoosts,
...(premiumAudience && { premiumSubscribers: buildStatisticsPercentage(premiumAudience) }),
};
}

export function buildApiMyBoost(myBoost: GramJs.MyBoost): ApiMyBoost {
const {
date, expires, slot, cooldownUntilDate, peer,
} = myBoost;

return {
date,
expires,
slot,
cooldownUntil: cooldownUntilDate,
chatId: peer && getApiChatIdFromMtpPeer(peer),
};
}

export function buildApiGiveawayInfo(info: GramJs.payments.TypeGiveawayInfo): ApiGiveawayInfo | undefined {
if (info instanceof GramJs.payments.GiveawayInfo) {
const {
startDate,
adminDisallowedChatId,
disallowedCountry,
joinedTooEarlyDate,
participating,
preparingResults,
} = info;

return {
type: 'active',
startDate,
isParticipating: participating,
adminDisallowedChatId: adminDisallowedChatId?.toString(),
disallowedCountry,
joinedTooEarlyDate,
isPreparingResults: preparingResults,
};
} else {
const {
activatedCount,
finishDate,
giftCodeSlug,
winner,
refunded,
startDate,
winnersCount,
} = info;

return {
type: 'results',
startDate,
activatedCount,
finishDate,
winnersCount,
giftCodeSlug,
isRefunded: refunded,
isWinner: winner,
};
}
}

export function buildApiCheckedGiftCode(giftcode: GramJs.payments.TypeCheckedGiftCode): ApiCheckedGiftCode {
const {
date, fromId, months, giveawayMsgId, toId, usedDate, viaGiveaway,
} = giftcode;

return {
date,
months,
toId: toId && buildApiPeerId(toId, 'user'),
fromId: fromId && getApiChatIdFromMtpPeer(fromId),
usedAt: usedDate,
isFromGiveaway: viaGiveaway,
giveawayMessageId: giveawayMsgId,
};
}
32 changes: 0 additions & 32 deletions src/api/gramjs/apiBuilders/stories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Api as GramJs } from '../../../lib/gramjs';

import type {
ApiBoostsStatus,
ApiMediaArea,
ApiMediaAreaCoordinates,
ApiMyBoost,
ApiStealthMode,
ApiStoryView,
ApiTypeStory,
Expand All @@ -16,7 +14,6 @@ import { buildPrivacyRules } from './common';
import { buildGeoPoint, buildMessageMediaContent, buildMessageTextContent } from './messageContent';
import { buildApiPeerId, getApiChatIdFromMtpPeer } from './peers';
import { buildApiReaction, buildReactionCount } from './reactions';
import { buildStatisticsPercentage } from './statistics';

export function buildApiStory(peerId: string, story: GramJs.TypeStoryItem): ApiTypeStory {
if (story instanceof GramJs.StoryItemDeleted) {
Expand Down Expand Up @@ -169,32 +166,3 @@ export function buildApiPeerStories(peerStories: GramJs.PeerStories) {

return buildCollectionByCallback(peerStories.stories, (story) => [story.id, buildApiStory(peerId, story)]);
}

export function buildApiBoostsStatus(boostStatus: GramJs.premium.BoostsStatus): ApiBoostsStatus {
const {
level, boostUrl, boosts, myBoost, currentLevelBoosts, nextLevelBoosts, premiumAudience,
} = boostStatus;
return {
level,
currentLevelBoosts,
boosts,
hasMyBoost: Boolean(myBoost),
boostUrl,
nextLevelBoosts,
...(premiumAudience && { premiumSubscribers: buildStatisticsPercentage(premiumAudience) }),
};
}

export function buildApiMyBoost(myBoost: GramJs.MyBoost): ApiMyBoost {
const {
date, expires, slot, cooldownUntilDate, peer,
} = myBoost;

return {
date,
expires,
slot,
cooldownUntil: cooldownUntilDate,
chatId: peer && getApiChatIdFromMtpPeer(peer),
};
}
9 changes: 5 additions & 4 deletions src/api/gramjs/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export {
allowBotSendMessages, fetchBotCanSendMessage, invokeWebViewCustomMethod,
} from './bots';

export {
validateRequestedInfo, sendPaymentForm, getPaymentForm, getReceipt, fetchPremiumPromo, fetchTemporaryPaymentPassword,
} from './payments';

export {
getGroupCall, joinGroupCall, discardGroupCall, createGroupCall,
editGroupCallTitle, editGroupCallParticipant, exportGroupCallInvite, fetchGroupCallParticipants,
Expand Down Expand Up @@ -111,3 +107,8 @@ export {
} from '../localDb';

export * from './stories';

export {
validateRequestedInfo, sendPaymentForm, getPaymentForm, getReceipt, fetchPremiumPromo, fetchTemporaryPaymentPassword,
applyBoost, fetchBoostsList, fetchBoostsStatus, fetchGiveawayInfo, fetchMyBoosts, applyGiftCode, checkGiftCode,
} from './payments';
Loading

0 comments on commit 2ad1c65

Please sign in to comment.