mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 01:35:49 +03:00
Wire up Start Chat button.
This commit is contained in:
parent
08c16e0d7a
commit
0baa2141fc
2 changed files with 51 additions and 1 deletions
|
@ -69,7 +69,7 @@ module.exports = React.createClass({
|
|||
<div className="mx_MemberInfo_field">{this.props.member.userId}</div>
|
||||
<div className="mx_MemberInfo_field">Presence: {this.state.presence}</div>
|
||||
<div className="mx_MemberInfo_field">Last active: {activeAgo}</div>
|
||||
<div className="mx_MemberInfo_button">Start chat</div>
|
||||
<div className="mx_MemberInfo_button" onClick={this.onChatClick}>Start chat</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||
var dis = require("../../dispatcher");
|
||||
|
||||
module.exports = {
|
||||
componentDidMount: function() {
|
||||
|
@ -55,6 +56,55 @@ module.exports = {
|
|||
MatrixClientPeg.get().removeListener("User.presence", this.userPresenceFn);
|
||||
},
|
||||
|
||||
onChatClick: function() {
|
||||
// check if there are any existing rooms with just us and them (1:1)
|
||||
// If so, just view that room. If not, create a private room with them.
|
||||
var rooms = MatrixClientPeg.get().getRooms();
|
||||
var userIds = [
|
||||
this.props.member.userId,
|
||||
MatrixClientPeg.get().credentials.userId
|
||||
];
|
||||
var existingRoomId = null;
|
||||
for (var i = 0; i < rooms.length; i++) {
|
||||
var members = rooms[i].getJoinedMembers();
|
||||
if (members.length === 2) {
|
||||
var hasTargetUsers = true;
|
||||
for (var j = 0; j < members.length; j++) {
|
||||
if (userIds.indexOf(members[j].userId) === -1) {
|
||||
hasTargetUsers = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasTargetUsers) {
|
||||
existingRoomId = rooms[i].roomId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (existingRoomId) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: existingRoomId
|
||||
});
|
||||
}
|
||||
else {
|
||||
MatrixClientPeg.get().createRoom({
|
||||
invite: [this.props.member.userId],
|
||||
preset: "private_chat"
|
||||
}).done(function(res) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: res.room_id
|
||||
});
|
||||
}, function(err) {
|
||||
console.error(
|
||||
"Failed to create room: %s", JSON.stringify(err)
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
presence: "offline",
|
||||
|
|
Loading…
Reference in a new issue