@ -2269,6 +2269,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope . draftMessage . text = '' ;
$scope . draftMessage . text = '' ;
$scope . $broadcast ( 'ui_peer_draft' ) ;
$scope . $broadcast ( 'ui_peer_draft' ) ;
}
}
delete $scope . draftMessage . inlineProgress ;
$scope . $broadcast ( 'inline_results' , false ) ;
}
}
function applyDraftAttachment ( e , attachment ) {
function applyDraftAttachment ( e , attachment ) {
@ -2396,8 +2399,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return cancelEvent ( $event ) ;
return cancelEvent ( $event ) ;
}
}
var inlineUsernameRegex = /^@([a-zA-Z\d_]{1,32})( | )([\s\S]*)$/ ;
var lastInlineBot = false ;
function onMessageChange ( newVal ) {
function onMessageChange ( newVal ) {
// console.log('ctrl text changed', newVal);
// console.log('ctrl text changed', newVal);
// console.trace('ctrl text changed', newVal);
// console.trace('ctrl text changed', newVal);
@ -2411,34 +2412,65 @@ angular.module('myApp.controllers', ['myApp.i18n'])
backupDraftObj [ 'draft' + $scope . curDialog . peerID ] = newVal ;
backupDraftObj [ 'draft' + $scope . curDialog . peerID ] = newVal ;
Storage . set ( backupDraftObj ) ;
Storage . set ( backupDraftObj ) ;
// console.log(dT(), 'draft save', backupDraftObj);
// console.log(dT(), 'draft save', backupDraftObj);
} else {
Storage . remove ( 'draft' + $scope . curDialog . peerID ) ;
// console.log(dT(), 'draft delete', 'draft' + $scope.curDialog.peerID);
}
checkInlinePattern ( newVal ) ;
}
var matches = newVal . match ( inlineUsernameRegex ) ;
var inlineUsernameRegex = /^@([a-zA-Z\d_]{1,32})( | )([\s\S]*)$/ ;
if ( matches ) {
var getInlineResultsTO = false ;
$scope . draftMessage . inlineProgress = true ;
var jump = 0 ;
function checkInlinePattern ( message ) {
if ( getInlineResultsTO ) {
$timeout . cancel ( getInlineResultsTO ) ;
}
var curJump = ++ jump ;
if ( ! message || ! message . length ) {
delete $scope . draftMessage . inlineProgress ;
$scope . $broadcast ( 'inline_results' , false ) ;
return ;
}
var matches = message . match ( inlineUsernameRegex ) ;
if ( ! matches ) {
delete $scope . draftMessage . inlineProgress ;
$scope . $broadcast ( 'inline_results' , false ) ;
return ;
}
var username = matches [ 1 ] ;
var username = matches [ 1 ] ;
$scope . draftMessage . inlineProgress = true ;
AppPeersManager . resolveInlineMention ( username ) . then ( function ( inlineBot ) {
AppPeersManager . resolveInlineMention ( username ) . then ( function ( inlineBot ) {
if ( curJump != jump ) {
return ;
}
$scope . $broadcast ( 'inline_placeholder' , {
$scope . $broadcast ( 'inline_placeholder' , {
prefix : '@' + username + matches [ 2 ] ,
prefix : '@' + username + matches [ 2 ] ,
placeholder : inlineBot . placeholder
placeholder : inlineBot . placeholder
} ) ;
} ) ;
if ( getInlineResultsTO ) {
$timeout . cancel ( getInlineResultsTO ) ;
}
getInlineResultsTO = $timeout ( function ( ) {
AppInlineBotsManager . getInlineResults ( inlineBot . id , matches [ 3 ] , '' ) . then ( function ( botResults ) {
AppInlineBotsManager . getInlineResults ( inlineBot . id , matches [ 3 ] , '' ) . then ( function ( botResults ) {
getInlineResultsTO = false ;
if ( curJump != jump ) {
return ;
}
botResults . text = message ;
$scope . $broadcast ( 'inline_results' , botResults ) ;
$scope . $broadcast ( 'inline_results' , botResults ) ;
delete $scope . draftMessage . inlineProgress ;
delete $scope . draftMessage . inlineProgress ;
} , function ( ) {
} , function ( ) {
$scope . $broadcast ( 'inline_results' , false ) ;
delete $scope . draftMessage . inlineProgress ;
delete $scope . draftMessage . inlineProgress ;
} ) ;
} ) ;
} , 500 ) ;
} , function ( ) {
} , function ( ) {
delete $scope . draftMessage . inlinePlaceholder ;
$scope . $broadcast ( 'inline_results' , false ) ;
delete $scope . draftMessage . inlineProgress ;
delete $scope . draftMessage . inlineProgress ;
} ) ;
} ) ;
}
}
} else {
Storage . remove ( 'draft' + $scope . curDialog . peerID ) ;
delete $scope . draftMessage . inlinePlaceholder ;
delete $scope . draftMessage . inlineProgress ;
// console.log(dT(), 'draft delete', 'draft' + $scope.curDialog.peerID);
}
}
function onTyping ( ) {
function onTyping ( ) {
if ( AppPeersManager . isChannel ( $scope . curDialog . peerID ) &&
if ( AppPeersManager . isChannel ( $scope . curDialog . peerID ) &&
@ -2499,7 +2531,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
fwdsSend ( ) ;
fwdsSend ( ) ;
}
}
delete $scope . draftMessage . sticker ;
delete $scope . draftMessage . sticker ;
resetDraft ( ) ;
}
}
function onCommandSelected ( command ) {
function onCommandSelected ( command ) {