From b5a60fef0b4a005f82545f2ae05c2ee2e608f7e9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 7 Jun 2016 14:07:59 +0300 Subject: [PATCH] Fixed trim message before send Close #1135 Close #1125 --- app/js/lib/ng_utils.js | 5 ++++- app/js/messages_manager.js | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index bd2159f8..f826ee20 100644 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -1397,7 +1397,7 @@ angular.module('izhukov.utils', []) function parseMarkdown (text, entities) { if (text.indexOf('`') == -1) { - return text; + return text.trim(); } var raw = text; var match; @@ -1448,6 +1448,9 @@ angular.module('izhukov.utils', []) newText = text; entities.splice(0, entities.length); } + if (!entities.length) { + newText = newText.trim(); + } return newText; } diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 4164b65c..f4e029d2 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -1297,10 +1297,18 @@ angular.module('myApp.services') } function sendText(peerID, text, options) { - if (!angular.isString(text) || !text.length) { + if (!angular.isString(text)) { return; } options = options || {}; + var entities = options.entities || []; + if (!options.viaBotID) { + text = RichTextProcessor.parseMarkdown(text, entities); + } + if (!text.length) { + return; + } + var messageID = tempID--, randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), @@ -1311,13 +1319,8 @@ angular.module('myApp.services') isChannel = AppPeersManager.isChannel(peerID), isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID), asChannel = isChannel && !isMegagroup ? true : false, - entities = options.entities || [], message; - if (!options.viaBotID) { - text = RichTextProcessor.parseMarkdown(text, entities); - } - if (historyStorage === undefined) { historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; }