|
|
@ -157,6 +157,10 @@ angular.module('myApp.services', []) |
|
|
|
return users[id] || {id: id, deleted: true}; |
|
|
|
return users[id] || {id: id, deleted: true}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hasUser(id) { |
|
|
|
|
|
|
|
return angular.isObject(users[id]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getUserPhoto(id, placeholder) { |
|
|
|
function getUserPhoto(id, placeholder) { |
|
|
|
var user = getUser(id); |
|
|
|
var user = getUser(id); |
|
|
|
|
|
|
|
|
|
|
@ -254,6 +258,7 @@ angular.module('myApp.services', []) |
|
|
|
getUser: getUser, |
|
|
|
getUser: getUser, |
|
|
|
getUserPhoto: getUserPhoto, |
|
|
|
getUserPhoto: getUserPhoto, |
|
|
|
getUserString: getUserString, |
|
|
|
getUserString: getUserString, |
|
|
|
|
|
|
|
hasUser: hasUser, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
openUser: openUser |
|
|
|
openUser: openUser |
|
|
|
} |
|
|
|
} |
|
|
@ -282,6 +287,10 @@ angular.module('myApp.services', []) |
|
|
|
return chats[id] || {id: id, deleted: true}; |
|
|
|
return chats[id] || {id: id, deleted: true}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hasChat (id) { |
|
|
|
|
|
|
|
return angular.isObject(chats[id]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getChatPhoto(id, placeholder) { |
|
|
|
function getChatPhoto(id, placeholder) { |
|
|
|
var chat = getChat(id); |
|
|
|
var chat = getChat(id); |
|
|
|
|
|
|
|
|
|
|
@ -353,6 +362,7 @@ angular.module('myApp.services', []) |
|
|
|
getChat: getChat, |
|
|
|
getChat: getChat, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatString: getChatString, |
|
|
|
getChatString: getChatString, |
|
|
|
|
|
|
|
hasChat: hasChat, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
openChat: openChat |
|
|
|
openChat: openChat |
|
|
|
} |
|
|
|
} |
|
|
@ -1511,14 +1521,34 @@ angular.module('myApp.services', []) |
|
|
|
AppUsersManager.saveApiUsers(updateMessage.users); |
|
|
|
AppUsersManager.saveApiUsers(updateMessage.users); |
|
|
|
AppChatsManager.saveApiChats(updateMessage.chats); |
|
|
|
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) { |
|
|
|
angular.forEach(updateMessage.updates, function (update) { |
|
|
|
saveUpdate(update); |
|
|
|
saveUpdate(update); |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateShortMessage': |
|
|
|
case 'updateShortMessage': |
|
|
|
var fromUser = AppUsersManager.getUser(updateMessage.from_id); |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id)) { |
|
|
|
if (!fromUser || fromUser.deleted) { |
|
|
|
dLog('User not found', updateMessage.from_id, 'getDiff'); |
|
|
|
getDifference(); |
|
|
|
getDifference(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -1540,10 +1570,9 @@ angular.module('myApp.services', []) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateShortChatMessage': |
|
|
|
case 'updateShortChatMessage': |
|
|
|
var fromUser = AppUsersManager.getUser(updateMessage.from_id), |
|
|
|
if (!AppUsersManager.hasUser(updateMessage.from_id) || |
|
|
|
chat = AppChatsManager.getChat(updateMessage.chat_id); |
|
|
|
!AppChatsManager.hasChat(updateMessage.chat_id)) { |
|
|
|
|
|
|
|
dLog('User or chat not found', updateMessage.from_id, updateMessage.chat_id, 'getDiff'); |
|
|
|
if (!fromUser || fromUser.deleted || !chat || chat.deleted) { |
|
|
|
|
|
|
|
getDifference(); |
|
|
|
getDifference(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -1564,6 +1593,8 @@ angular.module('myApp.services', []) |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getDifference (force) { |
|
|
|
function getDifference (force) { |
|
|
|