Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions src/Lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import UserActivity from './UserActivity';
import Presence from './Presence';
import dis from './dispatcher';
import DMRoomMap from './utils/DMRoomMap';
import RtsClient from './RtsClient';

/**
* Called at startup, to attempt to build a logged-in Matrix session. It tries
Expand Down Expand Up @@ -229,6 +230,11 @@ function _restoreFromLocalStorage() {
}
}

let rtsClient = null;
export function initRtsClient(url) {
rtsClient = new RtsClient(url);
}

/**
* Transitions to a logged-in state using the given credentials
* @param {MatrixClientCreds} credentials The credentials to use
Expand Down Expand Up @@ -261,6 +267,17 @@ export function setLoggedIn(credentials) {
} catch (e) {
console.warn("Error using local storage: can't persist session!", e);
}

if (rtsClient) {
rtsClient.login(credentials.userId).then((body) => {
localStorage.setItem("mx_team_token", body.team_token);
}, (err) =>{
console.error(
"Failed to get team token on login, not persisting to localStorage",
err
);
});
}
} else {
console.warn("No local storage available: can't persist session!");
}
Expand Down
17 changes: 17 additions & 0 deletions src/RtsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ export default class RtsClient {
}
);
}

/**
* Signal to the RTS that a login has occurred and that a user requires their team's
* token.
* @param {string} userId the user ID of the user who is a member of a team.
* @returns {Promise} a promise that resolves to { team_token: 'sometoken' } upon
* success.
*/
login(userId) {
return request(this._url + '/login',
{
qs: {
user_id: userId,
},
}
);
}
}
6 changes: 6 additions & 0 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ module.exports = React.createClass({
window.addEventListener('resize', this.handleResize);
this.handleResize();

if (this.props.config.teamServerConfig &&
this.props.config.teamServerConfig.teamServerURL
) {
Lifecycle.initRtsClient(this.props.config.teamServerConfig.teamServerURL);
}

// the extra q() ensures that synchronous exceptions hit the same codepath as
// asynchronous ones.
q().then(() => {
Expand Down