Skip to content

Commit 9d05bba

Browse files
committed
webview html: Get stream name from stream, rather than message
In particular this means that if the stream name changes, we'll show the right name.
1 parent 8846f56 commit 9d05bba

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/webview/html/__tests__/header-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { BackgroundData } from '../../MessageList';
77
const backgroundData: BackgroundData = ({
88
ownEmail: eg.selfUser.email,
99
subscriptions: [eg.stream],
10+
streams: new Map([[eg.stream.stream_id, eg.stream]]),
1011
}: $FlowFixMe);
1112

1213
describe('header', () => {

src/webview/html/__tests__/messageListElementHtml-test.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,26 @@ import getMessageListElements from '../../../message/getMessageListElements';
4949
* and `messageListElementHtml`.
5050
*/
5151
describe('messages -> piece descriptors -> content HTML is stable/sensible', () => {
52+
const user1 = eg.makeUser({ user_id: 1, name: 'nonrandom name one' });
53+
const user2 = eg.makeUser({ user_id: 2, name: 'nonrandom name two' });
54+
const user3 = eg.makeUser({ user_id: 3, name: 'nonrandom name three' });
55+
56+
const stream1 = { ...eg.makeStream({ name: 'stream 1' }), stream_id: 1 };
57+
const stream2 = { ...eg.makeStream({ name: 'stream 2' }), stream_id: 2 };
58+
59+
const topic1 = 'topic 1';
60+
const topic2 = 'topic 2';
61+
5262
// Tell ESLint to recognize `check` as a helper function that runs
5363
// assertions.
5464
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "check"] }] */
5565
const check = ({
5666
// TODO: Test with a variety of different things in
5767
// `backgroundData`.
58-
backgroundData = eg.backgroundData,
68+
backgroundData = {
69+
...eg.backgroundData,
70+
streams: new Map([stream1, stream2].map(s => [s.stream_id, s])),
71+
},
5972
narrow,
6073
messages,
6174
}) => {
@@ -79,16 +92,6 @@ describe('messages -> piece descriptors -> content HTML is stable/sensible', ()
7992
).toMatchSnapshot();
8093
};
8194

82-
const user1 = eg.makeUser({ user_id: 1, name: 'nonrandom name one' });
83-
const user2 = eg.makeUser({ user_id: 2, name: 'nonrandom name two' });
84-
const user3 = eg.makeUser({ user_id: 3, name: 'nonrandom name three' });
85-
86-
const stream1 = { ...eg.makeStream({ name: 'stream 1' }), stream_id: 1 };
87-
const stream2 = { ...eg.makeStream({ name: 'stream 2' }), stream_id: 2 };
88-
89-
const topic1 = 'topic 1';
90-
const topic2 = 'topic 2';
91-
9295
// Same sender, stream, topic, day
9396
const streamMessages1 = [
9497
eg.streamMessage({

src/webview/html/header.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
} from '../../utils/narrow';
1414
import { foregroundColorFromBackground } from '../../utils/color';
1515
import { humanDate } from '../../utils/date';
16-
import {
17-
pmUiRecipientsFromMessage,
18-
pmKeyRecipientsFromMessage,
19-
streamNameOfStreamMessage,
20-
} from '../../utils/recipient';
16+
import { pmUiRecipientsFromMessage, pmKeyRecipientsFromMessage } from '../../utils/recipient';
2117
import { base64Utf8Encode } from '../../utils/encoding';
2218

2319
const renderSubject = message =>
@@ -32,15 +28,17 @@ const renderSubject = message =>
3228
* This is a private helper of messageListElementHtml.
3329
*/
3430
export default (
35-
{ ownUser, subscriptions }: BackgroundData,
31+
{ ownUser, streams, subscriptions }: BackgroundData,
3632
element: HeaderMessageListElement,
3733
): string => {
3834
const { subsequentMessage: message, style: headerStyle } = element;
3935

4036
if (message.type === 'stream') {
37+
const stream = streams.get(message.stream_id);
38+
invariant(stream, 'stream should exist for message');
39+
4140
if (headerStyle === 'topic+date') {
42-
const streamName = streamNameOfStreamMessage(message);
43-
const topicNarrowStr = keyFromNarrow(topicNarrow(streamName, message.subject));
41+
const topicNarrowStr = keyFromNarrow(topicNarrow(stream.name, message.subject));
4442
const topicHtml = renderSubject(message);
4543

4644
return template`
@@ -54,13 +52,11 @@ export default (
5452
</div>
5553
`;
5654
} else if (headerStyle === 'full') {
57-
const streamName = streamNameOfStreamMessage(message);
5855
const subscription = subscriptions.get(message.stream_id);
59-
6056
const backgroundColor = subscription ? subscription.color : 'hsl(0, 0%, 80%)';
6157
const textColor = foregroundColorFromBackground(backgroundColor);
62-
const streamNarrowStr = keyFromNarrow(streamNarrow(streamName));
63-
const topicNarrowStr = keyFromNarrow(topicNarrow(streamName, message.subject));
58+
const streamNarrowStr = keyFromNarrow(streamNarrow(stream.name));
59+
const topicNarrowStr = keyFromNarrow(topicNarrow(stream.name, message.subject));
6460
const topicHtml = renderSubject(message);
6561

6662
return template`
@@ -71,7 +67,7 @@ export default (
7167
style="color: ${textColor};
7268
background: ${backgroundColor}"
7369
data-narrow="${base64Utf8Encode(streamNarrowStr)}">
74-
# ${streamName}
70+
# ${stream.name}
7571
</div>
7672
<div class="topic-text">$!${topicHtml}</div>
7773
<div class="topic-date">${humanDate(new Date(message.timestamp * 1000))}</div>

0 commit comments

Comments
 (0)