Skip to content

Commit

Permalink
types: Express Outbox as PmOutbox | StreamOutbox.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisbobbe committed Apr 16, 2021
1 parent 78d773a commit 7f003bd
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import type { IntlShape } from 'react-intl';
import type { DangerouslyImpreciseStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

import type { SubsetProperties } from './generics';
import type { Auth, Topic, Message, ReactionType, UserId } from './api/apiTypes';
import type {
Auth,
Topic,
Message,
PmMessage,
StreamMessage,
ReactionType,
UserId,
} from './api/apiTypes';
import type { ZulipVersion } from './utils/zulipVersion';
import type { PmKeyUsers } from './utils/recipient';

Expand Down Expand Up @@ -140,28 +148,7 @@ export type TopicExtended = {|
unreadCount: number,
|};

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

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

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

export type PmOutbox = {|
...OutboxBase,

...SubsetProperties<PmMessage, {||}>,
|};

export type StreamOutbox = {|
...OutboxBase,

...SubsetProperties<StreamMessage, {||}>,
|};

/**
* A message we're in the process of sending.
*
* We use these objects for two purposes:
*
* (a) They make up the queue of messages the user has asked us to send, and
* which we'll retry sending if initial attempts fail. See
* `trySendMessages`.
*
* (b) We show them immediately in the message list, even before we've
* successfully gotten them to the server (but with an activity
* indicator to show we're still working on them.)
*
* Even after (a) is complete for a given message, we still need the
* `Outbox` object for the sake of (b), until we hear an `EVENT_NEW_MESSAGE`
* event from the server that lets us replace it with the corresponding
* `Message` object.
*
* This type most often appears in the union `Message | Outbox`, and so its
* properties are deliberately similar to those of `Message`.
*/
export type Outbox = PmOutbox | StreamOutbox;

/**
* MessageLike: Imprecise alternative to `Message | Outbox`.
*
Expand Down

0 comments on commit 7f003bd

Please sign in to comment.