Skip to content

Commit b091544

Browse files
committed
ServerCompatNotice: Add, to nag users connected to servers <2.1.0.
That threshold comes from https://zulip.readthedocs.io/en/4.2/overview/release-lifecycle.html. As the jsdoc says, at some point we'll settle on a non-hard-coded threshold; see https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/compatibility.20documentation/near/1174966.
1 parent 4156248 commit b091544

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

src/common/ServerCompatNotice.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* @flow strict-local */
2+
3+
import React, { useContext } from 'react';
4+
import { View, Pressable } from 'react-native';
5+
import Color from 'color';
6+
import { SafeAreaView } from 'react-native-safe-area-context';
7+
8+
import { createStyleSheet, HALF_COLOR, ThemeContext } from '../styles';
9+
import { useSelector, useDispatch } from '../react-redux';
10+
import Label from './Label';
11+
import RawLabel from './RawLabel';
12+
import { Icon } from './Icons';
13+
import { getActiveAccount } from '../account/accountsSelectors';
14+
import WebLink from './WebLink';
15+
import { getIsAdmin, getSession } from '../directSelectors';
16+
import { dismissCompatNotice } from '../session/sessionActions';
17+
18+
const styles = createStyleSheet({
19+
wrapper: {
20+
flexDirection: 'row',
21+
justifyContent: 'flex-start',
22+
alignItems: 'center',
23+
backgroundColor: HALF_COLOR,
24+
},
25+
});
26+
27+
type Props = $ReadOnly<{||}>;
28+
29+
/**
30+
* A "nag banner" saying that the server version is unsupported.
31+
*
32+
* Currently just checks if it's less than 2.1.0, since that's the
33+
* marker that was put down in zulip/zulip@d7d79b57b. In the future,
34+
* this won't have to be so hard-coded; we may use a timer or
35+
* something.
36+
*/
37+
export default function ServerCompatNotice(props: Props) {
38+
const dispatch = useDispatch();
39+
const hasDismissedServerCompatNotice = useSelector(
40+
state => getSession(state).hasDismissedServerCompatNotice,
41+
);
42+
const zulipVersion = useSelector(state => getActiveAccount(state).zulipVersion);
43+
const realm = useSelector(state => getActiveAccount(state).realm);
44+
const isAdmin = useSelector(getIsAdmin);
45+
46+
const { color } = useContext(ThemeContext);
47+
48+
if (zulipVersion && !zulipVersion.isAtLeast('2.1.0') && !hasDismissedServerCompatNotice) {
49+
return (
50+
<SafeAreaView mode="padding" edges={['right', 'left']} style={styles.wrapper}>
51+
<Pressable
52+
onPress={() => {
53+
dispatch(dismissCompatNotice());
54+
}}
55+
hitSlop={12}
56+
style={{ margin: 12 }}
57+
>
58+
{({ pressed }) => (
59+
<Icon
60+
size={24}
61+
color={Color(color)
62+
.fade(pressed ? 0.75 : 0)
63+
.toString()}
64+
name="x"
65+
/>
66+
)}
67+
</Pressable>
68+
<View style={{ flex: 1, paddingVertical: 4, paddingRight: 4 }}>
69+
<RawLabel>
70+
{isAdmin ? (
71+
<Label
72+
text={{
73+
text:
74+
'{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. We work hard to make the upgrade process as easy as possible.',
75+
values: { realm: realm.toString(), serverVersionRaw: zulipVersion.raw() },
76+
}}
77+
/>
78+
) : (
79+
<Label
80+
text={{
81+
text:
82+
'{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. Please contact your administrator about upgrading.',
83+
values: { realm: realm.toString(), serverVersionRaw: zulipVersion.raw() },
84+
}}
85+
/>
86+
)}
87+
{' '}
88+
<WebLink
89+
label="Learn more"
90+
url={
91+
new URL(
92+
'https://zulip.readthedocs.io/en/stable/overview/release-lifecycle.html#compatibility-and-upgrading',
93+
)
94+
}
95+
/>
96+
</RawLabel>
97+
</View>
98+
</SafeAreaView>
99+
);
100+
} else {
101+
return null;
102+
}
103+
}

src/main/HomeScreen.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { doNarrow, navigateToSearch } from '../actions';
1616
import IconUnreadMentions from '../nav/IconUnreadMentions';
1717
import { BRAND_COLOR, createStyleSheet } from '../styles';
1818
import { LoadingBanner } from '../common';
19+
import ServerCompatNotice from '../common/ServerCompatNotice';
1920

2021
const styles = createStyleSheet({
2122
wrapper: {
@@ -68,6 +69,7 @@ class HomeScreen extends PureComponent<Props> {
6869
}}
6970
/>
7071
</View>
72+
<ServerCompatNotice />
7173
<LoadingBanner />
7274
<UnreadCards />
7375
</View>

src/session/sessionReducer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export type SessionState = {|
5959
debug: Debug,
6060

6161
/**
62-
* Whether `ServerCompatNotice` (which we'll add soon) has been
63-
* dismissed this session.
62+
* Whether `ServerCompatNotice` has been dismissed this session.
6463
*
6564
* We put this in `SessionState` deliberately, so that users see the
6665
* notice on every startup until the server is upgraded. That's a

static/translations/messages_en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
"Mute stream": "Mute stream",
6060
"Unmute stream": "Unmute stream",
6161
"No Internet connection": "No Internet connection",
62+
"{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. We work hard to make the upgrade process as easy as possible.": "{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. We work hard to make the upgrade process as easy as possible.",
63+
"{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. Please contact your administrator about upgrading.": "{realm} is running Zulip Server {serverVersionRaw}, which is unsupported. Please contact your administrator about upgrading.",
64+
"Learn more": "Learn more",
6265
"Settings": "Settings",
6366
"Night mode": "Night mode",
6467
"Open links with in-app browser": "Open links with in-app browser",

0 commit comments

Comments
 (0)