summaryrefslogtreecommitdiffstats
path: root/web/react/utils/async_client.jsx
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-08-26 12:09:01 -0400
committerJoramWilander <jwawilander@gmail.com>2015-08-27 08:21:26 -0400
commit041d89b85a22b0a498a4176d0d26fd5dc84c33f9 (patch)
tree37cc2ca9252b45f6f30ba4e88037a67a700ec0ad /web/react/utils/async_client.jsx
parent8356e25f80bbba3040ceeda5732b8843b8e493c1 (diff)
downloadchat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.tar.gz
chat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.tar.bz2
chat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.zip
Refactored post handling/updating on both the client and server.
Diffstat (limited to 'web/react/utils/async_client.jsx')
-rw-r--r--web/react/utils/async_client.jsx55
1 files changed, 49 insertions, 6 deletions
diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx
index 349fe9021..4b0b90dc7 100644
--- a/web/react/utils/async_client.jsx
+++ b/web/react/utils/async_client.jsx
@@ -344,14 +344,14 @@ module.exports.search = function(terms) {
);
}
-module.exports.getPosts = function(force, id, maxPosts) {
+module.exports.getPostsPage = function(force, id, maxPosts) {
if (PostStore.getCurrentPosts() == null || force) {
var channelId = id;
if (channelId == null) {
channelId = ChannelStore.getCurrentId();
}
- if (isCallInProgress('getPosts_' + channelId)) {
+ if (isCallInProgress('getPostsPage_' + channelId)) {
return;
}
@@ -371,9 +371,9 @@ module.exports.getPosts = function(force, id, maxPosts) {
}
if (channelId != null) {
- callTracker['getPosts_' + channelId] = utils.getTimestamp();
+ callTracker['getPostsPage_' + channelId] = utils.getTimestamp();
- client.getPosts(
+ client.getPostsPage(
channelId,
0,
numPosts,
@@ -389,15 +389,58 @@ module.exports.getPosts = function(force, id, maxPosts) {
module.exports.getProfiles();
},
function(err) {
- dispatchError(err, 'getPosts');
+ dispatchError(err, 'getPostsPage');
},
function() {
- callTracker['getPosts_' + channelId] = 0;
+ callTracker['getPostsPage_' + channelId] = 0;
}
);
}
}
+};
+
+function getPosts(id) {
+ var channelId = id;
+ if (channelId == null) {
+ if (ChannelStore.getCurrentId() == null) {
+ return;
+ }
+ channelId = ChannelStore.getCurrentId();
+ }
+
+ if (isCallInProgress('getPosts_' + channelId)) {
+ return;
+ }
+
+ var latestUpdate = PostStore.getLatestUpdate(channelId);
+
+ callTracker['getPosts_' + channelId] = utils.getTimestamp();
+
+ client.getPosts(
+ channelId,
+ latestUpdate,
+ function success(data, textStatus, xhr) {
+ if (xhr.status === 304 || !data) {
+ return;
+ }
+
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECIEVED_POSTS,
+ id: channelId,
+ post_list: data
+ });
+
+ module.exports.getProfiles();
+ },
+ function fail(err) {
+ dispatchError(err, 'getPosts');
+ },
+ function complete() {
+ callTracker['getPosts_' + channelId] = 0;
+ }
+ );
}
+module.exports.getPosts = getPosts;
function getMe() {
if (isCallInProgress('getMe')) {