From f52d741fcfb59479f0cd5232469f1e8d25f563d9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 1 Jul 2015 18:22:33 +0300 Subject: [PATCH] Highlight bot commands --- app/js/services.js | 51 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 1e9b15a8..0500d00b 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -854,7 +854,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) version: botInfo.version, shareText: botInfo.share_text, description: botInfo.description, - rAbout: RichTextProcessor.wrapRichText(botInfo.share_text, {noLinks: true, noLinebreaks: true}), + rAbout: RichTextProcessor.wrapRichText(botInfo.share_text, {noLinebreaks: true}), commands: commands }; } @@ -2184,10 +2184,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) message.media.progress = messagesStorage[msgID].media.progress; } + var fromUser = AppUsersManager.getUser(message.from_id); + var fromBot = fromUser.pFlags.bot && fromUser.username || false; + var withBot = (fromBot || + message.to_id && ( + message.to_id.chat_id || + message.to_id.user_id && AppUsersManager.isBot(message.to_id.user_id) + ) + ); + if (message.media) { if (message.media.caption && message.media.caption.length) { - message.media.rCaption = RichTextProcessor.wrapRichText(message.media.caption); + message.media.rCaption = RichTextProcessor.wrapRichText(message.media.caption, { + noCommands: !withBot, + fromBot: fromBot + }); } switch (message.media._) { @@ -2253,7 +2265,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) break; case 'messageActionBotIntro': - message.action.rDescription = RichTextProcessor.wrapRichText(message.action.description); + message.action.rDescription = RichTextProcessor.wrapRichText(message.action.description, { + noCommands: !withBot, + fromBot: fromBot + }); break; } } @@ -2274,7 +2289,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } if (message.message && message.message.length) { - var options = {}; + var options = { + noCommands: !withBot, + fromBot: fromBot + }; if (!Config.Navigator.mobile) { options.extractUrlEmbed = true; } @@ -4610,11 +4628,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } } else if (match[12]) { // Bot commands - if (!options.noLinks || contextExternal) { + if (!options.noLinks && + !options.noCommands && + !contextExternal) { + var bot = match[13] || options.fromBot; html.push( encodeEntities(match[11]), '', encodeEntities('/' + match[12] + (match[13] ? '@' + match[13] : '')), '', @@ -5630,7 +5651,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }) -.service('LocationParamsService', function ($rootScope, $routeParams, AppUsersManager, AppMessagesManager, AppStickersManager) { +.service('LocationParamsService', function ($rootScope, $routeParams, AppPeersManager, AppUsersManager, AppMessagesManager, AppStickersManager) { var tgAddrRegExp = /^(web\+)?tg:(\/\/)?(.+)/; @@ -5670,11 +5691,19 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } if (inner && - (matches = url.match(/^bot_command\?command=(.+?)(?:&bot=(.+))?/))) { - $rootScope.$broadcast('bot_command', { - command: matches[1], - bot: matches[2] || '' + (matches = url.match(/^bot_command\?command=(.+?)(?:&bot=(.+))?$/))) { + + var peerID = $rootScope.selectedPeerID; + var text = '/' + matches[1]; + if (peerID < 0 && matches[2]) { + text += '@' + matches[2]; + } + AppMessagesManager.sendText(peerID, text); + + $rootScope.$broadcast('history_focus', { + peerString: AppPeersManager.getPeerString(peerID) }); + return true; } return false;