Skip to content

Commit 7f003bd

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 78d773a commit 7f003bd

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

src/types.js

Lines changed: 47 additions & 23 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

@@ -140,28 +148,7 @@ export type TopicExtended = {|
140148
unreadCount: number,
141149
|};
142150

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

@@ -180,6 +167,8 @@ export type Outbox = $ReadOnly<{|
180167

181168
/* eslint-disable flowtype/generic-spacing */
182169
...SubsetProperties<
170+
// Could use `MessageBase` here, but Flow would complain anyway if
171+
// we tried to put something that's not in `MessageBase` below.
183172
Message,
184173
{|
185174
avatar_url: mixed,
@@ -197,6 +186,41 @@ export type Outbox = $ReadOnly<{|
197186
>,
198187
|}>;
199188

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

0 commit comments

Comments
 (0)