Skip to content

Commit 7c39641

Browse files
committed
ActionSheet [nfc]: Update signature of actionsheet to not use streamName.
Also involves necessary changes at call sites, and some actionsheet functions.
1 parent 9e80f62 commit 7c39641

File tree

5 files changed

+22
-35
lines changed

5 files changed

+22
-35
lines changed

src/message/__tests__/messageActionSheet-test.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow strict-local
22
import deepFreeze from 'deep-freeze';
33
import { HOME_NARROW } from '../../utils/narrow';
4-
import { streamNameOfStreamMessage } from '../../utils/recipient';
54

65
import * as eg from '../../__tests__/lib/exampleData';
76
import { constructMessageActionButtons, constructTopicActionButtons } from '../messageActionSheet';
@@ -62,10 +61,11 @@ describe('constructActionButtons', () => {
6261
});
6362

6463
describe('constructTopicActionButtons', () => {
65-
const streamMessage = eg.streamMessage();
66-
const streamName = streamNameOfStreamMessage(streamMessage);
64+
const stream = eg.makeStream();
65+
const streamMessage = eg.streamMessage({ stream });
6766
const topic = streamMessage.subject;
6867
const streamId = streamMessage.stream_id;
68+
const streams = deepFreeze(new Map([[streamMessage.stream_id, stream]]));
6969

7070
const baseState = (() => {
7171
const r = (state, action) => reducer(state, action, eg.plusReduxState);
@@ -77,8 +77,7 @@ describe('constructTopicActionButtons', () => {
7777
test('show mark as read if topic is unread', () => {
7878
const unreadStreams = baseState.streams;
7979
const buttons = constructTopicActionButtons({
80-
backgroundData: { ...baseBackgroundData, unreadStreams },
81-
streamName,
80+
backgroundData: { ...baseBackgroundData, streams, unreadStreams },
8281
streamId,
8382
topic,
8483
});
@@ -87,19 +86,17 @@ describe('constructTopicActionButtons', () => {
8786

8887
test('do not show mark as read if topic is read', () => {
8988
const buttons = constructTopicActionButtons({
90-
backgroundData: baseBackgroundData,
91-
streamName,
89+
backgroundData: { ...baseBackgroundData, streams },
9290
streamId,
9391
topic,
9492
});
9593
expect(buttonTitles(buttons)).not.toContain('Mark topic as read');
9694
});
9795

9896
test('show Unmute topic option if topic is muted', () => {
99-
const mute = deepFreeze([[streamName, topic]]);
97+
const mute = deepFreeze([[stream.name, topic]]);
10098
const buttons = constructTopicActionButtons({
101-
backgroundData: { ...baseBackgroundData, mute },
102-
streamName,
99+
backgroundData: { ...baseBackgroundData, streams, mute },
103100
streamId,
104101
topic,
105102
});
@@ -108,30 +105,27 @@ describe('constructTopicActionButtons', () => {
108105

109106
test('show mute topic option if topic is not muted', () => {
110107
const buttons = constructTopicActionButtons({
111-
backgroundData: { ...baseBackgroundData, mute: [] },
112-
streamName,
108+
backgroundData: { ...baseBackgroundData, streams, mute: [] },
113109
streamId,
114110
topic,
115111
});
116112
expect(buttonTitles(buttons)).toContain('Mute topic');
117113
});
118114

119115
test('show Unmute stream option if stream is not in home view', () => {
120-
const subscriptions = [{ ...eg.subscription, in_home_view: false }];
116+
const subscriptions = [{ ...eg.subscription, in_home_view: false, ...stream }];
121117
const buttons = constructTopicActionButtons({
122-
backgroundData: { ...baseBackgroundData, subscriptions },
123-
streamName,
118+
backgroundData: { ...baseBackgroundData, subscriptions, streams },
124119
streamId,
125120
topic,
126121
});
127122
expect(buttonTitles(buttons)).toContain('Unmute stream');
128123
});
129124

130125
test('show mute stream option if stream is in home view', () => {
131-
const subscriptions = [{ ...eg.subscription, in_home_view: true }];
126+
const subscriptions = [{ ...eg.subscription, in_home_view: true, ...stream }];
132127
const buttons = constructTopicActionButtons({
133-
backgroundData: { ...baseBackgroundData, subscriptions },
134-
streamName,
128+
backgroundData: { ...baseBackgroundData, subscriptions, streams },
135129
streamId,
136130
topic,
137131
});
@@ -141,8 +135,7 @@ describe('constructTopicActionButtons', () => {
141135
test('show delete topic option if current user is an admin', () => {
142136
const ownUser = { ...eg.selfUser, is_admin: true };
143137
const buttons = constructTopicActionButtons({
144-
backgroundData: { ...baseBackgroundData, ownUser },
145-
streamName,
138+
backgroundData: { ...baseBackgroundData, ownUser, streams },
146139
streamId,
147140
topic,
148141
});
@@ -151,8 +144,7 @@ describe('constructTopicActionButtons', () => {
151144

152145
test('do not show delete topic option if current user is not an admin', () => {
153146
const buttons = constructTopicActionButtons({
154-
backgroundData: baseBackgroundData,
155-
streamName,
147+
backgroundData: { ...baseBackgroundData, streams },
156148
streamId,
157149
topic,
158150
});

src/message/messageActionSheet.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow strict-local */
22
import { Clipboard, Share, Alert } from 'react-native';
3+
import invariant from 'invariant';
34

45
import * as NavigationService from '../nav/NavigationService';
56
import type {
@@ -39,7 +40,6 @@ export type ShowActionSheetWithOptions = (
3940

4041
type TopicArgs = {
4142
auth: Auth,
42-
streamName: string,
4343
streamId: number,
4444
topic: string,
4545
subscriptions: Subscription[],
@@ -228,7 +228,6 @@ cancel.errorMessage = 'Failed to hide menu';
228228

229229
export const constructTopicActionButtons = ({
230230
backgroundData: { mute, ownUser, streams, subscriptions, unreadStreams },
231-
streamName,
232231
streamId,
233232
topic,
234233
}: {|
@@ -240,7 +239,6 @@ export const constructTopicActionButtons = ({
240239
ownUser: User,
241240
...
242241
}>,
243-
streamName: string,
244242
streamId: number,
245243
topic: string,
246244
|}): Button<TopicArgs>[] => {
@@ -252,12 +250,14 @@ export const constructTopicActionButtons = ({
252250
if (unreadCount !== undefined && unreadCount > 0) {
253251
buttons.push(markTopicAsRead);
254252
}
255-
if (isTopicMuted(streamName, topic, mute)) {
253+
const stream = streams.get(streamId);
254+
invariant(stream !== undefined, 'Stream with provided streamId not found.');
255+
if (isTopicMuted(stream.name, topic, mute)) {
256256
buttons.push(unmuteTopic);
257257
} else {
258258
buttons.push(muteTopic);
259259
}
260-
const sub = subscriptions.find(x => x.name === streamName);
260+
const sub = subscriptions.find(x => x.stream_id === streamId);
261261
if (sub && !sub.in_home_view) {
262262
buttons.push(unmuteStream);
263263
} else {
@@ -402,7 +402,6 @@ export const showTopicActionSheet = ({
402402
callbacks,
403403
backgroundData,
404404
topic,
405-
streamName,
406405
streamId,
407406
}: {|
408407
showActionSheetWithOptions: ShowActionSheetWithOptions,
@@ -420,26 +419,25 @@ export const showTopicActionSheet = ({
420419
flags: FlagsState,
421420
...
422421
}>,
423-
streamName: string,
424422
streamId: number,
425423
topic: string,
426424
|}): void => {
427425
const buttonList = constructTopicActionButtons({
428426
backgroundData,
429-
streamName,
430427
streamId,
431428
topic,
432429
});
430+
const stream = backgroundData.streams.get(streamId);
431+
invariant(stream !== undefined, 'Stream with provided streamId not found.');
433432
showActionSheetWithOptions(
434433
{
435-
title: `#${streamName} > ${topic}`,
434+
title: `#${stream.name} > ${topic}`,
436435
options: buttonList.map(button => callbacks._(button.title)),
437436
cancelButtonIndex: buttonList.length - 1,
438437
},
439438
makeButtonCallback(buttonList, {
440439
...backgroundData,
441440
...callbacks,
442-
streamName,
443441
streamId,
444442
topic,
445443
}),

src/streams/TopicItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export default function TopicItem(props: Props) {
7272
showActionSheetWithOptions,
7373
callbacks: { dispatch, _ },
7474
backgroundData,
75-
streamName,
7675
streamId: currentStream[0],
7776
topic: name,
7877
});

src/title/TitleStream.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const TitleStream = (props: Props) => {
8383
showActionSheetWithOptions,
8484
callbacks: { dispatch, _ },
8585
backgroundData,
86-
streamName: stream.name,
8786
streamId: stream.stream_id,
8887
topic: topicOfNarrow(narrow),
8988
});

src/webview/handleOutboundEvents.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ const handleLongPress = (
224224
showActionSheetWithOptions,
225225
callbacks: { dispatch, _ },
226226
backgroundData,
227-
streamName,
228227
streamId: currentStream[0],
229228
topic: message.subject,
230229
});

0 commit comments

Comments
 (0)