Skip to content

Commit

Permalink
Chore: Migrate helpers/parseUrls to Typescript (RocketChat#3735)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlsilva authored Feb 16, 2022
1 parent 278eca6 commit dd4be8f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
8 changes: 1 addition & 7 deletions app/definitions/IThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { IAttachment } from './IAttachment';
import { IEditedBy, IUserChannel, IUserMention, IUserMessage } from './IMessage';
import { IReaction } from './IReaction';
import { SubscriptionType } from './ISubscription';

export interface IUrl {
title: string;
description: string;
image: string;
url: string;
}
import { IUrl } from './IUrl';

interface IFileThread {
_id: string;
Expand Down
43 changes: 43 additions & 0 deletions app/definitions/IUrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
export interface IUrl {
_id: number;
title: string;
description: string;
image: string;
url: string;
}

export interface IUrlFromServer {
url: string;
meta: {
pageTitle: string;
description: string;
fbAppId: string;
twitterImageSrc: string;
twitterSite: string;
twitterCard: string;
twitterTitle: string;
twitterDescription: string;
ogImage: string;
ogImageAlt: string;
ogImageWidth: string;
ogImageHeight: string;
ogSiteName: string;
ogType: string;
ogTitle: string;
ogUrl: string;
ogDescription: string;
title: string;
oembedTitle: string;
oembedAuthorName: string;
twitterImage: string;
oembedThumbnailUrl: string;
};
headers: {
contentType: string;
};
parsedUrl: {
host: string;
hash: any;
pathname: string;
protocol: string;
port: any;
query: any;
search: any;
hostname: string;
};
ignoreParse: boolean;
}
1 change: 1 addition & 0 deletions app/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export * from './ILoggedUser';
export * from './IServerHistory';
export * from './IRocketChat';
export * from './ICertificate';
export * from './IUrl';

export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
navigation: StackNavigationProp<T, S>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export default urls =>
import { IUrl, IUrlFromServer } from '../../../definitions';

export default (urls: IUrlFromServer[]): IUrl[] =>
urls
.filter(url => url.meta && !url.ignoreParse)
.map((url, index) => {
const tmp = {};
.filter((url: IUrlFromServer) => url.meta && !url.ignoreParse)
.map((url: IUrlFromServer, index) => {
const tmp: IUrl = {} as any;
const { meta } = url;
tmp._id = index;
tmp.title = meta.ogTitle || meta.twitterTitle || meta.title || meta.pageTitle || meta.oembedTitle;
Expand Down

0 comments on commit dd4be8f

Please sign in to comment.