Browse Source

Added recent inline bots on '@'

master
Igor Zhukov 9 years ago
parent
commit
00f7229e3d
  1. 45
      app/js/controllers.js
  2. 2
      app/js/directives.js
  3. 2
      app/js/lib/utils.js
  4. 4
      app/js/message_composer.js
  5. 57
      app/js/services.js
  6. 6
      app/less/app.less
  7. 4
      app/partials/desktop/message_attach_webpage.html

45
app/js/controllers.js

@ -2081,7 +2081,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2081,7 +2081,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$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.$on('user_update', angular.noop);
@ -2117,6 +2117,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2117,6 +2117,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_peer_draft', {focus: true});
});
$scope.$on('inline_bots_popular', updateMentions);
$scope.replyKeyboardToggle = replyKeyboardToggle;
$scope.toggleSlash = toggleSlash;
@ -2163,19 +2165,45 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2163,19 +2165,45 @@ angular.module('myApp.controllers', ['myApp.i18n'])
function updateMentions () {
var peerID = $scope.curDialog.peerID;
if (!peerID || peerID > 0) {
if (!peerID) {
safeReplaceObject($scope.mentions, {});
$scope.$broadcast('mentions_update');
return;
}
AppProfileManager.getChatFull(-peerID).then(function (chatFull) {
var participantsVector = (chatFull.participants || {}).participants || [];
var mentionUsers = [];
var mentionIndex = SearchIndexManager.createIndex();
var mentionUsers = [];
var mentionIndex = SearchIndexManager.createIndex();
var inlineBotsPromise = AppInlineBotsManager.getPopularBots().then(function (inlineBots) {
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([]);
}
angular.forEach(participantsVector, function (participant) {
var user = AppUsersManager.getUser(participant.user_id);
$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) {
mentionUsers.push(user);
SearchIndexManager.indexObject(user.id, AppUsersManager.getUserSearchText(user.id), mentionIndex);
@ -2187,6 +2215,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2187,6 +2215,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
index: mentionIndex
});
$scope.$broadcast('mentions_update');
});
}

2
app/js/directives.js

@ -1539,7 +1539,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -1539,7 +1539,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}
$scope.$on('inline_results', function (e, inlineResults) {
var w = ((richTextarea || messageField).offsetWidth || 382) - 2;
var w = (messageFieldWrap.offsetWidth || 382) - 2;
var h = 80;
if (inlineResults) {
AppInlineBotsManager.regroupWrappedResults(inlineResults.results, w, h);

2
app/js/lib/utils.js

@ -55,6 +55,8 @@ function cancelEvent (event) { @@ -55,6 +55,8 @@ function cancelEvent (event) {
if (event.stopPropagation) event.stopPropagation();
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
event.cancelBubble = true;
}
return false;

4
app/js/message_composer.js

@ -1465,6 +1465,10 @@ MessageComposer.prototype.showInlineSuggestions = function (botResults) { @@ -1465,6 +1465,10 @@ MessageComposer.prototype.showInlineSuggestions = function (botResults) {
return;
}
var self = this;
if (self.autoCompleteScope.type == 'inline' &&
self.autoCompleteScope.botResults == botResults) {
return;
}
setZeroTimeout(function () {
self.autoCompleteScope.$apply(function () {
self.autoCompleteScope.type = 'inline';

57
app/js/services.js

@ -2596,16 +2596,68 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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 = {};
return {
sendInlineResult: sendInlineResult,
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) {
return MtpApiManager.invokeApi('messages.getInlineBotResults', {
bot: AppUsersManager.getUserInput(botID),
@ -2716,6 +2768,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2716,6 +2768,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (inlineResult === undefined) {
return false;
}
pushPopularBot(inlineResult.botID);
var splitted = qID.split('_');
var queryID = splitted.shift();
var resultID = splitted.join('_');

6
app/less/app.less

@ -1662,6 +1662,10 @@ div.im_message_video_thumb { @@ -1662,6 +1662,10 @@ div.im_message_video_thumb {
.im_message_twitter_embed > blockquote {
visibility: hidden;
}
.im_message_webpage_gif .img_gif_with_progress_wrap {
margin-top: 5px;
display: block;
}
.im_message_gif_wrap {
position: relative;
@ -2878,7 +2882,7 @@ a.composer_emoji_btn { @@ -2878,7 +2882,7 @@ a.composer_emoji_btn {
border-radius: 0;
margin-top: -5px;
margin-left: -1px;
width: 180px;
width: 380px;
}
.composer_dropdown {

4
app/partials/desktop/message_attach_webpage.html

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
<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 class="im_message_webpage_site" ng-bind="webpage.site_name || webpage.display_url"></div>
<div class="im_message_webpage_title">
<a href="{{webpage.url}}" target="_blank" ng-bind-html="webpage.rTitle"></a>
</div>
@ -35,6 +34,9 @@ @@ -35,6 +34,9 @@
</div>
<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>

Loading…
Cancel
Save