Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c09d173

Browse files
committed
Merge branch 'develop' into matthew/warn-unknown-devices
2 parents 2c7b3d9 + f8d7902 commit c09d173

20 files changed

+416
-176
lines changed

.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ module.exports = {
5353
* things that are errors in the js-sdk config that the current
5454
* code does not adhere to, turned down to warn
5555
*/
56-
"max-len": ["warn"],
56+
"max-len": ["warn", {
57+
// apparently people believe the length limit shouldn't apply
58+
// to JSX.
59+
ignorePattern: '^\\s*<',
60+
}],
5761
"valid-jsdoc": ["warn"],
5862
"new-cap": ["warn"],
5963
"key-spacing": ["warn"],

karma.conf.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ module.exports = function (config) {
165165
},
166166
devtool: 'inline-source-map',
167167
},
168+
169+
webpackMiddleware: {
170+
stats: {
171+
// don't fill the console up with a mahoosive list of modules
172+
chunks: false,
173+
},
174+
},
175+
168176
browserNoActivityTimeout: 15000,
169177
});
170178
};

src/RtsClient.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'whatwg-fetch';
2+
3+
function checkStatus(response) {
4+
if (!response.ok) {
5+
return response.text().then((text) => {
6+
throw new Error(text);
7+
});
8+
}
9+
return response;
10+
}
11+
12+
function parseJson(response) {
13+
return response.json();
14+
}
15+
16+
function encodeQueryParams(params) {
17+
return '?' + Object.keys(params).map((k) => {
18+
return k + '=' + encodeURIComponent(params[k]);
19+
}).join('&');
20+
}
21+
22+
const request = (url, opts) => {
23+
if (opts && opts.qs) {
24+
url += encodeQueryParams(opts.qs);
25+
delete opts.qs;
26+
}
27+
if (opts && opts.body) {
28+
if (!opts.headers) {
29+
opts.headers = {};
30+
}
31+
opts.body = JSON.stringify(opts.body);
32+
opts.headers['Content-Type'] = 'application/json';
33+
}
34+
return fetch(url, opts)
35+
.then(checkStatus)
36+
.then(parseJson);
37+
};
38+
39+
40+
export default class RtsClient {
41+
constructor(url) {
42+
this._url = url;
43+
}
44+
45+
getTeamsConfig() {
46+
return request(this._url + '/teams');
47+
}
48+
49+
/**
50+
* Track a referral with the Riot Team Server. This should be called once a referred
51+
* user has been successfully registered.
52+
* @param {string} referrer the user ID of one who referred the user to Riot.
53+
* @param {string} userId the user ID of the user being referred.
54+
* @param {string} userEmail the email address linked to `userId`.
55+
* @returns {Promise} a promise that resolves to { team_token: 'sometoken' } upon
56+
* success.
57+
*/
58+
trackReferral(referrer, userId, userEmail) {
59+
return request(this._url + '/register',
60+
{
61+
body: {
62+
referrer: referrer,
63+
user_id: userId,
64+
user_email: userEmail,
65+
},
66+
method: 'POST',
67+
}
68+
);
69+
}
70+
71+
getTeam(teamToken) {
72+
return request(this._url + '/teamConfiguration',
73+
{
74+
qs: {
75+
team_token: teamToken,
76+
},
77+
}
78+
);
79+
}
80+
}

