diff --git a/app/css/app.css b/app/css/app.css index ba7a3503..6648aefb 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -461,6 +461,12 @@ input[type="number"] { .modal_simple_form .form-group { margin-bottom: 13px; } +.modal_simple_form_description { + color: #777; + line-height: 160%; + margin: 10px 0 0; + text-align: justify; +} .modal_section_header { font-size: 12px; @@ -2112,6 +2118,10 @@ img.img_fullsize { .settings_modal_wrap .im_attach_input { z-index: 999; } +.settings_modal_username_link, +.settings_modal_username_link:hover { + color: inherit; +} .settings_external_service { line-height: 0; display: inline-block; diff --git a/app/css/desktop.css b/app/css/desktop.css index 113ce26f..ee690d2a 100644 --- a/app/css/desktop.css +++ b/app/css/desktop.css @@ -555,10 +555,6 @@ div.im_panel_own_photo { .modal_section_body dd { display: inline-block; } -.settings_modal_username_link, -.settings_modal_username_link:hover { - color: inherit; -} .user_modal_main_btn { border: 0; diff --git a/app/css/mobile.css b/app/css/mobile.css index ffa2381a..f77916b1 100644 --- a/app/css/mobile.css +++ b/app/css/mobile.css @@ -181,6 +181,7 @@ html { } .navbar-quick-media-back h4 { margin: 9px 0 12px 0; + line-height: 120%; } .navbar-quick-profile-back h4, .navbar-quick-group-back h4 { @@ -884,6 +885,7 @@ a.mobile_modal_action .tg_checkbox_label { } .mobile_modal_section { + display: block; border-bottom: 1px solid #e0e0e0; padding: 15px 0; } diff --git a/app/js/controllers.js b/app/js/controllers.js index ba20f4ef..33362ed1 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -439,6 +439,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.dialogs = []; $scope.contacts = []; + $scope.foundUsers = []; $scope.contactsLoaded = false; if ($scope.search === undefined) { $scope.search = {}; @@ -636,6 +637,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) getDialogs(force).then(function (dialogsResult) { $scope.dialogs = []; $scope.contacts = []; + $scope.foundUsers = []; if (dialogsResult.dialogs.length) { offset += dialogsResult.dialogs.length; @@ -678,7 +680,6 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.contacts.push({ userID: userID, user: AppUsersManager.getUser(userID), - userPhoto: AppUsersManager.getUserPhoto(userID, 'User'), peerString: AppUsersManager.getUserString(userID) }); } @@ -689,8 +690,31 @@ angular.module('myApp.controllers', ['myApp.i18n']) } else if (!$scope.search.query) { $scope.isEmpty.contacts = true; } + $scope.$broadcast('ui_dialogs_append'); }); - $scope.$broadcast('ui_dialogs_append'); + + if ($scope.search.query && $scope.search.query.length >= 5) { + MtpApiManager.invokeApi('contacts.search', {q: $scope.search.query, limit: 10}).then(function (result) { + console.log($scope.search.query, result); + AppUsersManager.saveApiUsers(result.users); + if (curJump != jump) return; + $scope.foundUsers = []; + angular.forEach(result.results, function(contactFound) { + var userID = contactFound.user_id; + if (peersInDialogs[userID] === undefined) { + $scope.foundUsers.push({ + userID: userID, + user: AppUsersManager.getUser(userID), + peerString: AppUsersManager.getUserString(userID) + }); + } + }); + }, function (error) { + if (error.code == 400) { + error.handled = true; + } + }); + } } function showMoreDialogs () { @@ -2214,7 +2238,17 @@ angular.module('myApp.controllers', ['myApp.i18n']) } }) - .controller('ProfileEditModalController', function ($rootScope, $scope, $timeout, $modal, $modalInstance, AppUsersManager, AppChatsManager, MtpApiManager, Storage, NotificationsManager, MtpApiFileManager, ApiUpdatesManager) { + .controller('ChangelogModalController', function ($scope, $modal) { + $scope.changeUsername = function () { + $modal.open({ + templateUrl: templateUrl('username_edit_modal'), + controller: 'UsernameEditModalController', + windowClass: 'username_edit_modal_window mobile_modal' + }); + }; + }) + + .controller('ProfileEditModalController', function ($scope, $modalInstance, AppUsersManager, MtpApiManager) { $scope.profile = {}; $scope.error = {}; @@ -2256,6 +2290,76 @@ angular.module('myApp.controllers', ['myApp.i18n']) } }) + .controller('UsernameEditModalController', function ($scope, $modalInstance, AppUsersManager, MtpApiManager) { + + $scope.profile = {}; + $scope.error = {}; + + MtpApiManager.getUserID().then(function (id) { + $scope.profile = angular.copy(AppUsersManager.getUser(id)); + }); + + $scope.updateUsername = function () { + $scope.profile.updating = true; + + MtpApiManager.invokeApi('account.updateUsername', { + username: $scope.profile.username || '' + }).then(function (user) { + $scope.checked = {}; + AppUsersManager.saveApiUser(user); + $modalInstance.close(); + }, function (error) { + switch (error.type) { + case 'USERNAME_INVALID': + $scope.checked = {error: true}; + error.handled = true; + break; + + case 'USERNAME_OCCUPIED': + $scope.checked = {error: true}; + error.handled = true; + break; + + case 'USERNAME_NOT_MODIFIED': + error.handled = true; + $modalInstance.close(); + break; + } + })['finally'](function () { + delete $scope.profile.updating; + }); + } + + $scope.$watch('profile.username', function (newVal) { + if (!newVal.length) { + $scope.checked = {}; + return; + } + MtpApiManager.invokeApi('account.checkUsername', { + username: newVal || '' + }).then(function (valid) { + if ($scope.profile.username != newVal) { + return; + } + if (valid) { + $scope.checked = {success: true}; + } else { + $scope.checked = {error: true}; + } + }, function (error) { + if ($scope.profile.username != newVal) { + return; + } + switch (error.type) { + case 'USERNAME_INVALID': + $scope.checked = {error: true}; + error.handled = true; + break; + } + }); + }) + }) + .controller('ContactsModalController', function ($scope, $modal, $modalInstance, AppUsersManager, ErrorService) { $scope.contacts = []; diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 5611d838..8a10f988 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -59,7 +59,7 @@ "username_edit_modal_title": "Change username", "username_edit_placeholder": "Username", - "username_edit_description_md": "Username lets other people find you and have a chat in\n**Telegram** without exposing your phone number.\n\nYou can only use symbols like a-z and 0-9.", + "username_edit_description_md": "Choose a username so that other people can find you on **Telegram** and message you without knowing your phone number.\n\nYou can use a-z, 0-9 and underscores.", "username_edit_submit": "Save", "username_edit_submit_active": "Saving...", @@ -228,6 +228,7 @@ "head_new_contact": "New Contact", "head_contacts": "Contacts", "head_contacts_title": "Contacts", + "im_found_title": "Global search", "head_settings": "Settings", "head_log_out": "Log Out", "head_edit_messages": "Edit messages", diff --git a/app/js/services.js b/app/js/services.js index c7fc6d87..8bf4ced4 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -52,7 +52,7 @@ angular.module('myApp.services', ['myApp.i18n']) return false; } - return (user.first_name || '') + ' ' + (user.last_name || '') + ' ' + (user.phone || ''); + return (user.first_name || '') + ' ' + (user.last_name || '') + ' ' + (user.phone || '') + ' ' + (user.username || ''); } function getContacts (query) { @@ -1268,6 +1268,9 @@ angular.module('myApp.services', ['myApp.i18n']) } function sendText(peerID, text) { + if (!angular.isString(text) || !text.length) { + return; + } var messageID = tempID--, randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), @@ -3947,6 +3950,7 @@ angular.module('myApp.services', ['myApp.i18n']) }; $modal.open({ + controller: 'ChangelogModalController', templateUrl: templateUrl('changelog_modal'), scope: $scope, windowClass: 'changelog_modal_window mobile_modal' diff --git a/app/partials/desktop/changelog_modal.html b/app/partials/desktop/changelog_modal.html index 3be42c78..fed1a914 100644 --- a/app/partials/desktop/changelog_modal.html +++ b/app/partials/desktop/changelog_modal.html @@ -19,7 +19,20 @@