Skip to content

Commit

Permalink
narrow [nfc]: Explicitly convert to ApiNarrow where appropriate.
Browse files Browse the repository at this point in the history
This conversion is a no-op.  But we'll shortly be converting `Narrow`
into an opaque type -- which will make it a no-op that only the
`narrow` module can perform.  That means Flow will check for us that
we've explicitly marked all the places where we intend this
conversion to happen; these are those places.
  • Loading branch information
gnprice authored and chrisbobbe committed Dec 17, 2020
1 parent e7485e4 commit ca745d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/message/fetchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
MESSAGE_FETCH_COMPLETE,
} from '../actionConstants';
import { FIRST_UNREAD_ANCHOR, LAST_MESSAGE_ANCHOR } from '../anchor';
import { ALL_PRIVATE_NARROW } from '../utils/narrow';
import { ALL_PRIVATE_NARROW, apiNarrowOfNarrow } from '../utils/narrow';
import { BackoffMachine } from '../utils/async';
import { initNotifications } from '../notification/notificationActions';
import { addToOutbox, sendOutbox } from '../outbox/outboxActions';
Expand Down Expand Up @@ -88,6 +88,7 @@ export const fetchMessages = (fetchArgs: {|
try {
const { messages, found_newest, found_oldest } = await api.getMessages(getAuth(getState()), {
...fetchArgs,
narrow: apiNarrowOfNarrow(fetchArgs.narrow),
useFirstUnread: fetchArgs.anchor === FIRST_UNREAD_ANCHOR, // TODO: don't use this; see #4203
});
dispatch(
Expand Down Expand Up @@ -235,7 +236,7 @@ export const fetchMessagesInNarrow = (
const fetchPrivateMessages = () => async (dispatch: Dispatch, getState: GetState) => {
const auth = getAuth(getState());
const { messages, found_newest, found_oldest } = await api.getMessages(auth, {
narrow: ALL_PRIVATE_NARROW,
narrow: apiNarrowOfNarrow(ALL_PRIVATE_NARROW),
anchor: LAST_MESSAGE_ANCHOR,
numBefore: 100,
numAfter: 0,
Expand Down
7 changes: 6 additions & 1 deletion src/utils/narrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
* into a data structure;
* * `caseNarrow` and its relatives, for pattern-matching or destructuring;
* * `ApiNarrow` for the form we put a narrow in when talking to the
* server.
* server, and `apiNarrowOfNarrow` for converting to it.
*/
export type Narrow = ApiNarrow;

Expand Down Expand Up @@ -459,6 +459,11 @@ export const isStreamOrTopicNarrow = (narrow?: Narrow): boolean =>
export const isSearchNarrow = (narrow?: Narrow): boolean =>
!!narrow && caseNarrowDefault(narrow, { search: () => true }, () => false);
/**
* Convert the narrow into the form used in the Zulip API at get-messages.
*/
export const apiNarrowOfNarrow = (narrow: Narrow): ApiNarrow => narrow;
/**
* True just if the given message is part of the given narrow.
*
Expand Down

0 comments on commit ca745d9

Please sign in to comment.