Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave room button #1

Merged
merged 7 commits into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions skins/base/css/molecules/MemberTile.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ limitations under the License.

.mx_MemberTile_avatarImg {
z-index: 20;
border-radius: 20px;
border-radius: 20px;
background-color: #dbdbdb;
}

Expand Down Expand Up @@ -96,4 +96,9 @@ limitations under the License.
.mx_MemberTile_offline .mx_MemberTile_nameSpan
{
opacity: 0.5;
}
}


.mx_MemberTile_leave {
float: right;
}
21 changes: 15 additions & 6 deletions skins/base/views/molecules/MemberTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ var React = require('react');

var MatrixClientPeg = require("../../../../src/MatrixClientPeg");
var ComponentBroker = require('../../../../src/ComponentBroker');
var Modal = require("../../../../src/Modal");
var MemberTileController = require("../../../../src/controllers/molecules/MemberTile");
var MemberInfo = ComponentBroker.get('molecules/MemberInfo');
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");

module.exports = React.createClass({
displayName: 'MemberTile',
Expand All @@ -41,6 +43,8 @@ module.exports = React.createClass({
},

render: function() {
var isMyUser = MatrixClientPeg.get().credentials.userId == this.props.member.userId;

var power;
if (this.props.member) {
var img = "img/p/p" + Math.floor(20 * this.props.member.powerLevelNorm / 100) + ".png";
Expand All @@ -58,18 +62,23 @@ module.exports = React.createClass({
}
mainClassName += presenceClass;

var name;
var name = this.props.member.name;
if (isMyUser) name += " (me)";
var leave = isMyUser ? <span className="mx_MemberTile_leave" onClick={this.onLeaveClick}>X</span> : null;
var nameEl;
if (this.state.hover) {
name =
nameEl =
<div className="mx_MemberTile_nameWrapper">
<MemberInfo member={this.props.member} />
<span className="mx_MemberTile_nameSpan">{this.props.member.name}</span>
<span className="mx_MemberTile_nameSpan">{name}</span>
{leave}
</div>
}
else {
name =
nameEl =
<div className="mx_MemberTile_name">
{this.props.member.name}
{name}
{leave}
</div>
}

Expand All @@ -81,7 +90,7 @@ module.exports = React.createClass({
width="40" height="40" alt=""/>
{ power }
</div>
{ name }
{ nameEl }
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ module.exports = {
);

React.render(dialog, this.getOrCreateContainer());

return {close: closeDialog};
},
};
19 changes: 19 additions & 0 deletions src/controllers/molecules/MemberTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
'use strict';

var dis = require("../../dispatcher");
var Modal = require("../../Modal");
var Loader = require("react-loader");

var MatrixClientPeg = require("../../MatrixClientPeg");

Expand All @@ -27,4 +29,21 @@ module.exports = {
user_id: this.props.member.userId
});
},

onLeaveClick: function() {
var d = MatrixClientPeg.get().leave(this.props.member.roomId);

var modal = Modal.createDialog(Loader);

d.then(function() {
modal.close();
dis.dispatch({action: 'view_next_room'});
}, function(err) {
modal.close();
Modal.createDialog(ErrorDialog, {
title: "Failed to leave room",
description: err.toString()
});
});
}
};
10 changes: 8 additions & 2 deletions src/controllers/organisms/RoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ module.exports = {
},

getRoomList: function() {
return RoomListSorter.mostRecentActivityFirst(MatrixClientPeg.get().getRooms());
return RoomListSorter.mostRecentActivityFirst(
MatrixClientPeg.get().getRooms().filter(function(room) {
return room.hasMembershipState(
MatrixClientPeg.get().credentials.userId,
"join"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for invites?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

);
})
);
},

makeRoomTiles: function() {
Expand All @@ -115,4 +122,3 @@ module.exports = {
});
},
};