Pull out welcome user chat code to a separate function
also expand on comment
This commit is contained in:
parent
929e9dc653
commit
30726d6cf9
1 changed files with 59 additions and 52 deletions
|
@ -1134,14 +1134,10 @@ export default React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a new logged in session has started
|
* Starts a chat with the welcome user, if the user doesn't already have one
|
||||||
|
* @returns {string} The room ID of the new room, or null if no room was created
|
||||||
*/
|
*/
|
||||||
_onLoggedIn: function() {
|
async _startWelcomeUserChat() {
|
||||||
this.setStateForNewView({ view: VIEWS.LOGGED_IN });
|
|
||||||
if (MatrixClientPeg.currentUserIsJustRegistered()) {
|
|
||||||
MatrixClientPeg.setJustRegisteredUserId(null);
|
|
||||||
|
|
||||||
if (this.props.config.welcomeUserId && getCurrentLanguage().startsWith("en")) {
|
|
||||||
// We can end up with multiple tabs post-registration where the user
|
// We can end up with multiple tabs post-registration where the user
|
||||||
// might then end up with a session and we don't want them all making
|
// might then end up with a session and we don't want them all making
|
||||||
// a chat with the welcome user: try to de-dupe.
|
// a chat with the welcome user: try to de-dupe.
|
||||||
|
@ -1153,7 +1149,8 @@ export default React.createClass({
|
||||||
} else {
|
} else {
|
||||||
waitFor = Promise.resolve();
|
waitFor = Promise.resolve();
|
||||||
}
|
}
|
||||||
waitFor.then(async () => {
|
await waitFor;
|
||||||
|
|
||||||
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(
|
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(
|
||||||
this.props.config.welcomeUserId,
|
this.props.config.welcomeUserId,
|
||||||
);
|
);
|
||||||
|
@ -1169,7 +1166,8 @@ export default React.createClass({
|
||||||
// tab before the next save happens (a few minutes), the
|
// tab before the next save happens (a few minutes), the
|
||||||
// saved sync will be restored from the db and this code will
|
// saved sync will be restored from the db and this code will
|
||||||
// run without the update to m.direct, making another welcome
|
// run without the update to m.direct, making another welcome
|
||||||
// user room.
|
// user room (it doesn't wait for new data from the server, just
|
||||||
|
// the saved sync to be loaded).
|
||||||
const saveWelcomeUser = (ev) => {
|
const saveWelcomeUser = (ev) => {
|
||||||
if (
|
if (
|
||||||
ev.getType() == 'm.direct' &&
|
ev.getType() == 'm.direct' &&
|
||||||
|
@ -1184,17 +1182,26 @@ export default React.createClass({
|
||||||
};
|
};
|
||||||
MatrixClientPeg.get().on("accountData", saveWelcomeUser);
|
MatrixClientPeg.get().on("accountData", saveWelcomeUser);
|
||||||
|
|
||||||
// if successful, return because we're already
|
return roomId;
|
||||||
// viewing the welcomeUserId room
|
|
||||||
// else, if failed, fall through to view_home_page
|
|
||||||
if (roomId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a new logged in session has started
|
||||||
|
*/
|
||||||
|
_onLoggedIn: async function() {
|
||||||
|
this.setStateForNewView({ view: VIEWS.LOGGED_IN });
|
||||||
|
if (true || MatrixClientPeg.currentUserIsJustRegistered()) {
|
||||||
|
MatrixClientPeg.setJustRegisteredUserId(null);
|
||||||
|
|
||||||
|
if (this.props.config.welcomeUserId && getCurrentLanguage().startsWith("en")) {
|
||||||
|
const welcomeUserRoom = await this._startWelcomeUserChat();
|
||||||
|
if (welcomeUserRoom === null) {
|
||||||
// We didn't rediret to the welcome user room, so show
|
// We didn't rediret to the welcome user room, so show
|
||||||
// the homepage.
|
// the homepage.
|
||||||
dis.dispatch({action: 'view_home_page'});
|
dis.dispatch({action: 'view_home_page'});
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
// The user has just logged in after registering,
|
// The user has just logged in after registering,
|
||||||
// so show the homepage.
|
// so show the homepage.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue