mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 22:22:03 +03:00
Restructure limits to be set at RoomView, so they may change if the
upload fails
This commit is contained in:
parent
76f0f15e49
commit
caf2086585
2 changed files with 29 additions and 11 deletions
|
@ -49,6 +49,8 @@ import SettingsStore, {SettingLevel} from "../../settings/SettingsStore";
|
||||||
const DEBUG = false;
|
const DEBUG = false;
|
||||||
let debuglog = function() {};
|
let debuglog = function() {};
|
||||||
|
|
||||||
|
let mediaLimitCache = null;
|
||||||
|
|
||||||
const BROWSER_SUPPORTS_SANDBOX = 'sandbox' in document.createElement('iframe');
|
const BROWSER_SUPPORTS_SANDBOX = 'sandbox' in document.createElement('iframe');
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -95,6 +97,9 @@ module.exports = React.createClass({
|
||||||
peekLoading: false,
|
peekLoading: false,
|
||||||
shouldPeek: true,
|
shouldPeek: true,
|
||||||
|
|
||||||
|
// Media limits for uploading, this may change.
|
||||||
|
mediaLimits: {},
|
||||||
|
|
||||||
// The event to be scrolled to initially
|
// The event to be scrolled to initially
|
||||||
initialEventId: null,
|
initialEventId: null,
|
||||||
// The offset in pixels from the event with which to scroll vertically
|
// The offset in pixels from the event with which to scroll vertically
|
||||||
|
@ -147,12 +152,26 @@ module.exports = React.createClass({
|
||||||
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
|
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
|
||||||
MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership);
|
MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership);
|
||||||
MatrixClientPeg.get().on("accountData", this.onAccountData);
|
MatrixClientPeg.get().on("accountData", this.onAccountData);
|
||||||
|
this._fetchMediaLimits();
|
||||||
// Start listening for RoomViewStore updates
|
// Start listening for RoomViewStore updates
|
||||||
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
||||||
this._onRoomViewStoreUpdate(true);
|
this._onRoomViewStoreUpdate(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_fetchMediaLimits: function(invalidateCache: boolean = false) {
|
||||||
|
let limits;
|
||||||
|
if(invalidateCache || mediaLimitCache == null) {
|
||||||
|
MatrixClientPeg.get().getMediaLimits().then((_limits) => {
|
||||||
|
limits = _limits;
|
||||||
|
}).catch(() => {
|
||||||
|
// Media repo can't or won't report limits, so provide an empty object (no limits).
|
||||||
|
limits = {};
|
||||||
|
});
|
||||||
|
mediaLimitCache = limits;
|
||||||
|
}
|
||||||
|
this.state.mediaLimits = limits;
|
||||||
|
},
|
||||||
|
|
||||||
_onRoomViewStoreUpdate: function(initial) {
|
_onRoomViewStoreUpdate: function(initial) {
|
||||||
if (this.unmounted) {
|
if (this.unmounted) {
|
||||||
return;
|
return;
|
||||||
|
@ -481,6 +500,7 @@ module.exports = React.createClass({
|
||||||
break;
|
break;
|
||||||
case 'notifier_enabled':
|
case 'notifier_enabled':
|
||||||
case 'upload_failed':
|
case 'upload_failed':
|
||||||
|
this._fetchMediaLimits(true);
|
||||||
case 'upload_started':
|
case 'upload_started':
|
||||||
case 'upload_finished':
|
case 'upload_finished':
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
|
@ -1654,6 +1674,7 @@ module.exports = React.createClass({
|
||||||
callState={this.state.callState}
|
callState={this.state.callState}
|
||||||
disabled={this.props.disabled}
|
disabled={this.props.disabled}
|
||||||
showApps={this.state.showApps}
|
showApps={this.state.showApps}
|
||||||
|
mediaLimits={this.state.mediaLimits}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,6 @@ export default class MessageComposer extends React.Component {
|
||||||
// XXX: fragile as all hell - fixme somehow, perhaps with a dedicated Room.encryption event or something.
|
// XXX: fragile as all hell - fixme somehow, perhaps with a dedicated Room.encryption event or something.
|
||||||
MatrixClientPeg.get().on("event", this.onEvent);
|
MatrixClientPeg.get().on("event", this.onEvent);
|
||||||
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
||||||
|
|
||||||
MatrixClientPeg.get().getMediaLimits().then((limits) => {
|
|
||||||
this._uploadLimits = limits;
|
|
||||||
}).catch(() => {
|
|
||||||
// HS can't or won't provide limits, so don't give any.
|
|
||||||
this._uploadLimits = {};
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -110,8 +103,10 @@ export default class MessageComposer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
isFileUploadAllowed(file) {
|
isFileUploadAllowed(file) {
|
||||||
if (this._uploadLimits.upload_size !== undefined && file.size > this._uploadLimits.upload_size) {
|
if (this.props.mediaLimits !== undefined &&
|
||||||
return _t("File is too big. Maximum file size is %(fileSize)s", {fileSize: filesize(this._uploadLimits.upload_size)});
|
this.props.mediaLimits.upload_size !== undefined &&
|
||||||
|
file.size > this.props.mediaLimits.upload_size) {
|
||||||
|
return _t("File is too big. Maximum file size is %(fileSize)s", {fileSize: filesize(this.mediaLimits.upload_size)});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -430,6 +425,8 @@ MessageComposer.propTypes = {
|
||||||
// callback when a file to upload is chosen
|
// callback when a file to upload is chosen
|
||||||
uploadFile: PropTypes.func.isRequired,
|
uploadFile: PropTypes.func.isRequired,
|
||||||
|
|
||||||
|
mediaLimits: PropTypes.object,
|
||||||
|
|
||||||
// string representing the current room app drawer state
|
// string representing the current room app drawer state
|
||||||
showApps: PropTypes.bool,
|
showApps: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue