From a7bb7ecb730024192349adb41ca315c56585c82c Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 22 Jan 2016 19:35:38 +0000 Subject: [PATCH] Inline bots wip --- app/js/controllers.js | 11 +++++++++++ app/js/services.js | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/js/controllers.js b/app/js/controllers.js index b79009c4..57415f60 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -2380,6 +2380,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) return cancelEvent($event); } + var inlineUsernameRegex = /^@([a-zA-Z\d_]{1,32}) /; + var lastInlineBot = false; function onMessageChange(newVal) { // console.log('ctrl text changed', newVal); // console.trace('ctrl text changed', newVal); @@ -2393,6 +2395,15 @@ angular.module('myApp.controllers', ['myApp.i18n']) backupDraftObj['draft' + $scope.curDialog.peerID] = newVal; Storage.set(backupDraftObj); // console.log(dT(), 'draft save', backupDraftObj); + + var matches; + if (matches = newVal.match(inlineUsernameRegex)) { + AppPeersManager.resolveInlineMention(matches[1]).then(function (placeholder) { + $scope.draftMessage.inlinePlaceholder = placeholder; + }, function () { + + }) + } } else { Storage.remove('draft' + $scope.curDialog.peerID); // console.log(dT(), 'draft delete', 'draft' + $scope.curDialog.peerID); diff --git a/app/js/services.js b/app/js/services.js index ab4d4133..42fcb126 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -944,6 +944,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }); } + function resolveInlineMention (username) { + return resolveUsername(username).then(function (peerID) { + if (peerID > 0) { + var bot = AppUsersManager.getUser(peerID); + if (bot.pFlags.bot && bot.bot_inline_placeholder !== undefined) { + return bot.bot_inline_placeholder; + } + } + return $q.reject(); + }, function (error) { + error.handled = true; + return $q.reject(error); + }); + } + function getPeerID (peerString) { if (angular.isObject(peerString)) { return peerString.user_id @@ -990,6 +1005,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) getPeer: getPeer, getPeerPhoto: getPeerPhoto, resolveUsername: resolveUsername, + resolveInlineMention: resolveInlineMention, isChannel: isChannel, isMegagroup: isMegagroup, isBot: isBot