|
|
@ -11,7 +11,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, qSync, MtpApiManager, RichTextProcessor, ErrorService, Storage, _) { |
|
|
|
.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, qSync, MtpApiManager, RichTextProcessor, Storage, _) { |
|
|
|
var users = {}, |
|
|
|
var users = {}, |
|
|
|
usernames = {}, |
|
|
|
usernames = {}, |
|
|
|
userAccess = {}, |
|
|
|
userAccess = {}, |
|
|
@ -960,24 +960,6 @@ 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 qSync.when({ |
|
|
|
|
|
|
|
id: peerID, |
|
|
|
|
|
|
|
placeholder: bot.bot_inline_placeholder |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $q.reject(); |
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
|
|
|
|
error.handled = true; |
|
|
|
|
|
|
|
return $q.reject(error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPeerID (peerString) { |
|
|
|
function getPeerID (peerString) { |
|
|
|
if (angular.isObject(peerString)) { |
|
|
|
if (angular.isObject(peerString)) { |
|
|
|
return peerString.user_id |
|
|
|
return peerString.user_id |
|
|
@ -1024,7 +1006,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
getPeer: getPeer, |
|
|
|
getPeer: getPeer, |
|
|
|
getPeerPhoto: getPeerPhoto, |
|
|
|
getPeerPhoto: getPeerPhoto, |
|
|
|
resolveUsername: resolveUsername, |
|
|
|
resolveUsername: resolveUsername, |
|
|
|
resolveInlineMention: resolveInlineMention, |
|
|
|
|
|
|
|
isChannel: isChannel, |
|
|
|
isChannel: isChannel, |
|
|
|
isMegagroup: isMegagroup, |
|
|
|
isMegagroup: isMegagroup, |
|
|
|
isBot: isBot |
|
|
|
isBot: isBot |
|
|
@ -2402,19 +2383,20 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppInlineBotsManager', function ($rootScope, Storage, MtpApiManager, AppMessagesManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager, AppPeersManager, PeersSelectService) { |
|
|
|
.service('AppInlineBotsManager', function (qSync, $q, $rootScope, Storage, ErrorService, MtpApiManager, AppMessagesManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager, AppPeersManager, PeersSelectService, GeoLocationManager) { |
|
|
|
|
|
|
|
|
|
|
|
var inlineResults = {}; |
|
|
|
var inlineResults = {}; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
|
|
|
|
resolveInlineMention: resolveInlineMention, |
|
|
|
|
|
|
|
getPopularBots: getPopularBots, |
|
|
|
sendInlineResult: sendInlineResult, |
|
|
|
sendInlineResult: sendInlineResult, |
|
|
|
|
|
|
|
getInlineResults: getInlineResults, |
|
|
|
regroupWrappedResults: regroupWrappedResults, |
|
|
|
regroupWrappedResults: regroupWrappedResults, |
|
|
|
switchToPM: switchToPM, |
|
|
|
switchToPM: switchToPM, |
|
|
|
checkSwitchReturn: checkSwitchReturn, |
|
|
|
checkSwitchReturn: checkSwitchReturn, |
|
|
|
switchInlineButtonClick: switchInlineButtonClick, |
|
|
|
switchInlineButtonClick: switchInlineButtonClick, |
|
|
|
callbackButtonClick: callbackButtonClick, |
|
|
|
callbackButtonClick: callbackButtonClick |
|
|
|
getInlineResults: getInlineResults, |
|
|
|
|
|
|
|
getPopularBots: getPopularBots |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function getPopularBots () { |
|
|
|
function getPopularBots () { |
|
|
@ -2468,12 +2450,46 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getInlineResults (peerID, botID, query, offset) { |
|
|
|
function resolveInlineMention (username) { |
|
|
|
|
|
|
|
return AppPeersManager.resolveUsername(username).then(function (peerID) { |
|
|
|
|
|
|
|
if (peerID > 0) { |
|
|
|
|
|
|
|
var bot = AppUsersManager.getUser(peerID); |
|
|
|
|
|
|
|
if (bot.pFlags.bot && bot.bot_inline_placeholder !== undefined) { |
|
|
|
|
|
|
|
var resolvedBot = { |
|
|
|
|
|
|
|
username: username, |
|
|
|
|
|
|
|
id: peerID, |
|
|
|
|
|
|
|
placeholder: bot.bot_inline_placeholder |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (bot.pFlags.bot_inline_geo) { |
|
|
|
|
|
|
|
return checkGeoLocationAccess(peerID).then(function () { |
|
|
|
|
|
|
|
// console.log('bot has access');
|
|
|
|
|
|
|
|
return GeoLocationManager.getPosition().then(function (coords) { |
|
|
|
|
|
|
|
resolvedBot.geo = coords; |
|
|
|
|
|
|
|
console.log('got position', resolvedBot); |
|
|
|
|
|
|
|
return qSync.when(resolvedBot); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
})['catch'](function () { |
|
|
|
|
|
|
|
console.log('resolve', resolvedBot); |
|
|
|
|
|
|
|
return qSync.when(resolvedBot); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return qSync.when(resolvedBot); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $q.reject(); |
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
|
|
|
|
error.handled = true; |
|
|
|
|
|
|
|
return $q.reject(error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getInlineResults (peerID, botID, query, geo, offset) { |
|
|
|
return MtpApiManager.invokeApi('messages.getInlineBotResults', { |
|
|
|
return MtpApiManager.invokeApi('messages.getInlineBotResults', { |
|
|
|
flags: 0, |
|
|
|
flags: 0 | (geo ? 1 : 0), |
|
|
|
bot: AppUsersManager.getUserInput(botID), |
|
|
|
bot: AppUsersManager.getUserInput(botID), |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
query: query, |
|
|
|
query: query, |
|
|
|
|
|
|
|
geo_point: geo && {_: 'inputGeoPoint', lat: geo['lat'], long: geo['long']}, |
|
|
|
offset: offset |
|
|
|
offset: offset |
|
|
|
}, {timeout: 1, stopTime: -1, noErrorBox: true}).then(function(botResults) { |
|
|
|
}, {timeout: 1, stopTime: -1, noErrorBox: true}).then(function(botResults) { |
|
|
|
var queryID = botResults.query_id; |
|
|
|
var queryID = botResults.query_id; |
|
|
@ -2661,31 +2677,72 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
options.viaBotID = inlineResult.botID; |
|
|
|
options.viaBotID = inlineResult.botID; |
|
|
|
options.queryID = queryID; |
|
|
|
options.queryID = queryID; |
|
|
|
options.resultID = resultID; |
|
|
|
options.resultID = resultID; |
|
|
|
|
|
|
|
if (inlineResult.send_message.reply_markup) { |
|
|
|
|
|
|
|
options.reply_markup = inlineResult.send_message.reply_markup; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (inlineResult.send_message._ == 'botInlineMessageText') { |
|
|
|
if (inlineResult.send_message._ == 'botInlineMessageText') { |
|
|
|
options.entities = inlineResult.send_message.entities; |
|
|
|
options.entities = inlineResult.send_message.entities; |
|
|
|
AppMessagesManager.sendText(peerID, inlineResult.send_message.message, options); |
|
|
|
AppMessagesManager.sendText(peerID, inlineResult.send_message.message, options); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var caption = ''; |
|
|
|
var caption = ''; |
|
|
|
if (inlineResult.send_message._ == 'botInlineMessageMediaAuto') { |
|
|
|
|
|
|
|
caption = inlineResult.send_message.caption; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var inputMedia = false; |
|
|
|
var inputMedia = false; |
|
|
|
if (inlineResult._ == 'botInlineMediaResultDocument') { |
|
|
|
switch (inlineResult.send_message._) { |
|
|
|
var doc = inlineResult.document; |
|
|
|
case 'botInlineMessageMediaAuto': |
|
|
|
inputMedia = { |
|
|
|
caption = inlineResult.send_message.caption; |
|
|
|
_: 'inputMediaDocument', |
|
|
|
if (inlineResult._ == 'botInlineMediaResult') { |
|
|
|
id: {_: 'inputDocument', id: doc.id, access_hash: doc.access_hash}, |
|
|
|
var doc = inlineResult.document; |
|
|
|
caption: caption |
|
|
|
var photo = inlineResult.photo; |
|
|
|
}; |
|
|
|
if (doc) { |
|
|
|
} |
|
|
|
inputMedia = { |
|
|
|
else if (inlineResult._ == 'botInlineMediaResultPhoto') { |
|
|
|
_: 'inputMediaDocument', |
|
|
|
var photo = inlineResult.photo; |
|
|
|
id: {_: 'inputDocument', id: doc.id, access_hash: doc.access_hash}, |
|
|
|
inputMedia = { |
|
|
|
caption: caption |
|
|
|
_: 'inputMediaPhoto', |
|
|
|
}; |
|
|
|
id: {_: 'inputPhoto', id: photo.id, access_hash: photo.access_hash}, |
|
|
|
} else { |
|
|
|
caption: caption |
|
|
|
inputMedia = { |
|
|
|
}; |
|
|
|
_: 'inputMediaPhoto', |
|
|
|
|
|
|
|
id: {_: 'inputPhoto', id: photo.id, access_hash: photo.access_hash}, |
|
|
|
|
|
|
|
caption: caption |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'botInlineMessageMediaGeo': |
|
|
|
|
|
|
|
inputMedia = { |
|
|
|
|
|
|
|
_: 'inputMediaGeoPoint', |
|
|
|
|
|
|
|
geo_point: { |
|
|
|
|
|
|
|
_: 'inputGeoPoint', |
|
|
|
|
|
|
|
'lat': inlineResult.send_message.geo['lat'], |
|
|
|
|
|
|
|
'long': inlineResult.send_message.geo['long'] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'botInlineMessageMediaVenue': |
|
|
|
|
|
|
|
inputMedia = { |
|
|
|
|
|
|
|
_: 'inputMediaVenue', |
|
|
|
|
|
|
|
geo_point: { |
|
|
|
|
|
|
|
_: 'inputGeoPoint', |
|
|
|
|
|
|
|
'lat': inlineResult.send_message.geo['lat'], |
|
|
|
|
|
|
|
'long': inlineResult.send_message.geo['long'] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
title: title, |
|
|
|
|
|
|
|
address: address, |
|
|
|
|
|
|
|
provider: provider, |
|
|
|
|
|
|
|
venue_id: venue_id |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'botInlineMessageMediaContact': |
|
|
|
|
|
|
|
inputMedia = { |
|
|
|
|
|
|
|
_: 'inputMediaContact', |
|
|
|
|
|
|
|
phone_number: inlineResult.send_message.phone_number, |
|
|
|
|
|
|
|
first_name: inlineResult.send_message.first_name, |
|
|
|
|
|
|
|
last_name: inlineResult.send_message.last_name |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!inputMedia) { |
|
|
|
if (!inputMedia) { |
|
|
|
inputMedia = { |
|
|
|
inputMedia = { |
|
|
@ -2700,6 +2757,28 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function checkGeoLocationAccess(botID) { |
|
|
|
|
|
|
|
var key = 'bot_access_geo' + botID; |
|
|
|
|
|
|
|
return Storage.get(key).then(function (geoAccess) { |
|
|
|
|
|
|
|
if (geoAccess && geoAccess.granted) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ErrorService.confirm({ |
|
|
|
|
|
|
|
type: 'BOT_ACCESS_GEO' |
|
|
|
|
|
|
|
}).then(function () { |
|
|
|
|
|
|
|
var setHash = {}; |
|
|
|
|
|
|
|
setHash[key] = {granted: true, time: tsNow()}; |
|
|
|
|
|
|
|
Storage.set(setHash); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
}, function () { |
|
|
|
|
|
|
|
var setHash = {}; |
|
|
|
|
|
|
|
setHash[key] = {denied: true, time: tsNow()}; |
|
|
|
|
|
|
|
Storage.set(setHash); |
|
|
|
|
|
|
|
return $q.reject(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|
.service('ApiUpdatesManager', function ($rootScope, MtpNetworkerFactory, AppUsersManager, AppChatsManager, AppPeersManager, MtpApiManager) { |
|
|
|