src/async-components/views/dialogs/ExportE2eKeysDialog.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default React.createClass({
7171
return this.props.matrixClient.exportRoomKeys();
7272
}).then((k) => {
7373
return MegolmExportEncryption.encryptMegolmKeyFile(
74-
JSON.stringify(k), passphrase
74+
JSON.stringify(k), passphrase,
7575
);
7676
}).then((f) => {
7777
const blob = new Blob([f], {
@@ -95,9 +95,14 @@ export default React.createClass({
9595
});
9696
},
9797

98+
_onCancelClick: function(ev) {
99+
ev.preventDefault();
100+
this.props.onFinished(false);
101+
return false;
102+
},
103+
98104
render: function() {
99105
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
100-
const AccessibleButton = sdk.getComponent('views.elements.AccessibleButton');
101106

102107
const disableForm = (this.state.phase === PHASE_EXPORTING);
103108

@@ -159,10 +164,9 @@ export default React.createClass({
159164
<input className='mx_Dialog_primary' type='submit' value='Export'
160165
disabled={disableForm}
161166
/>
162-
<AccessibleButton element='button' onClick={this.props.onFinished}
163-
disabled={disableForm}>
167+
<button onClick={this._onCancelClick} disabled={disableForm}>
164168
Cancel
165-
</AccessibleButton>
169+
</button>
166170
</div>
167171
</form>
168172
</BaseDialog>

src/async-components/views/dialogs/ImportE2eKeysDialog.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default React.createClass({
8080

8181
return readFileAsArrayBuffer(file).then((arrayBuffer) => {
8282
return MegolmExportEncryption.decryptMegolmKeyFile(
83-
arrayBuffer, passphrase
83+
arrayBuffer, passphrase,
8484
);
8585
}).then((keys) => {
8686
return this.props.matrixClient.importRoomKeys(JSON.parse(keys));
@@ -98,9 +98,14 @@ export default React.createClass({
9898
});
9999
},
100100

101+
_onCancelClick: function(ev) {
102+
ev.preventDefault();
103+
this.props.onFinished(false);
104+
return false;
105+
},
106+
101107
render: function() {
102108
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
103-
const AccessibleButton = sdk.getComponent('views.elements.AccessibleButton');
104109

105110
const disableForm = (this.state.phase !== PHASE_EDIT);
106111

@@ -158,10 +163,9 @@ export default React.createClass({
158163
<input className='mx_Dialog_primary' type='submit' value='Import'
159164
disabled={!this.state.enableSubmit || disableForm}
160165
/>
161-
<AccessibleButton element='button' onClick={this.props.onFinished}
162-
disabled={disableForm}>
166+
<button onClick={this._onCancelClick} disabled={disableForm}>
163167
Cancel
164-
</AccessibleButton>
168+
</button>
165169
</div>
166170
</form>
167171
</BaseDialog>

src/components/structures/LoggedInView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export default React.createClass({
171171
brand={this.props.config.brand}
172172
collapsedRhs={this.props.collapse_rhs}
173173
enableLabs={this.props.config.enableLabs}
174+
referralBaseUrl={this.props.config.referralBaseUrl}
174175
/>;
175176
if (!this.props.collapse_rhs) right_panel = <RightPanel opacity={this.props.sideOpacity}/>;
176177
break;

src/components/structures/MatrixChat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,12 +1055,13 @@ module.exports = React.createClass({
10551055
sessionId={this.state.register_session_id}
10561056
idSid={this.state.register_id_sid}
10571057
email={this.props.startingFragmentQueryParams.email}
1058+
referrer={this.props.startingFragmentQueryParams.referrer}
10581059
username={this.state.upgradeUsername}
10591060
guestAccessToken={this.state.guestAccessToken}
10601061
defaultHsUrl={this.getDefaultHsUrl()}
10611062
defaultIsUrl={this.getDefaultIsUrl()}
10621063
brand={this.props.config.brand}
1063-
teamsConfig={this.props.config.teamsConfig}
1064+
teamServerConfig={this.props.config.teamServerConfig}
10641065
customHsUrl={this.getCurrentHsUrl()}
10651066
customIsUrl={this.getCurrentIsUrl()}
10661067
registrationUrl={this.props.registrationUrl}

src/components/structures/RoomView.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,12 +1332,14 @@ module.exports = React.createClass({
13321332
},
13331333

13341334
onStatusBarVisible: function() {
1335+
if (this.unmounted) return;
13351336
this.setState({
13361337
statusBarVisible: true,
13371338
});
13381339
},
13391340

13401341
onStatusBarHidden: function() {
1342+
if (this.unmounted) return;
13411343
this.setState({
13421344
statusBarVisible: false,
13431345
});
@@ -1507,13 +1509,14 @@ module.exports = React.createClass({
15071509
});
15081510

15091511
var statusBar;
1512+
let isStatusAreaExpanded = true;
15101513

15111514
if (ContentMessages.getCurrentUploads().length > 0) {
15121515
var UploadBar = sdk.getComponent('structures.UploadBar');
15131516
statusBar = <UploadBar room={this.state.room} />;
15141517
} else if (!this.state.searchResults) {
15151518
var RoomStatusBar = sdk.getComponent('structures.RoomStatusBar');
1516-
1519+
isStatusAreaExpanded = this.state.statusBarVisible;
15171520
statusBar = <RoomStatusBar
15181521
room={this.state.room}
15191522
tabComplete={this.tabComplete}
@@ -1683,7 +1686,7 @@ module.exports = React.createClass({
16831686
);
16841687
}
16851688
let statusBarAreaClass = "mx_RoomView_statusArea mx_fadable";
1686-
if (this.state.statusBarVisible) {
1689+
if (isStatusAreaExpanded) {
16871690
statusBarAreaClass += " mx_RoomView_statusArea_expanded";
16881691
}
16891692

src/components/structures/ScrollPanel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ module.exports = React.createClass({
570570
var boundingRect = node.getBoundingClientRect();
571571
var scrollDelta = boundingRect.bottom + pixelOffset - wrapperRect.bottom;
572572

573-
debuglog("Scrolling to token '" + node.dataset.scrollToken + "'+" +
573+
debuglog("ScrollPanel: scrolling to token '" + node.dataset.scrollToken + "'+" +
574574
pixelOffset + " (delta: "+scrollDelta+")");
575575

576576
if(scrollDelta != 0) {
@@ -582,7 +582,7 @@ module.exports = React.createClass({
582582
_saveScrollState: function() {
583583
if (this.props.stickyBottom && this.isAtBottom()) {
584584
this.scrollState = { stuckAtBottom: true };
585-
debuglog("Saved scroll state", this.scrollState);
585+
debuglog("ScrollPanel: Saved scroll state", this.scrollState);
586586
return;
587587
}
588588

@@ -601,12 +601,12 @@ module.exports = React.createClass({
601601
trackedScrollToken: node.dataset.scrollToken,
602602
pixelOffset: wrapperRect.bottom - boundingRect.bottom,
603603
};
604-
debuglog("Saved scroll state", this.scrollState);
604+
debuglog("ScrollPanel: saved scroll state", this.scrollState);
605605
return;
606606
}
607607
}
608608

609-
debuglog("Unable to save scroll state: found no children in the viewport");
609+
debuglog("ScrollPanel: unable to save scroll state: found no children in the viewport");
610610
},
611611

612612
_restoreSavedScrollState: function() {
@@ -640,7 +640,7 @@ module.exports = React.createClass({
640640
this._lastSetScroll = scrollNode.scrollTop;
641641
}
642642

643-
debuglog("Set scrollTop:", scrollNode.scrollTop,
643+
debuglog("ScrollPanel: set scrollTop:", scrollNode.scrollTop,
644644
"requested:", scrollTop,
645645
"_lastSetScroll:", this._lastSetScroll);
646646
},

src/components/structures/UserSettings.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ module.exports = React.createClass({
9292
// True to show the 'labs' section of experimental features
9393
enableLabs: React.PropTypes.bool,
9494

95+
// The base URL to use in the referral link. Defaults to window.location.origin.
96+
referralBaseUrl: React.PropTypes.string,
97+
9598
// true if RightPanel is collapsed
9699
collapsedRhs: React.PropTypes.bool,
97100
},
@@ -444,6 +447,27 @@ module.exports = React.createClass({
444447
);
445448
},
446449

450+
_renderReferral: function() {
451+
const teamToken = window.localStorage.getItem('mx_team_token');
452+
if (!teamToken) {
453+
return null;
454+
}
455+
if (typeof teamToken !== 'string') {
456+
console.warn('Team token not a string');
457+
return null;
458+
}
459+
const href = (this.props.referralBaseUrl || window.location.origin) +
460+
`/#/register?referrer=${this._me}&team_token=${teamToken}`;
461+
return (
462+
<div>
463+
<h3>Referral</h3>
464+
<div className="mx_UserSettings_section">
465+
Refer a friend to Riot: <a href={href}>{href}</a>
466+
</div>
467+
</div>
468+
);
469+
},
470+
447471
_renderUserInterfaceSettings: function() {
448472
var client = MatrixClientPeg.get();
449473

@@ -819,6 +843,8 @@ module.exports = React.createClass({
819843
{accountJsx}
820844
</div>
821845

846+
{this._renderReferral()}
847+
822848
{notification_area}
823849

824850
{this._renderUserInterfaceSettings()}

0 commit comments

Comments
 (0)