Skip to content

Commit 0c251bf

Browse files
committed
outbox: Add a stream_id property
Compare a1fad7c, which did the same for the sender_id property. We actually did part of this a few months ago, in fce3e8b in #4667. That commit added it to the type, but we hadn't yet taken the step of supplying this property in any actual Outbox values. Also add back to a TODO comment a bit that got dropped in 8171f2d. This makes #3998 mostly complete: the remaining steps will be to get a release with this change out, wait a few weeks, then make `stream_id` required with a migration to drop `Outbox` values that lack it, just as we did for `sender_id` before. Issue: #3998
1 parent 87ee111 commit 0c251bf

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/outbox/outboxActions.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
Outbox,
1313
PmOutbox,
1414
StreamOutbox,
15+
Stream,
1516
UserOrBot,
1617
UserId,
1718
Action,
@@ -24,7 +25,7 @@ import {
2425
DELETE_OUTBOX_MESSAGE,
2526
MESSAGE_SEND_COMPLETE,
2627
} from '../actionConstants';
27-
import { getAuth } from '../selectors';
28+
import { getAuth, getStreamsByName } from '../selectors';
2829
import * as api from '../api';
2930
import { getAllUsersById, getOwnUser } from '../users/userSelectors';
3031
import { getUsersAndWildcards } from '../users/userHelpers';
@@ -127,12 +128,14 @@ const recipientsFromIds = (ids, allUsersById, ownUser) => {
127128
return result;
128129
};
129130

131+
// prettier-ignore
130132
type DataFromNarrow =
131133
| SubsetProperties<PmOutbox, {| type: mixed, display_recipient: mixed, subject: mixed |}>
132-
| SubsetProperties<StreamOutbox, {| type: mixed, display_recipient: mixed, subject: mixed |}>;
134+
| SubsetProperties<StreamOutbox, {| type: mixed, stream_id: mixed, display_recipient: mixed, subject: mixed |}>;
133135

134136
const outboxPropertiesForNarrow = (
135137
destinationNarrow: Narrow,
138+
streamsByName: Map<string, Stream>,
136139
allUsersById: Map<UserId, UserOrBot>,
137140
ownUser: UserOrBot,
138141
): DataFromNarrow =>
@@ -143,11 +146,16 @@ const outboxPropertiesForNarrow = (
143146
subject: '',
144147
}),
145148

146-
topic: (streamName, topic) => ({
147-
type: 'stream',
148-
display_recipient: streamName,
149-
subject: topic,
150-
}),
149+
topic: (streamName, topic) => {
150+
const stream = streamsByName.get(streamName);
151+
invariant(stream, 'narrow must be known stream');
152+
return {
153+
type: 'stream',
154+
stream_id: stream.stream_id,
155+
display_recipient: stream.name,
156+
subject: topic,
157+
};
158+
},
151159
});
152160

153161
const getContentPreview = (content: string, state: GlobalState): string => {
@@ -177,7 +185,12 @@ export const addToOutbox = (
177185
dispatch(
178186
messageSendStart({
179187
isSent: false,
180-
...outboxPropertiesForNarrow(destinationNarrow, getAllUsersById(state), ownUser),
188+
...outboxPropertiesForNarrow(
189+
destinationNarrow,
190+
getStreamsByName(state),
191+
getAllUsersById(state),
192+
ownUser,
193+
),
181194
markdownContent: content,
182195
content: getContentPreview(content, state),
183196
timestamp: localTime,

src/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ export type StreamOutbox = $ReadOnly<{|
223223
// in the Outbox values we create; compare a1fad7ca9, for sender_id.
224224
//
225225
// Once it is required, it should move from here to the second type
226-
// argument passed to `SubsetProperties` of `StreamMessage`, below.
226+
// argument passed to `SubsetProperties` of `StreamMessage`, below;
227+
// and we can also drop the hack line about it in `MessageLike`.
227228
stream_id?: number,
228229

229230
...SubsetProperties<

0 commit comments

Comments
 (0)