Merge pull request #1978 from hmhealey/plt1484

PLT-1484 Changed first preference load to be done synchronously
Этот коммит содержится в:
Corey Hulen
2016-01-26 15:10:08 -05:00
родитель 163bab98b5 c889d9bee1
Коммит f6540c4b5e
6 изменённых файлов: 29 добавлений и 26 удалений

Просмотреть файл

@@ -45,6 +45,7 @@ type Page struct {
User *model.User
Team *model.Team
Channel *model.Channel
Preferences *model.Preferences
PostID string
SessionTokenIndex int64
Locale string

Просмотреть файл

@@ -18,14 +18,8 @@ import RegisterAppModal from '../components/register_app_modal.jsx';
import ImportThemeModal from '../components/user_settings/import_theme_modal.jsx';
import InviteMemberModal from '../components/invite_member_modal.jsx';
import PreferenceStore from '../stores/preference_store.jsx';
import * as Utils from '../utils/utils.jsx';
import * as AsyncClient from '../utils/async_client.jsx';
import * as EventHelpers from '../dispatcher/event_helpers.jsx';
import Constants from '../utils/constants.jsx';
var IntlProvider = ReactIntl.IntlProvider;
class Root extends React.Component {
@@ -92,12 +86,6 @@ class Root extends React.Component {
}
}
function onPreferenceChange() {
const selectedFont = PreferenceStore.get(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'selected_font', Constants.DEFAULT_FONT);
Utils.applyFont(selectedFont);
PreferenceStore.removeChangeListener(onPreferenceChange);
}
global.window.setup_channel_page = function setup(props, team, channel) {
if (props.PostId === '') {
EventHelpers.emitChannelClickEvent(channel);
@@ -105,11 +93,8 @@ global.window.setup_channel_page = function setup(props, team, channel) {
EventHelpers.emitPostFocusEvent(props.PostId);
}
PreferenceStore.addChangeListener(onPreferenceChange);
AsyncClient.getAllPreferences();
ReactDOM.render(
<Root map={props} />,
document.getElementById('channel_view')
);
};
};

Просмотреть файл

@@ -133,6 +133,16 @@ class PreferenceStoreClass extends EventEmitter {
return preference;
}
setPreferences(newPreferences) {
const preferences = this.getAllPreferences();
for (const preference of newPreferences) {
preferences.set(getPreferenceKeyForModel(preference), preference);
}
this.setAllPreferences(preferences);
}
emitChange() {
this.emit(CHANGE_EVENT);
}
@@ -155,18 +165,11 @@ class PreferenceStoreClass extends EventEmitter {
this.emitChange();
break;
}
case ActionTypes.RECIEVED_PREFERENCES: {
const preferences = this.getAllPreferences();
for (const preference of action.preferences) {
preferences.set(getPreferenceKeyForModel(preference), preference);
}
this.setAllPreferences(preferences);
case ActionTypes.RECIEVED_PREFERENCES:
this.setPreferences(action.preferences);
this.emitChange();
break;
}
}
}
}

Просмотреть файл

@@ -6,7 +6,7 @@
<body>
<div id="channel_view" class='channel-view'></div>
<script>
window.setup_channel_page({{ .Props }}, {{ .Team }}, {{ .Channel }}, {{ .User }});
window.setup_channel_page({{ .Props }}, {{ .Team }}, {{ .Channel }});
$('body').tooltip( {selector: '[data-toggle=tooltip]'} );
var modals = $('.modal-body').not('.edit-modal-body');
if($(window).height() > 1200){

Просмотреть файл

@@ -74,6 +74,11 @@
window.mm_user = {{ .User }};
window.mm_channel = {{ .Channel }};
window.mm_locale = {{ .Locale }};
window.mm_preferences = {{ .Preferences }};
$(function() {
PreferenceStore.setPreferences(window.mm_preferences);
});
if ({{.SessionTokenIndex}} >= 0) {
window.mm_session_token_index = {{.SessionTokenIndex}};

Просмотреть файл

@@ -518,6 +518,7 @@ func checkSessionSwitch(c *api.Context, w http.ResponseWriter, r *http.Request,
func doLoadChannel(c *api.Context, w http.ResponseWriter, r *http.Request, team *model.Team, channel *model.Channel, postid string) {
userChan := api.Srv.Store.User().Get(c.Session.UserId)
prefChan := api.Srv.Store.Preference().GetAll(c.Session.UserId)
var user *model.User
if ur := <-userChan; ur.Err != nil {
@@ -529,6 +530,13 @@ func doLoadChannel(c *api.Context, w http.ResponseWriter, r *http.Request, team
user = ur.Data.(*model.User)
}
var preferences model.Preferences
if result := <-prefChan; result.Err != nil {
l4g.Error("Error in getting preferences for id=%v", c.Session.UserId)
} else {
preferences = result.Data.(model.Preferences)
}
page := NewHtmlTemplatePage("channel", "", c.Locale)
page.Props["Title"] = channel.DisplayName + " - " + team.DisplayName + " " + page.ClientCfg["SiteName"]
page.Props["TeamDisplayName"] = team.DisplayName
@@ -538,6 +546,7 @@ func doLoadChannel(c *api.Context, w http.ResponseWriter, r *http.Request, team
page.Team = team
page.User = user
page.Channel = channel
page.Preferences = &preferences
page.Render(c, w)
}