Skip to content

Commit f44af8b

Browse files
committed
ActionSheet [nfc]: Update signature of actionsheet to use streamId.
This is to facilitate complete migration to using stream id for actionsheet functions instead of stream name.
1 parent bf6add0 commit f44af8b

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

src/message/__tests__/messageActionSheet-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ describe('constructTopicActionButtons', () => {
6262
const streamMessage = eg.streamMessage();
6363
const streamName = streamNameOfStreamMessage(streamMessage);
6464
const topic = streamMessage.subject;
65+
const streamId = streamMessage.stream_id;
6566

6667
test('show Unmute topic option if topic is muted', () => {
6768
const mute = deepFreeze([[streamName, topic]]);
6869
const buttons = constructTopicActionButtons({
6970
backgroundData: { ...baseBackgroundData, mute },
7071
streamName,
72+
streamId,
7173
topic,
7274
});
7375
expect(buttonTitles(buttons)).toContain('Unmute topic');
@@ -77,6 +79,7 @@ describe('constructTopicActionButtons', () => {
7779
const buttons = constructTopicActionButtons({
7880
backgroundData: { ...baseBackgroundData, mute: [] },
7981
streamName,
82+
streamId,
8083
topic,
8184
});
8285
expect(buttonTitles(buttons)).toContain('Mute topic');
@@ -87,6 +90,7 @@ describe('constructTopicActionButtons', () => {
8790
const buttons = constructTopicActionButtons({
8891
backgroundData: { ...baseBackgroundData, subscriptions },
8992
streamName,
93+
streamId,
9094
topic,
9195
});
9296
expect(buttonTitles(buttons)).toContain('Unmute stream');
@@ -97,6 +101,7 @@ describe('constructTopicActionButtons', () => {
97101
const buttons = constructTopicActionButtons({
98102
backgroundData: { ...baseBackgroundData, subscriptions },
99103
streamName,
104+
streamId,
100105
topic,
101106
});
102107
expect(buttonTitles(buttons)).toContain('Mute stream');
@@ -107,6 +112,7 @@ describe('constructTopicActionButtons', () => {
107112
const buttons = constructTopicActionButtons({
108113
backgroundData: { ...baseBackgroundData, ownUser },
109114
streamName,
115+
streamId,
110116
topic,
111117
});
112118
expect(buttonTitles(buttons)).toContain('Delete topic');
@@ -116,6 +122,7 @@ describe('constructTopicActionButtons', () => {
116122
const buttons = constructTopicActionButtons({
117123
backgroundData: baseBackgroundData,
118124
streamName,
125+
streamId,
119126
topic,
120127
});
121128
expect(buttonTitles(buttons)).not.toContain('Delete topic');

src/message/messageActionSheet.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type ShowActionSheetWithOptions = (
3939
type TopicArgs = {
4040
auth: Auth,
4141
streamName: string,
42+
streamId: number,
4243
topic: string,
4344
subscriptions: Subscription[],
4445
dispatch: Dispatch,
@@ -230,6 +231,7 @@ cancel.errorMessage = 'Failed to hide menu';
230231
export const constructTopicActionButtons = ({
231232
backgroundData: { mute, ownUser, streams, subscriptions },
232233
streamName,
234+
streamId,
233235
topic,
234236
}: {|
235237
backgroundData: $ReadOnly<{
@@ -240,6 +242,7 @@ export const constructTopicActionButtons = ({
240242
...
241243
}>,
242244
streamName: string,
245+
streamId: number,
243246
topic: string,
244247
|}): Button<TopicArgs>[] => {
245248
const buttons = [];
@@ -397,6 +400,7 @@ export const showTopicActionSheet = ({
397400
backgroundData,
398401
topic,
399402
streamName,
403+
streamId,
400404
}: {|
401405
showActionSheetWithOptions: ShowActionSheetWithOptions,
402406
callbacks: {|
@@ -413,11 +417,13 @@ export const showTopicActionSheet = ({
413417
...
414418
}>,
415419
streamName: string,
420+
streamId: number,
416421
topic: string,
417422
|}): void => {
418423
const buttonList = constructTopicActionButtons({
419424
backgroundData,
420425
streamName,
426+
streamId,
421427
topic,
422428
});
423429
showActionSheetWithOptions(
@@ -430,6 +436,7 @@ export const showTopicActionSheet = ({
430436
...backgroundData,
431437
...callbacks,
432438
streamName,
439+
streamId,
433440
topic,
434441
}),
435442
);

src/streams/TopicItem.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { useContext } from 'react';
33
import { View } from 'react-native';
44
import { useActionSheet } from '@expo/react-native-action-sheet';
5+
import invariant from 'invariant';
56

67
import styles, { BRAND_COLOR, createStyleSheet } from '../styles';
78
import { RawLabel, Touchable, UnreadCount } from '../common';
@@ -58,6 +59,9 @@ export default function TopicItem(props: Props) {
5859
flags: getFlags(state),
5960
}));
6061

62+
const currentStream = [...backgroundData.streams.entries()].find(x => x[1].name === streamName);
63+
invariant(currentStream !== undefined, 'No stream with provided stream name was found.');
64+
6165
return (
6266
<Touchable
6367
onPress={() => onPress(streamName, name)}
@@ -67,6 +71,7 @@ export default function TopicItem(props: Props) {
6771
callbacks: { dispatch, _ },
6872
backgroundData,
6973
streamName,
74+
streamId: currentStream[0],
7075
topic: name,
7176
});
7277
}}

src/title/TitleStream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const TitleStream = (props: Props) => {
8181
callbacks: { dispatch, _ },
8282
backgroundData,
8383
streamName: stream.name,
84+
streamId: stream.stream_id,
8485
topic: topicOfNarrow(narrow),
8586
});
8687
}

src/webview/handleOutboundEvents.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @flow strict-local */
22
import { Clipboard, Alert } from 'react-native';
33

4+
import invariant from 'invariant';
45
import * as NavigationService from '../nav/NavigationService';
56
import * as api from '../api';
67
import config from '../config';
@@ -214,11 +215,17 @@ const handleLongPress = (
214215
const { dispatch, showActionSheetWithOptions, backgroundData, narrow, startEditMessage } = props;
215216
if (target === 'header') {
216217
if (message.type === 'stream') {
218+
const streamName = streamNameOfStreamMessage(message);
219+
const currentStream = [...backgroundData.streams.entries()].find(
220+
x => x[1].name === streamName,
221+
);
222+
invariant(currentStream !== undefined, 'No stream with provided stream name was found.');
217223
showTopicActionSheet({
218224
showActionSheetWithOptions,
219225
callbacks: { dispatch, _ },
220226
backgroundData,
221-
streamName: streamNameOfStreamMessage(message),
227+
streamName,
228+
streamId: currentStream[0],
222229
topic: message.subject,
223230
});
224231
} else if (message.type === 'private') {

0 commit comments

Comments
 (0)