Skip to content

Commit

Permalink
Merge branch 'original-master' into merge-v10.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sim31 committed Oct 11, 2023
2 parents 1f93e5d + faec0d1 commit 9ddf10b
Show file tree
Hide file tree
Showing 186 changed files with 4,070 additions and 1,827 deletions.
2 changes: 1 addition & 1 deletion .patch-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1
3
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const isTest = process.env.APP_ENV === 'test';
const isMocked = Boolean(process.env.APP_MOCKED_CLIENT);

module.exports = {
presets: [
Expand All @@ -16,6 +17,6 @@ module.exports = {
'@babel/plugin-transform-class-properties',
'@babel/plugin-syntax-nullish-coalescing-operator',
'@babel/plugin-transform-logical-assignment-operators',
...(isTest ? ['babel-plugin-transform-import-meta'] : []),
...(isTest && !isMocked ? ['babel-plugin-transform-import-meta'] : []),
],
};
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fractalgram",
"version": "1.3.2",
"version": "1.3.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2
1.3.3
4 changes: 4 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type Undefined<T> = {
};
type OptionalCombine<A, B> = (A & B) | (A & Undefined<B>);

type CommonProperties<T, U> = {
[K in keyof T & keyof U]: T[K] & U[K];
};

// Fix to make Boolean() work as !!
// https://github.com/microsoft/TypeScript/issues/16655
type Falsy = false | 0 | '' | null | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/api/gramjs/apiBuilders/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface GramJsAppConfig extends LimitsConfig {
default_emoji_statuses_stickerset_id: string;
hidden_members_group_size_min: number;
autoarchive_setting_available: boolean;
authorization_autoconfirm_period: number;
// Forums
topics_pinned_limit: number;
// Stories
Expand Down
6 changes: 6 additions & 0 deletions src/api/gramjs/apiBuilders/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function buildApiChatFieldsFromPeerEntity(
const isJoinRequest = Boolean('joinRequest' in peerEntity && peerEntity.joinRequest);
const usernames = buildApiUsernames(peerEntity);
const isForum = Boolean('forum' in peerEntity && peerEntity.forum);
const areStoriesHidden = Boolean('storiesHidden' in peerEntity && peerEntity.storiesHidden);
const maxStoryId = 'storiesMaxId' in peerEntity ? peerEntity.storiesMaxId : undefined;
const storiesUnavailable = Boolean('storiesUnavailable' in peerEntity && peerEntity.storiesUnavailable);

return {
isMin,
Expand All @@ -77,6 +80,9 @@ function buildApiChatFieldsFromPeerEntity(
isJoinToSend,
isJoinRequest,
isForum,
areStoriesHidden,
maxStoryId,
hasStories: Boolean(maxStoryId) && !storiesUnavailable,
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/api/gramjs/apiBuilders/messageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ export function buildMessageStoryData(media: GramJs.TypeMessageMedia): ApiMessag
return undefined;
}

const userId = buildApiPeerId(media.userId, 'user');
const peerId = getApiChatIdFromMtpPeer(media.peer);

return { id: media.id, userId, ...(media.viaMention && { isMention: true }) };
return { id: media.id, peerId, ...(media.viaMention && { isMention: true }) };
}

export function buildPoll(poll: GramJs.Poll, pollResults: GramJs.PollResults): ApiPoll {
Expand Down Expand Up @@ -564,14 +564,14 @@ export function buildWebPage(media: GramJs.TypeMessageMedia): ApiWebPage | undef
const attributeStory = attributes
?.find((a: any): a is GramJs.WebPageAttributeStory => a instanceof GramJs.WebPageAttributeStory);
if (attributeStory) {
const userId = buildApiPeerId(attributeStory.userId, 'user');
const peerId = getApiChatIdFromMtpPeer(attributeStory.peer);
story = {
id: attributeStory.id,
userId,
peerId,
};

if (attributeStory.story instanceof GramJs.StoryItem) {
addStoryToLocalDb(attributeStory.story, userId);
addStoryToLocalDb(attributeStory.story, peerId);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/gramjs/apiBuilders/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ApiMessageEntity,
ApiMessageForwardInfo,
ApiNewPoll,
ApiPeer,
ApiPhoto,
ApiReplyKeyboard,
ApiSponsoredMessage,
Expand All @@ -19,7 +20,6 @@ import type {
ApiStorySkipped,
ApiThreadInfo,
ApiTypeReplyTo,
ApiUser,
ApiVideo,
PhoneCallAction,
} from '../../types';
Expand Down Expand Up @@ -690,7 +690,7 @@ export function buildLocalMessage(
contact?: ApiContact,
groupedId?: string,
scheduledAt?: number,
sendAs?: ApiChat | ApiUser,
sendAs?: ApiPeer,
story?: ApiStory | ApiStorySkipped,
): ApiMessage {
const localId = getNextLocalMessageId(chat.lastMessage?.id);
Expand Down
1 change: 1 addition & 0 deletions src/api/gramjs/apiBuilders/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function buildApiSession(session: GramJs.Authorization): ApiSession {
hash: String(session.hash),
areCallsEnabled: !session.callRequestsDisabled,
areSecretChatsEnabled: !session.encryptedRequestsDisabled,
isUnconfirmed: session.unconfirmed,
...pick(session, [
'deviceModel', 'platform', 'systemVersion', 'appName', 'appVersion', 'dateCreated', 'dateActive',
'ip', 'country', 'region',
Expand Down
4 changes: 2 additions & 2 deletions src/api/gramjs/apiBuilders/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function buildApiInvoiceFromForm(form: GramJs.payments.PaymentForm): ApiI
invoice, description: text, title, photo,
} = form;
const {
test, currency, prices, recurring, recurringTermsUrl, maxTipAmount, suggestedTipAmounts,
test, currency, prices, recurring, termsUrl, maxTipAmount, suggestedTipAmounts,
} = invoice;

const totalAmount = prices.reduce((ac, cur) => ac + cur.amount.toJSNumber(), 0);
Expand All @@ -159,7 +159,7 @@ export function buildApiInvoiceFromForm(form: GramJs.payments.PaymentForm): ApiI
currency,
isTest: test,
isRecurring: recurring,
recurringTermsUrl,
termsUrl,
maxTipAmount: maxTipAmount?.toJSNumber(),
...(suggestedTipAmounts && { suggestedTipAmounts: suggestedTipAmounts.map((tip) => tip.toJSNumber()) }),
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/gramjs/apiBuilders/reactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function reactionCountComparator(a: ApiReactionCount, b: ApiReactionCount) {
return 0;
}

function buildReactionCount(reactionCount: GramJs.ReactionCount): ApiReactionCount | undefined {
export function buildReactionCount(reactionCount: GramJs.ReactionCount): ApiReactionCount | undefined {
const { chosenOrder, count, reaction } = reactionCount;

const apiReaction = buildApiReaction(reaction);
Expand Down
2 changes: 1 addition & 1 deletion src/api/gramjs/apiBuilders/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function buildStatisticsOverview({ current, previous }: GramJs.StatsAbsValueAndP
};
}

function buildStatisticsPercentage(data: GramJs.StatsPercentValue): StatisticsOverviewPercentage {
export function buildStatisticsPercentage(data: GramJs.StatsPercentValue): StatisticsOverviewPercentage {
return {
percentage: ((data.part / data.total) * 100).toFixed(2),
};
Expand Down
98 changes: 87 additions & 11 deletions src/api/gramjs/apiBuilders/stories.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { Api as GramJs } from '../../../lib/gramjs';
import { Api as GramJs, errors } from '../../../lib/gramjs';

import type {
ApiApplyBoostInfo,
ApiBoostsStatus,
ApiMediaArea, ApiMediaAreaCoordinates, ApiMessage, ApiStealthMode, ApiStoryView, ApiTypeStory,
} from '../../types';

import { buildCollectionByCallback } from '../../../util/iteratees';
import { getServerTime } from '../../../util/serverTime';
import { buildPrivacyRules } from './common';
import { buildGeoPoint, buildMessageMediaContent, buildMessageTextContent } from './messageContent';
import { buildApiPeerId } from './peers';
import { buildApiReaction } from './reactions';
import { buildApiPeerId, getApiChatIdFromMtpPeer } from './peers';
import { buildApiReaction, buildReactionCount } from './reactions';
import { buildStatisticsPercentage } from './statistics';

export function buildApiStory(userId: string, story: GramJs.TypeStoryItem): ApiTypeStory {
export function buildApiStory(peerId: string, story: GramJs.TypeStoryItem): ApiTypeStory {
if (story instanceof GramJs.StoryItemDeleted) {
return {
id: story.id,
userId,
peerId,
isDeleted: true,
};
}
Expand All @@ -26,7 +30,7 @@ export function buildApiStory(userId: string, story: GramJs.TypeStoryItem): ApiT

return {
id,
userId,
peerId,
...(closeFriends && { isForCloseFriends: true }),
date,
expireDate,
Expand All @@ -37,7 +41,7 @@ export function buildApiStory(userId: string, story: GramJs.TypeStoryItem): ApiT
edited, pinned, expireDate, id, date, caption,
entities, media, privacy, views,
public: isPublic, noforwards, closeFriends, contacts, selectedContacts,
mediaAreas, sentReaction,
mediaAreas, sentReaction, out,
} = story;

const content: ApiMessage['content'] = {
Expand All @@ -50,7 +54,7 @@ export function buildApiStory(userId: string, story: GramJs.TypeStoryItem): ApiT

return {
id,
userId,
peerId,
date,
expireDate,
content,
Expand All @@ -63,9 +67,11 @@ export function buildApiStory(userId: string, story: GramJs.TypeStoryItem): ApiT
...(noforwards && { noForwards: true }),
...(views?.viewsCount && { viewsCount: views.viewsCount }),
...(views?.reactionsCount && { reactionsCount: views.reactionsCount }),
...(views?.reactions && { reactions: views.reactions.map(buildReactionCount) }),
...(views?.recentViewers && {
recentViewerIds: views.recentViewers.map((viewerId) => buildApiPeerId(viewerId, 'user')),
}),
...(out && { isOut: true }),
...(privacy && { visibility: buildPrivacyRules(privacy) }),
...(mediaAreas && { mediaAreas: mediaAreas.map(buildApiMediaArea).filter(Boolean) }),
...(sentReaction && { sentReaction: buildApiReaction(sentReaction) }),
Expand Down Expand Up @@ -134,11 +140,81 @@ export function buildApiMediaArea(area: GramJs.TypeMediaArea): ApiMediaArea | un
};
}

if (area instanceof GramJs.MediaAreaSuggestedReaction) {
const {
coordinates, reaction, dark, flipped,
} = area;

const apiReaction = buildApiReaction(reaction);
if (!apiReaction) return undefined;

return {
type: 'suggestedReaction',
coordinates: buildApiMediaAreaCoordinates(coordinates),
reaction: apiReaction,
...(dark && { isDark: true }),
...(flipped && { isFlipped: true }),
};
}

return undefined;
}

export function buildApiUsersStories(userStories: GramJs.UserStories) {
const userId = buildApiPeerId(userStories.userId, 'user');
export function buildApiPeerStories(peerStories: GramJs.PeerStories) {
const peerId = getApiChatIdFromMtpPeer(peerStories.peer);

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

export function buildApiApplyBoostInfo(
applyBoostInfo: GramJs.stories.TypeCanApplyBoostResult,
): ApiApplyBoostInfo | undefined {
if (applyBoostInfo instanceof GramJs.stories.CanApplyBoostOk) {
return { type: 'ok' };
}

if (applyBoostInfo instanceof GramJs.stories.CanApplyBoostReplace) {
return {
type: 'replace',
boostedChatId: getApiChatIdFromMtpPeer(applyBoostInfo.currentBoost),
};
}

return buildCollectionByCallback(userStories.stories, (story) => [story.id, buildApiStory(userId, story)]);
return undefined;
}

export function buildApiApplyBoostInfoFromError(
error: unknown,
): ApiApplyBoostInfo | undefined {
if (error instanceof errors.FloodWaitError) {
return {
type: 'wait',
waitUntil: getServerTime() + error.seconds,
};
}

if (error instanceof Error) {
if (error.message === 'BOOST_NOT_MODIFIED') {
return {
type: 'already',
};
}
}

return undefined;
}

export function buildApiBoostsStatus(boostStatus: GramJs.stories.BoostsStatus): ApiBoostsStatus {
const {
level, boostUrl, boosts, myBoost, currentLevelBoosts, nextLevelBoosts, premiumAudience,
} = boostStatus;
return {
level,
currentLevelBoosts,
boosts,
hasMyBoost: Boolean(myBoost),
boostUrl,
nextLevelBoosts,
...(premiumAudience && { premiumAudience: buildStatisticsPercentage(premiumAudience) }),
};
}
4 changes: 2 additions & 2 deletions src/api/gramjs/gramjsBuilders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ export function buildFilterFromApiFolder(folder: ApiChatFolder): GramJs.DialogFi
}

export function buildInputStory(story: ApiStory | ApiStorySkipped) {
const user = localDb.users[story.userId];
const peer = buildInputPeerFromLocalDb(story.peerId)!;
return new GramJs.InputMediaStory({
userId: new GramJs.InputUser({ userId: BigInt(user!.id), accessHash: user!.accessHash! }),
peer,
id: story.id,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/gramjs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ export function addMessageToLocalDb(message: GramJs.Message | GramJs.MessageServ
}
}

export function addStoryToLocalDb(story: GramJs.TypeStoryItem, userId: string) {
export function addStoryToLocalDb(story: GramJs.TypeStoryItem, peerId: string) {
if (!(story instanceof GramJs.StoryItem)) {
return;
}

const storyData = {
id: story.id,
userId,
peerId,
};

if (story.media instanceof GramJs.MessageMediaPhoto) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/gramjs/localDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const IS_MULTITAB_SUPPORTED = 'BroadcastChannel' in self;

export type StoryRepairInfo = {
storyData?: {
userId: string;
peerId: string;
id: number;
};
};
Expand Down
Loading

0 comments on commit 9ddf10b

Please sign in to comment.