summaryrefslogtreecommitdiffstats
path: root/web/react/dispatcher/event_helpers.jsx
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-11-18 17:29:06 -0500
committerChristopher Speller <crspeller@gmail.com>2015-11-23 09:53:15 -0500
commit9e8cd937908d5d2e730e94f761d6533eb2d95e28 (patch)
treefb6324a5896da7123b76854e7eb504c239113824 /web/react/dispatcher/event_helpers.jsx
parent5ee226d7f92d9408736b0e2a9ff105eb6f520a19 (diff)
downloadchat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.tar.gz
chat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.tar.bz2
chat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.zip
Implementing Permalinks and jumping to post from search. Performance
improvements.
Diffstat (limited to 'web/react/dispatcher/event_helpers.jsx')
-rw-r--r--web/react/dispatcher/event_helpers.jsx83
1 files changed, 83 insertions, 0 deletions
diff --git a/web/react/dispatcher/event_helpers.jsx b/web/react/dispatcher/event_helpers.jsx
new file mode 100644
index 000000000..85329b38f
--- /dev/null
+++ b/web/react/dispatcher/event_helpers.jsx
@@ -0,0 +1,83 @@
+// Copyright (c) 2015 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 Constants from '../utils/constants.jsx';
+const ActionTypes = Constants.ActionTypes;
+import * as AsyncClient from '../utils/async_client.jsx';
+import * as Client from '../utils/client.jsx';
+
+export function emitChannelClickEvent(channel) {
+ AsyncClient.getChannels();
+ AsyncClient.getChannelExtraInfo();
+ AsyncClient.updateLastViewedAt();
+ AsyncClient.getPosts(channel.id);
+
+ AppDispatcher.handleViewAction({
+ type: ActionTypes.CLICK_CHANNEL,
+ name: channel.name,
+ id: channel.id
+ });
+}
+
+export function emitPostFocusEvent(postId) {
+ Client.getPostById(
+ postId,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECIEVED_FOCUSED_POST,
+ postId,
+ post_list: data
+ });
+
+ AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
+ AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
+ }
+ );
+}
+
+export function emitLoadMorePostsEvent() {
+ const id = ChannelStore.getCurrentId();
+ loadMorePostsTop(id);
+}
+
+export function emitLoadMorePostsFocusedTopEvent() {
+ const id = PostStore.getFocusedPostId();
+ loadMorePostsTop(id);
+}
+
+export function loadMorePostsTop(id) {
+ const earliestPostId = PostStore.getEarliestPost(id).id;
+ if (PostStore.requestVisibilityIncrease(id, Constants.POST_CHUNK_SIZE)) {
+ AsyncClient.getPostsBefore(earliestPostId, 0, Constants.POST_CHUNK_SIZE);
+ }
+}
+
+export function emitLoadMorePostsFocusedBottomEvent() {
+ const id = PostStore.getFocusedPostId();
+ const latestPostId = PostStore.getLatestPost(id).id;
+ AsyncClient.getPostsAfter(latestPostId, 0, Constants.POST_CHUNK_SIZE);
+}
+
+export function emitPostRecievedEvent(post) {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECIEVED_POST,
+ post
+ });
+}
+
+export function emitUserPostedEvent(post) {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.CREATE_POST,
+ post
+ });
+}
+
+export function emitPostDeletedEvent(post) {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.POST_DELETED,
+ post
+ });
+}