Add ability to delete an alias from room directory

Hidden behind shift-click for now, but we're going to need to do this a lot to moderate the public room list.
pull/1680/head
David Baker 2016-06-21 16:47:40 +01:00
parent 9556795611
commit ad2541299f
1 changed files with 48 additions and 9 deletions

View File

@ -52,6 +52,18 @@ module.exports = React.createClass({
}, },
componentDidMount: function() { componentDidMount: function() {
this.getPublicRooms();
},
componentWillUnmount: function() {
// dis.dispatch({
// action: 'ui_opacity',
// sideOpacity: 1.0,
// middleOpacity: 1.0,
// });
},
getPublicRooms: function() {
var self = this; var self = this;
MatrixClientPeg.get().publicRooms(function (err, data) { MatrixClientPeg.get().publicRooms(function (err, data) {
if (err) { if (err) {
@ -68,20 +80,43 @@ module.exports = React.createClass({
publicRooms: data.chunk, publicRooms: data.chunk,
loading: false, loading: false,
}); });
self.forceUpdate();
} }
}); });
}, },
componentWillUnmount: function() { deleteAliasClicked: function(roomAlias) {
// dis.dispatch({ var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
// action: 'ui_opacity', var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
// sideOpacity: 1.0, Modal.createDialog(QuestionDialog, {
// middleOpacity: 1.0, title: "Delete Alias",
// }); description: `Are you sure you want to remove the alias '${roomAlias}'?`,
onFinished: (should_delete) => {
if (should_delete) {
var Loader = sdk.getComponent("elements.Spinner");
var modal = Modal.createDialog(Loader);
MatrixClientPeg.get().deleteAlias(roomAlias).done(() => {
modal.close();
this.getPublicRooms();
}, function(err) {
modal.close();
Modal.createDialog(ErrorDialog, {
title: "Failed to delete alias",
description: err.toString()
});
});
}
}
});
}, },
showRoom: function(roomId, roomAlias) { showRoom: function(roomId, roomAlias, ev) {
if (ev.shiftKey) {
ev.preventDefault();
this.deleteAliasClicked(roomAlias);
return;
}
// extract the metadata from the publicRooms structure to pass // extract the metadata from the publicRooms structure to pass
// as out-of-band data to view_room, because we get information // as out-of-band data to view_room, because we get information
// here that we can't get other than by joining the room in some // here that we can't get other than by joining the room in some
@ -175,7 +210,11 @@ module.exports = React.createClass({
topic = linkifyString(sanitizeHtml(topic)); topic = linkifyString(sanitizeHtml(topic));
rows.unshift( rows.unshift(
<tr key={ rooms[i].room_id } onClick={self.showRoom.bind(null, rooms[i].room_id, alias)}> <tr key={ rooms[i].room_id }
onClick={self.showRoom.bind(null, rooms[i].room_id, alias)}
// cancel onMouseDown otherwise shift-clicking highlights text
onMouseDown={(ev) => {ev.preventDefault();}}
>
<td className="mx_RoomDirectory_roomAvatar"> <td className="mx_RoomDirectory_roomAvatar">
<BaseAvatar width={24} height={24} resizeMethod='crop' <BaseAvatar width={24} height={24} resizeMethod='crop'
name={ name } idName={ name } name={ name } idName={ name }