Skip to content

Commit 1b488c2

Browse files
committed
types: Express Outbox as PmOutbox | StreamOutbox.
Like we did with `PmMessage` and `StreamMessage` in zulip#4506. We don't actually make `PmOutbox` any different from `StreamOutbox` in this commit; that'll come later.
1 parent ea58a61 commit 1b488c2

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

src/types.js

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import type { IntlShape } from 'react-intl';
33
import type { DangerouslyImpreciseStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
44

55
import type { SubsetProperties } from './generics';
6-
import type { Auth, Topic, Message, ReactionType, UserId } from './api/apiTypes';
6+
import type {
7+
Auth,
8+
Topic,
9+
Message,
10+
PmMessage,
11+
StreamMessage,
12+
ReactionType,
13+
UserId,
14+
} from './api/apiTypes';
715
import type { ZulipVersion } from './utils/zulipVersion';
816
import type { PmKeyUsers } from './utils/recipient';
917

@@ -145,27 +153,10 @@ export type TopicExtended = {|
145153
|};
146154

147155
/**
148-
* A message we're in the process of sending.
149-
*
150-
* We use these objects for two purposes:
151-
*
152-
* (a) They make up the queue of messages the user has asked us to send, and
153-
* which we'll retry sending if initial attempts fail. See
154-
* `trySendMessages`.
155-
*
156-
* (b) We show them immediately in the message list, even before we've
157-
* successfully gotten them to the server (but with an activity
158-
* indicator to show we're still working on them.)
159-
*
160-
* Even after (a) is complete for a given message, we still need the
161-
* `Outbox` object for the sake of (b), until we hear an `EVENT_NEW_MESSAGE`
162-
* event from the server that lets us replace it with the corresponding
163-
* `Message` object.
164-
*
165-
* This type most often appears in the union `Message | Outbox`, and so its
166-
* properties are deliberately similar to those of `Message`.
156+
* Properties in common among the two different flavors of a
157+
* `Outbox`: `PmOutbox` and `StreamOutbox`.
167158
*/
168-
export type Outbox = $ReadOnly<{|
159+
export type OutboxBase = $ReadOnly<{|
169160
/** Used for distinguishing from a `Message` object. */
170161
isOutbox: true,
171162

@@ -184,6 +175,8 @@ export type Outbox = $ReadOnly<{|
184175

185176
/* eslint-disable flowtype/generic-spacing */
186177
...SubsetProperties<
178+
// Could use `MessageBase` here, but Flow would complain anyway if
179+
// we tried to put something that's not in `MessageBase` below.
187180
Message,
188181
{|
189182
avatar_url: mixed,
@@ -201,6 +194,41 @@ export type Outbox = $ReadOnly<{|
201194
>,
202195
|}>;
203196

197+
export type PmOutbox = {|
198+
...OutboxBase,
199+
200+
...SubsetProperties<PmMessage, {||}>,
201+
|};
202+
203+
export type StreamOutbox = {|
204+
...OutboxBase,
205+
206+
...SubsetProperties<StreamMessage, {||}>,
207+
|};
208+
209+
/**
210+
* A message we're in the process of sending.
211+
*
212+
* We use these objects for two purposes:
213+
*
214+
* (a) They make up the queue of messages the user has asked us to send, and
215+
* which we'll retry sending if initial attempts fail. See
216+
* `trySendMessages`.
217+
*
218+
* (b) We show them immediately in the message list, even before we've
219+
* successfully gotten them to the server (but with an activity
220+
* indicator to show we're still working on them.)
221+
*
222+
* Even after (a) is complete for a given message, we still need the
223+
* `Outbox` object for the sake of (b), until we hear an `EVENT_NEW_MESSAGE`
224+
* event from the server that lets us replace it with the corresponding
225+
* `Message` object.
226+
*
227+
* This type most often appears in the union `Message | Outbox`, and so its
228+
* properties are deliberately similar to those of `Message`.
229+
*/
230+
export type Outbox = PmOutbox | StreamOutbox;
231+
204232
/**
205233
* MessageLike: Imprecise alternative to `Message | Outbox`.
206234
*

0 commit comments

Comments
 (0)