Skip to content

Commit 813cf04

Browse files
committed
Merge branch 'vector' of github.com:matrix-org/matrix-react-sdk into erikj/room_editing
2 parents 3a7ebf7 + 0a3cddb commit 813cf04

11 files changed

Lines changed: 199 additions & 49 deletions

File tree

‎skins/base/css/molecules/MemberTile.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ limitations under the License.
5151
overflow: hidden;
5252
text-overflow: ellipsis;
5353
}
54+
55+
.mx_MemberTile_unavailable {
56+
opacity: 0.75;
57+
}
58+
59+
.mx_MemberTile_offline {
60+
opacity: 0.5;
61+
}

‎skins/base/views/molecules/MemberTile.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,21 @@ module.exports = React.createClass({
4646
var img = "img/p/p" + Math.floor(20 * this.props.member.powerLevelNorm / 100) + ".png";
4747
power = <img src={ img } className="mx_MemberTile_power" width="48" height="48" alt=""/>;
4848
}
49+
var presenceClass = "mx_MemberTile_offline";
50+
var mainClassName = "mx_MemberTile ";
51+
if (this.props.member.user) {
52+
if (this.props.member.user.presence === "online") {
53+
presenceClass = "mx_MemberTile_online";
54+
}
55+
else if (this.props.member.user.presence === "unavailable") {
56+
presenceClass = "mx_MemberTile_unavailable";
57+
}
58+
}
59+
mainClassName += presenceClass;
4960

5061
return (
51-
<div className="mx_MemberTile" onMouseEnter={ this.mouseEnter } onMouseLeave={ this.mouseLeave } >
62+
<div className={mainClassName} onMouseEnter={ this.mouseEnter } onMouseLeave={ this.mouseLeave }
63+
>
5264
<div className="mx_MemberTile_avatar">
5365
<img className="mx_MemberTile_avatarImg"
5466
src={ this.props.member ? MatrixClientPeg.get().getAvatarUrlForMember(this.props.member, 40, 40, "crop") : null }

‎skins/base/views/organisms/MemberList.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = React.createClass({
4747
return Object.keys(self.state.memberDict).map(function(userId) {
4848
var m = self.state.memberDict[userId];
4949
return (
50-
<MemberTile key={userId} member={m} />
50+
<MemberTile key={userId} member={m} ref={userId} />
5151
);
5252
});
5353
},

‎src/CallHandler.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ function _setCallListeners(call) {
116116
_setCallState(call, call.roomId, "busy");
117117
pause("ringbackAudio");
118118
play("busyAudio");
119+
Modal.createDialog(ErrorDialog, {
120+
title: "Call Timeout",
121+
description: "The remote side failed to pick up."
122+
});
119123
}
120124
else if (oldState === "invite_sent") {
121125
_setCallState(call, call.roomId, "stop_ringback");

‎src/MatrixClientPeg.js‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@ var Matrix = require("matrix-js-sdk");
2222
var matrixClient = null;
2323

2424
var localStorage = window.localStorage;
25+
26+
function createClient(hs_url, is_url, user_id, access_token) {
27+
var opts = {
28+
baseUrl: hs_url,
29+
idBaseUrl: is_url,
30+
accessToken: access_token,
31+
userId: user_id
32+
};
33+
34+
matrixClient = Matrix.createClient(opts);
35+
}
36+
2537
if (localStorage) {
2638
var hs_url = localStorage.getItem("mx_hs_url");
2739
var is_url = localStorage.getItem("mx_is_url") || 'https://matrix.org';
2840
var access_token = localStorage.getItem("mx_access_token");
2941
var user_id = localStorage.getItem("mx_user_id");
3042
if (access_token && user_id && hs_url) {
31-
matrixClient = Matrix.createClient({
32-
baseUrl: hs_url,
33-
idBaseUrl: is_url,
34-
accessToken: access_token,
35-
userId: user_id
36-
});
43+
createClient(hs_url, is_url, user_id, access_token);
3744
}
3845
}
3946

@@ -42,15 +49,32 @@ module.exports = {
4249
return matrixClient;
4350
},
4451

45-
replace: function(cli) {
46-
matrixClient = cli;
52+
unset: function() {
53+
matrixClient = null;
4754
},
4855

4956
replaceUsingUrls: function(hs_url, is_url) {
5057
matrixClient = Matrix.createClient({
5158
baseUrl: hs_url,
5259
idBaseUrl: is_url
5360
});
61+
},
62+
63+
replaceUsingAccessToken: function(hs_url, is_url, user_id, access_token) {
64+
createClient(hs_url, is_url, user_id, access_token);
65+
if (localStorage) {
66+
try {
67+
localStorage.clear();
68+
localStorage.setItem("mx_hs_url", hs_url);
69+
localStorage.setItem("mx_is_url", is_url);
70+
localStorage.setItem("mx_user_id", user_id);
71+
localStorage.setItem("mx_access_token", access_token);
72+
} catch (e) {
73+
console.warn("Error using local storage: can't persist session!");
74+
}
75+
} else {
76+
console.warn("No local storage available: can't persist session!");
77+
}
5478
}
5579
};
5680

‎src/Presence.js‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
"use strict";
17+
var MatrixClientPeg = require("./MatrixClientPeg");
18+
19+
// Time in ms after that a user is considered as unavailable/away
20+
var UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins
21+
var PRESENCE_STATES = ["online", "offline", "unavailable"];
22+
23+
// The current presence state
24+
var state, timer;
25+
26+
module.exports = {
27+
28+
/**
29+
* Start listening the user activity to evaluate his presence state.
30+
* Any state change will be sent to the Home Server.
31+
*/
32+
start: function() {
33+
var self = this;
34+
this.running = true;
35+
if (undefined === state) {
36+
// The user is online if they move the mouse or press a key
37+
document.onmousemove = function() { self._resetTimer(); };
38+
document.onkeypress = function() { self._resetTimer(); };
39+
this._resetTimer();
40+
}
41+
},
42+
43+
/**
44+
* Stop tracking user activity
45+
*/
46+
stop: function() {
47+
this.running = false;
48+
if (timer) {
49+
clearTimeout(timer);
50+
timer = undefined;
51+
}
52+
state = undefined;
53+
},
54+
55+
/**
56+
* Get the current presence state.
57+
* @returns {string} the presence state (see PRESENCE enum)
58+
*/
59+
getState: function() {
60+
return state;
61+
},
62+
63+
/**
64+
* Set the presence state.
65+
* If the state has changed, the Home Server will be notified.
66+
* @param {string} newState the new presence state (see PRESENCE enum)
67+
*/
68+
setState: function(newState) {
69+
if (newState === state) {
70+
return;
71+
}
72+
if (PRESENCE_STATES.indexOf(newState) === -1) {
73+
throw new Error("Bad presence state: " + newState);
74+
}
75+
if (!this.running) {
76+
return;
77+
}
78+
state = newState;
79+
MatrixClientPeg.get().setPresence(state).catch(function(err) {
80+
console.error("Failed to set presence: %s", err);
81+
});
82+
},
83+
84+
/**
85+
* Callback called when the user made no action on the page for UNAVAILABLE_TIME ms.
86+
* @private
87+
*/
88+
_onUnavailableTimerFire: function() {
89+
this.setState("unavailable");
90+
},
91+
92+
/**
93+
* Callback called when the user made an action on the page
94+
* @private
95+
*/
96+
_resetTimer: function() {
97+
var self = this;
98+
this.setState("online");
99+
// Re-arm the timer
100+
clearTimeout(timer);
101+
timer = setTimeout(function() {
102+
self._onUnavailableTimerFire();
103+
}, UNAVAILABLE_TIME_MS);
104+
}
105+
};

‎src/controllers/molecules/MessageComposer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module.exports = {
106106
// show the message
107107
this.element.value = this.data[this.position];
108108
}
109-
else if (this.originalText) {
109+
else if (this.originalText !== undefined) {
110110
// restore the original text the user was typing.
111111
this.element.value = this.originalText;
112112
}

‎src/controllers/organisms/MemberList.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ limitations under the License.
1818

1919
var React = require("react");
2020
var MatrixClientPeg = require("../../MatrixClientPeg");
21+
var Modal = require("../../Modal");
22+
var ComponentBroker = require('../../ComponentBroker');
23+
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
2124

2225
var INITIAL_LOAD_NUM_MEMBERS = 50;
2326

@@ -37,6 +40,7 @@ module.exports = {
3740
componentWillUnmount: function() {
3841
if (MatrixClientPeg.get()) {
3942
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
43+
MatrixClientPeg.get().removeListener("User.presence", this.userPresenceFn);
4044
}
4145
},
4246

@@ -48,8 +52,19 @@ module.exports = {
4852
memberDict: self.roomMembers()
4953
});
5054
}, 50);
51-
},
5255

56+
// Attach a SINGLE listener for global presence changes then locate the
57+
// member tile and re-render it. This is more efficient than every tile
58+
// evar attaching their own listener.
59+
function updateUserState(event, user) {
60+
var tile = self.refs[user.userId];
61+
if (tile) {
62+
tile.forceUpdate();
63+
}
64+
}
65+
MatrixClientPeg.get().on("User.presence", updateUserState);
66+
this.userPresenceFn = updateUserState;
67+
},
5368
// Remember to set 'key' on a MemberList to the ID of the room it's for
5469
/*componentWillReceiveProps: function(newProps) {
5570
},*/
@@ -67,6 +82,10 @@ module.exports = {
6782
inputText = inputText.trim(); // react requires es5-shim so we know trim() exists
6883
if (inputText[0] !== '@' || inputText.indexOf(":") === -1) {
6984
console.error("Bad user ID to invite: %s", inputText);
85+
Modal.createDialog(ErrorDialog, {
86+
title: "Invite Error",
87+
description: "Malformed user ID. Should look like '@localpart:domain'"
88+
});
7089
return;
7190
}
7291
self.setState({
@@ -81,6 +100,10 @@ module.exports = {
81100
});
82101
}, function(err) {
83102
console.error("Failed to invite: %s", JSON.stringify(err));
103+
Modal.createDialog(ErrorDialog, {
104+
title: "Invite Server Error",
105+
description: err.message
106+
});
84107
self.setState({
85108
inviting: false
86109
});

‎src/controllers/pages/MatrixChat.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var Loader = require("react-loader");
2121

2222
var MatrixClientPeg = require("../../MatrixClientPeg");
2323
var RoomListSorter = require("../../RoomListSorter");
24-
24+
var Presence = require("../../Presence");
2525
var dis = require("../../dispatcher");
2626

2727
var ComponentBroker = require('../../ComponentBroker');
@@ -89,8 +89,9 @@ module.exports = {
8989
window.localStorage.clear();
9090
}
9191
Notifier.stop();
92+
Presence.stop();
9293
MatrixClientPeg.get().removeAllListeners();
93-
MatrixClientPeg.replace(null);
94+
MatrixClientPeg.unset();
9495
break;
9596
case 'start_registration':
9697
if (this.state.logged_in) return;
@@ -187,6 +188,7 @@ module.exports = {
187188
});
188189
});
189190
Notifier.start();
191+
Presence.start();
190192
cli.startClient();
191193
},
192194

