Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ActionSheets: Change HeaderButton callback to take stream and topic
Browse files Browse the repository at this point in the history
This changes the HeaderButton callback to take a stream and topic,
rather than a message, since the only thing the callbacks need is the
stream and topic.

I have manually tested this commit on Android.
WesleyAC committed Mar 18, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tvdeyen Thomas von Deyen
1 parent 3f443c6 commit 63d03d5
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/message/messageActionSheet.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,8 @@ export type ShowActionSheetWithOptions = (
type HeaderButton = {|
({
auth: Auth,
message: Message | Outbox,
stream: string,
topic: string,
subscriptions: Subscription[],
dispatch: Dispatch,
_: GetText,
@@ -118,25 +119,20 @@ const deleteMessage = async ({ auth, message, dispatch }) => {
deleteMessage.title = 'Delete message';
deleteMessage.errorMessage = 'Failed to delete message';

const unmuteTopic = async ({ auth, message }) => {
invariant(message.type === 'stream', 'unmuteTopic: got PM');
await api.unmuteTopic(auth, streamNameOfStreamMessage(message), message.subject);
const unmuteTopic = async ({ auth, stream, topic }) => {
await api.unmuteTopic(auth, stream, topic);
};
unmuteTopic.title = 'Unmute topic';
unmuteTopic.errorMessage = 'Failed to unmute topic';

const muteTopic = async ({ auth, message }) => {
invariant(message.type === 'stream', 'muteTopic: got PM');
await api.muteTopic(auth, streamNameOfStreamMessage(message), message.subject);
const muteTopic = async ({ auth, stream, topic }) => {
await api.muteTopic(auth, stream, topic);
};
muteTopic.title = 'Mute topic';
muteTopic.errorMessage = 'Failed to mute topic';

const deleteTopic = async ({ auth, message, dispatch, _ }) => {
invariant(message.type === 'stream', 'deleteTopic: got PM');
const alertTitle = _('Are you sure you want to delete the topic “{topic}”?', {
topic: message.subject,
});
const deleteTopic = async ({ auth, stream, topic, dispatch, _ }) => {
const alertTitle = _('Are you sure you want to delete the topic “{topic}”?', { topic });
const AsyncAlert = async (): Promise<boolean> =>
new Promise((resolve, reject) => {
Alert.alert(
@@ -162,25 +158,23 @@ const deleteTopic = async ({ auth, message, dispatch, _ }) => {
);
});
if (await AsyncAlert()) {
await dispatch(deleteMessagesForTopic(streamNameOfStreamMessage(message), message.subject));
await dispatch(deleteMessagesForTopic(stream, topic));
}
};
deleteTopic.title = 'Delete topic';
deleteTopic.errorMessage = 'Failed to delete topic';

const unmuteStream = async ({ auth, message, subscriptions }) => {
invariant(message.type === 'stream', 'unmuteStream: got PM');
const sub = subscriptions.find(x => x.name === streamNameOfStreamMessage(message));
const unmuteStream = async ({ auth, stream, subscriptions }) => {
const sub = subscriptions.find(x => x.name === stream);
if (sub) {
await api.toggleMuteStream(auth, sub.stream_id, false);
}
};
unmuteStream.title = 'Unmute stream';
unmuteStream.errorMessage = 'Failed to unmute stream';

const muteStream = async ({ auth, message, subscriptions }) => {
invariant(message.type === 'stream', 'muteStream: got PM');
const sub = subscriptions.find(x => x.name === streamNameOfStreamMessage(message));
const muteStream = async ({ auth, stream, subscriptions }) => {
const sub = subscriptions.find(x => x.name === stream);
if (sub) {
await api.toggleMuteStream(auth, sub.stream_id, true);
}
@@ -411,7 +405,8 @@ export const showHeaderActionSheet = (
auth: params.auth,
ownUser: params.ownUser,
flags: params.flags,
message,
stream: streamNameOfStreamMessage(message),
topic: message.subject,
...callbacks,
});
} catch (err) {

0 comments on commit 63d03d5

Please sign in to comment.