From ccdb5fa7704362fc7911ac664bc6f0523d8dadac Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 3 Aug 2018 18:02:09 +0100 Subject: [PATCH] Don't show 'connection lost' bar on MAU error We don't need both warning bars Requires https://github.com/matrix-org/matrix-js-sdk/pull/680 --- src/components/structures/LoggedInView.js | 6 +++-- src/components/structures/RoomStatusBar.js | 31 +++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index 3273989630..65ef69d547 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -1,7 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd -Copyright 2017 New Vector Ltd +Copyright 2017, 2018 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -144,7 +144,9 @@ const LoggedInView = React.createClass({ }, onSync: function(syncState, oldSyncState, data) { - if (syncState === oldSyncState) return; + const oldErrCode = this.state.syncErrorData && this.state.syncErrorData.error && this.state.syncErrorData.error.errcode; + const newErrCode = data && data.error && data.error.errcode; + if (syncState === oldSyncState && oldErrCode === newErrCode) return; if (syncState === 'ERROR') { this.setState({ diff --git a/src/components/structures/RoomStatusBar.js b/src/components/structures/RoomStatusBar.js index 941cab4dda..ef82ed4bad 100644 --- a/src/components/structures/RoomStatusBar.js +++ b/src/components/structures/RoomStatusBar.js @@ -1,6 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd -Copyright 2017 New Vector Ltd +Copyright 2017, 2018 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -107,6 +107,7 @@ module.exports = React.createClass({ getInitialState: function() { return { syncState: MatrixClientPeg.get().getSyncState(), + syncStateData: MatrixClientPeg.get().getSyncStateData(), usersTyping: WhoIsTyping.usersTypingApartFromMe(this.props.room), unsentMessages: getUnsentMessages(this.props.room), }; @@ -134,12 +135,13 @@ module.exports = React.createClass({ } }, - onSyncStateChange: function(state, prevState) { + onSyncStateChange: function(state, prevState, data) { if (state === "SYNCING" && prevState === "SYNCING") { return; } this.setState({ syncState: state, + syncStateData: data, }); }, @@ -191,7 +193,7 @@ module.exports = React.createClass({ // changed - so we use '0' to indicate normal size, and other values to // indicate other sizes. _getSize: function() { - if (this.state.syncState === "ERROR" || + if (this._shouldShowConnectionError() || (this.state.usersTyping.length > 0) || this.props.numUnreadMessages || !this.props.atEndOfLiveTimeline || @@ -238,7 +240,7 @@ module.exports = React.createClass({ ); } - if (this.state.syncState === "ERROR") { + if (this._shouldShowConnectionError()) { return null; } @@ -285,6 +287,21 @@ module.exports = React.createClass({ return avatars; }, + _shouldShowConnectionError: function() { + // no conn bar trumps unread count since you can't get unread messages + // without a connection! (technically may already have some but meh) + // 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. + const errorIsMauError = Boolean( + this.state.syncStateData && + this.state.syncStateData.error && + this.state.syncStateData.error.errcode === 'M_MAU_LIMIT_EXCEEDED' + ); + return this.state.syncState === "ERROR" && !errorIsMauError; + }, + _getUnsentMessageContent: function() { const unsentMessages = this.state.unsentMessages; if (!unsentMessages.length) return null; @@ -372,11 +389,7 @@ module.exports = React.createClass({ _getContent: function() { const EmojiText = sdk.getComponent('elements.EmojiText'); - // no conn bar trumps unread count since you can't get unread messages - // without a connection! (technically may already have some but meh) - // It also trumps the "some not sent" msg since you can't resend without - // a connection! - if (this.state.syncState === "ERROR") { + if (this._shouldShowConnectionError()) { return (
/!\