From 656a88efdd2606ce8449097e740535f41aee9d64 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Tue, 25 Aug 2015 12:47:18 -0700
Subject: Fixed issue with carriage returns being counted improperly in non-ie
 browsers and updated error messages to be appropriate to what is being typed
 (message vs. post vs. edit)

---
 web/react/utils/utils.jsx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

(limited to 'web/react/utils/utils.jsx')

diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index f718f7435..33c103c2e 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -1004,6 +1004,34 @@ 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;
+};
+
 // Used to get the id of the other user from a DM channel
 module.exports.getUserIdFromChannelName = function(channel) {
     var ids = channel.name.split('__');
-- 
cgit v1.2.3-1-g7c22


From a56603d666a4f3e22a92a0271eef56ab613ce848 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Wed, 26 Aug 2015 09:38:06 -0700
Subject: Moved duplicate code into functions and added better handling of
 large paste text dumps

---
 web/react/utils/utils.jsx | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'web/react/utils/utils.jsx')

diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 33c103c2e..77b204793 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -1032,6 +1032,30 @@ module.exports.getLengthOfTextInTextarea = function(messageText) {
     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('__');
-- 
cgit v1.2.3-1-g7c22

