Skip to content

Commit fce06d8

Browse files
authored
TS Constants (keybase#17752)
* convert all but fs * WIP cleaning errors * WIP fix errors * WIP fixing tsc * RecordFactory -> Record.Factory * WIP fixing tsc * WIP fixing tsc * WIP fixing tsc * WIP no errors in constants/ * WIP home stretch * WIP fix tsc * Don't use Record.Factory * Don't use two more Record.Factory * chat reducer * last errors * no as const * clean up * prettier + lint * fix new errors * storyshots
1 parent b50519c commit fce06d8

136 files changed

Lines changed: 2892 additions & 2580 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎shared/chat/conversation/info-panel/notifications/index.stories.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {Notifications} from './index'
44

55
const defaultProps = {
66
channelWide: false,
7-
desktop: 'onWhenAtMentioned',
8-
mobile: 'never',
7+
desktop: 'onWhenAtMentioned' as 'onWhenAtMentioned',
8+
mobile: 'never' as 'never',
99
muted: false,
1010
saving: false,
1111
toggleChannelWide: action('onToggleChannelwide'),

‎shared/chat/conversation/list-area/normal/container.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ type OwnProps = {
1616

1717
const mapStateToProps = (state, {conversationIDKey}: OwnProps) => {
1818
const messageOrdinals = Constants.getMessageOrdinals(state, conversationIDKey)
19-
const lastOrdinal = messageOrdinals.last()
20-
const centeredOrdinal = // Auto generated from flowToTs. Please clean me!
21-
Constants.getMessageCenterOrdinal(state, conversationIDKey) === null ||
22-
Constants.getMessageCenterOrdinal(state, conversationIDKey) === undefined
23-
? undefined
24-
: Constants.getMessageCenterOrdinal(state, conversationIDKey).ordinal
19+
const lastOrdinal = messageOrdinals.last(null)
20+
const maybeCenterMessage = Constants.getMessageCenterOrdinal(state, conversationIDKey)
21+
const centeredOrdinal =
22+
maybeCenterMessage === null || maybeCenterMessage === undefined ? undefined : maybeCenterMessage.ordinal
2523
const containsLatestMessage = state.chat2.containsLatestMessageMap.get(conversationIDKey, false)
2624
const showThreadSearch = Constants.getThreadSearchInfo(state, conversationIDKey).visible
2725
let lastMessageIsOurs = false

‎shared/chat/conversation/messages/account-payment/container.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const mapStateToProps = (state, ownProps: OwnProps) => {
125125
}
126126
}
127127
default:
128+
// @ts-ignore message is type `never` correctly
128129
throw new Error(`AccountPayment: impossible case encountered: '${ownProps.message.type}'`)
129130
}
130131
}

‎shared/chat/conversation/messages/message-popup/index.stories.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ const attachmentMessage = makeMessageAttachment({
2424
const defaultProps = {
2525
attachTo: () => null,
2626
isDeleteable: true,
27+
onAddReaction: Sb.action('onAddReaction'),
2728
onCopy: Sb.action('onCopy'),
2829
onDelete: Sb.action('onDelete'),
2930
onDeleteMessageHistory: Sb.action('onDeleteMessageHistory'),
3031
onDownload: Sb.action('onDownload'),
3132
onEdit: Sb.action('onEdit'),
3233
onHidden: Sb.action('onHidden'),
3334
onQuote: Sb.action('onQuote'),
35+
onReply: Sb.action('onReply'),
3436
onReplyPrivately: Sb.action('onReplyPrivately'),
3537
onSaveAttachment: Sb.action('onSaveAttachment'),
3638
onShareAttachment: Sb.action('onShareAttachment'),
3739
onShowInFinder: Sb.action('onShowInFinder'),
3840
onViewProfile: Sb.action('onViewProfile'),
41+
pending: false,
3942
position: 'top left',
4043
showDivider: true,
4144
toggleChannelWide: Sb.action('onToggleChannelwide'),

‎shared/chat/conversation/messages/message-popup/payment/container.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const getTopLineUser = (paymentInfo, sender, you) => {
8888

8989
const sendMergeProps = (stateProps, dispatchProps, ownProps: SendOwnProps) => {
9090
if (ownProps.message.type !== 'sendPayment' && ownProps.message.type !== 'text') {
91+
// @ts-ignore message is type `never` correctly
9192
throw new Error(`SendPaymentPopup: impossible case encountered: ${ownProps.message.type}`)
9293
}
9394
const {paymentInfo} = stateProps

‎shared/chat/conversation/search/index.stories.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ const hits = [
3535
const initial = {
3636
...base,
3737
hits: [],
38-
status: 'initial',
38+
status: 'initial' as 'initial',
3939
}
4040

4141
const started = {
4242
...base,
4343
hits: [],
44-
status: 'inprogress',
44+
status: 'inprogress' as 'inprogress',
4545
}
4646

4747
const partial = {
4848
...base,
4949
hits,
50-
status: 'inprogress',
50+
status: 'inprogress' as 'inprogress',
5151
}
5252

5353
const complete = {
5454
...base,
5555
hits,
56-
status: 'done',
56+
status: 'done' as 'done',
5757
}
5858

5959
const none = {
6060
...base,
6161
hits: [],
62-
status: 'done',
62+
status: 'done' as 'done',
6363
}
6464

6565
const load = () => {
File renamed without changes.

shared/constants/chat2/__test__/message.test.js renamed to shared/constants/chat2/__test__/message.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
/* eslint-env jest */
32
import * as RPCChatTypes from '../../types/rpc-chat-gen'
43
import {serviceMessageTypeToMessageTypes} from '../message'
Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// @flow
21
import * as I from 'immutable'
32
import * as Types from '../types/chat2'
43
import * as RPCChatTypes from '../types/rpc-chat-gen'
54
import * as RPCTypes from '../../constants/types/rpc-gen'
65
import * as TeamBuildingConstants from '../../constants/team-building'
76
import {clamp} from 'lodash-es'
87
import {chatTab} from '../tabs'
9-
import type {TypedState} from '../reducer'
8+
import {TypedState} from '../reducer'
109
import {isMobile} from '../platform'
1110
import {
1211
noConversationIDKey,
@@ -19,7 +18,7 @@ import {formatTextForQuoting} from '../../util/chat'
1918
import * as Router2 from '../router2'
2019
import HiddenString from '../../util/hidden-string'
2120

22-
export const makeState: I.RecordFactory<Types._State> = I.Record({
21+
export const makeState = I.Record<Types._State>({
2322
accountsInfoMap: I.Map(),
2423
attachmentFullscreenMessage: null,
2524
badgeMap: I.Map(),
@@ -45,9 +44,7 @@ export const makeState: I.RecordFactory<Types._State> = I.Record({
4544
orangeLineMap: I.Map(),
4645
paymentConfirmInfo: null,
4746
paymentStatusMap: I.Map(),
48-
pendingMode: 'none',
4947
pendingOutboxToOrdinal: I.Map(),
50-
pendingStatus: 'none',
5148
quote: null,
5249
replyToMap: I.Map(),
5350
selectedConversation: noConversationIDKey,
@@ -65,19 +62,25 @@ export const makeState: I.RecordFactory<Types._State> = I.Record({
6562
...TeamBuildingConstants.makeSubState(),
6663
})
6764

68-
export const makeQuoteInfo: I.RecordFactory<Types._QuoteInfo> = I.Record({
65+
export const makeQuoteInfo = I.Record<Types._QuoteInfo>({
6966
counter: 0,
7067
ordinal: Types.numberToOrdinal(0),
7168
sourceConversationIDKey: noConversationIDKey,
7269
targetConversationIDKey: noConversationIDKey,
7370
})
7471

75-
export const makeStaticConfig: I.RecordFactory<Types._StaticConfig> = I.Record({
76-
builtinCommands: [],
72+
export const makeStaticConfig = I.Record<Types._StaticConfig>({
73+
builtinCommands: {
74+
[RPCChatTypes.ConversationBuiltinCommandTyp.adhoc]: [],
75+
[RPCChatTypes.ConversationBuiltinCommandTyp.bigteam]: [],
76+
[RPCChatTypes.ConversationBuiltinCommandTyp.bigteamgeneral]: [],
77+
[RPCChatTypes.ConversationBuiltinCommandTyp.none]: [],
78+
[RPCChatTypes.ConversationBuiltinCommandTyp.smallteam]: [],
79+
},
7780
deletableByDeleteHistory: I.Set(),
7881
})
7982

80-
export const makeThreadSearchInfo: I.RecordFactory<Types._ThreadSearchInfo> = I.Record({
83+
export const makeThreadSearchInfo = I.Record<Types._ThreadSearchInfo>({
8184
hits: I.List(),
8285
status: 'initial',
8386
visible: false,
@@ -88,7 +91,7 @@ export const inboxSearchMaxTextResults = 50
8891
export const inboxSearchMaxNameResults = 7
8992
export const inboxSearchMaxUnreadNameResults = isMobile ? 5 : 10
9093

91-
export const makeInboxSearchInfo: I.RecordFactory<Types._InboxSearchInfo> = I.Record({
94+
export const makeInboxSearchInfo = I.Record<Types._InboxSearchInfo>({
9295
indexPercent: 0,
9396
nameResults: I.List(),
9497
nameResultsUnread: false,
@@ -99,12 +102,12 @@ export const makeInboxSearchInfo: I.RecordFactory<Types._InboxSearchInfo> = I.Re
99102
textStatus: 'initial',
100103
})
101104

102-
export const makeInboxSearchConvHit: I.RecordFactory<Types._InboxSearchConvHit> = I.Record({
105+
export const makeInboxSearchConvHit = I.Record<Types._InboxSearchConvHit>({
103106
conversationIDKey: noConversationIDKey,
104107
teamType: 'small',
105108
})
106109

107-
export const makeInboxSearchTextHit: I.RecordFactory<Types._InboxSearchTextHit> = I.Record({
110+
export const makeInboxSearchTextHit = I.Record<Types._InboxSearchTextHit>({
108111
conversationIDKey: noConversationIDKey,
109112
numHits: 0,
110113
query: '',
@@ -114,7 +117,11 @@ export const makeInboxSearchTextHit: I.RecordFactory<Types._InboxSearchTextHit>
114117

115118
export const getInboxSearchSelected = (inboxSearch: Types.InboxSearchInfo) => {
116119
if (inboxSearch.selectedIndex < inboxSearch.nameResults.size) {
117-
const conversationIDKey = inboxSearch.nameResults.get(inboxSearch.selectedIndex)?.conversationIDKey
120+
const maybeNameResults = inboxSearch.nameResults.get(inboxSearch.selectedIndex)
121+
const conversationIDKey =
122+
maybeNameResults === null || maybeNameResults === undefined
123+
? undefined
124+
: maybeNameResults.conversationIDKey
118125
if (conversationIDKey) {
119126
return {
120127
conversationIDKey,
@@ -144,7 +151,7 @@ export const getMessage = (
144151
state: TypedState,
145152
id: Types.ConversationIDKey,
146153
ordinal: Types.Ordinal
147-
): ?Types.Message => state.chat2.messageMap.getIn([id, ordinal])
154+
): Types.Message | null => state.chat2.messageMap.getIn([id, ordinal])
148155
export const getMessageKey = (message: Types.Message) =>
149156
`${message.conversationIDKey}:${Types.ordinalToNumber(message.ordinal)}`
150157
export const getHasBadge = (state: TypedState, id: Types.ConversationIDKey) =>
@@ -157,7 +164,8 @@ export const getReplyToOrdinal = (state: TypedState, conversationIDKey: Types.Co
157164
}
158165
export const getReplyToMessageID = (state: TypedState, conversationIDKey: Types.ConversationIDKey) => {
159166
const ordinal = getReplyToOrdinal(state, conversationIDKey)
160-
return ordinal ? getMessage(state, conversationIDKey, ordinal)?.id : null
167+
const maybeMessage = getMessage(state, conversationIDKey, ordinal)
168+
return ordinal ? (maybeMessage === null || maybeMessage === undefined ? undefined : maybeMessage.id) : null
161169
}
162170

163171
export const getEditInfo = (state: TypedState, id: Types.ConversationIDKey) => {
@@ -202,7 +210,11 @@ export const isUserActivelyLookingAtThisThread = (
202210
if (isMobile) {
203211
chatThreadSelected = true // conversationIDKey === selectedConversationIDKey is the only thing that matters in the new router
204212
} else {
205-
chatThreadSelected = Router2.getVisibleScreen()?.routeName === 'chatRoot'
213+
const maybeVisibleScreen = Router2.getVisibleScreen()
214+
chatThreadSelected =
215+
(maybeVisibleScreen === null || maybeVisibleScreen === undefined
216+
? undefined
217+
: maybeVisibleScreen.routeName) === 'chatRoot'
206218
}
207219

208220
return (
@@ -216,8 +228,14 @@ export const isTeamConversationSelected = (state: TypedState, teamname: string)
216228
const meta = getMeta(state, getSelectedConversation(state))
217229
return meta.teamname === teamname
218230
}
219-
export const isInfoPanelOpen = (state: TypedState) =>
220-
Router2.getVisibleScreen()?.routeName === 'chatInfoPanel'
231+
export const isInfoPanelOpen = (state: TypedState) => {
232+
const maybeVisibleScreen = Router2.getVisibleScreen()
233+
return (
234+
(maybeVisibleScreen === null || maybeVisibleScreen === undefined
235+
? undefined
236+
: maybeVisibleScreen.routeName) === 'chatInfoPanel'
237+
)
238+
}
221239

222240
export const inboxSearchNewKey = 'chat:inboxSearchNew'
223241
export const waitingKeyJoinConversation = 'chat:joinConversation'
@@ -253,17 +271,17 @@ export const explodingModeGregorKeyPrefix = 'exploding:'
253271
export const explodingModeGregorKey = (c: Types.ConversationIDKey): string =>
254272
`${explodingModeGregorKeyPrefix}${c}`
255273
export const getConversationExplodingMode = (state: TypedState, c: Types.ConversationIDKey): number => {
256-
let mode = state.chat2.getIn(['explodingModeLocks', c], null)
274+
let mode = state.chat2.explodingModeLocks.get(c, null)
257275
if (mode === null) {
258-
mode = state.chat2.getIn(['explodingModes', c], 0)
276+
mode = state.chat2.explodingModes.get(c, 0)
259277
}
260278
const meta = getMeta(state, c)
261279
const convRetention = getEffectiveRetentionPolicy(meta)
262280
mode = convRetention.type === 'explode' ? Math.min(mode || Infinity, convRetention.seconds) : mode
263281
return mode || 0
264282
}
265283
export const isExplodingModeLocked = (state: TypedState, c: Types.ConversationIDKey) =>
266-
state.chat2.getIn(['explodingModeLocks', c], null) !== null
284+
state.chat2.explodingModeLocks.get(c, null) !== null
267285

268286
export const getTeamMentionName = (name: string, channel: string) => {
269287
return name + (channel ? `#${channel}` : '')
@@ -290,7 +308,7 @@ export const makeInboxQuery = (
290308
}
291309
}
292310

293-
export const anyToConversationMembersType = (a: any): ?RPCChatTypes.ConversationMembersType => {
311+
export const anyToConversationMembersType = (a: any): RPCChatTypes.ConversationMembersType | null => {
294312
const membersTypeNumber: number = typeof a === 'string' ? parseInt(a, 10) : a || -1
295313
switch (membersTypeNumber) {
296314
case RPCChatTypes.ConversationMembersType.kbfs:

0 commit comments

Comments
 (0)