Skip to content

Commit a30cd74

Browse files
committed
autocomplete: Create component to warn unsibscribed @-mentionee.
Creates a component 'MentionedUserNotSubscribed' that can be used to shows a warning when an @-mentioned user is not subscribed to a stream they are mentioned in, with a button to subscribe them.
1 parent 2ff2f04 commit a30cd74

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* @flow strict-local */
2+
3+
import React, { Component } from 'react';
4+
import { View, TouchableOpacity } from 'react-native';
5+
6+
import type { Auth, Stream, Dispatch, Narrow, UserOrBot, GetText } from '../types';
7+
import { withGetText } from '../boot/TranslationProvider';
8+
import { connect } from '../react-redux';
9+
import * as api from '../api';
10+
import { ZulipButton, RawLabel } from '../common';
11+
import { getAuth, getStreamInNarrow, getUserForId } from '../selectors';
12+
import styles from '../styles';
13+
14+
type SelectorProps = {|
15+
auth: Auth,
16+
stream: { ...Stream },
17+
user: UserOrBot,
18+
|};
19+
20+
type Props = $ReadOnly<{|
21+
narrow: Narrow,
22+
userId: number,
23+
onDismiss: (user: UserOrBot) => void,
24+
dispatch: Dispatch,
25+
...SelectorProps,
26+
_: GetText,
27+
|}>;
28+
29+
class MentionedUserNotSubscribed extends Component<Props> {
30+
subscribeToStream = () => {
31+
const { auth, stream, user } = this.props;
32+
api.subscriptionAdd(auth, [{ name: stream.name }], [user.email]);
33+
this.handleDismiss();
34+
};
35+
36+
handleDismiss = () => {
37+
const { user, onDismiss } = this.props;
38+
onDismiss(user);
39+
};
40+
41+
render() {
42+
const { user, _ } = this.props;
43+
44+
const alertTitle = _.intl.formatMessage(
45+
{
46+
id: '{username} will not be notified unless you subscribe them to this stream.',
47+
defaultMessage: '{username} will not be notified unless you subscribe them to this stream.',
48+
},
49+
{ username: user.full_name },
50+
);
51+
52+
return (
53+
<View>
54+
<TouchableOpacity onPress={this.handleDismiss} style={styles.mentionedUserNotSubscribed}>
55+
<RawLabel style={styles.mentionedUserNotSubscribedText} text={alertTitle} />
56+
<ZulipButton
57+
style={styles.mentionedUserNotSubscribedButton}
58+
text="Subscribe"
59+
onPress={this.subscribeToStream}
60+
/>
61+
</TouchableOpacity>
62+
</View>
63+
);
64+
}
65+
}
66+
67+
export default connect<SelectorProps, _, _>((state, props) => ({
68+
auth: getAuth(state),
69+
stream: getStreamInNarrow(state, props.narrow),
70+
user: getUserForId(state, props.userId),
71+
}))(withGetText(MentionedUserNotSubscribed));

src/styles/composeBoxStyles.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,22 @@ export default {
1616
flex: 1,
1717
color: 'white',
1818
},
19+
mentionedUserNotSubscribed: {
20+
flexDirection: 'row',
21+
alignItems: 'center',
22+
justifyContent: 'space-around',
23+
backgroundColor: 'rgb(230, 203, 67)',
24+
paddingHorizontal: 16,
25+
paddingVertical: 8,
26+
borderTopWidth: 1,
27+
borderTopColor: 'rgb(214, 161, 54)',
28+
},
29+
mentionedUserNotSubscribedText: {
30+
flex: 1,
31+
color: 'white',
32+
},
33+
mentionedUserNotSubscribedButton: {
34+
backgroundColor: 'orange',
35+
padding: 6,
36+
},
1937
};

static/translations/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"Enable notifications": "Enable notifications",
108108
"Jot down something": "Jot down something",
109109
"Message {recipient}": "Message {recipient}",
110+
"{username} will not be notified unless you subscribe them to this stream.": "{username} will not be notified unless you subscribe them to this stream.",
110111
"Send private message": "Send private message",
111112
"View private messages": "View private messages",
112113
"(This user has been deactivated)": "(This user has been deactivated)",

0 commit comments

Comments
 (0)