Supported share url
This commit is contained in:
parent
7acc4bfdab
commit
f00ce3165d
@ -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 {
|
||||
$scope.curDialog = angular.extend({
|
||||
peer: $routeParams.p || false
|
||||
}, addParams);
|
||||
peerStringPromise = qSync.when($routeParams.p);
|
||||
}
|
||||
peerStringPromise.then(function (peerString) {
|
||||
$scope.curDialog = angular.extend({
|
||||
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'}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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) +
|
||||
'<span id="composer_sel' + this.selId + '">' +
|
||||
this.getRichHtml(selection) +
|
||||
'</span>' +
|
||||
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 $('<div>').text(text).html().replace(/\n/g, '<br/>').replace(/:([A-Za-z0-9\-\+\*_]+?):/gi, (function (all, shortcut) {
|
||||
var code = EmojiHelper.shortcuts[shortcut];
|
||||
|
@ -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=(.+))?$/))) {
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
<my-i18n>
|
||||
<span ng-switch-when="FORWARD_PEER" my-i18n-format="confirm_modal_forward_to_peer"></span>
|
||||
<span ng-switch-when="SHARE_CONTACT_PEER" my-i18n-format="confirm_modal_send_to_peer"></span>
|
||||
<span ng-switch-when="SHARE_URL" my-i18n-format="confirm_modal_send_to_peer"></span>
|
||||
<span ng-switch-when="EXT_SHARE_PEER" my-i18n-format="confirm_modal_share_file_peer"></span>
|
||||
<span ng-switch-when="INVITE_TO_GROUP" my-i18n-format="confirm_modal_invite_peer"></span>
|
||||
<my-i18n-param name="peer">
|
||||
|
Loading…
x
Reference in New Issue
Block a user