Add ability to click-to-invite

pull/21833/head
Kegan Dougal 2016-01-18 17:12:35 +00:00
parent 165adde0c8
commit 36616a97a1
2 changed files with 22 additions and 8 deletions

View File

@ -55,10 +55,23 @@ class MemberEntity extends Entity {
class UserEntity extends Entity {
constructor(model, showInviteButton, inviteFn) {
super(model);
this.showInviteButton = Boolean(showInviteButton);
this.inviteFn = inviteFn;
}
onClick() {
if (this.inviteFn) {
this.inviteFn(this.model.userId);
}
}
getJsx() {
var UserTile = sdk.getComponent("rooms.UserTile");
return (
<UserTile key={this.model.userId} user={this.model} />
<UserTile key={this.model.userId} user={this.model}
showInviteButton={this.showInviteButton} onClick={this.onClick.bind(this)} />
);
}
@ -82,11 +95,13 @@ module.exports = {
/**
* @param {User[]} users
* @param {boolean} showInviteButton
* @param {Function} inviteFn Called with the user ID.
* @return {Entity[]}
*/
fromUsers: function(users) {
fromUsers: function(users, showInviteButton, inviteFn) {
return users.map(function(u) {
return new UserEntity(u);
return new UserEntity(u, showInviteButton, inviteFn);
})
}
};

View File

@ -320,11 +320,10 @@ module.exports = React.createClass({
// TODO: Cache this calculation
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
var allUsers = MatrixClientPeg.get().getUsers();
// only add Users if they don't exist in the member list
// only add Users if they are not joined
allUsers = allUsers.filter(function(u) {
return room.getMember(u.userId) === null;
return !room.hasMembershipState(u.userId, "join");
});
var SearchableEntityList = sdk.getComponent("rooms.SearchableEntityList");
return (
@ -332,9 +331,9 @@ module.exports = React.createClass({
onSubmit={this.onInvite}
entities={
Entities.fromRoomMembers(
room.currentState.getMembers() // ALLLLL OF THEM
room.getJoinedMembers()
).concat(
Entities.fromUsers(allUsers)
Entities.fromUsers(allUsers, true, this.onInvite)
)
} />
);