diff --git a/app/js/controllers.js b/app/js/controllers.js index 26dd8634..2bdd9460 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -408,11 +408,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) LayoutSwitchService.start(); }) - .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, AppPeersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService, LocationParamsService, AppStickersManager) { + .controller('AppIMController', function ($q, qSync, $scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, AppPeersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService, LocationParamsService, AppStickersManager) { $scope.$on('$routeUpdate', updateCurDialog); var pendingParams = false; + var pendingShare = false; $scope.$on('history_focus', function (e, peerData) { $modalStack.dismissAll(); if (peerData.peerString == $scope.curDialog.peer && @@ -423,7 +424,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) var peerID = AppPeersManager.getPeerID(peerData.peerString); var username = AppPeersManager.getPeer(peerID).username; var peer = username ? '@' + username : peerData.peerString; - if (peerData.messageID || peerData.startParam) { + if (peerData.messageID || peerData.startParam || peerData.shareUrl) { pendingParams = { messageID: peerData.messageID, startParam: peerData.startParam @@ -431,6 +432,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) } else { pendingParams = false; } + if (peerData.shareUrl) { + pendingShare = { + url: peerData.shareUrl, + text: peerData.shareText + }; + } if ($routeParams.p != peer) { $location.url('/im?p=' + peer); } else { @@ -595,22 +602,28 @@ angular.module('myApp.controllers', ['myApp.i18n']) var addParams = pendingParams || {}; pendingParams = false; addParams.messageID = parseInt(addParams.messageID) || false; - addParams.startParam = addParams.startParam || false; + addParams.startParam = addParams.startParam; + var peerStringPromise; if ($routeParams.p && $routeParams.p.charAt(0) == '@') { if ($scope.curDialog === undefined) { $scope.curDialog = {}; } - AppPeersManager.resolveUsername($routeParams.p.substr(1)).then(function (peerID) { - $scope.curDialog = angular.extend({ - peer: AppPeersManager.getPeerString(peerID) - }, addParams); + peerStringPromise = AppPeersManager.resolveUsername($routeParams.p.substr(1)).then(function (peerID) { + return qSync.when(AppPeersManager.getPeerString(peerID)); }); } else { + peerStringPromise = qSync.when($routeParams.p); + } + peerStringPromise.then(function (peerString) { $scope.curDialog = angular.extend({ - peer: $routeParams.p || false + peer: peerString }, addParams); - } + if (pendingShare) { + $scope.$broadcast('peer_share', pendingShare); + pendingShare = false; + } + }); } ChangelogNotifyService.checkUpdate(); @@ -2010,6 +2023,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$watch('curDialog.peer', resetDraft); $scope.$on('user_update', angular.noop); + $scope.$on('peer_share', applyShare); $scope.$on('reply_selected', function (e, messageID) { replySelect(messageID); }); @@ -2171,6 +2185,23 @@ angular.module('myApp.controllers', ['myApp.i18n']) } } + function applyShare (e, shareData) { + console.log('apply share', shareData); + var url = shareData.url; + var text = shareData.text || ''; + + $timeout(function () { + $scope.draftMessage.text = url + "\n" + text; + $scope.$broadcast('ui_peer_draft', { + customSelection: [ + url + "\n", + text, + '' + ] + }); + }, 100); + } + function replySelect(messageID) { $scope.draftMessage.replyToMessage = AppMessagesManager.wrapForDialog(messageID); $scope.$broadcast('ui_peer_reply'); @@ -2259,6 +2290,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) } function onTyping () { + if ($scope.curDialog.inputPeer._ == 'inputPeerChannel') { + return false; + } MtpApiManager.invokeApi('messages.setTyping', { peer: $scope.curDialog.inputPeer, action: {_: 'sendMessageTypingAction'} diff --git a/app/js/directives.js b/app/js/directives.js index 32b5d89a..0488f90f 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -1578,15 +1578,21 @@ angular.module('myApp.directives', ['myApp.filters']) $scope.$on('ui_peer_change', composer.resetTyping.bind(composer)); $scope.$on('ui_peer_draft', function (e, options) { + options = options || {}; var isBroadcast = $scope.draftMessage.isBroadcast; composer.setPlaceholder(_(isBroadcast ? 'im_broadcast_field_placeholder_raw' : 'im_message_field_placeholder_raw')); - if (richTextarea) { - composer.setValue($scope.draftMessage.text || ''); + if (options.customSelection) { + composer.setFocusedValue(options.customSelection); updateHeight(); - } - if (!Config.Navigator.touch || options && options.focus) { - composer.focus(); + } else { + if (richTextarea) { + composer.setValue($scope.draftMessage.text || ''); + updateHeight(); + } + if (!Config.Navigator.touch || options && options.focus) { + composer.focus(); + } } onContentLoaded(function () { composer.checkAutocomplete(true); diff --git a/app/js/lib/utils.js b/app/js/lib/utils.js index e229b20e..c8b212b4 100644 --- a/app/js/lib/utils.js +++ b/app/js/lib/utils.js @@ -229,9 +229,12 @@ function getRichElementValue(node, lines, line, selNode, selOffset) { } } -function setRichFocus(field, selectNode) { +function setRichFocus(field, selectNode, noCollapse) { field.focus(); - if (selectNode && selectNode.parentNode == field && !selectNode.nextSibling) { + if (selectNode && + selectNode.parentNode == field && + !selectNode.nextSibling && + !noCollapse) { field.removeChild(selectNode); selectNode = null; } @@ -242,7 +245,9 @@ function setRichFocus(field, selectNode) { } else { range.selectNodeContents(field); } - range.collapse(false); + if (!noCollapse) { + range.collapse(false); + } var sel = window.getSelection(); sel.removeAllRanges(); @@ -251,7 +256,9 @@ function setRichFocus(field, selectNode) { else if (document.body.createTextRange !== undefined) { var textRange = document.body.createTextRange(); textRange.moveToElementText(selectNode || field); - textRange.collapse(false); + if (!noCollapse) { + textRange.collapse(false); + } textRange.select(); } } diff --git a/app/js/message_composer.js b/app/js/message_composer.js index 4355ddae..8e7525e8 100644 --- a/app/js/message_composer.js +++ b/app/js/message_composer.js @@ -602,7 +602,6 @@ EmojiTooltip.prototype.show = function () { }; EmojiTooltip.prototype.hide = function () { - return; if (this.tooltipEl) { this.tooltipEl.removeClass('composer_emoji_tooltip_shown'); this.btnEl.removeClass('composer_emoji_insert_btn_on'); @@ -1294,6 +1293,31 @@ MessageComposer.prototype.setValue = function (text) { } } +MessageComposer.prototype.setFocusedValue = function (parts) { + var prefix = parts[0]; + var selection = parts[1]; + var suffix = parts[2]; + + if (this.richTextareaEl) { + this.selId = (this.selId || 0) + 1; + var html = + this.getRichHtml(prefix) + + '' + + this.getRichHtml(selection) + + '' + + this.getRichHtml(suffix); + + this.richTextareaEl.html(html); + + setRichFocus(this.richTextareaEl[0], $('#composer_sel' + this.selId)[0], true); + } else { + this.textareaEl.val(prefix + selection + suffix); + setFieldSelection(this.textareaEl[0], prefix.length, prefix.length + selection.length); + } +} + + + MessageComposer.prototype.getRichHtml = function (text) { return $('
').text(text).html().replace(/\n/g, '
').replace(/:([A-Za-z0-9\-\+\*_]+?):/gi, (function (all, shortcut) { var code = EmojiHelper.shortcuts[shortcut]; diff --git a/app/js/services.js b/app/js/services.js index 415095e8..1920fc34 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -3715,7 +3715,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var toPeerID = AppPeersManager.getPeerID(toPeerString); var toChatID = toPeerID < 0 ? -toPeerID : 0; AppMessagesManager.startBot(peerID, toChatID, matches[3]).then(function () { - $rootScope.$broadcast('history_focus', {toPeerString: toPeerString}); + $rootScope.$broadcast('history_focus', {peerString: toPeerString}); }); }); return true; @@ -3739,6 +3739,17 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return true; } + if (matches = url.match(/^msg_url\?url=(.+)(?:&text=(.*))?$/)) { + PeersSelectService.selectPeer({ + confirm_type: 'SHARE_URL' + }).then(function (toPeerString) { + var url = decodeURIComponent(matches[1]); + var text = matches[3] ? decodeURIComponent(matches[3]) : ''; + $rootScope.$broadcast('history_focus', {peerString: toPeerString, shareUrl: url, shareText: text}); + }); + return true; + } + if (inner && (matches = url.match(/^bot_command\?command=(.+?)(?:&bot=(.+))?$/))) { diff --git a/app/partials/desktop/confirm_modal.html b/app/partials/desktop/confirm_modal.html index 3af146ab..2e4374cc 100644 --- a/app/partials/desktop/confirm_modal.html +++ b/app/partials/desktop/confirm_modal.html @@ -32,6 +32,7 @@ +