1- // @flow
21import * as I from 'immutable'
32import * as Types from '../types/chat2'
43import * as RPCChatTypes from '../types/rpc-chat-gen'
54import * as RPCTypes from '../../constants/types/rpc-gen'
65import * as TeamBuildingConstants from '../../constants/team-building'
76import { clamp } from 'lodash-es'
87import { chatTab } from '../tabs'
9- import type { TypedState } from '../reducer'
8+ import { TypedState } from '../reducer'
109import { isMobile } from '../platform'
1110import {
1211 noConversationIDKey ,
@@ -19,7 +18,7 @@ import {formatTextForQuoting} from '../../util/chat'
1918import * as Router2 from '../router2'
2019import 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
8891export const inboxSearchMaxNameResults = 7
8992export 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
115118export 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 ] )
148155export const getMessageKey = ( message : Types . Message ) =>
149156 `${ message . conversationIDKey } :${ Types . ordinalToNumber ( message . ordinal ) } `
150157export const getHasBadge = ( state : TypedState , id : Types . ConversationIDKey ) =>
@@ -157,7 +164,8 @@ export const getReplyToOrdinal = (state: TypedState, conversationIDKey: Types.Co
157164}
158165export 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
163171export 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
222240export const inboxSearchNewKey = 'chat:inboxSearchNew'
223241export const waitingKeyJoinConversation = 'chat:joinConversation'
@@ -253,17 +271,17 @@ export const explodingModeGregorKeyPrefix = 'exploding:'
253271export const explodingModeGregorKey = ( c : Types . ConversationIDKey ) : string =>
254272 `${ explodingModeGregorKeyPrefix } ${ c } `
255273export 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}
265283export const isExplodingModeLocked = ( state : TypedState , c : Types . ConversationIDKey ) =>
266- state . chat2 . getIn ( [ ' explodingModeLocks' , c ] , null ) !== null
284+ state . chat2 . explodingModeLocks . get ( c , null ) !== null
267285
268286export 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