Skip to content

Commit e3f68e1

Browse files
committed
compose box: Show error on sending message when not caught up.
Check if we are caught up in the current narrow, and if so, show an error when trying to send a message asking the user to try again after some time. This prevents the user from possibly responding to a very old message when the messages after it have not been loaded yet - this can lead to the reply being out of context without the sender realizing it. Fixes: zulip#3800
1 parent e044c7c commit e3f68e1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/compose/ComposeBox.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import type {
1414
UserOrBot,
1515
Dispatch,
1616
Dimensions,
17+
CaughtUp,
18+
GetText,
1719
} from '../types';
1820
import { connect } from '../react-redux';
21+
import { withGetText } from '../boot/TranslationProvider';
1922
import {
2023
addToOutbox,
2124
draftUpdate,
@@ -39,6 +42,7 @@ import {
3942
getSession,
4043
getLastMessageTopic,
4144
getActiveUsersByEmail,
45+
getCaughtUpForNarrow,
4246
} from '../selectors';
4347
import {
4448
getIsActiveStreamSubscribed,
@@ -59,6 +63,7 @@ type SelectorProps = {|
5963
isSubscribed: boolean,
6064
draft: string,
6165
lastMessageTopic: string,
66+
caughtUp: CaughtUp,
6267
|};
6368

6469
type Props = $ReadOnly<{|
@@ -68,6 +73,9 @@ type Props = $ReadOnly<{|
6873

6974
dispatch: Dispatch,
7075
...SelectorProps,
76+
77+
// From 'withGetText'
78+
_: GetText,
7179
|}>;
7280

7381
type State = {|
@@ -242,9 +250,14 @@ class ComposeBox extends PureComponent<Props, State> {
242250
};
243251

244252
handleSend = () => {
245-
const { dispatch, narrow } = this.props;
253+
const { dispatch, narrow, caughtUp, _ } = this.props;
246254
const { message } = this.state;
247255

256+
if (!caughtUp.newer) {
257+
showErrorAlert(_('Please try again after some time'), _('Failed to send message'));
258+
return;
259+
}
260+
248261
dispatch(addToOutbox(this.getDestinationNarrow(), message));
249262

250263
this.setMessageInputValue('');
@@ -436,4 +449,5 @@ export default connect<SelectorProps, _, _>((state, props) => ({
436449
isSubscribed: getIsActiveStreamSubscribed(state, props.narrow),
437450
draft: getDraftForNarrow(state, props.narrow),
438451
lastMessageTopic: getLastMessageTopic(state, props.narrow),
439-
}))(ComposeBox);
452+
caughtUp: getCaughtUpForNarrow(state, props.narrow),
453+
}))(withGetText(ComposeBox));

static/translations/messages_en.json

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"Narrow": "Narrow",
214214
"Sending Message...": "Sending Message...",
215215
"Failed to send message": "Failed to send message",
216+
"Please try again after some time": "Please try again after some time",
216217
"Message sent": "Message sent",
217218
"What's your status?": "What's your status?",
218219
"📅 In a meeting": "📅 In a meeting",

0 commit comments

Comments
 (0)