Inline bots wip

This commit is contained in:
Igor Zhukov 2016-01-22 19:35:38 +00:00
parent 64efe88880
commit a7bb7ecb73
2 changed files with 27 additions and 0 deletions

View File

@ -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);

View File

@ -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