‎src/controllers/templates/Login.js‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,10 @@ module.exports = {
7575
'user': formVals.username,
7676
'password': formVals.password
7777
}).done(function(data) {
78-
// XXX: we assume this means we're logged in, but there could be a next stage
79-
MatrixClientPeg.replace(Matrix.createClient({
80-
baseUrl: self.state.hs_url,
81-
idBaseUrl: self.state.is_url,
82-
userId: data.user_id,
83-
accessToken: data.access_token
84-
}));
85-
var localStorage = window.localStorage;
86-
if (localStorage) {
87-
try {
88-
localStorage.clear();
89-
localStorage.setItem("mx_hs_url", self.state.hs_url);
90-
localStorage.setItem("mx_is_url", self.state.is_url);
91-
localStorage.setItem("mx_user_id", data.user_id);
92-
localStorage.setItem("mx_access_token", data.access_token);
93-
} catch (e) {
94-
console.warn("Error using local storage: can't persist session!");
95-
}
96-
} else {
97-
console.warn("No local storage available: can't persist session!");
98-
}
78+
MatrixClientPeg.replaceUsingAccessToken(
79+
self.state.hs_url, self.state.is_url,
80+
data.user_id, data.access_token
81+
);
9982
if (self.props.onLoggedIn) {
10083
self.props.onLoggedIn();
10184
}

0 commit comments

Comments
 (0)