Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More gen 22: Flow coverage exploration #9575

Conversation

chrisnojima
Copy link
Contributor

@chrisnojima chrisnojima commented Nov 16, 2017

Did some analysis of the flow coverage and found some underlying issues

  • Fix flow-types Promise
  • Flow-types usage of Buffer pulls in 3rd party buffer (for RN) but has no real types so it falls back to any. This caused a TON of issues. Instead we pull in the Node buffer and that reveals a bunch of stuff.

Chat

  • Fixed a bunch of mismatch types of string/buffer re: outboxid and messageid, convID vs conversationIDKey

Search/Teams:
Split the constants/types to remove cyclic dependencies in flow (if you run flow check --profile it'll tell you when it detects one)

@@ -17,7 +17,7 @@ export const mobileAppState = 'app:mobileAppState'
export const createChangedActive = (payload: {|+userActive: boolean|}) => ({error: false, payload, type: changedActive})
export const createChangedFocus = (payload: {|+appFocused: boolean|}) => ({error: false, payload, type: changedFocus})
export const createLink = (payload: {|+link: string|}) => ({error: false, payload, type: link})
export const createMobileAppState = (payload: {|+nextAppState: string|}) => ({error: false, payload, type: mobileAppState})
export const createMobileAppState = (payload: {|+nextAppState: 'active' | 'background' | 'inactive'|}) => ({error: false, payload, type: mobileAppState})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from RN docs

@@ -151,7 +151,7 @@ export const createSaveAttachment = (payload: {|+messageKey: Types.MessageKey|})
export const createSaveAttachmentNative = (payload: {|+messageKey: Types.MessageKey|}) => ({error: false, payload, type: saveAttachmentNative})
export const createSelectAttachment = (payload: {|+input: Types.AttachmentInput|}) => ({error: false, payload, type: selectAttachment})
export const createSelectConversation = (payload: {|+conversationIDKey: ?Types.ConversationIDKey, +fromUser?: boolean|}) => ({error: false, payload, type: selectConversation})
export const createSelectNext = (payload: {|+rows: Array<any>, +direction: -1 | 1|}) => ({error: false, payload, type: selectNext})
export const createSelectNext = (payload: {|+rows: Array<{conversationIDKey: Types.ConversationIDKey}>, +direction: -1 | 1|}) => ({error: false, payload, type: selectNext})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really we care about pulling the convoId out

@@ -40,6 +40,7 @@ const _getInboxQuery = {
// Update inboxes that have been reset
function* _updateFinalized(inbox: RPCChatTypes.UnverifiedInboxUIItems): Generator<any, void, any> {
const finalizedState: Types.FinalizedState = I.Map(
// TODO i *think* this typing is totally incorrect. should be .items etc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong

@@ -387,7 +392,7 @@ function* _chatInboxFailedSubSaga(params) {
? I.List([].concat(error.rekeyInfo.writerNames, error.rekeyInfo.readerNames).filter(Boolean))
: I.List(error.unverifiedTLFName.split(',')),
status: 'unfiled',
time: error.remoteConv.readerInfo.mtime,
time: error.remoteConv.readerInfo ? error.remoteConv.readerInfo.mtime : 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avdl says this can be missing

@@ -650,7 +655,7 @@ function* _sendNotifications(action: ChatGen.AppendMessagesPayload): Saga.SagaGe
if (message && message.type === 'Text') {
console.log('Sending Chat notification')
const snippet = Constants.makeSnippet(Constants.serverMessageToMessageText(message))
yield Saga.put((dispatch: Dispatch) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use Dispatch globally a lot but its really untyped. The one from redux also doesn't understand thunks

@@ -42,9 +42,12 @@ function* deleteMessage(action: ChatGen.DeleteMessagePayload): SagaGenerator<any
}
const tlfName: string = inboxConvo.name

const parsedMessageID = lastMessageID ? Constants.parseMessageID(lastMessageID) : null
const clientPrev = parsedMessageID && parsedMessageID.type === 'rpcMessageID' ? parsedMessageID.msgID : 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only valid clientPrevs are from real messages and not the other things in the stream

@@ -386,7 +386,7 @@ function _unboxedToMessage(
: null
// $FlowIssue
const messageText: ChatTypes.MessageText = message.outbox.body
const outboxIDKey = payload.outboxID && Constants.outboxIDToKey(payload.outboxID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outboxIDKeys are already coming down as the hex strings

@@ -1,6 +1,5 @@
// @flow
import {RPCError} from '../util/errors'
import {Buffer} from 'buffer'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we caused the confusion w/ Buffer

totals[conversationIDKey] = total
if (badged) {
badges[conversationIDKey] = badged
const convID = conv.get('convID')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely never null in practice but is possible

@@ -156,7 +156,7 @@ const _onTabChange = (action: RouteTreeTypes.SwitchTo) => {
}

function* _handleIncomingGregor(action: GitGen.HandleIncomingGregorPayload): Saga.SagaGenerator<any, any> {
const msgs = action.payload.messages.map(msg => JSON.parse(msg.body))
const msgs = action.payload.messages.map(msg => JSON.parse(msg.body.toString()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this worked before because the buffer is essentially casting to a string implicitly using toString() but this thing really is a buffer

const createdTLFs = msgsWithParsedBodies.filter(m => m.body.action === 'create')

const username: string = (yield Saga.select(usernameSelector): any)
const createdTLFs: Array<{action: string, tlf: ?string}> = kbfsFavoriteMessages
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flow got confused when we overwrote the body prop with a new body. we don't even use the raw ...m part so lets just get rid of it

@@ -371,9 +371,8 @@ function _afterGetChannels(

const convs = results.convs || []
convs.forEach(conv => {
const convID = ChatConstants.conversationIDToKey(conv.convID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conv.convID is actually a string already

ChatConstants.keyToConversationID(channelnameToConvID[channelname]),
})
})
const convID =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpc needs this to be non null

convID,
})
}
}).filter(Boolean)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filtering this cause we can return from map w/ undefined

@@ -26,7 +27,9 @@ const getIsEmpty = (state: TypedState) => state.chat.get('inboxIsEmpty')
const getPending = (state: TypedState) => state.chat.get('pendingConversations')
const getSmallTimestamps = (state: TypedState) => state.chat.getIn(['inboxSmallTimestamps'], I.Map())
const getSupersededBy = (state: TypedState) => state.chat.get('inboxSupersededBy')
const _rowsForSelect = (rows: Array<any>) => rows.filter(r => ['small', 'big'].includes(r.type))
const _rowsForSelect = (rows: Array<Inbox.RowItem>): Array<Inbox.RowItemSmall | Inbox.RowItemBig> =>
// $FlowIssue doesn't underestand filter refinement sadly
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

const mapDispatchToProps = (dispatch: Dispatch, {focusFilter, routeState, setRouteState}) => ({
const mapDispatchToProps = (dispatch: any => void, {focusFilter, routeState, setRouteState}: OwnProps) => ({
Copy link
Contributor Author

@chrisnojima chrisnojima Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO (later) we could update our dispatch type

@chrisnojima chrisnojima changed the title WIP: Flow coverage exploration More gen 22: Flow coverage exploration Nov 16, 2017
@@ -114,54 +59,18 @@ function maybeUpgradeSearchResultIdToKeybaseId(
return id
}

function platformToIcon(service: Service): IconType {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are never used

@@ -0,0 +1,37 @@
// @flow
// Sep. engine file so we can avoid import cycles w/ flow-types.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flow-types pulls in engine which pulls in flow-types etc, lets not have that happen

@chrisnojima
Copy link
Contributor Author

@keybase/react-hackers this is ready

@chrisnojima
Copy link
Contributor Author

I merged 21 and below so this needs to be reopened vs master

WIP

WIP

WIP

WIP

WIP

WIP

remove flow cyclic deps. split teams / search consts

add coverage to packagejson
@chrisnojima
Copy link
Contributor Author

replaced by #9685

@chrisnojima chrisnojima deleted the nojima/DESKTOP-more-gen-2-22-2 branch March 14, 2018 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant