diff options
-rw-r--r-- | api/context.go | 1 | ||||
-rw-r--r-- | web/react/pages/channel.jsx | 17 | ||||
-rw-r--r-- | web/react/stores/preference_store.jsx | 21 | ||||
-rw-r--r-- | web/templates/channel.html | 2 | ||||
-rw-r--r-- | web/templates/head.html | 5 | ||||
-rw-r--r-- | web/web.go | 9 |
6 files changed, 29 insertions, 26 deletions
diff --git a/api/context.go b/api/context.go index 41a52fa0c..b91981ecd 100644 --- a/api/context.go +++ b/api/context.go @@ -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 diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx index 1e28dab8b..bfb95e1fc 100644 --- a/web/react/pages/channel.jsx +++ b/web/react/pages/channel.jsx @@ -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') ); -};
\ No newline at end of file +}; diff --git a/web/react/stores/preference_store.jsx b/web/react/stores/preference_store.jsx index 79eab4fe1..7ecaf0a95 100644 --- a/web/react/stores/preference_store.jsx +++ b/web/react/stores/preference_store.jsx @@ -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; } - } } } diff --git a/web/templates/channel.html b/web/templates/channel.html index dcc50115b..94d79a022 100644 --- a/web/templates/channel.html +++ b/web/templates/channel.html @@ -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){ diff --git a/web/templates/head.html b/web/templates/head.html index fc16eb2dc..14b447325 100644 --- a/web/templates/head.html +++ b/web/templates/head.html @@ -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}}; diff --git a/web/web.go b/web/web.go index 95d6024f5..36349dd5e 100644 --- a/web/web.go +++ b/web/web.go @@ -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) } |