diff --git a/app/js/directives.js b/app/js/directives.js index df65729f..44429727 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -1430,7 +1430,7 @@ angular.module('myApp.directives', ['myApp.filters']) }) - .directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, shouldFocusOnInteraction) { + .directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, AppInlineBotsManager, shouldFocusOnInteraction) { return { link: link, scope: { @@ -1534,6 +1534,9 @@ angular.module('myApp.directives', ['myApp.filters']) }); $scope.$on('inline_results', function (e, inlineResults) { + var w = 180; + var h = 50; + AppInlineBotsManager.regroupWrappedResults(inlineResults.results, w, h); setZeroTimeout(function () { composer.showInlineSuggestions(inlineResults); }); diff --git a/app/js/services.js b/app/js/services.js index aa5284a2..0f304503 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -2600,6 +2600,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return { sendInlineResult: sendInlineResult, + regroupWrappedResults: regroupWrappedResults, getInlineResults: getInlineResults }; @@ -2613,6 +2614,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) delete botResults._; delete botResults.flags; delete botResults.query_id; + angular.forEach(botResults.results, function (result) { var qID = queryID + '_' + result.id; result.qID = qID; @@ -2622,10 +2624,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) result.rDescription = RichTextProcessor.wrapRichText(result.description, {noLinebreaks: true, noLinks: true}); result.initials = (result.url || result.title || result.type || '').substr(0, 1) - if (result._ == 'botInlineMediaResultDocument') { + if (result.document) { AppDocsManager.saveDoc(result.document); } - else if (result._ == 'botInlineMediaResultPhoto') { + if (result.photo) { AppPhotosManager.savePhoto(result.photo); } @@ -2635,6 +2637,79 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }); } + function regroupWrappedResults (results, rowW, rowH) { + if (!results || + !results[0] || + results[0].type != 'photo' && results[0].type != 'gif') { + return; + } + var ratios = []; + angular.forEach(results, function (result) { + var w, h; + if (result._ == 'botInlineMediaResultDocument') { + w = result.document.w; + h = result.document.h; + } + else if (result._ == 'botInlineMediaResultPhoto') { + var photoSize = (result.photo.sizes || [])[0]; + w = photoSize && photoSize.w; + h = photoSize && photoSize.h; + } + else { + w = result.w; + h = result.h; + } + if (!w || !h) { + w = h = 1; + } + ratios.push(w / h); + }); + + var rows = []; + var curCnt = 0; + var curW = 0; + angular.forEach(ratios, function (ratio) { + var w = ratio * rowH; + curW += w; + console.log(curCnt, w, curW, rowW); + if (!curCnt || curCnt < 4 && curW < (rowW * 1.1)) { + curCnt++; + } else { + rows.push(curCnt); + curCnt = 1; + curW = w; + } + }); + if (curCnt) { + rows.push(curCnt); + } + + var i = 0; + var thumbs = []; + var lastRowI = rows.length - 1; + angular.forEach(rows, function (rowCnt, rowI) { + var lastRow = rowI == lastRowI; + var curRatios = ratios.slice(i, i + rowCnt); + var sumRatios = 0; + angular.forEach(curRatios, function (ratio) { + sumRatios += ratio; + }); + angular.forEach(curRatios, function (ratio, j) { + var thumbH = rowH; + var thumbW = rowW * ratio / sumRatios; + var realW = thumbH * ratio; + if (lastRow && thumbW > realW) { + thumbW = realW; + } + var result = results[i + j]; + result.thumbW = Math.floor(thumbW); + result.thumbH = Math.floor(thumbH); + }); + + i += rowCnt; + }); + } + function sendInlineResult (peerID, qID, options) { var inlineResult = inlineResults[qID]; if (inlineResult === undefined) { diff --git a/app/less/app.less b/app/less/app.less index 9c7bab0a..1c9cc057 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -3153,7 +3153,7 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { } .inline_result_wrap { - display: block; + display: inline-block; } .inline_result_article { display: block; @@ -3184,6 +3184,13 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { font-weight: bold; } +.inline_result_gif { + display: inline-block; +} +.composer_dropdown > li > a.inline_result_gif { + padding: 0; +} + .error_modal_window { .modal-dialog { diff --git a/app/partials/desktop/inline_results.html b/app/partials/desktop/inline_results.html index b92c0a8c..3ea3ea5c 100644 --- a/app/partials/desktop/inline_results.html +++ b/app/partials/desktop/inline_results.html @@ -1,5 +1,11 @@