summaryrefslogtreecommitdiffstats
path: root/web/react/utils/utils.jsx
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-27 10:01:54 -0400
committerChristopher Speller <crspeller@gmail.com>2015-08-27 10:01:54 -0400
commitd5e202a4d9b735dca2e3cc54137b8d66cb167580 (patch)
treea61e54ec8a7d6eb318ac9077ede6dc1ef00c3ef8 /web/react/utils/utils.jsx
parentcf1c2ad2cc5d5c24eabc3ebd2bce9f79b2e420fc (diff)
parenta56603d666a4f3e22a92a0271eef56ab613ce848 (diff)
downloadchat-d5e202a4d9b735dca2e3cc54137b8d66cb167580.tar.gz
chat-d5e202a4d9b735dca2e3cc54137b8d66cb167580.tar.bz2
chat-d5e202a4d9b735dca2e3cc54137b8d66cb167580.zip
Merge pull request #472 from rgarmsen2295/mm-1853
MM-1853 Prevents users from typing more than 4000 characters into any any post/comment
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r--web/react/utils/utils.jsx52
1 files changed, 52 insertions, 0 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index f19dd2b47..00da9ce5f 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -987,6 +987,58 @@ module.exports.isBrowserFirefox = function() {
return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
};
+// Checks if browser is IE10 or IE11
+module.exports.isBrowserIE = function() {
+ if (window.navigator && window.navigator.userAgent) {
+ var ua = window.navigator.userAgent;
+
+ return ua.indexOf('Trident/7.0') > 0 || ua.indexOf('Trident/6.0') > 0;
+ }
+
+ return false;
+};
+
+module.exports.isBrowserEdge = function() {
+ return window.naviagtor && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('edge') > -1;
+};
+
+// Gets text length consistent with maxlength property of textarea html tag
+module.exports.getLengthOfTextInTextarea = function(messageText) {
+ // Need to get length with carriage returns counting as two characters to match textbox maxlength behavior
+ // unless ie10/ie11/edge which already do
+
+ var len = messageText.length;
+ if (!module.exports.isBrowserIE() && !module.exports.isBrowserEdge()) {
+ len = messageText.replace(/\r(?!\n)|\n(?!\r)/g, '--').length;
+ }
+
+ return len;
+};
+
+module.exports.checkMessageLengthError = function(message, currentError, newError) {
+ var updatedError = currentError;
+ var len = module.exports.getLengthOfTextInTextarea(message);
+
+ if (!currentError && len >= Constants.MAX_POST_LEN) {
+ updatedError = newError;
+ } else if (currentError === newError && len < Constants.MAX_POST_LEN) {
+ updatedError = '';
+ }
+
+ return updatedError;
+};
+
+// Necessary due to issues with textarea max length and pasting newlines
+module.exports.truncateText = function(message) {
+ var lengthDifference = module.exports.getLengthOfTextInTextarea(message) - message.length;
+
+ if (lengthDifference > 0) {
+ return message.substring(0, Constants.MAX_POST_LEN - lengthDifference);
+ }
+
+ return message.substring(0, Constants.MAX_POST_LEN);
+};
+
// Used to get the id of the other user from a DM channel
module.exports.getUserIdFromChannelName = function(channel) {
var ids = channel.name.split('__');