Skip to content

Commit

Permalink
modelTypes: Move .subject_links from Message to StreamMessage.
Browse files Browse the repository at this point in the history
The last field we need to do this for! :)
  • Loading branch information
chrisbobbe committed Mar 10, 2021
1 parent 17b92c9 commit a5aeb4c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ const messagePropertiesBase = deepFreeze({
is_me_message: false,
// last_edit_timestamp omitted
reactions: [],
subject_links: [],
submessages: [],
});

Expand Down Expand Up @@ -393,6 +392,7 @@ export const streamMessage = (args?: {|
content_type: 'text/markdown',
id: randMessageId(),
subject: 'example topic',
subject_links: [],
timestamp: 1556579727,
type: 'stream',
};
Expand Down
9 changes: 1 addition & 8 deletions src/api/modelTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,11 @@ type MessageBase = $ReadOnly<{|

/** Deprecated; a server implementation detail not useful in a client. */
// recipient_id: number,

//
// Properties that behave differently for stream vs. private messages.
// TODO: Move all these to `PmMessage` and `StreamMessage`.

subject_links: $ReadOnlyArray<string>,
|}>;

export type PmMessage = $ReadOnly<{|
...MessageBase,

// TODO: Put PM-message fields here.
type: 'private',

// Notes from studying the server code:
Expand Down Expand Up @@ -556,7 +549,6 @@ export type PmMessage = $ReadOnly<{|
export type StreamMessage = $ReadOnly<{|
...MessageBase,

// TODO: Put stream-message fields here.
type: 'stream',

/**
Expand All @@ -569,6 +561,7 @@ export type StreamMessage = $ReadOnly<{|
stream_id: number,

subject: string,
subject_links: $ReadOnlyArray<string>,
|}>;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/message/messagesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export default (state: MessagesState = initialState, action: Action): MessagesSt
const messageWithNewCommonFields: M = {
...(oldMessage: M),
content: action.rendered_content || oldMessage.content,
subject_links: action.subject_links || oldMessage.subject_links,
edit_history: [
action.orig_rendered_content
? action.orig_subject !== undefined
Expand Down Expand Up @@ -170,7 +169,8 @@ export default (state: MessagesState = initialState, action: Action): MessagesSt
return messageWithNewCommonFields.type === 'stream'
? {
...messageWithNewCommonFields,
subject: action.subject || oldMessage.subject,
subject: action.subject || messageWithNewCommonFields.subject,
subject_links: action.subject_links || messageWithNewCommonFields.subject_links,
}
: {
...messageWithNewCommonFields,
Expand Down

0 comments on commit a5aeb4c

Please sign in to comment.