Skip to content

Commit 8cec78b

Browse files
committed
modelTypes: Move .stream_id from Message to StreamMessage.
Flow gives us one substantive bit of feedback and one kind of false alarm: - We shouldn't be putting a `stream_id` on PMs in exampleData; so, stop doing that. - When we start putting things together to call `addItemsToStreamArray`, we need to be sure `action.message` is a stream message. We were already sure of that; there's already an early return on `action.message.type !== stream`. But that early return needs to be just a bit later in order to satisfy Flow that `action.message` can't be a stream message. In particular, as Greg explains [1], """ Specifically what's happening is: we check `action.message.type`, but then we call `getOwnUserId` -- and that's some function that might go and do anything. So in particular it might go and mutate the same object that we're looking at as `action.message`. So that object *had* had a `type` of `'private'`, but now it might not and so it might not have a `stream_id`. """ [1] zulip#4506 (comment) In particular, Flow sees the `getOwnUserId` call, and that's some function that might go and do anything -- including But Flow seems to think it's done too early, and that something in the intervening code might thwart the job it's doing. So, move that early return a bit later.
1 parent 14ceae4 commit 8cec78b

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ export const pmMessage = (args?: {|
348348
// in real messages. (See comments on the Message type.)
349349
display_recipient: recipients.map(displayRecipientFromUser),
350350
id: randMessageId(),
351-
stream_id: -1,
352351
subject: '',
353352
timestamp: 1556579160,
354353
type: 'private',

src/api/modelTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,6 @@ type MessageBase = $ReadOnly<{|
543543
*/
544544
display_recipient: string | $ReadOnlyArray<PmRecipientUser>, // `string` for type stream, else PmRecipientUser[]
545545

546-
stream_id: number, // FixMe: actually only for type `stream`, else absent.
547-
548546
subject: string,
549547
subject_links: $ReadOnlyArray<string>,
550548
|}>;
@@ -561,6 +559,8 @@ export type StreamMessage = $ReadOnly<{|
561559

562560
// TODO: Put stream-message fields here.
563561
type: 'stream',
562+
563+
stream_id: number,
564564
|}>;
565565

566566
/**

src/unread/unreadStreamsReducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import { getOwnUserId } from '../users/userSelectors';
1616
const initialState: UnreadStreamsState = NULL_ARRAY;
1717

1818
const eventNewMessage = (state, action, globalState) => {
19-
if (action.message.type !== 'stream') {
19+
if (getOwnUserId(globalState) === action.message.sender_id) {
2020
return state;
2121
}
2222

23-
if (getOwnUserId(globalState) === action.message.sender_id) {
23+
if (action.message.type !== 'stream') {
2424
return state;
2525
}
2626

0 commit comments

Comments
 (0)