Skip to content

Commit

Permalink
refactor: remove unused code (#734)
Browse files Browse the repository at this point in the history
* refactor: remove unused code

Cleaned up code no longer needed by updating twi-ext to v0.9

* refactor: convert an import statement to a type import
  • Loading branch information
Robot-Inventor authored May 28, 2024
1 parent 8d89133 commit b7e350f
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 118 deletions.
2 changes: 0 additions & 2 deletions src/ts/core/messageDataGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ class MessageDataGenerator {
): SbsMessageWrapperOptionsForTweets {
const translations = TranslationKeyProvider.fromTweetAnalyzer(analyzer);
const tweetText = ShareTextGenerator.generateShareText(analyzer);
const { meta } = analyzer;

return {
...translations,
...meta,

isAlert: analyzer.tweet.hasAnyProblem,
isExpanded: options.alwaysDetailedView,
Expand Down
11 changes: 0 additions & 11 deletions src/ts/core/parser/tweetParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { BasicTweetProps, Tweet } from "twi-ext";
import { getReactProps } from "./utility";
import { isFocalTweetOuterReactPropsData } from "../../../types/core/reactProps/reactProps.guard";

/**
* React props of the tweet.
Expand All @@ -23,15 +21,6 @@ class TweetParser {
public parse(): BasicTweetProps {
return this.tweet.props;
}

/**
* Check whether the tweet is focal.
* @returns whether the tweet is focal
*/
public get isFocal(): boolean {
const tweetReactProps = getReactProps(this.tweet.element);
return isFocalTweetOuterReactPropsData(tweetReactProps);
}
}

export { TweetParser };
8 changes: 0 additions & 8 deletions src/ts/core/propsAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ interface TweetAnalysisResult extends ProfileAnalysisResult {
possiblySensitive: boolean;
searchability: "searchable" | "unsearchable" | "possiblyUnsearchable";
};

meta: {
isFocal: boolean;
};
}

class PropsAnalyzer {
Expand Down Expand Up @@ -65,10 +61,6 @@ class PropsAnalyzer {
return {
...userAnalysisResult,

meta: {
isFocal: parser.isFocal
},

tweet: {
ageRestriction,
hasAnyProblem: searchability !== "searchable" || userAnalysisResult.user.hasAnyProblem,
Expand Down
3 changes: 1 addition & 2 deletions src/ts/core/sbsMessageWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface SbsMessageWrapperOptionsForTweets {
notes: TranslationKey[];

isAlert: boolean;
isFocal: boolean;
isExpanded: boolean;
isTweetButtonShown: boolean;
isNoteShown: boolean;
Expand Down Expand Up @@ -51,7 +50,7 @@ class SbsMessageWrapper {
this.tweet = options.tweet;
sbsMessage.details = options.details;
sbsMessage.notes = options.notes;
sbsMessage.isFocalMode = options.isFocal;
sbsMessage.isFocalMode = options.tweet.metadata.isFocalMode;
sbsMessage.isExpanded = options.isExpanded;
sbsMessage.isTweetButtonShown = options.isTweetButtonShown;
sbsMessage.isNoteShown = options.isNoteShown;
Expand Down
53 changes: 1 addition & 52 deletions src/types/core/reactProps/reactProps.d.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,8 @@
type ProfileInterstitialType = "" | "sensitive_media" | "fake_account" | "offensive_profile_content" | "timeout";
interface UserProps {
possibly_sensitive?: boolean | null;
screen_name: string;
profile_interstitial_type: ProfileInterstitialType;
withheld_in_countries: string[];
}

/** @see {isCellInnerDivProps} ts-auto-guard:type-guard */
interface CellInnerDivProps {
export interface CellInnerDivProps {
children: {
_owner?: {
key: string;
};
};
}

/** @see {isFocalTweetOuterReactPropsData} ts-auto-guard:type-guard */
export interface FocalTweetOuterReactPropsData {
children: [
[
unknown,
{
props: {
children: [
{
props: {
children: [
unknown,
unknown,
{
props: {
children: [
unknown,
unknown,
unknown,
unknown,
unknown,
unknown,
unknown,
{
props: {
loggedInUser: {
screen_name: string;
};
};
}
];
};
}
];
};
}
];
};
}
]
];
}
44 changes: 1 addition & 43 deletions src/types/core/reactProps/reactProps.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated type guards for "reactProps.d.ts".
* WARNING: Do not manually change this file.
*/
import { CellInnerDivProps, FocalTweetOuterReactPropsData } from "./reactProps";
import { CellInnerDivProps } from "./reactProps";

export function isCellInnerDivProps(obj: unknown): obj is CellInnerDivProps {
const typedObj = obj as CellInnerDivProps
Expand All @@ -20,45 +20,3 @@ export function isCellInnerDivProps(obj: unknown): obj is CellInnerDivProps {
typeof typedObj["children"]["_owner"]["key"] === "string")
)
}

export function isFocalTweetOuterReactPropsData(obj: unknown): obj is FocalTweetOuterReactPropsData {
const typedObj = obj as FocalTweetOuterReactPropsData
return (
(typedObj !== null &&
typeof typedObj === "object" ||
typeof typedObj === "function") &&
Array.isArray(typedObj["children"]) &&
Array.isArray(typedObj["children"][0]) &&
(typedObj["children"][0][1] !== null &&
typeof typedObj["children"][0][1] === "object" ||
typeof typedObj["children"][0][1] === "function") &&
(typedObj["children"][0][1]["props"] !== null &&
typeof typedObj["children"][0][1]["props"] === "object" ||
typeof typedObj["children"][0][1]["props"] === "function") &&
Array.isArray(typedObj["children"][0][1]["props"]["children"]) &&
(typedObj["children"][0][1]["props"]["children"][0] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0] === "function") &&
(typedObj["children"][0][1]["props"]["children"][0]["props"] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"] === "function") &&
Array.isArray(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"]) &&
(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2] === "function") &&
(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"] === "function") &&
Array.isArray(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"]) &&
(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7] === "function") &&
(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"] === "function") &&
(typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"]["loggedInUser"] !== null &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"]["loggedInUser"] === "object" ||
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"]["loggedInUser"] === "function") &&
typeof typedObj["children"][0][1]["props"]["children"][0]["props"]["children"][2]["props"]["children"][7]["props"]["loggedInUser"]["screen_name"] === "string"
)
}

0 comments on commit b7e350f

Please sign in to comment.