From 2a6dcc1cd0895b1c4f14783dbada223d9414c2f5 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 14 Dec 2014 21:55:03 -0800 Subject: [PATCH] Various bug fixes --- README.md | 2 +- app/css/app.css | 20 ++++---- app/css/desktop.css | 16 ++++++- app/index.html | 2 +- app/js/controllers.js | 32 ++++++++++--- app/js/directives_mobile.js | 2 +- app/js/locales/en-us.json | 1 + app/js/services.js | 67 ++++++++++++++++++++++----- app/partials/desktop/error_modal.html | 2 + app/partials/desktop/im.html | 2 +- app/partials/mobile/im.html | 4 +- app/partials/mobile/peer_select.html | 6 ++- app/partials/mobile/user_modal.html | 2 +- 13 files changed, 122 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 71a41af9..17f9e439 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Here are some screenshots of the interface: ### Unsupported at the moment * Secret chats -* Black list and blocking user +* Black list * ... diff --git a/app/css/app.css b/app/css/app.css index 6a88ddf8..16b7a190 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1467,6 +1467,10 @@ div.im_message_video_thumb { background-position: -2px -542px; } +.im_history_selectable a[ng-click] { + pointer-events: none; +} + .im_message_document_link_disabled { cursor: default; pointer-events: none; @@ -2545,14 +2549,14 @@ ce671b orange .user_color_8, .user_color_8:hover {color: #c07844;} -.user_bgcolor_1 {background: #e57979;} -.user_bgcolor_2 {background: #fba76f;} +.user_bgcolor_1 {background: #cc90e2;} +.user_bgcolor_2 {background: #80d066;} .user_bgcolor_3 {background: #ecd074;} -.user_bgcolor_4 {background: #80d066;} -.user_bgcolor_5 {background: #73cdd0;} -.user_bgcolor_6 {background: #6fb1e4;} -.user_bgcolor_7 {background: #cc90e2;} -.user_bgcolor_8 {background: #f98bae;} +.user_bgcolor_4 {background: #6fb1e4;} +.user_bgcolor_5 {background: #e57979;} +.user_bgcolor_6 {background: #f98bae;} +.user_bgcolor_7 {background: #73cdd0;} +.user_bgcolor_8 {background: #fba76f;} a.peer_photo_init:hover, a.peer_photo_init:active, @@ -2970,7 +2974,7 @@ div.peer_modal_photo { } .peer_modal_photo .peer_initials { line-height: 72px; - font-size: 17px; + font-size: 22px; } .peer_modal_profile_name { font-size: 17px; diff --git a/app/css/desktop.css b/app/css/desktop.css index 2dd25631..5af76d0d 100644 --- a/app/css/desktop.css +++ b/app/css/desktop.css @@ -545,9 +545,16 @@ a.im_panel_peer_photo { margin-left: 12px; height: 55px; } -div.im_panel_own_photo { +a.im_panel_own_photo { + display: block; margin-right: 12px; } +a.im_panel_own_photo .peer_initials, +div.im_panel_peer_photo .peer_initials, +a.im_panel_peer_photo .peer_initials { + font-size: 18px; + line-height: 50px; +} .im_panel_peer_online { background: #6ec26d; @@ -996,6 +1003,11 @@ div.im_panel_own_photo { div.im_dialog_photo { margin-right: 12px; } +div.im_dialog_photo .peer_initials { + line-height: 48px; + font-size: 18px; +} + .im_dialog_message { margin-top: 4px; } @@ -1159,7 +1171,7 @@ div.im_dialog_photo { overflow: hidden; } .media_modal_author_photo .peer_initials { - line-height: 32px; + line-height: 32px; } a.media_modal_author_photo { margin: 1px 10px 1px 0; diff --git a/app/index.html b/app/index.html index 0420a240..f78f6a7f 100644 --- a/app/index.html +++ b/app/index.html @@ -36,7 +36,7 @@
- +
diff --git a/app/js/controllers.js b/app/js/controllers.js index 949bfeb9..f316c9dc 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -307,7 +307,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) LayoutSwitchService.start(); }) - .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService) { + .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, AppPeersManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService, LayoutSwitchService) { $scope.$on('$routeUpdate', updateCurDialog); @@ -316,7 +316,15 @@ angular.module('myApp.controllers', ['myApp.i18n']) if (peerData.peerString == $scope.curDialog.peer && peerData.messageID == $scope.curDialog.messageID) { $scope.$broadcast(peerData.messageID ? 'ui_history_change_scroll' : 'ui_history_focus'); } else { - $location.url('/im?p=' + peerData.peerString + (peerData.messageID ? '&m=' + peerData.messageID : '')); + var peerID = AppPeersManager.getPeerID(peerData.peerString); + var peer = peerData.peerString; + if (peerID > 0) { + var username = AppUsersManager.getUser(peerID).username; + if (username) { + peer = '@' + username; + } + } + $location.url('/im?p=' + peer + (peerData.messageID ? '&m=' + peerData.messageID : '')); } }); @@ -428,10 +436,22 @@ angular.module('myApp.controllers', ['myApp.i18n']) } else { lastSearch = false; } - $scope.curDialog = { - peer: $routeParams.p || false, - messageID: $routeParams.m || false - }; + if ($routeParams.p && $routeParams.p.charAt(0) == '@') { + if ($scope.curDialog === undefined) { + $scope.curDialog = {}; + } + AppUsersManager.resolveUsername($routeParams.p.substr(1)).then(function (userID) { + $scope.curDialog = { + peer: AppUsersManager.getUserString(userID), + messageID: $routeParams.m || false + }; + }); + } else { + $scope.curDialog = { + peer: $routeParams.p || false, + messageID: $routeParams.m || false + }; + } } ChangelogNotifyService.checkUpdate(); diff --git a/app/js/directives_mobile.js b/app/js/directives_mobile.js index a0d4714f..ce9f1543 100644 --- a/app/js/directives_mobile.js +++ b/app/js/directives_mobile.js @@ -129,7 +129,7 @@ angular.module('myApp.directives') if (!atBottom && !options.my) { return; } - + var pr = parseInt($(scrollableWrap).css('paddingRight')) $(scrollableWrap).addClass('im_history_to_bottom'); $(scrollable).css({bottom: 0, marginLeft: -Math.ceil(pr / 2)}); diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index e65b6130..b9854744 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -240,6 +240,7 @@ "error_modal_phonebook_required_description": "Telegram needs access to phonebook to import contacts.", "error_modal_username_occupied_description": "Sorry, this username is already taken.", "error_modal_media_not_supported_description": "Your browser cannot play this media file. Try downloading the file and opening it in a standalone player.", + "error_modal_username_not_found_description": "There is no Telegram account with the username you provided.", "error_modal_bad_request_description": "One of the params is missing or invalid.", "error_modal_unauthorized_description": "This action requires authorization access. Please {login-link: log in}.", diff --git a/app/js/services.js b/app/js/services.js index f8abb334..93fea430 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -11,8 +11,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) -.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, MtpApiFileManager, MtpApiManager, RichTextProcessor, SearchIndexManager, ErrorService, Storage, _) { +.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, qSync, MtpApiFileManager, MtpApiManager, RichTextProcessor, SearchIndexManager, ErrorService, Storage, _) { var users = {}, + usernames = {}, cachedPhotoLocations = {}, contactsFillPromise, contactsList, @@ -73,6 +74,23 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }); }; + function userNameClean (username) { + return username && username.toLowerCase() || ''; + } + + function resolveUsername (username) { + var searchUserName = userNameClean(username); + var foundUserID = usernames[searchUserName]; + if (foundUserID && + userNameClean(users[foundUserID].username) == searchUserName) { + return qSync.when(foundUserID); + } + return MtpApiManager.invokeApi('contacts.resolveUsername', {username: username}).then(function (resolveResult) { + saveApiUser(resolveResult); + return resolveResult.id; + }); + } + function saveApiUsers (apiUsers) { angular.forEach(apiUsers, saveApiUser); }; @@ -83,11 +101,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return; } + var userID = apiUser.id; + if (apiUser.phone) { apiUser.rPhone = $filter('phoneNumber')(apiUser.phone); } - apiUser.num = (Math.abs(apiUser.id) % 8) + 1; + apiUser.num = (Math.abs(userID) % 8) + 1; if (apiUser.first_name) { apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.first_name, {noLinks: true, noLinebreaks: true}); @@ -97,6 +117,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || _('user_name_deleted'); } + if (apiUser.username) { + usernames[userNameClean(apiUser.username)] = userID; + } + apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || '')); var nameWords = apiUser.sortName.split(' '); @@ -107,15 +131,16 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) apiUser.sortStatus = getUserStatusForSort(apiUser.status); - if (users[apiUser.id] === undefined) { - users[apiUser.id] = apiUser; + var result = users[userID]; + if (result === undefined) { + result = users[userID] = apiUser; } else { - safeReplaceObject(users[apiUser.id], apiUser); + safeReplaceObject(result, apiUser); } - $rootScope.$broadcast('user_update', apiUser.id); + $rootScope.$broadcast('user_update', userID); - if (cachedPhotoLocations[apiUser.id] !== undefined) { - safeReplaceObject(cachedPhotoLocations[apiUser.id], apiUser && apiUser.photo && apiUser.photo.photo_small || {empty: true}); + if (cachedPhotoLocations[userID] !== undefined) { + safeReplaceObject(cachedPhotoLocations[userID], apiUser && apiUser.photo && apiUser.photo.photo_small || {empty: true}); } }; @@ -193,7 +218,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) if (user.status && user.status._ == 'userStatusOnline' && user.status.expires < timestampNow) { - user.status = user.status.wasStatus || + user.status = user.status.wasStatus || {_: 'userStatusOffline', was_online: user.status.expires}; delete user.status.wasStatus; $rootScope.$broadcast('user_update', user.id); @@ -392,6 +417,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) deleteContacts: deleteContacts, wrapForFull: wrapForFull, openUser: openUser, + resolveUsername: resolveUsername, openImportContact: openImportContact } }) @@ -500,7 +526,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var lastWord = titleWords.pop(); apiChat.initials = firstWord.charAt(0) + (lastWord ? lastWord.charAt(0) : firstWord.charAt(1)); - apiChat.num = (Math.abs(apiChat.id) % 4) + 1; + apiChat.num = (Math.abs(apiChat.id >> 1) % (Config.Mobile ? 4 : 8)) + 1; if (chats[apiChat.id] === undefined) { chats[apiChat.id] = apiChat; @@ -592,7 +618,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }) -.service('AppPeersManager', function (AppUsersManager, AppChatsManager) { +.service('AppPeersManager', function (AppUsersManager, AppChatsManager, MtpApiManager) { return { getInputPeer: function (peerString) { var isUser = peerString.charAt(0) == 'u', @@ -3177,7 +3203,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) emojiUtf.push(emojiData[emojiCode][0]); emojiMap[emojiData[emojiCode][0]] = emojiCode; } - + var regexAlphaChars = "a-z" + "\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff" + // Latin-1 "\\u0100-\\u024f" + // Latin Extended A and B @@ -4075,3 +4101,20 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) switchLayout: switchLayout } }) + + +// .service('LocationParamsService', function ($routeParams) { + +// var started = false; +// function start () { +// if (started) { +// return; +// } +// started = true; +// navigator.registerProtocolHandler('web+tg', '#im?tgaddr=%s', 'Telegram Web'); +// }; + +// return { +// start: start +// }; +// }) diff --git a/app/partials/desktop/error_modal.html b/app/partials/desktop/error_modal.html index ac925e91..a5a979ac 100644 --- a/app/partials/desktop/error_modal.html +++ b/app/partials/desktop/error_modal.html @@ -4,6 +4,7 @@

+ @@ -35,6 +36,7 @@ +
diff --git a/app/partials/desktop/im.html b/app/partials/desktop/im.html index eda6f2e7..47c23adb 100644 --- a/app/partials/desktop/im.html +++ b/app/partials/desktop/im.html @@ -233,7 +233,7 @@ -
+
diff --git a/app/partials/mobile/im.html b/app/partials/mobile/im.html index 3d71e840..f6191076 100644 --- a/app/partials/mobile/im.html +++ b/app/partials/mobile/im.html @@ -8,7 +8,9 @@
diff --git a/app/partials/mobile/peer_select.html b/app/partials/mobile/peer_select.html index 88aa7996..ced9f554 100644 --- a/app/partials/mobile/peer_select.html +++ b/app/partials/mobile/peer_select.html @@ -32,8 +32,10 @@
diff --git a/app/partials/mobile/user_modal.html b/app/partials/mobile/user_modal.html index aad4cd4d..59d4288d 100644 --- a/app/partials/mobile/user_modal.html +++ b/app/partials/mobile/user_modal.html @@ -79,7 +79,7 @@
-
+