Shift to M_RESOURCE_LIMIT_EXCEEDED errors
With support for admin_contact and limit_type fields For https://github.com/vector-im/riot-web/issues/7091
This commit is contained in:
parent
4c69c8d0f1
commit
9bde468e30
6 changed files with 111 additions and 31 deletions
|
@ -434,17 +434,21 @@ const LoggedInView = React.createClass({
|
|||
}
|
||||
|
||||
const mauLimitEvent = this.state.serverNoticeEvents.find((e) => {
|
||||
return e && e.getType() === 'm.server_notice.usage_limit_reached' &&
|
||||
e.getContent().limit_type &&
|
||||
e.getContent().limit_type === 'monthly_active_user'
|
||||
return e && e.getType() === 'm.server_notice.usage_limit_reached';
|
||||
});
|
||||
|
||||
let topBar;
|
||||
const isGuest = this.props.matrixClient.isGuest();
|
||||
if (this.state.syncErrorData && this.state.syncErrorData.error.errcode === 'M_MAU_LIMIT_EXCEEDED') {
|
||||
topBar = <ServerLimitBar kind='hard' />;
|
||||
if (this.state.syncErrorData && this.state.syncErrorData.error.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
|
||||
topBar = <ServerLimitBar kind='hard'
|
||||
adminContact={this.state.syncErrorData.error.data.admin_contact}
|
||||
limitType={this.state.syncErrorData.error.data.limit_type}
|
||||
/>;
|
||||
} else if (mauLimitEvent) {
|
||||
topBar = <ServerLimitBar kind='soft' adminContact={mauLimitEvent.getContent().admin_contact} />;
|
||||
topBar = <ServerLimitBar kind='soft'
|
||||
adminContact={mauLimitEvent.getContent().admin_contact}
|
||||
limitType={mauLimitEvent.getContent().limit_type}
|
||||
/>;
|
||||
} else if (this.props.showCookieBar &&
|
||||
this.props.config.piwik
|
||||
) {
|
||||
|
|
|
@ -293,11 +293,11 @@ module.exports = React.createClass({
|
|||
// It also trumps the "some not sent" msg since you can't resend without
|
||||
// a connection!
|
||||
// There's one situation in which we don't show this 'no connection' bar, and that's
|
||||
// if it's a monthly-active-user limit error: those are shown in the top bar.
|
||||
// if it's a resource limit exceeded error: those are shown in the top bar.
|
||||
const errorIsMauError = Boolean(
|
||||
this.state.syncStateData &&
|
||||
this.state.syncStateData.error &&
|
||||
this.state.syncStateData.error.errcode === 'M_MAU_LIMIT_EXCEEDED'
|
||||
this.state.syncStateData.error.errcode === 'M_RESOURCE_LIMIT_EXCEEDED'
|
||||
);
|
||||
return this.state.syncState === "ERROR" && !errorIsMauError;
|
||||
},
|
||||
|
@ -327,11 +327,18 @@ module.exports = React.createClass({
|
|||
} else {
|
||||
let consentError = null;
|
||||
let mauError = null;
|
||||
const translateMauError = sub => {
|
||||
if (mauError.data.admin_contact) {
|
||||
return <a href={mauError.data.admin_contact} target="_blank" rel="noopener">{sub}</a>;
|
||||
} else {
|
||||
return sub;
|
||||
}
|
||||
};
|
||||
for (const m of unsentMessages) {
|
||||
if (m.error && m.error.errcode === 'M_CONSENT_NOT_GIVEN') {
|
||||
consentError = m.error;
|
||||
break;
|
||||
} else if (m.error && m.error.errcode === 'M_MAU_LIMIT_EXCEEDED') {
|
||||
} else if (m.error && m.error.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
|
||||
mauError = m.error;
|
||||
break;
|
||||
}
|
||||
|
@ -348,8 +355,18 @@ module.exports = React.createClass({
|
|||
</a>,
|
||||
},
|
||||
);
|
||||
} else if (mauError && mauError.data.limit_type === 'monthly_active_user') {
|
||||
title = _t(
|
||||
"Your message wasn't sent because this homeserver has hit its Monthly Active User Limit. " +
|
||||
"Please <a>contact your service administrator</a> to continue using the service.",
|
||||
{}, { 'a' : translateMauError },
|
||||
);
|
||||
} else if (mauError) {
|
||||
title = _t("Your message wasn’t sent because this homeserver has hit its Monthly Active User Limit. Please contact your service administrator to continue using the service.");
|
||||
title = _t(
|
||||
"Your message wasn't sent because this homeserver has exceeded a resource limit. " +
|
||||
"Please <a>contact your service administrator</a> to continue using the service.",
|
||||
{}, { 'a' : translateMauError },
|
||||
);
|
||||
} else if (
|
||||
unsentMessages.length === 1 &&
|
||||
unsentMessages[0].error &&
|
||||
|
|
|
@ -121,12 +121,24 @@ module.exports = React.createClass({
|
|||
const usingEmail = username.indexOf("@") > 0;
|
||||
if (error.httpStatus === 400 && usingEmail) {
|
||||
errorText = _t('This Home Server does not support login using email address.');
|
||||
} else if (error.errcode == 'M_MAU_LIMIT_EXCEEDED') {
|
||||
} else if (error.errcode == 'M_RESOURCE_LIMIT_EXCEEDED') {
|
||||
errorText = (
|
||||
<div>
|
||||
<div>{ _t('This homeserver has hit its Monthly Active User limit') }</div>
|
||||
<div>{error.data.error ? error.data.error : _t("This server has exceeded its available resources")}</div>
|
||||
<div className="mx_Login_smallError">
|
||||
{ _t('Please contact your service administrator to continue using this service.') }
|
||||
{_t(
|
||||
"Please <a>contact your service administrator</a> to continue using this service.",
|
||||
{},
|
||||
{
|
||||
a: (sub) => {
|
||||
if (error.data.admin_contact) {
|
||||
return <a rel="noopener" target="_blank" href={error.data.admin_contact}>{sub}</a>;
|
||||
} else {
|
||||
return sub;
|
||||
}
|
||||
},
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -164,10 +164,22 @@ module.exports = React.createClass({
|
|||
if (!success) {
|
||||
let msg = response.message || response.toString();
|
||||
// can we give a better error message?
|
||||
if (response.errcode == 'M_MAU_LIMIT_EXCEEDED') {
|
||||
if (response.errcode == 'M_RESOURCE_LIMIT_EXCEEDED') {
|
||||
msg = <div>
|
||||
<p>{_t("This homeserver has hit its Monthly Active User limit")}</p>
|
||||
<p>{_t("Please contact your service administrator to continue using this service.")}</p>
|
||||
<p>{response.data.error ? response.data.error : _t("This server has exceeded its available resources")}</p>
|
||||
<p>{_t(
|
||||
"Please <a>contact your service administrator</a> to continue using this service.",
|
||||
{},
|
||||
{
|
||||
a: (sub) => {
|
||||
if (response.data.admin_contact) {
|
||||
return <a rel="noopener" target="_blank" href={response.data.admin_contact}>{sub}</a>;
|
||||
} else {
|
||||
return sub;
|
||||
}
|
||||
},
|
||||
},
|
||||
)}</p>
|
||||
</div>;
|
||||
} else if (response.required_stages && response.required_stages.indexOf('m.login.msisdn') > -1) {
|
||||
let msisdnAvailable = false;
|
||||
|
|
|
@ -23,7 +23,9 @@ export default React.createClass({
|
|||
propTypes: {
|
||||
// 'hard' if the logged in user has been locked out, 'soft' if they haven't
|
||||
kind: PropTypes.string,
|
||||
adminContent: PropTypes.string,
|
||||
adminContact: PropTypes.string,
|
||||
// The type of limit that has been hit.
|
||||
limitType: PropTypes.string.isRequired,
|
||||
},
|
||||
|
||||
getDefaultProps: function() {
|
||||
|
@ -36,42 +38,60 @@ export default React.createClass({
|
|||
const toolbarClasses = {
|
||||
'mx_MatrixToolbar': true,
|
||||
};
|
||||
let content;
|
||||
|
||||
const translateLink = (sub) => {
|
||||
if (this.props.adminContent) {
|
||||
return <a href={this.props.adminContent}>{sub}</a>;
|
||||
if (this.props.adminContact) {
|
||||
return <a rel="noopener" target="_blank" href={this.props.adminContact}>{sub}</a>;
|
||||
} else {
|
||||
return sub;
|
||||
}
|
||||
};
|
||||
|
||||
let adminContact;
|
||||
let limitError;
|
||||
if (this.props.kind === 'hard') {
|
||||
toolbarClasses['mx_MatrixToolbar_error'] = true;
|
||||
content = _t(
|
||||
"This homeserver has hit its Monthly Active User limit. " +
|
||||
adminContact = _t(
|
||||
"Please <a>contact your service administrator</a> to continue using the service.",
|
||||
{},
|
||||
{
|
||||
'a': translateLink,
|
||||
},
|
||||
);
|
||||
if (this.props.limitType === 'monthly_active_user') {
|
||||
limitError = _t("This homeserver has hit its Monthly Active User limit.");
|
||||
} else {
|
||||
limitError = _t("This homeserver has exceeded one of its resource limits.");
|
||||
}
|
||||
} else {
|
||||
toolbarClasses['mx_MatrixToolbar_info'] = true;
|
||||
content = _t(
|
||||
"This homeserver has hit its Monthly Active User " +
|
||||
"limit so some users will not be able to log in. " +
|
||||
adminContact = _t(
|
||||
"Please <a>contact your service administrator</a> to get this limit increased.",
|
||||
{},
|
||||
{
|
||||
'a': translateLink,
|
||||
},
|
||||
);
|
||||
if (this.props.limitType === 'monthly_active_user') {
|
||||
limitError = _t(
|
||||
"This homeserver has hit its Monthly Active User limit so " +
|
||||
"<b>some users will not be able to log in</b>.", {},
|
||||
{'b': sub => <b>{sub}</b>},
|
||||
);
|
||||
} else {
|
||||
limitError = _t(
|
||||
"This homeserver has exceeded one of its resource limits so " +
|
||||
"<b>some users will not be able to log in</b>.", {},
|
||||
{'b': sub => <b>{sub}</b>},
|
||||
);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className={classNames(toolbarClasses)}>
|
||||
<div className="mx_MatrixToolbar_content">
|
||||
{ content }
|
||||
{limitError}
|
||||
{' '}
|
||||
{adminContact}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue