Browse Source

Inline bots wip

master
Igor Zhukov 9 years ago
parent
commit
a7bb7ecb73
  1. 11
      app/js/controllers.js
  2. 16
      app/js/services.js

11
app/js/controllers.js

@ -2380,6 +2380,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -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']) @@ -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);

16
app/js/services.js

@ -944,6 +944,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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']) @@ -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

Loading…
Cancel
Save