From deae4717a6b96a00e1b80b83d95ba979c13147d9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 17 Jan 2014 22:26:27 +0400 Subject: [PATCH] Fixed short updates, improved styles --- app/css/app.css | 1 + app/index.html | 8 ++++---- app/js/app.js | 2 +- app/js/controllers.js | 2 +- app/js/services.js | 43 +++++++++++++++++++++++++++++++++++++------ app/partials/im.html | 2 +- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index d05d90db..2df1de0b 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -172,6 +172,7 @@ fieldset[disabled] .btn-tg.active { overflow-y: auto; } .modal-content { + border: 0; border-radius: 4px; -webkit-box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); diff --git a/app/index.html b/app/index.html index c4c644d9..23625b3d 100644 --- a/app/index.html +++ b/app/index.html @@ -7,7 +7,7 @@ - + @@ -36,9 +36,9 @@ - - - + + + diff --git a/app/js/app.js b/app/js/app.js index 917ace19..af77b933 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -49,7 +49,7 @@ config(['$locationProvider', '$routeProvider', '$compileProvider', function($loc // $locationProvider.html5Mode(true); $routeProvider.when('/', {templateUrl: 'partials/welcome.html', controller: 'AppWelcomeController'}); $routeProvider.when('/login', {templateUrl: 'partials/login.html?1', controller: 'AppLoginController'}); - $routeProvider.when('/im', {templateUrl: 'partials/im.html?1', controller: 'AppIMController', reloadOnSearch: false}); + $routeProvider.when('/im', {templateUrl: 'partials/im.html?2', controller: 'AppIMController', reloadOnSearch: false}); $routeProvider.otherwise({redirectTo: '/'}); }]); diff --git a/app/js/controllers.js b/app/js/controllers.js index fa72d72f..8810b7d5 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -359,7 +359,7 @@ angular.module('myApp.controllers', []) // dLog('on apiUpdate inline', update); switch (update._) { case 'updateUserTyping': - if (update.user_id == $scope.curDialog.peerID) { + if (update.user_id == $scope.curDialog.peerID && AppUsersManager.hasUser(update.user_id)) { $scope.typing = {user: AppUsersManager.getUser(update.user_id)}; $timeout.cancel(typingTimeouts[update.user_id]); diff --git a/app/js/services.js b/app/js/services.js index 8e0fb63c..36610521 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -157,6 +157,10 @@ angular.module('myApp.services', []) return users[id] || {id: id, deleted: true}; } + function hasUser(id) { + return angular.isObject(users[id]); + } + function getUserPhoto(id, placeholder) { var user = getUser(id); @@ -254,6 +258,7 @@ angular.module('myApp.services', []) getUser: getUser, getUserPhoto: getUserPhoto, getUserString: getUserString, + hasUser: hasUser, wrapForFull: wrapForFull, openUser: openUser } @@ -282,6 +287,10 @@ angular.module('myApp.services', []) return chats[id] || {id: id, deleted: true}; } + function hasChat (id) { + return angular.isObject(chats[id]); + } + function getChatPhoto(id, placeholder) { var chat = getChat(id); @@ -353,6 +362,7 @@ angular.module('myApp.services', []) getChat: getChat, getChatPhoto: getChatPhoto, getChatString: getChatString, + hasChat: hasChat, wrapForFull: wrapForFull, openChat: openChat } @@ -1511,14 +1521,34 @@ angular.module('myApp.services', []) AppUsersManager.saveApiUsers(updateMessage.users); AppChatsManager.saveApiChats(updateMessage.chats); + var i, update, message; + for (var i = 0; i < updateMessage.updates.length; i++) { + update = updateMessage.updates[i]; + switch (update._) { + case 'updateNewMessage': + message = update.message; + if (message.from_id && !AppUsersManager.hasUser(message.from_id)) { + dLog('User not found', message.from_id, 'getDiff'); + getDifference(); + return false; + } + if (message.to_id.chat_id && !AppChatsManager.hasChat(message.to_id.chat_id)) { + dLog('Chat not found', message.to_id.chat_id, 'getDiff'); + getDifference(); + return false; + } + break; + } + } + angular.forEach(updateMessage.updates, function (update) { saveUpdate(update); }); break; case 'updateShortMessage': - var fromUser = AppUsersManager.getUser(updateMessage.from_id); - if (!fromUser || fromUser.deleted) { + if (!AppUsersManager.hasUser(updateMessage.from_id)) { + dLog('User not found', updateMessage.from_id, 'getDiff'); getDifference(); break; } @@ -1540,10 +1570,9 @@ angular.module('myApp.services', []) break; case 'updateShortChatMessage': - var fromUser = AppUsersManager.getUser(updateMessage.from_id), - chat = AppChatsManager.getChat(updateMessage.chat_id); - - if (!fromUser || fromUser.deleted || !chat || chat.deleted) { + if (!AppUsersManager.hasUser(updateMessage.from_id) || + !AppChatsManager.hasChat(updateMessage.chat_id)) { + dLog('User or chat not found', updateMessage.from_id, updateMessage.chat_id, 'getDiff'); getDifference(); break; } @@ -1564,6 +1593,8 @@ angular.module('myApp.services', []) }); break; } + + return true; } function getDifference (force) { diff --git a/app/partials/im.html b/app/partials/im.html index 0773340b..d8b455bb 100644 --- a/app/partials/im.html +++ b/app/partials/im.html @@ -116,7 +116,7 @@ -