-
-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make PmMessage
and StreamMessage
types.
#4506
Merged
gnprice
merged 19 commits into
zulip:master
from
chrisbobbe:draft-separate-pm-stream-message-types
Apr 1, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
00efd3a
fetchActions tests [nfc]: Drop an `omit` that we don't need anymore.
chrisbobbe 3dbfb3f
getMessages [nfc]: Stop using some variables we've defined.
chrisbobbe cb43516
getMessages [nfc]: Stop using `restMessage` in `migrateMessages`.
chrisbobbe c65b5b7
getMessages [nfc]: Straighten up after a recent refactor.
chrisbobbe ef6f11e
modelTypes: Move `recipient_id` higher up in `Message`.
chrisbobbe cd4820d
modelTypes: Remove `recipient_id` from `Message`.
chrisbobbe 09383f9
modelTypes: Start separating `PmMessage` and `StreamMessage`.
chrisbobbe 349bfae
exampleData types: Annotate PM-making functions as using `PmMessage`.
chrisbobbe 65de873
exampleData types: Annotate `streamMessage` as using `StreamMessage`.
chrisbobbe d011b98
modelTypes: Make `Message` a union of `PmMessage` and `StreamMessage`.
chrisbobbe de3a754
getMessages types: Make `messages` in `migrateMessages` a read-only a…
chrisbobbe c1e1824
messagesReducer types: Handle `Message` being `PmMessage` | `StreamMe…
chrisbobbe 2373c12
getMessages types: Handle `Message` being `PmMessage` | `StreamMessage`.
chrisbobbe 4e2d18d
modelTypes: Split `Message.type` into `PmMessage` and `StreamMessage`.
chrisbobbe d6d5109
modelTypes: Move `.stream_id` from `Message` to `StreamMessage`.
chrisbobbe 1fb5d0c
modelTypes: Split Message.display_recipient into PmMessage / StreamMe…
chrisbobbe 7ca46cd
messagesReducer [nfc]: Prepare for more splitting of `Message`.
chrisbobbe fad245b
modelTypes: Split `Message.subject` into `PmMessage` and `StreamMessa…
chrisbobbe ce55fbf
modelTypes: Move `.subject_links` from `Message` to `StreamMessage`.
chrisbobbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,48 +445,10 @@ export type Submessage = $ReadOnly<{| | |
|}>; | ||
|
||
/** | ||
* A Zulip message. | ||
* | ||
* This type is mainly intended to represent the data the server sends as | ||
* the `message` property of an event of type `message`. Caveat lector: we | ||
* pass these around to a lot of places, and do a lot of further munging, so | ||
* this type may not quite represent that. Any differences should | ||
* definitely be commented, and perhaps refactored. | ||
* | ||
* The server's behavior here is undocumented and the source is very | ||
* complex; this is naturally a place where a large fraction of all the | ||
* features of Zulip have to appear. | ||
* | ||
* Major appearances of this type include | ||
* * `message: Message` on a server event of type `message`, and our | ||
* `EVENT_NEW_MESSAGE` Redux action for the event; | ||
* * `messages: Message[]` in a `/messages` (our `getMessages`) response, | ||
* and our resulting `MESSAGE_FETCH_COMPLETE` Redux action; | ||
* * `messages: {| [id]: Message |}` in our global Redux state. | ||
* | ||
* References include: | ||
* * the two example events at https://zulip.com/api/get-events-from-queue | ||
* * `process_message_event` in zerver/tornado/event_queue.py; the call | ||
* `client.add_event(user_event)` makes the final determination of what | ||
* goes into the event, so `message_dict` is the final value of `message` | ||
* * `MessageDict.wide_dict` and its helpers in zerver/lib/message.py; | ||
* via `do_send_messages` in `zerver/lib/actions.py`, these supply most | ||
* of the data ultimately handled by `process_message_event` | ||
* * `messages_for_ids` and its helpers in zerver/lib/message.py; via | ||
* `get_messages_backend`, these supply the data ultimately returned by | ||
* `/messages` | ||
* * the `Message` and `AbstractMessage` models in zerver/models.py, but | ||
* with caution; many fields are adjusted between the DB row and the event | ||
* * empirical study looking at Redux events logged [to the | ||
* console](docs/howto/debugging.md). | ||
* | ||
* See also `Outbox`, which is deliberately similar so that we can use | ||
* the type `Message | Outbox` in many places. | ||
* | ||
* See also `MessagesState` for discussion of how we fetch and store message | ||
* data. | ||
* Properties in common among the two different flavors of a | ||
* `Message`: `PmMessage` and `StreamMessage`. | ||
*/ | ||
export type Message = $ReadOnly<{| | ||
type MessageBase = $ReadOnly<{| | ||
gnprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** Our own flag; if true, really type `Outbox`. */ | ||
isOutbox: false, | ||
|
||
|
@@ -544,10 +506,14 @@ export type Message = $ReadOnly<{| | |
|
||
timestamp: number, | ||
|
||
// | ||
// Properties that behave differently for stream vs. private messages. | ||
/** Deprecated; a server implementation detail not useful in a client. */ | ||
// recipient_id: number, | ||
|}>; | ||
|
||
type: 'stream' | 'private', | ||
export type PmMessage = $ReadOnly<{| | ||
...MessageBase, | ||
|
||
type: 'private', | ||
|
||
// Notes from studying the server code: | ||
// * Notes are primarily from the server as of 2020-04 at cb85763c7, but | ||
|
@@ -567,27 +533,81 @@ export type Message = $ReadOnly<{| | |
// it sorted by user ID; so, best not to assume current behavior. | ||
// | ||
/** | ||
* The set of all users in the thread, for a PM; else the stream name. | ||
* The set of all users in the thread. | ||
* | ||
* For a private message, this lists the sender as well as all (other) | ||
* recipients, and it lists each user just once. In particular the | ||
* self-user is always included. | ||
* This lists the sender as well as all (other) recipients, and it | ||
* lists each user just once. In particular the self-user is always | ||
* included. | ||
* | ||
* The ordering is less well specified; if it matters, sort first. | ||
* | ||
* For stream messages, prefer `stream_id`; see #3918. | ||
*/ | ||
display_recipient: string | $ReadOnlyArray<PmRecipientUser>, // `string` for type stream, else PmRecipientUser[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎊 |
||
display_recipient: $ReadOnlyArray<PmRecipientUser>, | ||
|
||
/** Deprecated; a server implementation detail not useful in a client. */ | ||
recipient_id: number, | ||
subject: '', | ||
|}>; | ||
|
||
export type StreamMessage = $ReadOnly<{| | ||
...MessageBase, | ||
|
||
stream_id: number, // FixMe: actually only for type `stream`, else absent. | ||
type: 'stream', | ||
|
||
/** | ||
* The stream name. | ||
* | ||
* Prefer `stream_id`; see #3918. | ||
*/ | ||
display_recipient: string, | ||
|
||
stream_id: number, | ||
|
||
subject: string, | ||
subject_links: $ReadOnlyArray<string>, | ||
|}>; | ||
|
||
/** | ||
* A Zulip message. | ||
* | ||
* This type is mainly intended to represent the data the server sends as | ||
* the `message` property of an event of type `message`. Caveat lector: we | ||
* pass these around to a lot of places, and do a lot of further munging, so | ||
* this type may not quite represent that. Any differences should | ||
* definitely be commented, and perhaps refactored. | ||
* | ||
* The server's behavior here is undocumented and the source is very | ||
* complex; this is naturally a place where a large fraction of all the | ||
* features of Zulip have to appear. | ||
* | ||
* Major appearances of this type include | ||
* * `message: Message` on a server event of type `message`, and our | ||
* `EVENT_NEW_MESSAGE` Redux action for the event; | ||
* * `messages: Message[]` in a `/messages` (our `getMessages`) response, | ||
* and our resulting `MESSAGE_FETCH_COMPLETE` Redux action; | ||
* * `messages: {| [id]: Message |}` in our global Redux state. | ||
* | ||
* References include: | ||
* * the two example events at https://zulip.com/api/get-events-from-queue | ||
* * `process_message_event` in zerver/tornado/event_queue.py; the call | ||
* `client.add_event(user_event)` makes the final determination of what | ||
* goes into the event, so `message_dict` is the final value of `message` | ||
* * `MessageDict.wide_dict` and its helpers in zerver/lib/message.py; | ||
* via `do_send_messages` in `zerver/lib/actions.py`, these supply most | ||
* of the data ultimately handled by `process_message_event` | ||
* * `messages_for_ids` and its helpers in zerver/lib/message.py; via | ||
* `get_messages_backend`, these supply the data ultimately returned by | ||
* `/messages` | ||
* * the `Message` and `AbstractMessage` models in zerver/models.py, but | ||
* with caution; many fields are adjusted between the DB row and the event | ||
* * empirical study looking at Redux events logged [to the | ||
* console](docs/howto/debugging.md). | ||
* | ||
* See also `Outbox`, which is deliberately similar so that we can use | ||
* the type `Message | Outbox` in many places. | ||
* | ||
* See also `MessagesState` for discussion of how we fetch and store message | ||
* data. | ||
*/ | ||
export type Message = PmMessage | StreamMessage; | ||
|
||
// | ||
// | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the
$ReadOnly
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On
ServerMessageOf
, right? Or onServerMessage
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep,
ServerMessageOf
(as you've done in the revision.) I.e. where the object-type syntax is. ThenServerMessage
gets the benefit too, as it just usesServerMessageOf
.