Add warning on inviting a user if sharing history with new users.

Fixes https://github.com/vector-im/vector-web/issues/60
pull/21833/head
David Baker 2016-01-15 15:18:55 +00:00
parent b60d14a408
commit 2638ee974e
1 changed files with 45 additions and 8 deletions

View File

@ -16,12 +16,18 @@ limitations under the License.
var React = require('react'); var React = require('react');
var classNames = require('classnames'); var classNames = require('classnames');
var Matrix = require("matrix-js-sdk"); var Matrix = require("matrix-js-sdk");
var q = require('q');
var MatrixClientPeg = require("../../../MatrixClientPeg"); var MatrixClientPeg = require("../../../MatrixClientPeg");
var Modal = require("../../../Modal"); var Modal = require("../../../Modal");
var sdk = require('../../../index'); var sdk = require('../../../index');
var GeminiScrollbar = require('react-gemini-scrollbar'); var GeminiScrollbar = require('react-gemini-scrollbar');
var INITIAL_LOAD_NUM_MEMBERS = 50; var INITIAL_LOAD_NUM_MEMBERS = 50;
var SHARE_HISTORY_WARNING = "Newly invited users will see the history of this room. "+
"If you'd prefer invited users not to see messages that were sent before they joined, "+
"turn off, 'Share message history with new users' in the settings for this room.";
var shown_invite_warning_this_session = false;
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'MemberList', displayName: 'MemberList',
@ -132,12 +138,41 @@ module.exports = React.createClass({
return; return;
} }
var promise; var invite_defer = q.defer();
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
var history_visibility = room.currentState.getStateEvents('m.room.history_visibility', '');
if (history_visibility) history_visibility = history_visibility.getContent().history_visibility;
if (history_visibility == 'shared' && !shown_invite_warning_this_session) {
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
Modal.createDialog(QuestionDialog, {
title: "Warning",
description: SHARE_HISTORY_WARNING,
button: "Invite",
onFinished: function(should_invite) {
if (should_invite) {
shown_invite_warning_this_session = true;
invite_defer.resolve();
} else {
invite_defer.reject(null);
}
}
});
} else {
invite_defer.resolve();
}
var promise = invite_defer.promise;;
if (isEmailAddress) { if (isEmailAddress) {
promise = MatrixClientPeg.get().inviteByEmail(this.props.roomId, inputText); promise = promise.then(function() {
MatrixClientPeg.get().inviteByEmail(self.props.roomId, inputText);
});
} }
else { else {
promise = MatrixClientPeg.get().invite(this.props.roomId, inputText); promise = promise.then(function() {
MatrixClientPeg.get().invite(self.props.roomId, inputText);
});
} }
self.setState({ self.setState({
@ -152,11 +187,13 @@ module.exports = React.createClass({
inviting: false inviting: false
}); });
}, function(err) { }, function(err) {
console.error("Failed to invite: %s", JSON.stringify(err)); if (err !== null) {
Modal.createDialog(ErrorDialog, { console.error("Failed to invite: %s", JSON.stringify(err));
title: "Server error whilst inviting", Modal.createDialog(ErrorDialog, {
description: err.message title: "Server error whilst inviting",
}); description: err.message
});
}
self.setState({ self.setState({
inviting: false inviting: false
}); });