diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-07-06 08:48:00 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-07-06 08:48:00 -0400 |
commit | 6c33350f5c7e58ac45d7300c035dd58ecf6b3330 (patch) | |
tree | a12ebc9d0b5df04bdbe36ae29fc06ddbcca54dc1 /webapp | |
parent | 31d956a0500f8fca49c82723aac5440659df77e3 (diff) | |
download | chat-6c33350f5c7e58ac45d7300c035dd58ecf6b3330.tar.gz chat-6c33350f5c7e58ac45d7300c035dd58ecf6b3330.tar.bz2 chat-6c33350f5c7e58ac45d7300c035dd58ecf6b3330.zip |
On receive of a comment that we don't have the thread for, acquire the thread (#3490)
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/actions/global_actions.jsx | 42 | ||||
-rw-r--r-- | webapp/actions/post_actions.jsx | 64 | ||||
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 3 | ||||
-rw-r--r-- | webapp/components/post_view/components/post_list.jsx | 4 |
4 files changed, 80 insertions, 33 deletions
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index c27ed66b2..4baed20c3 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -1,7 +1,8 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; + import ChannelStore from 'stores/channel_store.jsx'; import PostStore from 'stores/post_store.jsx'; import UserStore from 'stores/user_store.jsx'; @@ -10,20 +11,22 @@ import ErrorStore from 'stores/error_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import SearchStore from 'stores/search_store.jsx'; + +import * as Websockets from 'actions/websocket_actions.jsx'; +import {handleNewPost} from 'actions/post_actions.jsx'; + import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; -import * as AsyncClient from 'utils/async_client.jsx'; + import Client from 'utils/web_client.jsx'; +import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; -import * as Websockets from './websocket_actions.jsx'; -import * as I18n from 'i18n/i18n.jsx'; +import en from 'i18n/en.json'; +import * as I18n from 'i18n/i18n.jsx'; import {trackPage} from 'actions/analytics_actions.jsx'; - import {browserHistory} from 'react-router/es6'; -import en from 'i18n/en.json'; - export function emitChannelClickEvent(channel) { function userVisitedFakeChannel(chan, success, fail) { const otherUserId = Utils.getUserIdFromChannelName(chan); @@ -225,29 +228,6 @@ export function emitLoadMorePostsFocusedBottomEvent() { AsyncClient.getPostsAfter(latestPostId, 0, Constants.POST_CHUNK_SIZE, !!id); } -export function emitPostRecievedEvent(post, msg) { - if (ChannelStore.getCurrentId() === post.channel_id) { - if (window.isActive) { - AsyncClient.updateLastViewedAt(); - } else { - AsyncClient.getChannel(post.channel_id); - } - } else if (msg && (TeamStore.getCurrentId() === msg.team_id || msg.props.channel_type === Constants.DM_CHANNEL)) { - AsyncClient.getChannel(post.channel_id); - } - - var websocketMessageProps = null; - if (msg) { - websocketMessageProps = msg.props; - } - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_POST, - post, - websocketMessageProps - }); -} - export function emitUserPostedEvent(post) { AppDispatcher.handleServerAction({ type: ActionTypes.CREATE_POST, @@ -384,7 +364,7 @@ export function sendEphemeralPost(message, channelId) { props: {} }; - emitPostRecievedEvent(post); + handleNewPost(post); } export function newLocalizationSelected(locale) { diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx new file mode 100644 index 000000000..2b55e31ef --- /dev/null +++ b/webapp/actions/post_actions.jsx @@ -0,0 +1,64 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; + +import ChannelStore from 'stores/channel_store.jsx'; +import PostStore from 'stores/post_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; + +import Constants from 'utils/constants.jsx'; +const ActionTypes = Constants.ActionTypes; + +import Client from 'utils/web_client.jsx'; +import * as AsyncClient from 'utils/async_client.jsx'; + +export function handleNewPost(post, msg) { + if (ChannelStore.getCurrentId() === post.channel_id) { + if (window.isActive) { + AsyncClient.updateLastViewedAt(); + } else { + AsyncClient.getChannel(post.channel_id); + } + } else if (msg && (TeamStore.getCurrentId() === msg.team_id || msg.props.channel_type === Constants.DM_CHANNEL)) { + AsyncClient.getChannel(post.channel_id); + } + + var websocketMessageProps = null; + if (msg) { + websocketMessageProps = msg.props; + } + + if (post.root_id && PostStore.getPost(post.channel_id, post.root_id) == null) { + Client.getPost( + post.channel_id, + post.root_id, + (data) => { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POSTS, + id: post.channel_id, + numRequested: 0, + post_list: data + }); + + // Required to update order + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POST, + post, + websocketMessageProps + }); + }, + (err) => { + AsyncClient.dispatchError(err, 'getPost'); + } + ); + + return; + } + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POST, + post, + websocketMessageProps + }); +} diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index fba5632ca..17f84638d 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -14,6 +14,7 @@ import Client from 'utils/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; +import {handleNewPost} from 'actions/post_actions.jsx'; import Constants from 'utils/constants.jsx'; const SocketEvents = Constants.SocketEvents; @@ -190,7 +191,7 @@ export function close() { function handleNewPostEvent(msg) { const post = JSON.parse(msg.props.post); - GlobalActions.emitPostRecievedEvent(post, msg); + handleNewPost(post, msg); } function handlePostEditEvent(msg) { diff --git a/webapp/components/post_view/components/post_list.jsx b/webapp/components/post_view/components/post_list.jsx index bcd763d58..17e29da2e 100644 --- a/webapp/components/post_view/components/post_list.jsx +++ b/webapp/components/post_view/components/post_list.jsx @@ -136,7 +136,9 @@ export default class PostList extends React.Component { } } - loadMorePostsTop() { + loadMorePostsTop(e) { + e.preventDefault(); + if (this.props.isFocusPost) { return GlobalActions.emitLoadMorePostsFocusedTopEvent(); } |