mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 05:55:00 +08:00
Glue more things back together
This commit is contained in:
parent
78354d0bc7
commit
0cbf9dba87
@ -1245,7 +1245,7 @@ module.exports = React.createClass({
|
|||||||
uploadingRoomSettings: false,
|
uploadingRoomSettings: false,
|
||||||
editingRoomSettings: false
|
editingRoomSettings: false
|
||||||
});
|
});
|
||||||
});
|
}).done();
|
||||||
},
|
},
|
||||||
|
|
||||||
onCancelClick: function() {
|
onCancelClick: function() {
|
||||||
|
@ -19,6 +19,7 @@ var React = require('react');
|
|||||||
var MatrixClientPeg = require('../../../MatrixClientPeg');
|
var MatrixClientPeg = require('../../../MatrixClientPeg');
|
||||||
var sdk = require('../../../index');
|
var sdk = require('../../../index');
|
||||||
var Modal = require('../../../Modal');
|
var Modal = require('../../../Modal');
|
||||||
|
var ObjectUtils = require("../../../ObjectUtils");
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'RoomSettings',
|
displayName: 'RoomSettings',
|
||||||
@ -88,28 +89,65 @@ module.exports = React.createClass({
|
|||||||
const roomId = this.props.room.roomId;
|
const roomId = this.props.room.roomId;
|
||||||
var promises = this.saveAliases(); // returns Promise[]
|
var promises = this.saveAliases(); // returns Promise[]
|
||||||
var originalState = this.getInitialState();
|
var originalState = this.getInitialState();
|
||||||
|
|
||||||
// diff between original state and this.state to work out what has been changed
|
// diff between original state and this.state to work out what has been changed
|
||||||
console.log("Original: %s", JSON.stringify(originalState));
|
console.log("Original: %s", JSON.stringify(originalState));
|
||||||
console.log("New: %s", JSON.stringify(this.state));
|
console.log("New: %s", JSON.stringify(this.state));
|
||||||
|
|
||||||
|
// name and topic
|
||||||
if (this._hasDiff(this.state.name, originalState.name)) {
|
if (this._hasDiff(this.state.name, originalState.name)) {
|
||||||
promises.push(MatrixClientPeg.get().setRoomName(roomId, this.state.name));
|
promises.push(MatrixClientPeg.get().setRoomName(roomId, this.state.name));
|
||||||
}
|
}
|
||||||
if (this._hasDiff(this.state.topic, originalState.topic)) {
|
if (this._hasDiff(this.state.topic, originalState.topic)) {
|
||||||
promises.push(MatrixClientPeg.get().setRoomTopic(roomId, this.state.topic));
|
promises.push(MatrixClientPeg.get().setRoomTopic(roomId, this.state.topic));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// this.state.join_rule
|
// this.state.join_rule
|
||||||
// this.state.history_visibility
|
// this.state.history_visibility
|
||||||
// this.state.guest_access
|
// this.state.guest_access
|
||||||
|
|
||||||
// setRoomMutePushRule
|
// setRoomMutePushRule
|
||||||
|
if (this.state.areNotifsMuted !== originalState.areNotifsMuted) {
|
||||||
|
promises.push(MatrixClientPeg.get().setRoomMutePushRule(
|
||||||
|
"global", roomId, this.state.areNotifsMuted
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// power levels
|
// power levels
|
||||||
|
var powerLevels = this._getPowerLevels();
|
||||||
|
if (powerLevels) {
|
||||||
|
promises.push(MatrixClientPeg.get().sendStateEvent(
|
||||||
|
roomId, "m.room.power_levels", powerLevels, ""
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// tags
|
// tags
|
||||||
|
if (this.state.tags_changed) {
|
||||||
|
var tagDiffs = ObjectUtils.getKeyValueArrayDiffs(originalState.tags, this.state.tags);
|
||||||
|
// [ {place: add, key: "m.favourite", val: "yep"} ]
|
||||||
|
tagDiffs.forEach(function(diff) {
|
||||||
|
switch (diff.place) {
|
||||||
|
case "add":
|
||||||
|
promises.push(
|
||||||
|
MatrixClientPeg.get().setRoomTag(roomId, diff.key, {})
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "del":
|
||||||
|
promises.push(
|
||||||
|
MatrixClientPeg.get().deleteRoomTag(roomId, diff.key)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error("Unknown tag operation: %s", diff.place);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// color scheme
|
// color scheme
|
||||||
promises.push(this.saveColor());
|
promises.push(this.saveColor());
|
||||||
|
|
||||||
// submit diffs
|
|
||||||
|
|
||||||
return q.allSettled(promises);
|
return q.allSettled(promises);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -131,27 +169,7 @@ module.exports = React.createClass({
|
|||||||
return strA !== strB;
|
return strA !== strB;
|
||||||
},
|
},
|
||||||
|
|
||||||
resetState: function() {
|
_getPowerLevels: function() {
|
||||||
this.setState(this.getInitialState());
|
|
||||||
},
|
|
||||||
|
|
||||||
canGuestsRead: function() {
|
|
||||||
return this.refs.guests_read.checked;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTopic: function() {
|
|
||||||
return this.refs.topic ? this.refs.topic.value : "";
|
|
||||||
},
|
|
||||||
|
|
||||||
getHistoryVisibility: function() {
|
|
||||||
return this.refs.share_history.checked ? "shared" : "invited";
|
|
||||||
},
|
|
||||||
|
|
||||||
areNotificationsMuted: function() {
|
|
||||||
return this.state.are_notifications_muted;
|
|
||||||
},
|
|
||||||
|
|
||||||
getPowerLevels: function() {
|
|
||||||
if (!this.state.power_levels_changed) return undefined;
|
if (!this.state.power_levels_changed) return undefined;
|
||||||
|
|
||||||
var power_levels = this.props.room.currentState.getStateEvents('m.room.power_levels', '');
|
var power_levels = this.props.room.currentState.getStateEvents('m.room.power_levels', '');
|
||||||
@ -172,34 +190,6 @@ module.exports = React.createClass({
|
|||||||
return new_power_levels;
|
return new_power_levels;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTagOperations: function() {
|
|
||||||
if (!this.state.tags_changed) return undefined;
|
|
||||||
|
|
||||||
var ops = [];
|
|
||||||
|
|
||||||
var delta = {};
|
|
||||||
Object.keys(this.props.room.tags).forEach(function(oldTag) {
|
|
||||||
delta[oldTag] = delta[oldTag] || 0;
|
|
||||||
delta[oldTag]--;
|
|
||||||
});
|
|
||||||
Object.keys(this.state.tags).forEach(function(newTag) {
|
|
||||||
delta[newTag] = delta[newTag] || 0;
|
|
||||||
delta[newTag]++;
|
|
||||||
});
|
|
||||||
Object.keys(delta).forEach(function(tag) {
|
|
||||||
if (delta[tag] == 1) {
|
|
||||||
ops.push({ type: "put", tag: tag });
|
|
||||||
} else if (delta[tag] == -1) {
|
|
||||||
ops.push({ type: "delete", tag: tag });
|
|
||||||
} else {
|
|
||||||
console.error("Calculated tag delta of " + delta[tag] +
|
|
||||||
" - this should never happen!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return ops;
|
|
||||||
},
|
|
||||||
|
|
||||||
onPowerLevelsChanged: function() {
|
onPowerLevelsChanged: function() {
|
||||||
this.setState({
|
this.setState({
|
||||||
power_levels_changed: true
|
power_levels_changed: true
|
||||||
@ -222,7 +212,7 @@ module.exports = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
onTagChange: function(tagName, event) {
|
_onTagChange: function(tagName, event) {
|
||||||
if (event.target.checked) {
|
if (event.target.checked) {
|
||||||
if (tagName === 'm.favourite') {
|
if (tagName === 'm.favourite') {
|
||||||
delete this.state.tags['m.lowpriority'];
|
delete this.state.tags['m.lowpriority'];
|
||||||
@ -231,13 +221,12 @@ module.exports = React.createClass({
|
|||||||
delete this.state.tags['m.favourite'];
|
delete this.state.tags['m.favourite'];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.tags[tagName] = this.state.tags[tagName] || {};
|
this.state.tags[tagName] = this.state.tags[tagName] || ["yep"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete this.state.tags[tagName];
|
delete this.state.tags[tagName];
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: hacky say to deep-edit state
|
|
||||||
this.setState({
|
this.setState({
|
||||||
tags: this.state.tags,
|
tags: this.state.tags,
|
||||||
tags_changed: true
|
tags_changed: true
|
||||||
@ -390,7 +379,7 @@ module.exports = React.createClass({
|
|||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
ref={ tag.ref }
|
ref={ tag.ref }
|
||||||
checked={ tag.name in self.state.tags }
|
checked={ tag.name in self.state.tags }
|
||||||
onChange={ self.onTagChange.bind(self, tag.name) }/>
|
onChange={ self._onTagChange.bind(self, tag.name) }/>
|
||||||
{ tag.label }
|
{ tag.label }
|
||||||
</label>);
|
</label>);
|
||||||
}) : tags.map(function(tag) { return tag.label; }).join(", ")
|
}) : tags.map(function(tag) { return tag.label; }).join(", ")
|
||||||
|
Loading…
Reference in New Issue
Block a user