[PLT-4643] Don't show empheral messages on sidebar when it is reopened. (#6378)

Этот коммит содержится в:
Kacper Kula
2017-05-18 15:01:59 +02:00
коммит произвёл Joram Wilander
родитель 5f6a3a2cf8
Коммит 63e599c43b

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

@@ -55,6 +55,7 @@ export default class RhsThread extends React.Component {
this.onPostChange = this.onPostChange.bind(this); this.onPostChange = this.onPostChange.bind(this);
this.onUserChange = this.onUserChange.bind(this); this.onUserChange = this.onUserChange.bind(this);
this.onSelectedChange = this.onSelectedChange.bind(this);
this.forceUpdateInfo = this.forceUpdateInfo.bind(this); this.forceUpdateInfo = this.forceUpdateInfo.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this); this.onPreferenceChange = this.onPreferenceChange.bind(this);
this.onStatusChange = this.onStatusChange.bind(this); this.onStatusChange = this.onStatusChange.bind(this);
@@ -64,7 +65,8 @@ export default class RhsThread extends React.Component {
this.handleScrollStop = this.handleScrollStop.bind(this); this.handleScrollStop = this.handleScrollStop.bind(this);
this.scrollStopAction = new DelayedAction(this.handleScrollStop); this.scrollStopAction = new DelayedAction(this.handleScrollStop);
const state = this.getPosts(); const openTime = (new Date()).getTime();
const state = this.getPosts(openTime);
state.windowWidth = Utils.windowWidth(); state.windowWidth = Utils.windowWidth();
state.windowHeight = Utils.windowHeight(); state.windowHeight = Utils.windowHeight();
state.profiles = JSON.parse(JSON.stringify(UserStore.getProfiles())); state.profiles = JSON.parse(JSON.stringify(UserStore.getProfiles()));
@@ -77,11 +79,13 @@ export default class RhsThread extends React.Component {
this.state = { this.state = {
...state, ...state,
isScrolling: false, isScrolling: false,
topRhsPostCreateAt: 0 topRhsPostCreateAt: 0,
openTime
}; };
} }
componentDidMount() { componentDidMount() {
PostStore.addSelectedPostChangeListener(this.onSelectedChange);
PostStore.addSelectedPostChangeListener(this.onPostChange); PostStore.addSelectedPostChangeListener(this.onPostChange);
PostStore.addChangeListener(this.onPostChange); PostStore.addChangeListener(this.onPostChange);
PreferenceStore.addChangeListener(this.onPreferenceChange); PreferenceStore.addChangeListener(this.onPreferenceChange);
@@ -96,6 +100,7 @@ export default class RhsThread extends React.Component {
} }
componentWillUnmount() { componentWillUnmount() {
PostStore.addSelectedPostChangeListener(this.onSelectedChange);
PostStore.removeSelectedPostChangeListener(this.onPostChange); PostStore.removeSelectedPostChangeListener(this.onPostChange);
PostStore.removeChangeListener(this.onPostChange); PostStore.removeChangeListener(this.onPostChange);
PreferenceStore.removeChangeListener(this.onPreferenceChange); PreferenceStore.removeChangeListener(this.onPreferenceChange);
@@ -192,6 +197,12 @@ export default class RhsThread extends React.Component {
}); });
} }
onSelectedChange() {
this.setState({
openTime: (new Date()).getTime()
});
}
onPreferenceChange(category) { onPreferenceChange(category) {
let previewSuffix = ''; let previewSuffix = '';
if (category === Preferences.CATEGORY_DISPLAY_SETTINGS) { if (category === Preferences.CATEGORY_DISPLAY_SETTINGS) {
@@ -208,7 +219,7 @@ export default class RhsThread extends React.Component {
onPostChange() { onPostChange() {
if (this.mounted) { if (this.mounted) {
this.setState(this.getPosts()); this.setState(this.getPosts(this.state.openTime));
} }
} }
@@ -220,7 +231,7 @@ export default class RhsThread extends React.Component {
this.setState({isBusy}); this.setState({isBusy});
} }
getPosts() { getPosts(openTime) {
const selected = PostStore.getSelectedPost(); const selected = PostStore.getSelectedPost();
const posts = PostStore.getSelectedPostThread(); const posts = PostStore.getSelectedPostThread();
@@ -229,6 +240,12 @@ export default class RhsThread extends React.Component {
for (const id in posts) { for (const id in posts) {
if (posts.hasOwnProperty(id)) { if (posts.hasOwnProperty(id)) {
const cpost = posts[id]; const cpost = posts[id];
// Do not show empherals created before sidebar has been opened
if (cpost.type === 'system_ephemeral' && cpost.create_at < openTime) {
continue;
}
if (cpost.root_id === selected.id) { if (cpost.root_id === selected.id) {
postsArray.push(cpost); postsArray.push(cpost);
} }