Skip to content

Commit e4c1326

Browse files
committed
outbox: Add a sender_id property.
This will allow us to stop using sender_email to identify users in places like renderMessages.
1 parent 67125ef commit e4c1326

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ const outboxMessageBase: $Diff<Outbox, {| id: mixed, timestamp: mixed |}> = deep
376376
reactions: [],
377377
sender_email: selfUser.email,
378378
sender_full_name: selfUser.full_name,
379+
sender_id: selfUser.user_id,
379380
subject: 'test topic',
380381
// timestamp: ...,
381382
type: 'stream',

src/message/renderMessages.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ export default (
3232
});
3333
}
3434

35-
// TODO(#3674): Use sender_id, not sender_email. Needs adding
36-
// a property Outbox#sender_id.
35+
// TODO(#3674): Use sender_id, not sender_email. Needs making
36+
// Outbox#sender_id required; which needs a migration to drop Outbox
37+
// values that lack it; which is fine once the release that adds it
38+
// has been out for a few weeks.
3739
const shouldGroupWithPrev =
3840
!diffRecipient && !diffDays && prevItem && prevItem.sender_email === item.sender_email;
3941

src/outbox/outboxActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export const addToOutbox = (narrow: Narrow, content: string) => async (
186186
id: localTime,
187187
sender_full_name: ownUser.full_name,
188188
sender_email: ownUser.email,
189+
sender_id: ownUser.user_id,
189190
avatar_url: ownUser.avatar_url,
190191
isOutbox: true,
191192
reactions: [],

src/types.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,22 @@ export type Outbox = {|
175175
// It's used for sending the message to the server.
176176
markdownContent: string,
177177

178-
// These fields are modeled on `Message`.
178+
// The remaining fields are modeled on `Message`.
179+
179180
avatar_url: string | null,
180181
content: string,
181182
display_recipient: $FlowFixMe, // `string` for type stream, else PmRecipientUser[].
182183
id: number,
183184
reactions: Reaction[],
184185
sender_email: string,
185186
sender_full_name: string,
187+
188+
// TODO(#3674): Make sender_id required. Needs a migration to drop Outbox
189+
// values that lack it; which is fine once the release that adds it has
190+
// been out for a few weeks.
191+
// (Also drop the hack line about it in MessageLike.)
192+
sender_id?: number,
193+
186194
subject: string,
187195
timestamp: number,
188196
type: 'stream' | 'private',
@@ -194,7 +202,7 @@ export type Outbox = {|
194202
* Flow reasonably dispermits certain classes of access on union types. In
195203
* particular,
196204
* ```
197-
* const { sender_id } = (message: Message | Outbox); // error
205+
* const { match_content } = (message: Message | Outbox); // error
198206
* ```
199207
* is not allowed. However, as long as you're prepared to handle values of
200208
* `undefined`, it's both JavaScript-legal to do so and occasionally convenient.
@@ -203,7 +211,7 @@ export type Outbox = {|
203211
* subtype of `Message | Outbox`, but which Flow will permit us to directly (and
204212
* soundly) destructure certain `Message`-only fields from:
205213
* ```
206-
* const { sender_id } = (message: MessageLike); // ok!
214+
* const { match_content } = (message: MessageLike); // ok!
207215
* ```
208216
*
209217
* * Note: `MessageLike` <: `Message | Outbox`, but the converse does not hold.
@@ -221,6 +229,7 @@ export type MessageLike =
221229
| $ReadOnly<{
222230
// $Shape<T> is unsound, per Flow docs, but $ReadOnly<$Shape<T>> is not
223231
...$Shape<{ [$Keys<Message>]: void }>,
232+
sender_id?: number, // TODO: Drop this once required in Outbox.
224233
...Outbox,
225234
}>;
226235

0 commit comments

Comments
 (0)