Skip to content

Commit be6354e

Browse files
committed
ActionSheets: Change Button<HeaderArgs> callback to take stream and topic
This changes the Button<HeaderArgs> callback to take a stream and topic, rather than a message, since the only thing the callbacks need is the stream and topic.
1 parent ffb03e5 commit be6354e

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/message/messageActionSheet.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export type ShowActionSheetWithOptions = (
3939

4040
type HeaderArgs = {
4141
auth: Auth,
42-
message: Message | Outbox,
42+
stream: string,
43+
topic: string,
4344
subscriptions: Subscription[],
4445
dispatch: Dispatch,
4546
_: GetText,
@@ -112,25 +113,20 @@ const deleteMessage = async ({ auth, message, dispatch }) => {
112113
deleteMessage.title = 'Delete message';
113114
deleteMessage.errorMessage = 'Failed to delete message';
114115

115-
const unmuteTopic = async ({ auth, message }) => {
116-
invariant(message.type === 'stream', 'unmuteTopic: got PM');
117-
await api.unmuteTopic(auth, streamNameOfStreamMessage(message), message.subject);
116+
const unmuteTopic = async ({ auth, stream, topic }) => {
117+
await api.unmuteTopic(auth, stream, topic);
118118
};
119119
unmuteTopic.title = 'Unmute topic';
120120
unmuteTopic.errorMessage = 'Failed to unmute topic';
121121

122-
const muteTopic = async ({ auth, message }) => {
123-
invariant(message.type === 'stream', 'muteTopic: got PM');
124-
await api.muteTopic(auth, streamNameOfStreamMessage(message), message.subject);
122+
const muteTopic = async ({ auth, stream, topic }) => {
123+
await api.muteTopic(auth, stream, topic);
125124
};
126125
muteTopic.title = 'Mute topic';
127126
muteTopic.errorMessage = 'Failed to mute topic';
128127

129-
const deleteTopic = async ({ auth, message, dispatch, _ }) => {
130-
invariant(message.type === 'stream', 'deleteTopic: got PM');
131-
const alertTitle = _('Are you sure you want to delete the topic “{topic}”?', {
132-
topic: message.subject,
133-
});
128+
const deleteTopic = async ({ auth, stream, topic, dispatch, _ }) => {
129+
const alertTitle = _('Are you sure you want to delete the topic “{topic}”?', { topic });
134130
const AsyncAlert = async (): Promise<boolean> =>
135131
new Promise((resolve, reject) => {
136132
Alert.alert(
@@ -156,25 +152,23 @@ const deleteTopic = async ({ auth, message, dispatch, _ }) => {
156152
);
157153
});
158154
if (await AsyncAlert()) {
159-
await dispatch(deleteMessagesForTopic(streamNameOfStreamMessage(message), message.subject));
155+
await dispatch(deleteMessagesForTopic(stream, topic));
160156
}
161157
};
162158
deleteTopic.title = 'Delete topic';
163159
deleteTopic.errorMessage = 'Failed to delete topic';
164160

165-
const unmuteStream = async ({ auth, message, subscriptions }) => {
166-
invariant(message.type === 'stream', 'unmuteStream: got PM');
167-
const sub = subscriptions.find(x => x.name === streamNameOfStreamMessage(message));
161+
const unmuteStream = async ({ auth, stream, subscriptions }) => {
162+
const sub = subscriptions.find(x => x.name === stream);
168163
if (sub) {
169164
await api.toggleMuteStream(auth, sub.stream_id, false);
170165
}
171166
};
172167
unmuteStream.title = 'Unmute stream';
173168
unmuteStream.errorMessage = 'Failed to unmute stream';
174169

175-
const muteStream = async ({ auth, message, subscriptions }) => {
176-
invariant(message.type === 'stream', 'muteStream: got PM');
177-
const sub = subscriptions.find(x => x.name === streamNameOfStreamMessage(message));
170+
const muteStream = async ({ auth, stream, subscriptions }) => {
171+
const sub = subscriptions.find(x => x.name === stream);
178172
if (sub) {
179173
await api.toggleMuteStream(auth, sub.stream_id, true);
180174
}
@@ -409,7 +403,8 @@ export const showHeaderActionSheet = ({
409403
await pressedButton({
410404
...backgroundData,
411405
...callbacks,
412-
message,
406+
stream: streamNameOfStreamMessage(message),
407+
topic: message.subject,
413408
});
414409
} catch (err) {
415410
Alert.alert(callbacks._(pressedButton.errorMessage), err.message);

0 commit comments

Comments
 (0)