summaryrefslogtreecommitdiffstats
path: root/webapp/actions/post_actions.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-07-06 08:48:00 -0400
committerChristopher Speller <crspeller@gmail.com>2016-07-06 08:48:00 -0400
commit6c33350f5c7e58ac45d7300c035dd58ecf6b3330 (patch)
treea12ebc9d0b5df04bdbe36ae29fc06ddbcca54dc1 /webapp/actions/post_actions.jsx
parent31d956a0500f8fca49c82723aac5440659df77e3 (diff)
downloadchat-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/actions/post_actions.jsx')
-rw-r--r--webapp/actions/post_actions.jsx64
1 files changed, 64 insertions, 0 deletions
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
+ });
+}