Skip to content

Commit

Permalink
MessageActionSheet: Fix 'Reply' option to work correctly in different…
Browse files Browse the repository at this point in the history
… scenarios.

Show 'Reply' option for Outbox messages. Modify 'Reply' option
for announcement-only narrow messages based on whether the user is
an admin.

Fixes zulip#3810.
  • Loading branch information
agrawal-d committed Feb 6, 2020
1 parent 4ef9a13 commit 1caddd5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/message/messageActionSheet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* @flow strict-local */
import { Clipboard, Share, Alert } from 'react-native';
import type { Auth, Dispatch, GetText, Message, Narrow, Outbox, Subscription } from '../types';
import type {
Auth,
Dispatch,
GetText,
Message,
Narrow,
Outbox,
Stream,
Subscription,
} from '../types';
import type { BackgroundData } from '../webview/MessageList';
import {
getNarrowFromMessage,
Expand Down Expand Up @@ -46,6 +55,12 @@ const isAnOutboxMessage = (message: Message | Outbox): boolean => message.isOutb
// Options for the action sheet go below: ...
//

const narrowToTopic = ({ message, dispatch, ownEmail }) => {
dispatch(doNarrow(getNarrowFromMessage(message, ownEmail), message.id));
};
narrowToTopic.title = 'Narrow to topic';
narrowToTopic.errorMessage = 'Failed to narrow to topic';

const reply = ({ message, dispatch, ownEmail }) => {
dispatch(doNarrow(getNarrowFromMessage(message, ownEmail), message.id));
};
Expand Down Expand Up @@ -147,6 +162,7 @@ cancel.errorMessage = 'Failed to hide menu';
const allButtonsRaw = {
// For messages
addReaction,
narrowToTopic,
reply,
copyToClipboard,
shareMessage,
Expand Down Expand Up @@ -206,7 +222,7 @@ const messageNotDeleted = (message: Message | Outbox): boolean =>
message.content !== '<p>(deleted)</p>';

export const constructMessageActionButtons = ({
backgroundData: { ownUser, flags },
backgroundData: { ownUser, flags, streams },
message,
narrow,
}: ConstructSheetParams): ButtonCode[] => {
Expand All @@ -217,9 +233,23 @@ export const constructMessageActionButtons = ({
if (!isAnOutboxMessage(message) && messageNotDeleted(message)) {
buttons.push('addReaction');
}
if (!isAnOutboxMessage(message) && !isTopicNarrow(narrow) && !isPrivateOrGroupNarrow(narrow)) {
buttons.push('reply');
if (!isTopicNarrow(narrow) && !isPrivateOrGroupNarrow(narrow)) {
const messageNarrow: Narrow = getNarrowFromMessage(message, ownUser.email);
const messageStream: Stream | void = streams.find(
(stream: Stream) => messageNarrow[0].operand === stream.name,
);
if (messageStream) {
if (messageStream.is_announcement_only && !ownUser.is_admin) {
buttons.push('narrowToTopic');
} else {
buttons.push('reply');
}
} else if (Array.isArray(message.display_recipient)) {
// This means the message is a Private Message.
buttons.push('reply');
}
}

if (messageNotDeleted(message)) {
buttons.push('copyToClipboard');
buttons.push('shareMessage');
Expand Down Expand Up @@ -264,6 +294,7 @@ export const showActionSheet = (
await pressedButton({
dispatch,
subscriptions: params.backgroundData.subscriptions,
streams: params.backgroundData.streams,
auth: params.backgroundData.auth,
ownEmail: params.backgroundData.ownUser.email,
_,
Expand Down
4 changes: 4 additions & 0 deletions src/webview/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
Outbox,
ImageEmojiType,
RenderedSectionDescriptor,
Stream,
Subscription,
ThemeName,
User,
Expand Down Expand Up @@ -53,6 +54,7 @@ import { getUpdateEvents } from './webViewHandleUpdates';
import { handleMessageListEvent } from './webViewEventHandlers';
import { base64Utf8Encode } from '../utils/encoding';
import * as logging from '../utils/logging';
import { getStreams } from '../directSelectors';

// ESLint doesn't notice how `this.props` escapes, and complains about some
// props not being used here.
Expand All @@ -76,6 +78,7 @@ export type BackgroundData = $ReadOnly<{|
flags: FlagsState,
mute: MuteState,
ownUser: User,
streams: Stream[],
subscriptions: Subscription[],
theme: ThemeName,
twentyFourHourTime: boolean,
Expand Down Expand Up @@ -354,6 +357,7 @@ export default connect<SelectorProps, _, _>((state, props: OuterProps) => {
flags: getFlags(state),
mute: getMute(state),
ownUser: getOwnUser(state),
streams: getStreams(state),
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
Expand Down
2 changes: 2 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Enter a password": "Enter a password",
"Narrow to conversation": "Narrow to conversation",
"Reply": "Reply",
"Narrow to topic": "Narrow to topic",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Link copied to clipboard": "Link copied to clipboard",
Expand Down Expand Up @@ -123,6 +124,7 @@
"Network request failed": "Network request failed",
"Failed to add reaction": "Failed to add reaction",
"Failed to reply": "Failed to reply",
"Failed to narrow to topic": "Failed to narrow to topic",
"Failed to copy message to clipboard": "Failed to copy message to clipboard",
"Failed to share message": "Failed to share message",
"Failed to edit message": "Failed to edit message",
Expand Down

0 comments on commit 1caddd5

Please sign in to comment.