summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/async_client.jsx29
-rw-r--r--web/react/utils/client.jsx15
-rw-r--r--web/react/utils/constants.jsx5
-rw-r--r--web/react/utils/utils.jsx24
4 files changed, 58 insertions, 15 deletions
diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx
index 0b87bbd7b..349fe9021 100644
--- a/web/react/utils/async_client.jsx
+++ b/web/react/utils/async_client.jsx
@@ -346,24 +346,33 @@ module.exports.search = function(terms) {
module.exports.getPosts = function(force, id, maxPosts) {
if (PostStore.getCurrentPosts() == null || force) {
- var channelId = id ? id : ChannelStore.getCurrentId();
+ var channelId = id;
+ if (channelId == null) {
+ channelId = ChannelStore.getCurrentId();
+ }
- if (isCallInProgress('getPosts_'+channelId)) return;
+ if (isCallInProgress('getPosts_' + channelId)) {
+ return;
+ }
- var post_list = PostStore.getCurrentPosts();
+ var postList = PostStore.getCurrentPosts();
- if (!maxPosts) { maxPosts = Constants.POST_CHUNK_SIZE * Constants.MAX_POST_CHUNKS };
+ var max = maxPosts;
+ if (max == null) {
+ max = Constants.POST_CHUNK_SIZE * Constants.MAX_POST_CHUNKS;
+ }
// if we already have more than POST_CHUNK_SIZE posts,
// let's get the amount we have but rounded up to next multiple of POST_CHUNK_SIZE,
// with a max at maxPosts
- var numPosts = Math.min(maxPosts, Constants.POST_CHUNK_SIZE);
- if (post_list && post_list.order.length > 0) {
- numPosts = Math.min(maxPosts, Constants.POST_CHUNK_SIZE * Math.ceil(post_list.order.length / Constants.POST_CHUNK_SIZE));
+ var numPosts = Math.min(max, Constants.POST_CHUNK_SIZE);
+ if (postList && postList.order.length > 0) {
+ numPosts = Math.min(max, Constants.POST_CHUNK_SIZE * Math.ceil(postList.order.length / Constants.POST_CHUNK_SIZE));
}
if (channelId != null) {
- callTracker['getPosts_'+channelId] = utils.getTimestamp();
+ callTracker['getPosts_' + channelId] = utils.getTimestamp();
+
client.getPosts(
channelId,
0,
@@ -383,7 +392,7 @@ module.exports.getPosts = function(force, id, maxPosts) {
dispatchError(err, 'getPosts');
},
function() {
- callTracker['getPosts_'+channelId] = 0;
+ callTracker['getPosts_' + channelId] = 0;
}
);
}
@@ -396,7 +405,7 @@ function getMe() {
}
callTracker.getMe = utils.getTimestamp();
- client.getMe(
+ client.getMeSynchronous(
function(data, textStatus, xhr) {
callTracker.getMe = 0;
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index 5aab80d01..ce044457a 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -279,24 +279,33 @@ module.exports.getAudits = function(userId, success, error) {
});
};
-module.exports.getMe = function(success, error) {
+module.exports.getMeSynchronous = function(success, error) {
+ var currentUser = null;
$.ajax({
+ async: false,
url: "/api/v1/users/me",
dataType: 'json',
contentType: 'application/json',
type: 'GET',
- success: success,
+ success: function gotUser(data, textStatus, xhr) {
+ currentUser = data;
+ if (success) {
+ success(data, textStatus, xhr);
+ }
+ },
error: function(xhr, status, err) {
var ieChecker = window.navigator.userAgent; // This and the condition below is used to check specifically for browsers IE10 & 11 to suppress a 200 'OK' error from appearing on login
if (xhr.status != 200 || !(ieChecker.indexOf("Trident/7.0") > 0 || ieChecker.indexOf("Trident/6.0") > 0)) {
if (error) {
- e = handleError("getMe", xhr, status, err);
+ e = handleError('getMeSynchronous', xhr, status, err);
error(e);
};
};
}
});
+
+ return currentUser;
};
module.exports.inviteMembers = function(data, success, error) {
diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx
index 508de9185..41b02c8d6 100644
--- a/web/react/utils/constants.jsx
+++ b/web/react/utils/constants.jsx
@@ -15,6 +15,7 @@ module.exports = {
RECIEVED_CHANNEL_EXTRA_INFO: null,
RECIEVED_POSTS: null,
+ RECIEVED_POST: null,
RECIEVED_SEARCH: null,
RECIEVED_POST_SELECTED: null,
RECIEVED_MENTION_DATA: null,
@@ -58,8 +59,12 @@ module.exports = {
THUMBNAIL_HEIGHT: 100,
DEFAULT_CHANNEL: 'town-square',
OFFTOPIC_CHANNEL: 'off-topic',
+ GITLAB_SERVICE: 'gitlab',
+ GOOGLE_SERVICE: 'google',
POST_CHUNK_SIZE: 60,
MAX_POST_CHUNKS: 3,
+ POST_LOADING: "loading",
+ POST_FAILED: "failed",
RESERVED_TEAM_NAMES: [
"www",
"web",
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 7591c138f..32793809d 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -124,8 +124,10 @@ module.exports.notifyMe = function(title, body, channel) {
}
module.exports.ding = function() {
- var audio = new Audio('/static/images/ding.mp3');
- audio.play();
+ if (!module.exports.isBrowserFirefox()) {
+ var audio = new Audio('/static/images/ding.mp3');
+ audio.play();
+ }
}
module.exports.getUrlParameter = function(sParam) {
@@ -855,6 +857,20 @@ module.exports.changeColor =function(col, amt) {
return (usePound?"#":"") + String("000000" + (g | (b << 8) | (r << 16)).toString(16)).slice(-6);
};
+module.exports.changeOpacity = function(oldColor, opacity) {
+
+ var col = oldColor;
+ if (col[0] === '#') {
+ col = col.slice(1);
+ }
+
+ var r = parseInt(col.substring(0, 2), 16);
+ var g = parseInt(col.substring(2, 4), 16);
+ var b = parseInt(col.substring(4, 6), 16);
+
+ return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')';
+};
+
module.exports.getFullName = function(user) {
if (user.first_name && user.last_name) {
return user.first_name + " " + user.last_name;
@@ -945,3 +961,7 @@ module.exports.generateId = function() {
return id;
};
+
+module.exports.isBrowserFirefox = function() {
+ return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
+}