Added recent inline bots on '@'
This commit is contained in:
parent
c0d94fe976
commit
00f7229e3d
@ -2081,7 +2081,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
$scope.$on('user_update', angular.noop);
|
$scope.$on('user_update', angular.noop);
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('AppImSendController', function ($scope, $timeout, MtpApiManager, Storage, AppProfileManager, AppChatsManager, AppUsersManager, AppPeersManager, AppDocsManager, AppMessagesManager, AppInlineBotsManager, MtpApiFileManager, RichTextProcessor) {
|
.controller('AppImSendController', function ($q, $scope, $timeout, MtpApiManager, Storage, AppProfileManager, AppChatsManager, AppUsersManager, AppPeersManager, AppDocsManager, AppMessagesManager, AppInlineBotsManager, MtpApiFileManager, RichTextProcessor) {
|
||||||
|
|
||||||
$scope.$watch('curDialog.peer', resetDraft);
|
$scope.$watch('curDialog.peer', resetDraft);
|
||||||
$scope.$on('user_update', angular.noop);
|
$scope.$on('user_update', angular.noop);
|
||||||
@ -2117,6 +2117,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
$scope.$broadcast('ui_peer_draft', {focus: true});
|
$scope.$broadcast('ui_peer_draft', {focus: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$on('inline_bots_popular', updateMentions);
|
||||||
|
|
||||||
$scope.replyKeyboardToggle = replyKeyboardToggle;
|
$scope.replyKeyboardToggle = replyKeyboardToggle;
|
||||||
$scope.toggleSlash = toggleSlash;
|
$scope.toggleSlash = toggleSlash;
|
||||||
|
|
||||||
@ -2163,19 +2165,45 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
function updateMentions () {
|
function updateMentions () {
|
||||||
var peerID = $scope.curDialog.peerID;
|
var peerID = $scope.curDialog.peerID;
|
||||||
|
|
||||||
if (!peerID || peerID > 0) {
|
if (!peerID) {
|
||||||
safeReplaceObject($scope.mentions, {});
|
safeReplaceObject($scope.mentions, {});
|
||||||
$scope.$broadcast('mentions_update');
|
$scope.$broadcast('mentions_update');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AppProfileManager.getChatFull(-peerID).then(function (chatFull) {
|
|
||||||
var participantsVector = (chatFull.participants || {}).participants || [];
|
|
||||||
|
|
||||||
var mentionUsers = [];
|
var mentionUsers = [];
|
||||||
var mentionIndex = SearchIndexManager.createIndex();
|
var mentionIndex = SearchIndexManager.createIndex();
|
||||||
|
|
||||||
angular.forEach(participantsVector, function (participant) {
|
var inlineBotsPromise = AppInlineBotsManager.getPopularBots().then(function (inlineBots) {
|
||||||
var user = AppUsersManager.getUser(participant.user_id);
|
var ids = [];
|
||||||
|
angular.forEach(inlineBots, function (bot) {
|
||||||
|
ids.push(bot.id);
|
||||||
|
});
|
||||||
|
return ids;
|
||||||
|
});
|
||||||
|
var chatParticipantsPromise;
|
||||||
|
if (peerID < 0) {
|
||||||
|
chatParticipantsPromise = AppProfileManager.getChatFull(-peerID).then(function (chatFull) {
|
||||||
|
var participantsVector = (chatFull.participants || {}).participants || [];
|
||||||
|
var ids = [];
|
||||||
|
angular.forEach(participantsVector, function (participant) {
|
||||||
|
ids.push(participant.user_id);
|
||||||
|
});
|
||||||
|
return ids;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
chatParticipantsPromise = $q.when([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$q.all({pop: inlineBotsPromise, chat: chatParticipantsPromise}).then(function (result) {
|
||||||
|
var done = {};
|
||||||
|
var ids = result.pop.concat(result.chat);
|
||||||
|
angular.forEach(ids, function (userID) {
|
||||||
|
if (done[userID]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
done[userID] = true;
|
||||||
|
var user = AppUsersManager.getUser(userID);
|
||||||
if (user.username) {
|
if (user.username) {
|
||||||
mentionUsers.push(user);
|
mentionUsers.push(user);
|
||||||
SearchIndexManager.indexObject(user.id, AppUsersManager.getUserSearchText(user.id), mentionIndex);
|
SearchIndexManager.indexObject(user.id, AppUsersManager.getUserSearchText(user.id), mentionIndex);
|
||||||
@ -2187,6 +2215,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
index: mentionIndex
|
index: mentionIndex
|
||||||
});
|
});
|
||||||
$scope.$broadcast('mentions_update');
|
$scope.$broadcast('mentions_update');
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1539,7 +1539,7 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.$on('inline_results', function (e, inlineResults) {
|
$scope.$on('inline_results', function (e, inlineResults) {
|
||||||
var w = ((richTextarea || messageField).offsetWidth || 382) - 2;
|
var w = (messageFieldWrap.offsetWidth || 382) - 2;
|
||||||
var h = 80;
|
var h = 80;
|
||||||
if (inlineResults) {
|
if (inlineResults) {
|
||||||
AppInlineBotsManager.regroupWrappedResults(inlineResults.results, w, h);
|
AppInlineBotsManager.regroupWrappedResults(inlineResults.results, w, h);
|
||||||
|
@ -55,6 +55,8 @@ function cancelEvent (event) {
|
|||||||
|
|
||||||
if (event.stopPropagation) event.stopPropagation();
|
if (event.stopPropagation) event.stopPropagation();
|
||||||
if (event.preventDefault) event.preventDefault();
|
if (event.preventDefault) event.preventDefault();
|
||||||
|
event.returnValue = false;
|
||||||
|
event.cancelBubble = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -1465,6 +1465,10 @@ MessageComposer.prototype.showInlineSuggestions = function (botResults) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
|
if (self.autoCompleteScope.type == 'inline' &&
|
||||||
|
self.autoCompleteScope.botResults == botResults) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setZeroTimeout(function () {
|
setZeroTimeout(function () {
|
||||||
self.autoCompleteScope.$apply(function () {
|
self.autoCompleteScope.$apply(function () {
|
||||||
self.autoCompleteScope.type = 'inline';
|
self.autoCompleteScope.type = 'inline';
|
||||||
|
@ -2596,16 +2596,68 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
.service('AppInlineBotsManager', function (MtpApiManager, AppMessagesManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager) {
|
.service('AppInlineBotsManager', function ($rootScope, Storage, MtpApiManager, AppMessagesManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager) {
|
||||||
|
|
||||||
var inlineResults = {};
|
var inlineResults = {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sendInlineResult: sendInlineResult,
|
sendInlineResult: sendInlineResult,
|
||||||
regroupWrappedResults: regroupWrappedResults,
|
regroupWrappedResults: regroupWrappedResults,
|
||||||
getInlineResults: getInlineResults
|
getInlineResults: getInlineResults,
|
||||||
|
getPopularBots: getPopularBots
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getPopularBots () {
|
||||||
|
return Storage.get('inline_bots_popular').then(function (bots) {
|
||||||
|
var result = [];
|
||||||
|
var i, len, userID;
|
||||||
|
if (bots && bots.length) {
|
||||||
|
var now = tsNow(true);
|
||||||
|
for (i = 0, len = bots.length; i < len; i++) {
|
||||||
|
if ((now - bots[i][3]) > 14 * 86400) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
userID = bots[i][0];
|
||||||
|
if (!AppUsersManager.hasUser(userID)) {
|
||||||
|
AppUsersManager.saveApiUser(bots[i][1]);
|
||||||
|
}
|
||||||
|
result.push({id: userID, rate: bots[i][2], date: bots[i][3]});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function pushPopularBot (id) {
|
||||||
|
getPopularBots().then(function (bots) {
|
||||||
|
var exists = false;
|
||||||
|
var count = bots.length;
|
||||||
|
var result = [];
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
if (bots[i].id == id) {
|
||||||
|
exists = true;
|
||||||
|
bots[i].rate++;
|
||||||
|
bots[i].date = tsNow(true);
|
||||||
|
}
|
||||||
|
var user = AppUsersManager.getUser(bots[i].id);
|
||||||
|
result.push([bots[i].id, user, bots[i].rate, bots[i].date]);
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
result.sort(function (a, b) {
|
||||||
|
return b[2] - a[2];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (result.length > 15) {
|
||||||
|
result = result.slice(0, 15);
|
||||||
|
}
|
||||||
|
result.push([id, AppUsersManager.getUser(id), 1, tsNow(true)]);
|
||||||
|
}
|
||||||
|
ConfigStorage.set({inline_bots_popular: result});
|
||||||
|
|
||||||
|
$rootScope.$broadcast('inline_bots_popular');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getInlineResults (botID, query, offset) {
|
function getInlineResults (botID, query, offset) {
|
||||||
return MtpApiManager.invokeApi('messages.getInlineBotResults', {
|
return MtpApiManager.invokeApi('messages.getInlineBotResults', {
|
||||||
bot: AppUsersManager.getUserInput(botID),
|
bot: AppUsersManager.getUserInput(botID),
|
||||||
@ -2716,6 +2768,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
if (inlineResult === undefined) {
|
if (inlineResult === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
pushPopularBot(inlineResult.botID);
|
||||||
var splitted = qID.split('_');
|
var splitted = qID.split('_');
|
||||||
var queryID = splitted.shift();
|
var queryID = splitted.shift();
|
||||||
var resultID = splitted.join('_');
|
var resultID = splitted.join('_');
|
||||||
|
@ -1662,6 +1662,10 @@ div.im_message_video_thumb {
|
|||||||
.im_message_twitter_embed > blockquote {
|
.im_message_twitter_embed > blockquote {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
.im_message_webpage_gif .img_gif_with_progress_wrap {
|
||||||
|
margin-top: 5px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.im_message_gif_wrap {
|
.im_message_gif_wrap {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -2878,7 +2882,7 @@ a.composer_emoji_btn {
|
|||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
margin-top: -5px;
|
margin-top: -5px;
|
||||||
margin-left: -1px;
|
margin-left: -1px;
|
||||||
width: 180px;
|
width: 380px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.composer_dropdown {
|
.composer_dropdown {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<div ng-show="webpage._ == 'webPage'" class="im_message_webpage_wrap clearfix" ng-switch="webpage.type">
|
<div ng-show="webpage._ == 'webPage'" class="im_message_webpage_wrap clearfix" ng-switch="webpage.type">
|
||||||
<div ng-switch-when="photo" class="im_message_webpage_photo">
|
<div ng-switch-when="photo" class="im_message_webpage_photo">
|
||||||
<div class="im_message_webpage_site" ng-bind="webpage.site_name || webpage.display_url"></div>
|
|
||||||
<div class="im_message_webpage_title">
|
<div class="im_message_webpage_title">
|
||||||
<a href="{{webpage.url}}" target="_blank" ng-bind-html="webpage.rTitle"></a>
|
<a href="{{webpage.url}}" target="_blank" ng-bind-html="webpage.rTitle"></a>
|
||||||
</div>
|
</div>
|
||||||
@ -35,6 +34,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-switch-when="gif" class="im_message_webpage_gif">
|
<div ng-switch-when="gif" class="im_message_webpage_gif">
|
||||||
|
<div class="im_message_webpage_title">
|
||||||
|
<a href="{{webpage.url}}" target="_blank" ng-bind-html="webpage.rTitle"></a>
|
||||||
|
</div>
|
||||||
<div my-message-document="webpage" message-id="messageId"></div>
|
<div my-message-document="webpage" message-id="messageId"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user