From 894bf1e880d20727e52dca66d24436ed049e23e2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 9 Mar 2022 12:16:24 -0600 Subject: [PATCH 1/7] Account normalizer: convert to Typescript, add type --- .../normalizers/{account.js => account.ts} | Bin 2491 -> 3670 bytes 1 file changed, 0 insertions(+), 0 deletions(-) rename app/soapbox/normalizers/{account.js => account.ts} (58%) diff --git a/app/soapbox/normalizers/account.js b/app/soapbox/normalizers/account.ts similarity index 58% rename from app/soapbox/normalizers/account.js rename to app/soapbox/normalizers/account.ts index 9515e12176c394ea8d5b4dd58b593a3afd6876ae..61db6691532c88c98f573dc255f0dfcf649e3cb4 100644 GIT binary patch literal 3670 zcmb_fOK;;g5WeSEOixk(uhm0)sJGc7i^UcJvc;lZw1*%tXlZP-r9_pal1;by@15a8 zrewQFf#wj1=W1|L*{ai~6-xev#(LGxq1lQW;kvH%(2-jg z0HUtl3am4-+r8%XgK)we@2ss8PS*LsMjE$o#M27i35W1E3|$i(VnZ8Eb~jop6dkW? zgCy0g1#PoD?={l)N<6JQ(PC~HTm8GVt3$dtG2e^s=?!abC93B9sa8rqQp{@~ z-JtP`{)hrSar9@GJFrL5;3NxS=R_7{lPfA=ofjJHBvPeoN}rxwLVJH8X=h1l^#kv8 zgHr5pr`;qky+VS7$Pz<1;=C*%CCBQ))TERnZ6-m594wy5&tPO8%V5-GY0=CJ^?*iF zIr1RL?W%$s23sdoEY_^n>%D6ywmHzXuX?a{z@tAQkjP2udf^Nw^L&&Bl~1_c%RZBv z0Lkw4pqjP8ExLN272^5gqShUeGcqMI@+wlZ{6g^r;uOV#zawe#)d-cac_7Qk64vxA z*$QQmS2;&IeDpjiFZpE3lwk5COM>`Gio~NiKfY%B+c`DDF0&$BmKc$*W+5^Y!ttC1 z(^w8%h|-Ysz_TQy7`LRr-_VsV;p&YaH3r>aIwlTl zEQh|KF;EtY*U%`M>59HLVFpZ9 z!@f|*YQDv8ws1GUn5nW0SII*)aALQ^S zTD>p}83D%`m(U(E!=}mDJjN^^EJ3;83dSHtQn1Z(vRX>(H(BWte(;{d3hr3{sP>=C z;P&u~uBA{_1OlYqI&!jPi8IS^*z||EvGx(v*WQny% z-R^QJyIKtm+OkMS6Or$iR=1cz;tU-U4XQjhkY?jNC%5ta`2XZ2-9kA@pJ#KD1b7nj z-yA>397!4@t&Ui7NC|%SKac`K$60e7f1tcdfqk$;tVpc_ou8c;qLmuuHKQ Date: Wed, 9 Mar 2022 13:23:52 -0600 Subject: [PATCH 2/7] eslint: fix typescript undefined globals --- .eslintrc.js | Bin 6002 -> 6188 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b478bcc3fb97768d92f1da2d6700e610e4c02337..f4b59595a2d9e88b181421df998e10d2f271e6bf 100644 GIT binary patch delta 207 zcmeyQx5i*YJd=#NURJTXjsl3P0MjK9ZV8aPxsYkM2y0PkPHORFV{yxR1qFS51((d? z#H5^5g}i*-(!7+^G= Date: Wed, 9 Mar 2022 13:26:48 -0600 Subject: [PATCH 3/7] Move Account interface to types/ directory --- app/soapbox/normalizers/account.ts | 41 ++-------------------------- app/soapbox/types/account.ts | 44 ++++++++++++++++++++++++++++++ app/soapbox/types/index.ts | 3 ++ 3 files changed, 49 insertions(+), 39 deletions(-) create mode 100644 app/soapbox/types/account.ts create mode 100644 app/soapbox/types/index.ts diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index 61db669153..def1b497e5 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -1,45 +1,8 @@ import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable'; +import { IAccount } from 'soapbox/types'; import { mergeDefined } from 'soapbox/utils/normalizers'; -interface Account { - acct: string; - avatar: string; - avatar_static: string; - birthday: Date | undefined; - bot: boolean; - created_at: Date; - display_name: string; - emojis: ImmutableList; - fields: ImmutableList; - followers_count: number; - following_count: number; - fqn: string; - header: string; - header_static: string; - id: string; - last_status_at: Date; - location: string; - locked: boolean; - moved: null; - note: string; - pleroma: ImmutableMap; - source: ImmutableMap; - statuses_count: number; - uri: string; - url: string; - username: string; - verified: boolean; - - // Internal fields - display_name_html: string; - note_emojified: string; - note_plain: string; - patron: ImmutableMap; - relationship: ImmutableList; - should_refetch: boolean; -} - const AccountRecord = Record({ acct: '', avatar: '', @@ -130,7 +93,7 @@ const normalizeLocation = (account: ImmutableMap) => { }); }; -export const normalizeAccount = (account: ImmutableMap): Account => { +export const normalizeAccount = (account: ImmutableMap): IAccount => { return AccountRecord( account.withMutations(account => { normalizePleromaLegacyFields(account); diff --git a/app/soapbox/types/account.ts b/app/soapbox/types/account.ts new file mode 100644 index 0000000000..b17935c359 --- /dev/null +++ b/app/soapbox/types/account.ts @@ -0,0 +1,44 @@ +/** + * Account entity. + * https://docs.joinmastodon.org/entities/account/ + **/ + +interface IAccount { + acct: string; + avatar: string; + avatar_static: string; + birthday: Date | undefined; + bot: boolean; + created_at: Date; + display_name: string; + emojis: Iterable; + fields: Iterable; + followers_count: number; + following_count: number; + fqn: string; + header: string; + header_static: string; + id: string; + last_status_at: Date; + location: string; + locked: boolean; + moved: null; + note: string; + pleroma: Record; + source: Record; + statuses_count: number; + uri: string; + url: string; + username: string; + verified: boolean; + + // Internal fields + display_name_html: string; + note_emojified: string; + note_plain: string; + patron: Record; + relationship: Iterable; + should_refetch: boolean; +} + +export { IAccount }; diff --git a/app/soapbox/types/index.ts b/app/soapbox/types/index.ts new file mode 100644 index 0000000000..bc8cbd94e1 --- /dev/null +++ b/app/soapbox/types/index.ts @@ -0,0 +1,3 @@ +import { IAccount } from './account'; + +export { IAccount }; From a2adaf2ffd7b10b161c430bc9e9ab6997d213ac9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 9 Mar 2022 14:26:57 -0600 Subject: [PATCH 4/7] Convert Status Normalizer to TypeScript --- .../normalizers/{status.js => status.ts} | Bin 4264 -> 4703 bytes app/soapbox/types/index.ts | 3 +- app/soapbox/types/status.ts | 45 ++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) rename app/soapbox/normalizers/{status.js => status.ts} (81%) create mode 100644 app/soapbox/types/status.ts diff --git a/app/soapbox/normalizers/status.js b/app/soapbox/normalizers/status.ts similarity index 81% rename from app/soapbox/normalizers/status.js rename to app/soapbox/normalizers/status.ts index 494a0ced747a263fc7841182f4c6dbccd17dd840..a4d8a8d3ff9d1439b6d635c9fc9fb69c6fa6a80a 100644 GIT binary patch delta 585 zcmZ3Xcwc2gl)PtfNn%N9u|lmvT2X$kf_ia&VnI@Vg?>q8L29wO^~L}ZR&|ZUl9I&a zjNH_`5-SDI+}zTV#H5^5-^2o&;*z4wymTFf#Joy7&CPkN4vfkg#b5*RDV*%Xp)mOh z+dNGTkdc}BdH577*xD&nPhwM^ypVkpvK|-E9Yh4iGp@^4NamsktByi^5+3Qvd$^wvW6kDeJbX;VD4e{D@18n# XcLQTtM*$M$cA7vp1#h0o&(8<|4j$3` delta 144 zcmcbwvO;k})W&8mR<6X7lEmbU+|<01&0AO<7#WKv2MCHx{=p$Q*_?eIJ4ie;KX39+ z_Oo!A#ccTnV8MNy*=)rni6y1QlYO{0u|q_QCmV8af(f(nTxQl$NSZ9n`vfYqS&EO3 R32Ic7zjb^i~vD|GnfDX diff --git a/app/soapbox/types/index.ts b/app/soapbox/types/index.ts index bc8cbd94e1..df14c27205 100644 --- a/app/soapbox/types/index.ts +++ b/app/soapbox/types/index.ts @@ -1,3 +1,4 @@ import { IAccount } from './account'; +import { IStatus } from './status'; -export { IAccount }; +export { IAccount, IStatus }; diff --git a/app/soapbox/types/status.ts b/app/soapbox/types/status.ts new file mode 100644 index 0000000000..a1a1ed0615 --- /dev/null +++ b/app/soapbox/types/status.ts @@ -0,0 +1,45 @@ +/** + * Status entity. + * https://docs.joinmastodon.org/entities/status/ + **/ + +interface IStatus { + account: Record; + application: Record | null; + bookmarked: boolean; + card: Record | null; + content: string; + created_at: Date; + emojis: Iterable; + favourited: boolean; + favourites_count: number; + in_reply_to_account_id: string | null; + in_reply_to_id: string | null; + id: string; + language: null; + media_attachments: Iterable; + mentions: Iterable; + muted: boolean; + pinned: boolean; + pleroma: Record; + poll: null; + quote: null; + reblog: null; + reblogged: boolean; + reblogs_count: number; + replies_count: number; + sensitive: boolean; + spoiler_text: string; + tags: Iterable; + uri: string; + url: string; + visibility: string; + + // Internal fields + contentHtml: string; + hidden: boolean; + search_index: string; + spoilerHtml: string; +} + +export { IStatus }; From 9537c879099d75d134c2465001c1913a333dc82e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 9 Mar 2022 16:00:43 -0600 Subject: [PATCH 5/7] Record --> ImmutableRecord --- app/soapbox/normalizers/account.ts | 8 ++++++-- app/soapbox/normalizers/instance.js | Bin 3127 -> 3162 bytes app/soapbox/normalizers/status.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index def1b497e5..f3006f3c28 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -1,9 +1,13 @@ -import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable'; +import { + Map as ImmutableMap, + List as ImmutableList, + Record as ImmutableRecord, +} from 'immutable'; import { IAccount } from 'soapbox/types'; import { mergeDefined } from 'soapbox/utils/normalizers'; -const AccountRecord = Record({ +const AccountRecord = ImmutableRecord({ acct: '', avatar: '', avatar_static: '', diff --git a/app/soapbox/normalizers/instance.js b/app/soapbox/normalizers/instance.js index 22f90fc8dfefa880aa6e63681a71fed8b4a05a7d..537c609310341fe60d46fced1b4b9cf4c1ec204c 100644 GIT binary patch delta 90 zcmdlkaZ5rmGq)hWs6?TfOF_Xmu|OfQSiv(lx3nZNDJK=k*Wpr_C@U@plnhEu&M!(q Vk%tKBa80!N#0l55S&xyE8vsvt9ozr_ delta 54 zcmca5v0XwoGq)hWs6?S!!8fr$A+cD&GdH)iBrz!`70B0_s3^{%5R{snUzDOSG3?Xk IKt@h(02C+^vj6}9 diff --git a/app/soapbox/normalizers/status.ts b/app/soapbox/normalizers/status.ts index a4d8a8d3ff..02c9b1f545 100644 --- a/app/soapbox/normalizers/status.ts +++ b/app/soapbox/normalizers/status.ts @@ -1,10 +1,14 @@ -import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable'; +import { + Map as ImmutableMap, + List as ImmutableList, + Record as ImmutableRecord, +} from 'immutable'; import { IStatus } from 'soapbox/types'; import { accountToMention } from 'soapbox/utils/accounts'; import { mergeDefined } from 'soapbox/utils/normalizers'; -const StatusRecord = Record({ +const StatusRecord = ImmutableRecord({ account: ImmutableMap(), application: null, bookmarked: false, From f75c0738a7f6da325dcbaab4b70cf7373f37373b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 9 Mar 2022 16:02:50 -0600 Subject: [PATCH 6/7] Instance normalizer: add default stats, remove default media_attachments --- .../normalizers/__tests__/instance-test.js | Bin 5471 -> 5349 bytes app/soapbox/normalizers/instance.js | Bin 3162 -> 3048 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/app/soapbox/normalizers/__tests__/instance-test.js b/app/soapbox/normalizers/__tests__/instance-test.js index f30f2749264c48f6853b0baef3503e755ea4ab0b..597fbbeee3c144ceb02a119ab9e20a0f71c3fce2 100644 GIT binary patch delta 102 zcmcbw^;C0%Bje;XT)~^;m>x3)a4A4RN`7u)W?p=9eraBbm4bl|T%x!nv81#Zi$rO0 NY7vI;W=B>z0RTh*9FhP4 delta 26 icmaE=d0%UTBje@_PFcpuw|T-hzh>-V+I*ZvP5=OrHwpFt diff --git a/app/soapbox/normalizers/instance.js b/app/soapbox/normalizers/instance.js index 537c609310341fe60d46fced1b4b9cf4c1ec204c..8ec6fde859e03c955063f881ad87256c04c1ddc4 100644 GIT binary patch delta 82 zcmca5@j`sVUB=B5nH-rX%dxZBq~zx&X6D5w=a=S{SSc9ja47&maYn>1 Micsz5ORODi0D%=6i~s-t delta 192 zcmaDMeoJD*UB=1lnK|k+a}(23 Date: Wed, 9 Mar 2022 16:07:24 -0600 Subject: [PATCH 7/7] Actually, we can access state.instance.version directly now --- app/soapbox/reducers/__tests__/index-test.js | Bin 388 -> 381 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/app/soapbox/reducers/__tests__/index-test.js b/app/soapbox/reducers/__tests__/index-test.js index 2b4a212666976342bc03113aa457f22a1d6c7974..15572f337f6a1cc3a7b36d201c7aef2af7773894 100644 GIT binary patch delta 19 acmZo+{>!u>f|0!}wWv5VKW}mxqZ|N6UIw)Q delta 26 hcmey%)WW