summaryrefslogtreecommitdiffstats
path: root/web/react/utils/utils.jsx
diff options
context:
space:
mode:
authorReed Garmsen <rgarmsen2295@gmail.com>2015-08-26 09:38:06 -0700
committerReed Garmsen <rgarmsen2295@gmail.com>2015-08-26 16:53:19 -0700
commita56603d666a4f3e22a92a0271eef56ab613ce848 (patch)
tree668afe7ba9fd1cd2f1a71f4da76247eb77f9c483 /web/react/utils/utils.jsx
parent656a88efdd2606ce8449097e740535f41aee9d64 (diff)
downloadchat-a56603d666a4f3e22a92a0271eef56ab613ce848.tar.gz
chat-a56603d666a4f3e22a92a0271eef56ab613ce848.tar.bz2
chat-a56603d666a4f3e22a92a0271eef56ab613ce848.zip
Moved duplicate code into functions and added better handling of large paste text dumps
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r--web/react/utils/utils.jsx24
1 files changed, 24 insertions, 0 deletions
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('__');